refactor: probes read the repository root

This commit is contained in:
Abdessamad Derraz committed 2026-11-18 20:37:17 +01:00
1 parent 3bfd72ba7f
commit a40c75e689
4 files changed
+41 -41

No files matched your search

+6 -6
View File
@@ -101,11 +101,11 @@ import campaign_profiles
import campaign_rules as rules
import measurement_records as mr
from autorun import now_iso
from core.paths import REPO_ROOT
T = TypeVar("T")
ROOT = Path(__file__).resolve().parent.parent
CONTENT_FILE = ROOT / "tests" / "campaign" / "content.yml"
CONTENT_FILE = REPO_ROOT / "tests" / "campaign" / "content.yml"
BUILDBOT = "https://buildbot.libretro.com/nightly/linux/x86_64/latest/"
LOCK_HELD_ENV = autorun.LOCK_HELD_ENV
ROMFETCH_ENV = "RETROBIOS_ROMFETCH"
@@ -315,8 +315,8 @@ class Paths:
@classmethod
def default(cls) -> Paths:
main = autorun.main_checkout()
return cls(root=ROOT, home=main / ".cache" / "campaign",
content=main / ".cache" / "test-content", db=ROOT / "database.json")
return cls(root=REPO_ROOT, home=main / ".cache" / "campaign",
content=main / ".cache" / "test-content", db=REPO_ROOT / "database.json")
ROMFETCH_PASSED = ("XDG_CONFIG_HOME", "XDG_CACHE_HOME", "XDG_DATA_HOME")
@@ -948,7 +948,7 @@ class Campaign:
self.paths = paths
self.settings = settings or Settings()
self.host = host or Host()
self.probe_script = probe_script or ROOT / "scripts" / "core_probe.py"
self.probe_script = probe_script or REPO_ROOT / "scripts" / "core_probe.py"
self.lock_path = lock_path or Path(os.environ.get(autorun.LOCK_ENV) or autorun.DEFAULT_LOCK)
self.state = load_state(paths.state)
self.cores = Cores(self)
@@ -1984,7 +1984,7 @@ def _parser() -> argparse.ArgumentParser:
help="with --commit, also commit after every N emulators")
refs_p = sub.add_parser("references", parents=[scope],
help="run the full set with PNG frames and list reference candidates")
refs_p.add_argument("--png-dir", default=str(ROOT / "tmp" / "campaign" / "references"),
refs_p.add_argument("--png-dir", default=str(REPO_ROOT / "tmp" / "campaign" / "references"),
help="where the frames are written, one folder per core and content")
status_p = sub.add_parser("status", help="done, failed and pending checks, and why")
status_p.add_argument("--json", action="store_true", help="the report as JSON")
+20 -20
View File
@@ -72,13 +72,13 @@ from core.cli import run_cli
from resolve.layout import runs_standalone
from resolve.validation import filter_files_by_mode
from core.ziptools import safe_extract_zip
from core.paths import REPO_ROOT
ROOT = Path(__file__).resolve().parent.parent
MAIN = autorun.main_checkout()
PACK_CONTENT_FILE = ROOT / "tests" / "campaign" / "pack_content.yml"
PACK_CONTENT_FILE = REPO_ROOT / "tests" / "campaign" / "pack_content.yml"
CONTENT_DIR = MAIN / ".cache" / "test-content"
CORE_CACHE = MAIN / ".cache" / "pack-probe" / "cores"
WORK_DIR = ROOT / "tmp" / "pack_probe"
WORK_DIR = REPO_ROOT / "tmp" / "pack_probe"
BUILDBOT = campaign.BUILDBOT
PACK_PROBES = mr.PACK_PROBES
INSTALLS = ("pack", "installer")
@@ -186,10 +186,10 @@ def installer_layout(platform: str, pack: Path, identity: dict, manifest_path: P
system_dir, save_dir = root / "system", root / "saves"
if root.exists():
shutil.rmtree(root)
argv = [sys.executable, str(ROOT / "install.py"), "--platform", platform, "--dest", str(system_dir),
argv = [sys.executable, str(REPO_ROOT / "install.py"), "--platform", platform, "--dest", str(system_dir),
"--save-dir", str(save_dir), "--from-pack", str(pack), "--manifest", str(manifest_path),
"--offline", "--yes", "--quiet", *narrow]
proc = subprocess.run(argv, capture_output=True, text=True, check=False, cwd=ROOT)
proc = subprocess.run(argv, capture_output=True, text=True, check=False, cwd=REPO_ROOT)
if proc.returncode != 0 or not system_dir.is_dir():
raise ProbeFailure(f"install.py exited {proc.returncode}: {(proc.stderr or proc.stdout)[-1500:]}")
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
@@ -197,7 +197,7 @@ def installer_layout(platform: str, pack: Path, identity: dict, manifest_path: P
files = {rel: entries.get(rel) for rel in walk(system_dir)}
source = {
"pack": identity,
"manifest": {"path": manifest_path.relative_to(ROOT).as_posix() if manifest_path.is_relative_to(ROOT)
"manifest": {"path": manifest_path.relative_to(REPO_ROOT).as_posix() if manifest_path.is_relative_to(REPO_ROOT)
else manifest_path.name,
"sha256": file_sha(manifest_path, "sha256"),
"generated": manifest.get("generated"), "pack_files": manifest.get("pack_files")},
@@ -213,9 +213,9 @@ def build_pack(platform: str, out_dir: Path, narrow: Sequence[str] = ()) -> Path
out_dir.mkdir(parents=True, exist_ok=True)
for old in out_dir.glob("*_BIOS_Pack*.zip"):
old.unlink()
argv = [sys.executable, str(ROOT / "scripts" / "generate_pack.py"), "--platform", platform,
argv = [sys.executable, str(REPO_ROOT / "scripts" / "generate_pack.py"), "--platform", platform,
"--offline", "--output-dir", str(out_dir), *narrow]
proc = subprocess.run(argv, capture_output=True, text=True, check=False, cwd=ROOT)
proc = subprocess.run(argv, capture_output=True, text=True, check=False, cwd=REPO_ROOT)
packs = sorted(p for p in out_dir.glob("*_BIOS_Pack*.zip") if ".part" not in p.name)
if proc.returncode != 0 or len(packs) != 1:
raise ProbeFailure(f"generate_pack.py exited {proc.returncode} with {len(packs)} packs: "
@@ -486,12 +486,12 @@ def core_probe(argv: list[str], staged: set[str], layout: Layout, work: Path) ->
argfile = work / "system-files.args"
argfile.write_text("".join(f"--system-file\n{rel}={layout.root / rel}\n" for rel in sorted(staged)),
encoding="utf-8")
command = [sys.executable, str(ROOT / "scripts" / "core_probe.py"), *argv, f"@{argfile}"]
command = [sys.executable, str(REPO_ROOT / "scripts" / "core_probe.py"), *argv, f"@{argfile}"]
with probe_lock():
if "--record" in argv:
wait_idle()
# core_probe takes the same lock unless told its caller holds it.
proc = subprocess.run(command, capture_output=True, text=True, check=False, cwd=ROOT,
proc = subprocess.run(command, capture_output=True, text=True, check=False, cwd=REPO_ROOT,
timeout=PROBE_TIMEOUT * 2 + 120,
env={**os.environ, PROBE_LOCK_HELD_ENV: "1", PROBE_LOCK_ENV: str(PROBE_LOCK)})
record = None
@@ -502,7 +502,7 @@ def core_probe(argv: list[str], staged: set[str], layout: Layout, work: Path) ->
record = None
# A traceback spells the checkout and the scratch folders: a record read
# on another machine names them by role.
places = [(str(work), "<work>"), (str(layout.root), "<dest>"), (str(ROOT), "<repo>")]
places = [(str(work), "<work>"), (str(layout.root), "<dest>"), (str(REPO_ROOT), "<repo>")]
error = proc.stderr.strip()
for prefix, name in sorted(places, key=lambda place: -len(place[0])):
error = error.replace(prefix, name)
@@ -514,9 +514,9 @@ def probe_argv(core: dict, choice: CoreChoice, content: campaign.Content, load:
argv = ["run", "--core", core["path"], "--content", str(load), "--content-label", content.name,
"--frames", str(content.frames), "--frame-hash-every", str(content.frame_hash_every),
"--require-sandbox", "--timeout", str(PROBE_TIMEOUT),
"--work-dir", str(ROOT / "tmp" / "core_probe"), "--core-artifact", core["url"]]
"--work-dir", str(REPO_ROOT / "tmp" / "core_probe"), "--core-artifact", core["url"]]
if record:
argv += ["--record", str(ROOT), "--emulator", choice.emulator, "--subject", subject]
argv += ["--record", str(REPO_ROOT), "--emulator", choice.emulator, "--subject", subject]
if supersedes:
argv += ["--supersedes", supersedes]
return argv
@@ -601,11 +601,11 @@ def probe_one(layout: Layout, platform: str, config: dict, profile: dict, target
def git_head() -> str | None:
proc = subprocess.run(["git", "rev-parse", "HEAD"], capture_output=True, text=True, check=False,
cwd=ROOT)
cwd=REPO_ROOT)
return proc.stdout.strip() or None
def append_line(line: dict, root: Path = ROOT) -> dict:
def append_line(line: dict, root: Path = REPO_ROOT) -> dict:
sealed = mr.seal_line(line, mr.CAMPAIGN_FILES[PACK_PROBES][0])
path = root / mr.records_path(PACK_PROBES)
path.parent.mkdir(parents=True, exist_ok=True)
@@ -627,9 +627,9 @@ class Unit:
def plan(platform: str, systems: set[str] | None, cores: set[str] | None,
buildbot: set[str]) -> tuple[dict, dict, list[Unit]]:
config = load_platform_config(platform, str(ROOT / "platforms"))
profiles = load_emulator_profiles(str(ROOT / "emulators"))
target = load_target_config(platform, TARGETS[platform], str(ROOT / "platforms"))
config = load_platform_config(platform, str(REPO_ROOT / "platforms"))
profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
target = load_target_config(platform, TARGETS[platform], str(REPO_ROOT / "platforms"))
units: list[Unit] = []
for system, contents in sorted(load_contents([campaign.CONTENT_FILE, PACK_CONTENT_FILE]).items()):
if systems and system not in systems:
@@ -662,7 +662,7 @@ def run(args: argparse.Namespace) -> int:
layout = pack_layout(pack, work / "pack", identity)
else:
layout = installer_layout(args.platform, pack, identity,
ROOT / "install" / f"{args.platform}.json", work / "installer")
REPO_ROOT / "install" / f"{args.platform}.json", work / "installer")
try:
for unit in units:
try:
@@ -712,7 +712,7 @@ def build_parser() -> argparse.ArgumentParser:
def main(argv: Sequence[str] | None = None) -> int:
args = build_parser().parse_args(argv)
require_platform(args.platform, str(ROOT / "platforms"))
require_platform(args.platform, str(REPO_ROOT / "platforms"))
if args.platform not in TARGETS:
print(f"ERROR: pack_probe tests {', '.join(sorted(TARGETS))}, not {args.platform}",
file=sys.stderr)
+14 -14
View File
@@ -47,10 +47,10 @@ if sys.version_info < (3, 9):
sys.path.insert(0, str(Path(__file__).resolve().parent))
import yaml
from core.paths import REPO_ROOT
ROOT = Path(__file__).resolve().parent.parent
CONTENT_FILE = ROOT / "tests" / "campaign" / "content.yml"
CORES = ROOT / ".cache" / "region" / "cores"
CONTENT_FILE = REPO_ROOT / "tests" / "campaign" / "content.yml"
CORES = REPO_ROOT / ".cache" / "region" / "cores"
NIGHTLY = "https://buildbot.libretro.com/nightly/linux/x86_64/latest/{core}_libretro.so.zip"
VARIANTS = ("full", "own", "others", "pack")
SUBJECT = re.compile(r"^region-(?P<core>[a-z0-9_]+)-(?P<game>[a-z0-9-]+)-(?P<variant>full|own|others|pack)$")
@@ -279,9 +279,9 @@ def pack_files(emulator: str, region: str, work: Path) -> dict[str, Path]:
from core.ziptools import safe_extract_zip
out_dir = work / "pack"
subprocess.run([sys.executable, str(ROOT / "scripts" / "generate_pack.py"), "--emulator", emulator,
subprocess.run([sys.executable, str(REPO_ROOT / "scripts" / "generate_pack.py"), "--emulator", emulator,
"--region", PACK_REGION[region], "--output-dir", str(out_dir)],
cwd=ROOT, check=True, capture_output=True, text=True)
cwd=REPO_ROOT, check=True, capture_output=True, text=True)
zips = sorted(out_dir.glob("*.zip"))
if len(zips) != 1:
raise FileNotFoundError(f"{out_dir}: {len(zips)} packs, one expected")
@@ -295,14 +295,14 @@ def local_resolver() -> Callable[[dict], Path | None]:
from model.database import load_database
from resolve.localfile import resolve_local_file
db = load_database(str(ROOT / "database.json"))
db = load_database(str(REPO_ROOT / "database.json"))
def local(entry: dict) -> Path | None:
hint = entry.get("path") if isinstance(entry.get("path"), str) else ""
path, status = resolve_local_file(entry, db, dest_hint=hint or "")
if not path or status in ("not_found", "hash_mismatch"):
return None
found = Path(path) if Path(path).is_absolute() else ROOT / path
found = Path(path) if Path(path).is_absolute() else REPO_ROOT / path
return found if found.is_file() else None
return local
@@ -322,7 +322,7 @@ def probe_when_idle(argv: list[str], max_wait: float,
threshold stays core_probe's own."""
started = clock()
while True:
proc = runner(argv, cwd=ROOT, capture_output=True, text=True)
proc = runner(argv, cwd=REPO_ROOT, capture_output=True, text=True)
if proc.returncode != BUSY or clock() - started >= max_wait:
return proc
pause(POLL_S)
@@ -331,7 +331,7 @@ def probe_when_idle(argv: list[str], max_wait: float,
def run(args: argparse.Namespace) -> int:
from model.profiles import load_emulator_profiles
profile = load_emulator_profiles(str(ROOT / "emulators"))[args.emulator]
profile = load_emulator_profiles(str(REPO_ROOT / "emulators"))[args.emulator]
entries = region_entries(profile, args.system)
if not entries:
print(f"ERROR: {args.emulator} declares no regional BIOS for {args.system}", file=sys.stderr)
@@ -345,15 +345,15 @@ def run(args: argparse.Namespace) -> int:
failures = 0
for game in games:
load = content_file(game, Path(args.content_dir))
with tempfile.TemporaryDirectory(dir=ROOT / "tmp") as scratch:
with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as scratch:
variants = plan_variants(entries, game["region"], local)
variants["pack"] = pack_files(args.emulator, game["region"], Path(scratch))
for label in args.variants or VARIANTS:
argv = [sys.executable, str(ROOT / "scripts" / "core_probe.py"), "run",
argv = [sys.executable, str(REPO_ROOT / "scripts" / "core_probe.py"), "run",
"--core", str(core), "--content", str(load), "--content-label", game["name"],
"--frames", str(game.get("frames", 3600)),
"--frame-hash-every", str(game.get("frame_hash_every", 10)),
"--record", str(ROOT), "--emulator", args.emulator,
"--record", str(REPO_ROOT), "--emulator", args.emulator,
"--subject", subject(core.name.removesuffix("_libretro.so"), game["name"], label),
"--require-sandbox", "--timeout", str(args.timeout)]
if url:
@@ -369,7 +369,7 @@ def run(args: argparse.Namespace) -> int:
return 1 if failures else 0
def collect(root: Path = ROOT, stored_records: list | None = None) -> list[dict]:
def collect(root: Path = REPO_ROOT, stored_records: list | None = None) -> list[dict]:
"""Every region outcome the records under measurements/ hold. A game
listed under several systems (sega-megacd and mega-cd) is judged under
the one whose profile ran it."""
@@ -411,7 +411,7 @@ def main(argv: list[str] | None = None) -> int:
go.add_argument("--core-name", help="buildbot core name, e.g. mednafen_psx (downloads the nightly)")
go.add_argument("--core", help="a core .so to use instead of the nightly")
go.add_argument("--core-artifact", help="where --core was downloaded from")
go.add_argument("--content-dir", default=str(ROOT / ".cache" / "test-content"),
go.add_argument("--content-dir", default=str(REPO_ROOT / ".cache" / "test-content"),
help="where romfetch keeps the test games (default: .cache/test-content)")
go.add_argument("--variants", nargs="*", choices=VARIANTS, help="a subset of the four runs")
go.add_argument("--timeout", type=int, default=900, help="seconds per run")