mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-23 10:07:48 -06:00
refactor: share resolver, content and nightly
The probes resolve held files, read content.yml, list the buildbot and fetch nightlies through one function each. - region_check resolves BIOS files from the repo root (probes.entries held_file), so a run outside the root no longer sees every file missing. - region_check reads content.yml as Content objects, and a malformed content folder raises Unavailable instead of FileNotFoundError. - region_check and pack_probe fetch nightlies like the campaign: retried on network errors, streamed to disk, and replaced when the buildbot's ETag or Last-Modified moves. region_check keeps its cores under .cache/region/cores/<core>/ with a build.json record. pack_probe --refresh-cores now downloads only a nightly the buildbot replaced. - The campaign loads profiles with load_emulator_profiles, so *.old.yml backups are skipped and hashes are normalized. Profile digests still come from the file on disk, so recorded checks keep their digest.
This commit is contained in:
1 parent
1165b910ed
commit
3a76cf48ba
7 files changed
+156
-170
No files matched your search
+19
-24
@@ -30,6 +30,7 @@ from probes.cores import Core, Cores
|
||||
from probes.entries import (
|
||||
entry_dest,
|
||||
entry_systems,
|
||||
held_file,
|
||||
is_bios,
|
||||
profile_digest,
|
||||
region_matches,
|
||||
@@ -43,7 +44,6 @@ from probes.host import (
|
||||
Unavailable,
|
||||
child_env,
|
||||
slug,
|
||||
working_directory,
|
||||
)
|
||||
from probes.state import DONE, FAILED, PENDING, load_state, should_run
|
||||
|
||||
@@ -152,14 +152,20 @@ class Campaign:
|
||||
# -- profiles and files -------------------------------------------------
|
||||
|
||||
def profiles(self) -> dict[str, dict]:
|
||||
out = {}
|
||||
for path in sorted(self.paths.emulators.glob("*.yml")):
|
||||
if path.name.startswith("_") or path.stem == "00_example":
|
||||
continue
|
||||
data = yaml.safe_load(path.read_text(encoding="utf-8")) or {}
|
||||
if "emulator" in data:
|
||||
out[path.stem] = data
|
||||
return out
|
||||
from model.profiles import emulator_profiles_cache, load_emulator_profiles
|
||||
|
||||
# The campaign writes these profiles itself: each pass reads them again.
|
||||
folder = os.path.realpath(self.paths.emulators)
|
||||
for key in [key for key in emulator_profiles_cache if key[0] == folder]:
|
||||
del emulator_profiles_cache[key]
|
||||
profiles = load_emulator_profiles(folder, skip_aliases=False)
|
||||
return {name: profile for name, profile in profiles.items() if name != "00_example"}
|
||||
|
||||
def digest_on_disk(self, emulator: str) -> str:
|
||||
"""profile_digest of the profile as its file reads now. The campaign's
|
||||
own edits land between the two reads of a unit, so both go to disk."""
|
||||
path = self.paths.emulators / f"{emulator}.yml"
|
||||
return profile_digest(yaml.safe_load(path.read_text(encoding="utf-8")))
|
||||
|
||||
@property
|
||||
def db(self) -> dict:
|
||||
@@ -169,17 +175,7 @@ class Campaign:
|
||||
|
||||
def local_file(self, entry: dict) -> Path | None:
|
||||
"""The collection's copy of an entry, by its declared hashes or its name."""
|
||||
from resolve.localfile import resolve_local_file
|
||||
|
||||
hint = entry.get("path") if isinstance(entry.get("path"), str) else ""
|
||||
# The database names files relative to the checkout it describes.
|
||||
with working_directory(self.paths.root):
|
||||
path, status = resolve_local_file(entry, self.db, dest_hint=hint or "")
|
||||
if not path or status in ("not_found", "hash_mismatch"):
|
||||
return None
|
||||
local = Path(path)
|
||||
local = local if local.is_absolute() else self.paths.root / local
|
||||
return local if local.is_file() else None
|
||||
return held_file(entry, self.db, self.paths.root)
|
||||
|
||||
def variant_files(self, entry: dict, primary: Path) -> list[Path]:
|
||||
"""The .variants/ copies of an entry's file the collection holds."""
|
||||
@@ -838,7 +834,7 @@ class Campaign:
|
||||
|
||||
def run_unit(self, unit: Unit, system: str | None) -> None:
|
||||
emulator, profile = unit.emulator, unit.profile
|
||||
digest = profile_digest(profile)
|
||||
digest = self.digest_on_disk(emulator)
|
||||
contents = self.unit_contents(unit, system)
|
||||
systems = [s for s in profile.get("systems") or () if not system or s == system]
|
||||
if unit.pending:
|
||||
@@ -865,9 +861,8 @@ class Campaign:
|
||||
self.run_unit_content(Unit(emulator, profile, core.name), core, content, digest)
|
||||
for content in contents:
|
||||
self.store.release(content, emulator)
|
||||
self.state["emulators"][emulator] = {"profile_digest": profile_digest(
|
||||
yaml.safe_load((self.paths.emulators / f"{emulator}.yml").read_text(encoding="utf-8"))),
|
||||
"at": now_iso()}
|
||||
self.state["emulators"][emulator] = {"profile_digest": self.digest_on_disk(emulator),
|
||||
"at": now_iso()}
|
||||
# The campaign's own edits do not make its checks run again.
|
||||
new_digest = self.state["emulators"][emulator]["profile_digest"]
|
||||
for entry in self.state["checks"].get(emulator, {}).values():
|
||||
|
||||
@@ -43,6 +43,7 @@ class Content:
|
||||
frame_hash_every: int
|
||||
pinned: bool
|
||||
boot_file: str | None
|
||||
also_regions: tuple[str, ...] = ()
|
||||
|
||||
@property
|
||||
def key(self) -> str:
|
||||
@@ -61,6 +62,7 @@ def load_content(path: Path) -> dict[str, list[Content]]:
|
||||
frames=int(item.get("frames", 3600)),
|
||||
frame_hash_every=int(item.get("frame_hash_every", 10)),
|
||||
pinned=bool(item.get("pinned", False)), boot_file=spec.get("boot_file"),
|
||||
also_regions=tuple(item.get("also_regions") or ()),
|
||||
))
|
||||
return out
|
||||
|
||||
|
||||
+89
-42
@@ -3,24 +3,27 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import stat
|
||||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
import zipfile
|
||||
from collections.abc import Callable
|
||||
from collections.abc import Callable, Sequence
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, TypeVar
|
||||
from typing import TYPE_CHECKING, Any, TypeVar
|
||||
|
||||
import core_probe
|
||||
from core.hashing import file_digest
|
||||
from core.statefile import now_iso
|
||||
from probes.host import Unavailable, child_env, run_group, slug
|
||||
from probes.host import NETWORK_DELAYS, Unavailable, child_env, run_group, slug
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from probes.campaign import Campaign
|
||||
@@ -207,6 +210,82 @@ def safe_extract_so(archive: Path, member: str, target: Path) -> None:
|
||||
os.replace(scratch, target)
|
||||
|
||||
|
||||
def retrying(what: str, call: Callable[[], T], *, delays: Sequence[float],
|
||||
sleep: Callable[[float], None], log: Callable[[str], None]) -> T:
|
||||
"""call, run again after each delay on a network failure. A client error
|
||||
other than 429 is final."""
|
||||
for attempt, delay in enumerate((*delays, None)):
|
||||
try:
|
||||
return call()
|
||||
except (urllib.error.URLError, TimeoutError, ConnectionError, OSError) as exc:
|
||||
if isinstance(exc, urllib.error.HTTPError) and exc.code < 500 and exc.code != 429:
|
||||
raise Unavailable(f"{what}: HTTP {exc.code}") from exc
|
||||
if delay is None:
|
||||
raise Unavailable(f"{what}: {exc}") from exc
|
||||
log(f"{what}: {exc}, retry {attempt + 1} in {delay}s")
|
||||
sleep(delay)
|
||||
raise AssertionError("unreachable")
|
||||
|
||||
|
||||
def buildbot_listing(urlopen: Callable[..., Any] = urllib.request.urlopen) -> set[str]:
|
||||
"""The core names the buildbot publishes a nightly of."""
|
||||
with urlopen(BUILDBOT, timeout=120) as response:
|
||||
page = response.read().decode("utf-8", "replace")
|
||||
return set(re.findall(r"([A-Za-z0-9_]+)_libretro\.so\.zip", page))
|
||||
|
||||
|
||||
def fetch_nightly(name: str, target: Path, cached: dict, *, urlopen: Callable[..., Any],
|
||||
retry: Callable[[str, Callable[[], Any]], Any]) -> dict:
|
||||
"""The buildbot nightly of a core at target, downloaded again when the
|
||||
buildbot's ETag or Last-Modified moved or the file on disk is not the one
|
||||
cached describes. Returns the record of the file now at target: cached
|
||||
itself when nothing changed."""
|
||||
url = f"{BUILDBOT}{name}_libretro.so.zip"
|
||||
|
||||
def head() -> dict:
|
||||
request = urllib.request.Request(url, method="HEAD")
|
||||
with urlopen(request, timeout=120) as response:
|
||||
return {"etag": response.headers.get("ETag"),
|
||||
"last_modified": response.headers.get("Last-Modified")}
|
||||
stamp = retry(f"{name} nightly", head)
|
||||
if (cached.get("etag"), cached.get("last_modified")) == (stamp["etag"], stamp["last_modified"]) \
|
||||
and target.is_file() and file_digest(target, "sha256") == cached.get("sha256"):
|
||||
return cached
|
||||
archive = target.parent / f"{name}_libretro.so.zip"
|
||||
archive.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def download() -> None:
|
||||
with urlopen(url, timeout=600) as response, archive.open("wb") as out:
|
||||
shutil.copyfileobj(response, out)
|
||||
retry(f"{name} nightly", download)
|
||||
safe_extract_so(archive, f"{name}_libretro.so", target)
|
||||
archive.unlink()
|
||||
return {**stamp, "url": url, "sha256": file_digest(target, "sha256"), "fetched_at": now_iso()}
|
||||
|
||||
|
||||
def cached_nightly(name: str, folder: Path, *, check: bool = True) -> dict:
|
||||
"""fetch_nightly for a tool without campaign state, its record kept in
|
||||
folder/build.json. Without check, a file on disk that matches its record
|
||||
is returned without asking the buildbot."""
|
||||
target, record_path = folder / f"{name}_libretro.so", folder / "build.json"
|
||||
cached: dict = {}
|
||||
if record_path.is_file():
|
||||
cached = json.loads(record_path.read_text(encoding="utf-8"))
|
||||
if not check and target.is_file() and cached.get("sha256") == file_digest(target, "sha256"):
|
||||
return {**cached, "path": str(target)}
|
||||
|
||||
def report(line: str) -> None:
|
||||
print(line, file=sys.stderr)
|
||||
|
||||
def retry(what: str, call: Callable[[], Any]) -> Any:
|
||||
return retrying(what, call, delays=NETWORK_DELAYS, sleep=time.sleep, log=report)
|
||||
record = fetch_nightly(name, target, cached, urlopen=urllib.request.urlopen, retry=retry)
|
||||
if record is not cached:
|
||||
record = {"name": name, **record}
|
||||
record_path.write_text(json.dumps(record, indent=1) + "\n", encoding="utf-8")
|
||||
return {**record, "path": str(target)}
|
||||
|
||||
|
||||
class Cores:
|
||||
"""Buildbot nightlies, downloaded once per build, else local builds of
|
||||
the profile's pinned commit."""
|
||||
@@ -216,28 +295,14 @@ class Cores:
|
||||
self.listing: set[str] | None = None
|
||||
|
||||
def retrying(self, what: str, call: Callable[[], T]) -> T:
|
||||
for attempt, delay in enumerate((*self.c.settings.delays, None)):
|
||||
try:
|
||||
return call()
|
||||
except (urllib.error.URLError, TimeoutError, ConnectionError, OSError) as exc:
|
||||
if isinstance(exc, urllib.error.HTTPError) and exc.code < 500 and exc.code != 429:
|
||||
raise Unavailable(f"{what}: HTTP {exc.code}") from exc
|
||||
if delay is None:
|
||||
raise Unavailable(f"{what}: {exc}") from exc
|
||||
self.c.log(f"{what}: {exc}, retry {attempt + 1} in {delay}s")
|
||||
self.c.host.sleep(delay)
|
||||
raise AssertionError("unreachable")
|
||||
return retrying(what, call, delays=self.c.settings.delays, sleep=self.c.host.sleep, log=self.c.log)
|
||||
|
||||
def buildbot(self) -> set[str]:
|
||||
if self.listing is None:
|
||||
if not self.c.settings.network:
|
||||
self.listing = set()
|
||||
else:
|
||||
def read() -> bytes:
|
||||
with self.c.host.urlopen(BUILDBOT, timeout=120) as response:
|
||||
return response.read()
|
||||
page = self.retrying("buildbot listing", read).decode("utf-8", "replace")
|
||||
self.listing = set(re.findall(r"([A-Za-z0-9_]+)_libretro\.so\.zip", page))
|
||||
self.listing = self.retrying("buildbot listing", lambda: buildbot_listing(self.c.host.urlopen))
|
||||
return self.listing
|
||||
|
||||
def names(self, profile: dict) -> list[str]:
|
||||
@@ -245,32 +310,14 @@ class Cores:
|
||||
return sorted({str(c) for c in profile.get("cores") or () if str(c) in listing})
|
||||
|
||||
def nightly(self, name: str, profile: dict) -> Core:
|
||||
url = f"{BUILDBOT}{name}_libretro.so.zip"
|
||||
cached = self.c.state["cores"].get(name) or {}
|
||||
|
||||
def head() -> dict:
|
||||
request = urllib.request.Request(url, method="HEAD")
|
||||
with self.c.host.urlopen(request, timeout=120) as response:
|
||||
return {"etag": response.headers.get("ETag"),
|
||||
"last_modified": response.headers.get("Last-Modified")}
|
||||
stamp = self.retrying(f"{name} nightly", head)
|
||||
target = self.c.paths.home / "cores" / name / f"{name}_libretro.so"
|
||||
if (cached.get("etag"), cached.get("last_modified")) != (stamp["etag"], stamp["last_modified"]) \
|
||||
or not target.is_file() or file_digest(target, "sha256") != cached.get("sha256"):
|
||||
archive = target.parent / f"{name}_libretro.so.zip"
|
||||
archive.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def download() -> None:
|
||||
with self.c.host.urlopen(url, timeout=600) as response, archive.open("wb") as out:
|
||||
shutil.copyfileobj(response, out)
|
||||
self.retrying(f"{name} nightly", download)
|
||||
safe_extract_so(archive, f"{name}_libretro.so", target)
|
||||
archive.unlink()
|
||||
cached = {**stamp, "url": url, "sha256": file_digest(target, "sha256"), "fetched_at": now_iso()}
|
||||
self.c.state["cores"][name] = cached
|
||||
self.c.log(f"core {name}: new nightly {cached['sha256'][:12]} ({stamp['last_modified']})")
|
||||
record = fetch_nightly(name, target, cached, urlopen=self.c.host.urlopen, retry=self.retrying)
|
||||
if record is not cached:
|
||||
self.c.state["cores"][name] = record
|
||||
self.c.log(f"core {name}: new nightly {record['sha256'][:12]} ({record['last_modified']})")
|
||||
repo = profile.get("source") if isinstance(profile.get("source"), str) else None
|
||||
return Core(name, target, cached["sha256"], artifact=url,
|
||||
return Core(name, target, record["sha256"], artifact=record["url"],
|
||||
repo=repo if repo and repo.startswith("http") else None)
|
||||
|
||||
def build(self, emulator: str, profile: dict) -> Core:
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
|
||||
from model import measurements as mr
|
||||
from probes.host import working_directory
|
||||
|
||||
|
||||
def profile_digest(profile: dict) -> str:
|
||||
@@ -17,6 +19,22 @@ def profile_digest(profile: dict) -> str:
|
||||
return hashlib.sha1(mr.canonical(body)).hexdigest()
|
||||
|
||||
|
||||
def held_file(entry: dict, db: dict, root: Path) -> Path | None:
|
||||
"""The collection's copy of an entry in the checkout at root, by its
|
||||
declared hashes or its name."""
|
||||
from resolve.localfile import resolve_local_file
|
||||
|
||||
hint = entry.get("path") if isinstance(entry.get("path"), str) else ""
|
||||
# The database names files relative to the checkout it describes.
|
||||
with working_directory(root):
|
||||
path, status = resolve_local_file(entry, db, dest_hint=hint or "")
|
||||
if not path or status in ("not_found", "hash_mismatch"):
|
||||
return None
|
||||
local = Path(path)
|
||||
local = local if local.is_absolute() else root / local
|
||||
return local if local.is_file() else None
|
||||
|
||||
|
||||
def entry_systems(entry: dict, profile: dict) -> list[str]:
|
||||
if entry.get("systems"):
|
||||
return list(entry["systems"])
|
||||
|
||||
@@ -7,19 +7,16 @@ import contextlib
|
||||
import fcntl
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import urllib.request
|
||||
from collections.abc import Iterable, Iterator, Sequence
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from unattended import worktree
|
||||
from core_probe import PROBE_LOCK_ENV, PROBE_LOCK_HELD_ENV, VERDICTS, probe_lock_path
|
||||
from core.hashing import file_digest
|
||||
from core.paths import REPO_ROOT
|
||||
from core.statefile import now_iso
|
||||
from model import measurements as mr
|
||||
@@ -28,7 +25,7 @@ from model.profiles import load_emulator_profiles
|
||||
from model.systems import norm_system_id
|
||||
from model.targets import load_target_config
|
||||
from probes.content import Content, load_content, load_file, verify_identity
|
||||
from probes.cores import BUILDBOT, safe_extract_so
|
||||
from probes.cores import buildbot_listing, cached_nightly
|
||||
from probes.entries import entry_dest
|
||||
from probes.host import CONTENT_FILE, PROBE_TIMEOUT, Unavailable, child_env
|
||||
from probes.packlayout import (
|
||||
@@ -232,32 +229,10 @@ def map_run(layout: Layout, staged: set[str], rep: dict, profile: dict) -> tuple
|
||||
# Cores and content
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
def buildbot_listing() -> set[str]:
|
||||
with urllib.request.urlopen(BUILDBOT, timeout=120) as response:
|
||||
page = response.read().decode("utf-8", "replace")
|
||||
return set(re.findall(r"([A-Za-z0-9_]+)_libretro\.so\.zip", page))
|
||||
|
||||
|
||||
def fetch_core(name: str, refresh: bool = False) -> dict:
|
||||
"""The buildbot nightly of a core, kept with where and when it came from."""
|
||||
folder = CORE_CACHE / name
|
||||
so, meta_path = folder / f"{name}_libretro.so", folder / "build.json"
|
||||
if so.is_file() and meta_path.is_file() and not refresh:
|
||||
meta = json.loads(meta_path.read_text(encoding="utf-8"))
|
||||
if meta.get("sha256") == file_digest(so, "sha256"):
|
||||
return {**meta, "path": str(so)}
|
||||
url = f"{BUILDBOT}{name}_libretro.so.zip"
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
archive = folder / f"{name}.zip.part"
|
||||
with urllib.request.urlopen(url, timeout=600) as response, archive.open("wb") as out:
|
||||
shutil.copyfileobj(response, out)
|
||||
modified = response.headers.get("Last-Modified")
|
||||
safe_extract_so(archive, f"{name}_libretro.so", so)
|
||||
archive.unlink()
|
||||
meta = {"name": name, "url": url, "last_modified": modified, "sha256": file_digest(so, "sha256"),
|
||||
"fetched_at": now_iso()}
|
||||
meta_path.write_text(json.dumps(meta, indent=1) + "\n", encoding="utf-8")
|
||||
return {**meta, "path": str(so)}
|
||||
"""The buildbot nightly of a core, kept with where and when it came from.
|
||||
refresh asks the buildbot whether a newer build replaced it."""
|
||||
return cached_nightly(name, CORE_CACHE / name, check=refresh)
|
||||
|
||||
|
||||
def load_contents(files: Sequence[Path]) -> dict[str, list[Content]]:
|
||||
|
||||
@@ -9,20 +9,18 @@ import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import urllib.request
|
||||
from collections.abc import Callable, Iterable
|
||||
from pathlib import Path
|
||||
|
||||
import yaml
|
||||
|
||||
from core.paths import REPO_ROOT
|
||||
from core_probe import BUILTIN
|
||||
from probes.entries import entry_dest, regions_of
|
||||
from probes.content import Content, load_content, load_file
|
||||
from probes.cores import cached_nightly
|
||||
from probes.entries import entry_dest, held_file, regions_of
|
||||
from probes.host import CONTENT_FILE
|
||||
|
||||
|
||||
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)$")
|
||||
# The territory a test game names, as generate_pack --region takes it.
|
||||
@@ -186,50 +184,11 @@ def sentence(game_region: str, result: dict) -> str:
|
||||
# Runs
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
def load_content(path: Path = CONTENT_FILE) -> dict[str, list[dict]]:
|
||||
data = yaml.safe_load(path.read_text(encoding="utf-8")) or {}
|
||||
out: dict[str, list[dict]] = {}
|
||||
for system, spec in (data.get("systems") or {}).items():
|
||||
for item in spec.get("content") or ():
|
||||
out.setdefault(system, []).append({**item, "romfetch": spec["romfetch"]})
|
||||
return out
|
||||
|
||||
|
||||
def content_file(item: dict, content_dir: Path) -> Path:
|
||||
folder = content_dir / item["romfetch"] / item["name"]
|
||||
if item.get("load") == "cue":
|
||||
cues = sorted(folder.glob("*.cue"))
|
||||
if len(cues) != 1:
|
||||
raise FileNotFoundError(f"{folder}: {len(cues)} .cue files, one expected")
|
||||
return cues[0]
|
||||
if item.get("load"):
|
||||
return folder / item["load"]
|
||||
files = [p for p in sorted(folder.iterdir()) if p.is_file() and p.name != "identity.json"]
|
||||
if len(files) != 1:
|
||||
raise FileNotFoundError(f"{folder}: {len(files)} files, name one with load:")
|
||||
return files[0]
|
||||
|
||||
|
||||
def nightly_core(core: str) -> tuple[Path, str]:
|
||||
"""The buildbot nightly of a core, downloaded once, and its URL."""
|
||||
import zipfile
|
||||
|
||||
url = NIGHTLY.format(core=core)
|
||||
target = CORES / f"{core}_libretro.so"
|
||||
if not target.is_file():
|
||||
CORES.mkdir(parents=True, exist_ok=True)
|
||||
archive = CORES / f"{core}.zip"
|
||||
with urllib.request.urlopen(url, timeout=300) as response, archive.open("wb") as out:
|
||||
out.write(response.read())
|
||||
with zipfile.ZipFile(archive) as handle:
|
||||
member = f"{core}_libretro.so"
|
||||
if member not in handle.namelist():
|
||||
raise FileNotFoundError(f"{archive.name}: no {member} inside")
|
||||
partial = target.with_suffix(".part")
|
||||
partial.write_bytes(handle.read(member))
|
||||
partial.replace(target)
|
||||
archive.unlink()
|
||||
return target, url
|
||||
"""The buildbot nightly of a core, downloaded again when the buildbot
|
||||
replaced it, and its URL."""
|
||||
record = cached_nightly(core, CORES / core)
|
||||
return Path(record["path"]), record["url"]
|
||||
|
||||
|
||||
def pack_files(emulator: str, region: str, work: Path) -> dict[str, Path]:
|
||||
@@ -252,19 +211,9 @@ def pack_files(emulator: str, region: str, work: Path) -> dict[str, Path]:
|
||||
|
||||
def local_resolver() -> Callable[[dict], Path | None]:
|
||||
from model.database import load_database
|
||||
from resolve.localfile import resolve_local_file
|
||||
|
||||
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 REPO_ROOT / path
|
||||
return found if found.is_file() else None
|
||||
|
||||
return local
|
||||
return lambda entry: held_file(entry, db, REPO_ROOT)
|
||||
|
||||
|
||||
BUSY = 3 # core_probe's exit status when it refuses to record on a busy host
|
||||
@@ -295,7 +244,7 @@ def run(args: argparse.Namespace) -> int:
|
||||
if not entries:
|
||||
print(f"ERROR: {args.emulator} declares no regional BIOS for {args.system}", file=sys.stderr)
|
||||
return 2
|
||||
games = [g for g in load_content().get(args.system, []) if g.get("region") in PACK_REGION]
|
||||
games = [g for g in load_content(CONTENT_FILE).get(args.system, []) if g.region in PACK_REGION]
|
||||
if not games:
|
||||
print(f"ERROR: content.yml has no regional game for {args.system}", file=sys.stderr)
|
||||
return 2
|
||||
@@ -303,17 +252,17 @@ def run(args: argparse.Namespace) -> int:
|
||||
local = local_resolver()
|
||||
failures = 0
|
||||
for game in games:
|
||||
load = content_file(game, Path(args.content_dir))
|
||||
load = load_file(Path(args.content_dir) / game.romfetch_system / game.name, game.load)
|
||||
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))
|
||||
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(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)),
|
||||
"--core", str(core), "--content", str(load), "--content-label", game.name,
|
||||
"--frames", str(game.frames),
|
||||
"--frame-hash-every", str(game.frame_hash_every),
|
||||
"--record", str(REPO_ROOT), "--emulator", args.emulator,
|
||||
"--subject", subject(core.name.removesuffix("_libretro.so"), game["name"], label),
|
||||
"--subject", subject(core.name.removesuffix("_libretro.so"), game.name, label),
|
||||
"--require-sandbox", "--timeout", str(args.timeout)]
|
||||
if url:
|
||||
argv += ["--core-artifact", url]
|
||||
@@ -321,7 +270,7 @@ def run(args: argparse.Namespace) -> int:
|
||||
argv += ["--system-file", f"{dest}={src}"]
|
||||
proc = probe_when_idle(argv, args.max_load_wait)
|
||||
status = "recorded" if proc.returncode == 0 else f"exit {proc.returncode}"
|
||||
print(json.dumps({"game": game["name"], "variant": label, "status": status,
|
||||
print(json.dumps({"game": game.name, "variant": label, "status": status,
|
||||
"error": proc.stderr.strip()[-400:] if proc.returncode else None}),
|
||||
flush=True)
|
||||
failures += proc.returncode != 0
|
||||
@@ -335,10 +284,10 @@ def collect(root: Path = REPO_ROOT, stored_records: list | None = None) -> list[
|
||||
from model.profiles import load_emulator_profiles
|
||||
from model.measurements import live, read_records
|
||||
|
||||
content: dict[str, list[tuple[str, dict]]] = {}
|
||||
content: dict[str, list[tuple[str, Content]]] = {}
|
||||
for system, items in load_content(root / "tests" / "campaign" / "content.yml").items():
|
||||
for item in items:
|
||||
content.setdefault(item["name"], []).append((system, item))
|
||||
content.setdefault(item.name, []).append((system, item))
|
||||
profiles = load_emulator_profiles(str(root / "emulators"))
|
||||
groups: dict[tuple[str, str, str], dict[str, dict]] = {}
|
||||
for stored in read_records(root) if stored_records is None else stored_records:
|
||||
@@ -355,7 +304,7 @@ def collect(root: Path = REPO_ROOT, stored_records: list | None = None) -> list[
|
||||
system, item = next(((s, i) for s, i in content[game] if s in (profile.get("systems") or ())),
|
||||
content[game][0])
|
||||
entries = region_entries(profile, system)
|
||||
result = outcome(records, entries, item["region"])
|
||||
result = outcome(records, entries, item.region)
|
||||
out.append({"emulator": emulator, "core": core, "system": system, "game": game, **result,
|
||||
"sentence": sentence(item["region"], result)})
|
||||
"sentence": sentence(item.region, result)})
|
||||
return out
|
||||
Reference in new issue
Block a user