mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-12-03 06:48:52 -06:00
refactor: read tree members the build recorded
This commit is contained in:
1 parent
e4845ea446
commit
9491c02887
8 files changed
+42
-79
No files matched your search
@@ -1,38 +1,10 @@
|
||||
"""What the step 5 comparisons share: the inputs they read, the members set aside, the difference lines."""
|
||||
"""What the step 5 comparisons share: the inputs they read and the difference lines."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
from core.paths import EMULATORS_DIR
|
||||
from model.registry import load_data_dir_registry
|
||||
|
||||
|
||||
def tree_members(
|
||||
platform: str, platforms_dir: str, emulators_dir: str = EMULATORS_DIR,
|
||||
) -> dict[str, int]:
|
||||
"""Archive path -> size of every file the platform's data trees can add."""
|
||||
from packs import datatrees
|
||||
from model.profiles import installed_data_refs_in, load_emulator_profiles
|
||||
from model.platforms import load_platform_config
|
||||
from packs.archive import Placed
|
||||
from packs.paths import flat_arcname
|
||||
|
||||
config = load_platform_config(platform, platforms_dir)
|
||||
base_dest = config.get("base_destination", "")
|
||||
registry = load_data_dir_registry(platforms_dir)
|
||||
profiles = load_emulator_profiles(emulators_dir)
|
||||
core_trees = datatrees.core_data_trees(config, profiles, platform, registry)
|
||||
members: dict[str, int] = {}
|
||||
for src, full in datatrees.data_directory_members(
|
||||
config.get("systems", {}), registry,
|
||||
platform, base_dest, Placed(False),
|
||||
core_trees=core_trees, installed=installed_data_refs_in(platform, profiles),
|
||||
):
|
||||
members[flat_arcname(full, base_dest, True)] = os.path.getsize(src)
|
||||
return members
|
||||
|
||||
|
||||
def set_difference_lines(label: str, credited: set[str], written: set[str]) -> list[str]:
|
||||
"""The paths one side has and the other lacks, ten of each at most."""
|
||||
lines = []
|
||||
|
||||
@@ -5,7 +5,6 @@ from __future__ import annotations
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from core.paths import PLATFORMS_DIR
|
||||
from orchestrate import compare
|
||||
from orchestrate.labels import STEP_LABELS, step_title
|
||||
from packs.archive import is_pack_note
|
||||
@@ -101,15 +100,13 @@ def check_consistency(
|
||||
return all_ok
|
||||
|
||||
|
||||
def check_pack_destinations(
|
||||
destinations_file: str, counts_file: str, platforms_dir: str = PLATFORMS_DIR,
|
||||
) -> bool:
|
||||
def check_pack_destinations(destinations_file: str, counts_file: str) -> bool:
|
||||
"""Compare the paths verify credits with the members of each archive.
|
||||
|
||||
Equal counts hid a file credited on one side and another written on the
|
||||
other. The trees and the notes are the archive's own: a tree member is
|
||||
set aside when its path and size are the cached file's and verify does
|
||||
not credit the path.
|
||||
other. The trees and the notes are the archive's own: a member the
|
||||
build recorded as taken from a data directory is set aside when verify
|
||||
does not credit its path.
|
||||
"""
|
||||
import zipfile
|
||||
|
||||
@@ -131,16 +128,13 @@ def check_pack_destinations(
|
||||
continue
|
||||
entry = credited_by[names[0]]
|
||||
credited = set(entry["pack_destinations"])
|
||||
trees = compare.tree_members(entry["platform"], platforms_dir)
|
||||
trees = set(pack["trees"]) - credited
|
||||
with zipfile.ZipFile(pack["archive"]) as zf:
|
||||
written = {
|
||||
info.filename for info in zf.infolist()
|
||||
if not info.is_dir()
|
||||
and not is_pack_note(info.filename)
|
||||
and not (
|
||||
trees.get(info.filename) == info.file_size
|
||||
and info.filename not in credited
|
||||
)
|
||||
and info.filename not in trees
|
||||
}
|
||||
lines = compare.set_difference_lines(label, credited, written)
|
||||
if lines:
|
||||
|
||||
@@ -14,7 +14,8 @@ class PackCounts:
|
||||
``ok`` and ``total`` are the platform's declared files judged in the
|
||||
pack's verification mode, ``core_files`` what the pack takes from the
|
||||
cores' profiles, and ``unsafe_excluded`` the files left out because the
|
||||
frontend would reject their hash.
|
||||
frontend would reject their hash. ``trees`` names the archive members the
|
||||
build took from its data directories, which verify does not credit.
|
||||
"""
|
||||
|
||||
archive: str
|
||||
@@ -22,10 +23,13 @@ class PackCounts:
|
||||
total: int
|
||||
core_files: int
|
||||
unsafe_excluded: int
|
||||
trees: tuple[str, ...]
|
||||
|
||||
|
||||
def pack_counts(archive: str, file_status: dict[str, str], core_files: int) -> PackCounts:
|
||||
"""A pack's counts from the verdict of each declared file."""
|
||||
def pack_counts(
|
||||
archive: str, file_status: dict[str, str], core_files: int, trees: list[str],
|
||||
) -> PackCounts:
|
||||
"""A pack's counts from the verdict of each declared file and its tree members."""
|
||||
statuses = list(file_status.values())
|
||||
return PackCounts(
|
||||
archive=archive,
|
||||
@@ -33,6 +37,7 @@ def pack_counts(archive: str, file_status: dict[str, str], core_files: int) -> P
|
||||
total=len(statuses),
|
||||
core_files=core_files,
|
||||
unsafe_excluded=statuses.count("excluded"),
|
||||
trees=tuple(trees),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -505,6 +505,8 @@ class _PlatformPackBuild:
|
||||
case_twins: list[str] = field(default_factory=list)
|
||||
# (registry key, cache path) of each data directory the cache lacks.
|
||||
uncached: list[tuple[str, str]] = field(default_factory=list)
|
||||
# The archive path of each member taken from a data directory.
|
||||
trees: list[str] = field(default_factory=list)
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
self.placed = Placed(self.plan.case_insensitive)
|
||||
@@ -919,10 +921,12 @@ class _PlatformPackBuild:
|
||||
core_trees=core_trees, uncached_out=uncached,
|
||||
installed=installed_data_refs_in(plan.platform_name, plan.emu_profiles or {}),
|
||||
):
|
||||
arcname = self._flat(full)
|
||||
# The installer writes a data tree member without the bit.
|
||||
add_pack_member(self.zf, src, self._flat(full), executable=False)
|
||||
add_pack_member(self.zf, src, arcname, executable=False)
|
||||
self.trees.append(arcname)
|
||||
if isinstance(self.zf, PackRecord):
|
||||
self.zf.trees.append(self._flat(full))
|
||||
self.zf.trees.append(arcname)
|
||||
added += 1
|
||||
self.uncached.extend(uncached)
|
||||
if plan.opts.uncached_out is not None:
|
||||
@@ -1095,7 +1099,9 @@ def build_platform_pack(
|
||||
build = _PlatformPackBuild(plan, zf, declarations, resolve_extra)
|
||||
build.run()
|
||||
if opts.counts is not None:
|
||||
opts.counts.append(pack_counts(plan.zip_path, build.file_status, build.core_count))
|
||||
opts.counts.append(
|
||||
pack_counts(plan.zip_path, build.file_status, build.core_count, build.trees)
|
||||
)
|
||||
return build.outcome()
|
||||
|
||||
|
||||
|
||||
@@ -1207,7 +1207,7 @@ class PipelineRegressions(unittest.TestCase):
|
||||
"""One full pack as generate_pack.py --counts records it."""
|
||||
return {"label": label, "platforms": [label.lower().replace(" ", "")],
|
||||
"archive": "pack.zip", "ok": ok, "total": total,
|
||||
"core_files": core_files, "unsafe_excluded": unsafe_excluded}
|
||||
"core_files": core_files, "unsafe_excluded": unsafe_excluded, "trees": []}
|
||||
|
||||
def test_missing_pack_is_a_consistency_failure(self):
|
||||
verify = self._verified("RetroArch", 2, 2)
|
||||
|
||||
@@ -1437,26 +1437,29 @@ class ANativeNameSelectsOneSetEverywhere(unittest.TestCase):
|
||||
db_path = REPO_ROOT / "database.json"
|
||||
if not db_path.exists():
|
||||
raise unittest.SkipTest("database.json is not built")
|
||||
from orchestrate import compare
|
||||
from model.profiles import load_emulator_profiles
|
||||
|
||||
cls.compare = compare
|
||||
cls.db = json.loads(db_path.read_text(encoding="utf-8"))
|
||||
cls.profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
|
||||
|
||||
def _packed(self, platform: str, systems: list[str]) -> set[str]:
|
||||
def _packed(self, platform: str, systems: list[str]) -> tuple[set[str], set[str]]:
|
||||
"""The pack's members and those the build took from data directories."""
|
||||
import zipfile
|
||||
|
||||
from packs.packcounts import PackCounts
|
||||
|
||||
counts: list[PackCounts] = []
|
||||
with tempfile.TemporaryDirectory() as out:
|
||||
zip_path = platformpack.build_platform_pack(
|
||||
platform, str(REPO_ROOT / "platforms"), self.db,
|
||||
str(REPO_ROOT / "bios"), out,
|
||||
emulators_dir=str(REPO_ROOT / "emulators"),
|
||||
emu_profiles=self.profiles, system_filter=systems, offline=True,
|
||||
counts=counts,
|
||||
).zip_path
|
||||
with zipfile.ZipFile(zip_path) as zf:
|
||||
infos = [i for i in zf.infolist() if not i.is_dir()]
|
||||
return {i.filename: i.file_size for i in infos}
|
||||
names = {i.filename for i in zf.infolist() if not i.is_dir()}
|
||||
return names, set(counts[0].trees)
|
||||
|
||||
def test_pack_verify_and_installer_agree(self):
|
||||
from model.platforms import load_platform_config
|
||||
@@ -1477,12 +1480,10 @@ class ANativeNameSelectsOneSetEverywhere(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(report["systems"], [system_id])
|
||||
credited = set(report["pack_destinations"])
|
||||
trees = self.compare.tree_members(platform, str(REPO_ROOT / "platforms"))
|
||||
members = self._packed(platform, chosen)
|
||||
members, trees = self._packed(platform, chosen)
|
||||
written = {
|
||||
name for name, size in members.items()
|
||||
if not is_pack_note(name)
|
||||
and not (trees.get(name) == size and name not in credited)
|
||||
name for name in members
|
||||
if not is_pack_note(name) and name not in trees - credited
|
||||
}
|
||||
self.assertTrue(written)
|
||||
self.assertEqual(credited, written)
|
||||
|
||||
@@ -291,12 +291,14 @@ class ThePipelineComparesPaths(unittest.TestCase):
|
||||
self.addCleanup(shutil.rmtree, root, True)
|
||||
zip_path = root / "Plat_BIOS_Pack.zip"
|
||||
with zipfile.ZipFile(zip_path, "w") as zf:
|
||||
for name in ("a.bin", "b.bin", "README.txt", "INSTRUCTIONS_x.bin.txt"):
|
||||
for name in ("a.bin", "b.bin", "README.txt", "INSTRUCTIONS_x.bin.txt", "tree/t.dat"):
|
||||
zf.writestr(name, name)
|
||||
counts = root / "counts.json"
|
||||
# The build records its tree members: set aside, never recomputed.
|
||||
counts.write_text(json.dumps([{
|
||||
"label": "plat", "platforms": ["plat"], "archive": str(zip_path),
|
||||
"ok": 2, "total": 2, "core_files": 0, "unsafe_excluded": 0,
|
||||
"trees": ["tree/t.dat"],
|
||||
}]))
|
||||
for credited, expected in ((["a.bin", "b.bin"], True), (["a.bin", "c.bin"], False)):
|
||||
with self.subTest(credited=credited):
|
||||
@@ -305,13 +307,8 @@ class ThePipelineComparesPaths(unittest.TestCase):
|
||||
{"plat": {"platform": "plat", "label": "Plat", "ok": 2, "total": 2,
|
||||
"core_files": 0, "pack_destinations": credited}}
|
||||
))
|
||||
previous = os.getcwd()
|
||||
os.chdir(REPO_ROOT)
|
||||
try:
|
||||
with mock_tree_members(), contextlib.redirect_stdout(io.StringIO()) as out:
|
||||
ok = check_pack_destinations(str(destinations), str(counts))
|
||||
finally:
|
||||
os.chdir(previous)
|
||||
with contextlib.redirect_stdout(io.StringIO()) as out:
|
||||
ok = check_pack_destinations(str(destinations), str(counts))
|
||||
self.assertIs(ok, expected, out.getvalue())
|
||||
if not expected:
|
||||
self.assertIn("verify only 1: c.bin", out.getvalue())
|
||||
@@ -327,18 +324,6 @@ class ThePipelineComparesPaths(unittest.TestCase):
|
||||
self.assertIn('"--counts",\n counts_file,', source)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def mock_tree_members():
|
||||
from orchestrate import compare
|
||||
|
||||
original = compare.tree_members
|
||||
compare.tree_members = lambda *_args: {}
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
compare.tree_members = original
|
||||
|
||||
|
||||
class EveryEmulatorPackMatchesItsReport(unittest.TestCase):
|
||||
"""Reads the repository: every profile, both builds, built in memory."""
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ class APlatformWithoutAPackFailsNoCheck(unittest.TestCase):
|
||||
}
|
||||
PACKS = [{"label": "retroarch", "platforms": ["retroarch"],
|
||||
"archive": "dist/RetroArch_BIOS_Pack.zip", "ok": 10, "total": 10,
|
||||
"core_files": 0, "unsafe_excluded": 0}]
|
||||
"core_files": 0, "unsafe_excluded": 0, "trees": []}]
|
||||
|
||||
def test_the_consistency_step_skips_a_setup_served_by_the_installer(self):
|
||||
from orchestrate.consistency import compare_counts
|
||||
|
||||
Reference in new issue
Block a user