mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-23 10:07:48 -06:00
refactor: share now_iso and the pack size label
This commit is contained in:
1 parent
9bb8d89acd
commit
f2fd49a9c9
5 files changed
+80
-70
No files matched your search
+8
-10
@@ -587,11 +587,10 @@ def sync_worktree(worktree: Path) -> str:
|
||||
ahead = int(git(worktree, "rev-list", "--count", f"{upstream}..HEAD").stdout)
|
||||
if ahead == 0:
|
||||
git(worktree, "merge", "--ff-only", "--quiet", upstream)
|
||||
elif git(worktree, "merge-base", "--is-ancestor", upstream, "HEAD",
|
||||
check=False).returncode != 0:
|
||||
if git(worktree, "rebase", "--quiet", upstream, check=False).returncode != 0:
|
||||
git(worktree, "rebase", "--abort", check=False)
|
||||
raise AutorunError(BLOCKED, f"{ahead} automation commits conflict with {upstream}")
|
||||
elif (git(worktree, "merge-base", "--is-ancestor", upstream, "HEAD", check=False).returncode != 0
|
||||
and git(worktree, "rebase", "--quiet", upstream, check=False).returncode != 0):
|
||||
git(worktree, "rebase", "--abort", check=False)
|
||||
raise AutorunError(BLOCKED, f"{ahead} automation commits conflict with {upstream}")
|
||||
return git(worktree, "rev-parse", upstream).stdout.strip()
|
||||
|
||||
|
||||
@@ -608,11 +607,10 @@ def push_batch(worktree: Path, gate_base: str, regate: Callable[[], bool]) -> st
|
||||
upstream = f"{REMOTE}/{TARGET}"
|
||||
if int(git(worktree, "rev-list", "--count", f"{upstream}..HEAD").stdout) == 0:
|
||||
return ""
|
||||
if git(worktree, "merge-base", "--is-ancestor", upstream, "HEAD",
|
||||
check=False).returncode != 0:
|
||||
if git(worktree, "rebase", "--quiet", upstream, check=False).returncode != 0:
|
||||
git(worktree, "rebase", "--abort", check=False)
|
||||
raise AutorunError(BLOCKED, f"rebase onto {upstream} conflicts, batch kept")
|
||||
if (git(worktree, "merge-base", "--is-ancestor", upstream, "HEAD", check=False).returncode != 0
|
||||
and git(worktree, "rebase", "--quiet", upstream, check=False).returncode != 0):
|
||||
git(worktree, "rebase", "--abort", check=False)
|
||||
raise AutorunError(BLOCKED, f"rebase onto {upstream} conflicts, batch kept")
|
||||
if git(worktree, "rev-parse", upstream).stdout.strip() != gate_base and not regate():
|
||||
raise AutorunError(FAILED, f"gate failed on the batch rebased onto {upstream}")
|
||||
git(worktree, "push", "--quiet", REMOTE, f"HEAD:{TARGET}", env=token_env())
|
||||
|
||||
+22
-14
@@ -41,7 +41,6 @@ from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import contextlib
|
||||
import datetime as dt
|
||||
import fcntl
|
||||
import hashlib
|
||||
import json
|
||||
@@ -62,6 +61,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
import autorun
|
||||
import campaign
|
||||
import measurement_records as mr
|
||||
from autorun import now_iso
|
||||
from common import (
|
||||
_norm_system_id,
|
||||
load_emulator_profiles,
|
||||
@@ -272,7 +272,7 @@ def so_names(name: str, profile: dict, buildbot: set[str], target: set[str] | No
|
||||
def choose_cores(config: dict, profiles: dict[str, dict], system: str, buildbot: set[str],
|
||||
target: set[str] | None) -> list[CoreChoice]:
|
||||
wanted = _norm_system_id(system)
|
||||
out = []
|
||||
out: list[CoreChoice] = []
|
||||
for name in sorted(resolve_platform_cores(config, profiles, target)):
|
||||
profile = profiles[name]
|
||||
if wanted not in {_norm_system_id(s) for s in profile.get("systems") or ()}:
|
||||
@@ -389,9 +389,8 @@ def map_run(layout: Layout, staged: set[str], rep: dict, profile: dict) -> tuple
|
||||
else:
|
||||
kind = "missing_declared" if names else "missing_undeclared"
|
||||
findings.append({"kind": kind, "path": path, "declared_by": names, "paths": elsewhere})
|
||||
for item in opened:
|
||||
if item["path"] in staged and item["entry"] is None:
|
||||
findings.append({"kind": "unlisted", "path": item["path"], "declared_by": [], "paths": []})
|
||||
findings.extend({"kind": "unlisted", "path": item["path"], "declared_by": [], "paths": []}
|
||||
for item in opened if item["path"] in staged and item["entry"] is None)
|
||||
return opened, findings
|
||||
|
||||
|
||||
@@ -456,10 +455,6 @@ def content_folder(content: campaign.Content, fetch: bool) -> Path:
|
||||
# One probe: a core, a game, a layout
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
def now_iso() -> str:
|
||||
return dt.datetime.now(dt.timezone.utc).replace(microsecond=0).isoformat()
|
||||
|
||||
|
||||
def wait_idle(limit: float = IDLE_WAIT, poll: float = 30.0) -> None:
|
||||
"""Wait for the load core_probe records under, a quarter of the CPUs.
|
||||
Extracting a pack loads the host itself for a minute or two."""
|
||||
@@ -535,10 +530,22 @@ def subject_for(platform: str, install: str, system: str, so: str, content: str)
|
||||
return f"{mr.PACK_SUBJECT_PREFIX}{subject}"
|
||||
|
||||
|
||||
def probe_one(layout: Layout, platform: str, config: dict, profile: dict, choice: CoreChoice,
|
||||
core: dict, system: str, content: campaign.Content, load: Path, work: Path) -> dict:
|
||||
@dataclass(frozen=True)
|
||||
class ProbeTarget:
|
||||
"""One core of one system, on the game loaded for it."""
|
||||
|
||||
choice: CoreChoice
|
||||
core: dict
|
||||
system: str
|
||||
content: campaign.Content
|
||||
load: Path
|
||||
|
||||
|
||||
def probe_one(layout: Layout, platform: str, config: dict, profile: dict, target: ProbeTarget,
|
||||
work: Path) -> dict:
|
||||
"""Run until the staging is closed. The first run is recorded, and when
|
||||
the staging grew, the closed one is recorded too and supersedes it."""
|
||||
choice, core, system, content, load = target.choice, target.core, target.system, target.content, target.load
|
||||
native = platform_system(config, system)
|
||||
dests = [f.get("destination") or f.get("name")
|
||||
for f in ((config.get("systems") or {}).get(native) or {}).get("files") or ()]
|
||||
@@ -626,7 +633,7 @@ def plan(platform: str, systems: set[str] | None, cores: set[str] | None,
|
||||
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"))
|
||||
units = []
|
||||
units: list[Unit] = []
|
||||
for system, contents in sorted(load_contents([campaign.CONTENT_FILE, PACK_CONTENT_FILE]).items()):
|
||||
if systems and system not in systems:
|
||||
continue
|
||||
@@ -668,8 +675,9 @@ def run(args: argparse.Namespace) -> int:
|
||||
continue
|
||||
for choice in unit.cores:
|
||||
core = fetch_core(choice.so_name, args.refresh_cores)
|
||||
line = probe_one(layout, args.platform, config, profiles[choice.emulator], choice,
|
||||
core, unit.system, unit.content, load, work / "runs")
|
||||
target = ProbeTarget(choice, core, unit.system, unit.content, load)
|
||||
line = probe_one(layout, args.platform, config, profiles[choice.emulator], target,
|
||||
work / "runs")
|
||||
sealed = append_line(line)
|
||||
print(f"{args.platform} {install} {unit.system} {choice.so_name}: {line['verdict']}, "
|
||||
f"{len(line['files_opened'])} opened, {len(line['findings'])} findings, "
|
||||
|
||||
@@ -53,12 +53,6 @@ SITE = "https://abdess.github.io/retrobios/"
|
||||
HANDHELD_PAGE = "wiki/installer/#on-a-handheld-the-retrobios-port"
|
||||
|
||||
|
||||
def _size(count: int) -> str:
|
||||
if count >= 1024**3:
|
||||
return f"{count / 1024**3:.1f} GB"
|
||||
return f"{count / 1024**2:.0f} MB"
|
||||
|
||||
|
||||
def _display(pack: str) -> str:
|
||||
"""RetroArch_Lakka_v1.22.2_BIOS_Pack.zip reads as RetroArch Lakka v1.22.2."""
|
||||
return pack.split("_BIOS_Pack", 1)[0].replace("_", " ")
|
||||
@@ -273,7 +267,7 @@ def render(record: dict, platforms_dir: str, whats_new: str,
|
||||
folder = folders.get(name)
|
||||
lines.append(
|
||||
f"| {_display(name)} | {_link(pack, tag)} |"
|
||||
f" {_size(pack['extracted_size'])} | {pack['files']:,} |"
|
||||
f" {release_record.size_text(pack['extracted_size'])} | {pack['files']:,} |"
|
||||
f" {f'`{folder}`' if folder else '-'} |"
|
||||
)
|
||||
lines += [
|
||||
|
||||
@@ -196,7 +196,7 @@ def manifest_mismatches(record: dict, install_dir: str | Path) -> list[str]:
|
||||
return found
|
||||
|
||||
|
||||
def _size(count: int) -> str:
|
||||
def size_text(count: int) -> str:
|
||||
if count >= 1024**3:
|
||||
return f"{count / 1024**3:.1f} GB"
|
||||
return f"{count / 1024**2:.0f} MB"
|
||||
@@ -230,8 +230,8 @@ def main() -> int:
|
||||
return 1
|
||||
for name, pack in record["packs"].items():
|
||||
print(
|
||||
f"{name:<44} download {_size(pack['download_size']):>8}"
|
||||
f" extracted {_size(pack['extracted_size']):>8}"
|
||||
f"{name:<44} download {size_text(pack['download_size']):>8}"
|
||||
f" extracted {size_text(pack['extracted_size']):>8}"
|
||||
f" {pack['files']:,} files {len(pack['assets'])} asset(s)"
|
||||
)
|
||||
mismatches = manifest_mismatches(record, args.install_dir)
|
||||
|
||||
+46
-36
@@ -27,7 +27,6 @@ from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import contextlib
|
||||
import datetime as dt
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
@@ -49,6 +48,7 @@ from typing import IO
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
|
||||
import core_probe as cp
|
||||
from autorun import now_iso
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
CACHE = ROOT / ".cache" / "standalone"
|
||||
@@ -293,10 +293,6 @@ def installed(emu: Emulator, sha256: str | None, cache: Path = CACHE) -> tuple[d
|
||||
# One repetition
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
def now_iso() -> str:
|
||||
return dt.datetime.now(dt.timezone.utc).replace(microsecond=0).isoformat()
|
||||
|
||||
|
||||
# The X server runs inside the sandbox, on the sandbox's own /tmp: the
|
||||
# display is private to the run, and the host's /tmp/.X11-unix (read-only
|
||||
# under WSLg) is never touched. Its fbdir option keeps the screen as an XWD
|
||||
@@ -338,6 +334,35 @@ def read_lines(stream: IO[bytes], out: list[dict], samples: list) -> None:
|
||||
out.append({"frame": len(samples), "level": "info", "text": text})
|
||||
|
||||
|
||||
def wait_for_screen(proc: subprocess.Popen, screen_file: Path, logs: list[dict]) -> None:
|
||||
deadline = time.monotonic() + 30
|
||||
while not screen_file.exists():
|
||||
if proc.poll() is not None or time.monotonic() > deadline:
|
||||
raise cp.ProbeError(f"Xvfb did not start in the sandbox (exit {proc.poll()}): "
|
||||
f"{' / '.join(line['text'] for line in logs[-5:])}")
|
||||
time.sleep(0.05)
|
||||
|
||||
|
||||
def sample_screen(proc: subprocess.Popen, screen_file: Path, args: argparse.Namespace,
|
||||
samples: list[tuple[float, str, bool]], png_dir: Path | None, started: float) -> dict | None:
|
||||
"""Hash the screen every interval. Returns how the emulator ended, None
|
||||
while it still runs."""
|
||||
for index in range(args.samples):
|
||||
target = started + (index + 1) * args.interval
|
||||
while time.monotonic() < target and proc.poll() is None:
|
||||
time.sleep(min(0.05, max(0.0, target - time.monotonic())))
|
||||
if proc.poll() is not None:
|
||||
code = proc.returncode
|
||||
return {"status": code if code >= 0 else None,
|
||||
"signal": signal.Signals(-code).name if code < 0 else None}
|
||||
width, height, rgb = parse_xwd(screen_file.read_bytes())
|
||||
sha1 = hashlib.sha1(rgb).hexdigest()
|
||||
samples.append((round(time.monotonic() - started, 3), sha1, cp.uniform_frame(rgb, 3)))
|
||||
if png_dir and not any(p.name.endswith(f"{sha1[:12]}.png") for p in png_dir.iterdir()):
|
||||
(png_dir / f"{index:04d}-{sha1[:12]}.png").write_bytes(cp.png_bytes(width, height, rgb))
|
||||
return None
|
||||
|
||||
|
||||
def run_once(args: argparse.Namespace, emu: Emulator, tree: Path, system_dir: Path, scratch: Path,
|
||||
png_dir: Path | None) -> dict:
|
||||
home = scratch / "home"
|
||||
@@ -375,28 +400,9 @@ def run_once(args: argparse.Namespace, emu: Emulator, tree: Path, system_dir: Pa
|
||||
reader = threading.Thread(target=read_lines, args=(proc.stdout, logs, samples), daemon=True)
|
||||
reader.start()
|
||||
try:
|
||||
deadline = time.monotonic() + 30
|
||||
while not screen_file.exists():
|
||||
if proc.poll() is not None or time.monotonic() > deadline:
|
||||
raise cp.ProbeError(f"Xvfb did not start in the sandbox (exit {proc.poll()}): "
|
||||
f"{' / '.join(line['text'] for line in logs[-5:])}")
|
||||
time.sleep(0.05)
|
||||
wait_for_screen(proc, screen_file, logs)
|
||||
started = time.monotonic()
|
||||
ended = None
|
||||
for index in range(args.samples):
|
||||
target = started + (index + 1) * args.interval
|
||||
while time.monotonic() < target and proc.poll() is None:
|
||||
time.sleep(min(0.05, max(0.0, target - time.monotonic())))
|
||||
if proc.poll() is not None:
|
||||
code = proc.returncode
|
||||
ended = {"status": code if code >= 0 else None,
|
||||
"signal": signal.Signals(-code).name if code < 0 else None}
|
||||
break
|
||||
width, height, rgb = parse_xwd(screen_file.read_bytes())
|
||||
sha1 = hashlib.sha1(rgb).hexdigest()
|
||||
samples.append((round(time.monotonic() - started, 3), sha1, cp.uniform_frame(rgb, 3)))
|
||||
if png_dir and not any(p.name.endswith(f"{sha1[:12]}.png") for p in png_dir.iterdir()):
|
||||
(png_dir / f"{index:04d}-{sha1[:12]}.png").write_bytes(cp.png_bytes(width, height, rgb))
|
||||
ended = sample_screen(proc, screen_file, args, samples, png_dir, started)
|
||||
wall = time.monotonic() - started
|
||||
finally:
|
||||
stop(proc)
|
||||
@@ -608,13 +614,23 @@ def _probe(args: argparse.Namespace, emu: Emulator) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
def _check_mode_problems(args: argparse.Namespace) -> list[str]:
|
||||
problems = []
|
||||
if len({dest for dest, _ in args.vary}) != 1:
|
||||
problems.append("--vary must name the same DEST in every occurrence")
|
||||
problems.extend(f"--vary {dest}={src}: not a file"
|
||||
for dest, src in args.vary if src and not Path(src).is_file())
|
||||
if args.observable not in OBSERVABLES:
|
||||
problems.append(f"--observable {args.observable}: not one of {', '.join(OBSERVABLES)}")
|
||||
return problems
|
||||
|
||||
|
||||
def validate(args: argparse.Namespace) -> list[str]:
|
||||
problems = []
|
||||
if not Path(args.content).is_file():
|
||||
problems.append(f"--content {args.content}: not a file")
|
||||
for dest, src in args.bios_file:
|
||||
if not Path(src).is_file():
|
||||
problems.append(f"--bios-file {dest}={src}: not a file")
|
||||
problems.extend(f"--bios-file {dest}={src}: not a file"
|
||||
for dest, src in args.bios_file if not Path(src).is_file())
|
||||
if args.oracle and not Path(args.oracle).is_file():
|
||||
problems.append(f"--oracle {args.oracle}: not a file")
|
||||
if args.samples < 2 or args.interval <= 0:
|
||||
@@ -630,13 +646,7 @@ def validate(args: argparse.Namespace) -> list[str]:
|
||||
if args.subject and not re.fullmatch(r"[a-z0-9]+(?:[-_][a-z0-9]+)*", args.subject):
|
||||
problems.append(f"--subject {args.subject!r}: lowercase letters, digits, - and _ only")
|
||||
if args.mode == "check":
|
||||
if len({dest for dest, _ in args.vary}) != 1:
|
||||
problems.append("--vary must name the same DEST in every occurrence")
|
||||
for dest, src in args.vary:
|
||||
if src and not Path(src).is_file():
|
||||
problems.append(f"--vary {dest}={src}: not a file")
|
||||
if args.observable not in OBSERVABLES:
|
||||
problems.append(f"--observable {args.observable}: not one of {', '.join(OBSERVABLES)}")
|
||||
problems += _check_mode_problems(args)
|
||||
return problems
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user