diff --git a/scripts/packs/crossref.py b/scripts/packs/crossref.py index 279c6a860..b8c1c4554 100644 --- a/scripts/packs/crossref.py +++ b/scripts/packs/crossref.py @@ -106,10 +106,52 @@ def whole_tree_gaps( standalone layout is proven against them. """ declared, scope = global_report_scope(configs, db, profiles) - return cross_reference( + report = cross_reference( emulator_profiles(profiles if compared is None else compared), declared, db, data_names, **scope, ) + _record_needing_platforms(report, configs, profiles) + return report + + +def _record_needing_platforms( + report: dict, configs: list[dict], profiles: dict[str, dict], +) -> None: + """Give each missing row the platforms whose build of its emulator needs it. + + A platform needs the entry when the build it runs reads it (BlastEm's + cdbios.bin is read by the standalone build only), its launcher does not + point the emulator elsewhere (`unread_on`) and its package of the + emulator does not install it (`installed_on`, `not_bundled_on`). + """ + from resolve.cores import resolve_platform_cores + from resolve.standalone import standalone_set + from resolve.validation import filter_files_by_mode + + missing = [ + (emu_name, gap) for emu_name, data in report.items() + for gap in data["gap_details"] if gap["source"] == "missing" + ] + if not missing: + return + runners: dict[str, list[tuple[str, set[str]]]] = {} + runnable = emulator_profiles(profiles) + for config in configs: + platform = str(config.get("_key") or "") + standalone = standalone_set(config, profiles) + for emu_name in resolve_platform_cores(config, runnable): + runners.setdefault(emu_name, []).append((platform, standalone)) + for emu_name, gap in missing: + profile = profiles[emu_name] + gap["platforms"] = sorted( + platform for platform, standalone in runners.get(emu_name, []) + if any( + f.get("name") == gap["name"] and not unread_on(f, platform) + and not installed_with_emulator(f, platform) + for view, is_standalone in platform_layouts(emu_name, profile, standalone) + for f in filter_files_by_mode(view.get("files") or [], is_standalone) + ) + ) diff --git a/scripts/sitegen/gaps.py b/scripts/sitegen/gaps.py index 016dc6db2..d183b0849 100644 --- a/scripts/sitegen/gaps.py +++ b/scripts/sitegen/gaps.py @@ -11,9 +11,7 @@ from core.hashing import declared_hash_lists from core.text import series from model.database import sha1_at from model.platforms import native_layer -from model.profiles import is_emulator from packs.crossref import gap_source_counts, whole_tree_gaps -from resolve.cores import resolve_platform_cores from resolve.nativemode import check_label from resolve.sendable import sendable from sitegen import markup, wanted as sitewanted @@ -369,25 +367,6 @@ PER_EMULATOR_STEM = "gaps-per-emulator" NOT_COLLECTED_STEM = "gaps-not-collected" -def reading_platforms(emu_name: str, profiles: dict[str, dict], name: str, - configs: dict[str, dict]) -> set[str]: - """Of the platforms running an emulator (name -> config), those whose - build of it reads the entry: BlastEm's cdbios.bin is read by the - standalone build only, and RetroBat hands that build other names. - *profiles* is every profile of the run, the emulator's among them.""" - from resolve.standalone import platform_layouts, standalone_set - from resolve.validation import filter_files_by_mode, unread_on - - profile = profiles[emu_name] - return { - platform for platform, config in configs.items() - if any(f.get("name") == name and not unread_on(f, platform) - for view, standalone in platform_layouts( - emu_name, profile, standalone_set(config, profiles)) - for f in filter_files_by_mode(view.get("files") or [], standalone)) - } - - @dataclass class _VerifyTally: """Verify results aggregated across all platforms.""" @@ -526,22 +505,6 @@ def _divergence_rows( return div_rows -def _emulator_platforms(profiles: dict, coverages: dict) -> dict[str, set[str]]: - """Each emulator with the platforms that run it.""" - emu_to_platforms: dict[str, set[str]] = {} - unique_profiles = { - k: v - for k, v in profiles.items() - if is_emulator(v) - } - for pname in coverages: - config = coverages[pname]["config"] - matched = resolve_platform_cores(config, unique_profiles) - for emu_name in matched: - emu_to_platforms.setdefault(emu_name, set()).add(pname) - return emu_to_platforms - - @dataclass class _MissingFiles: """The files to find, one row each, and the entries they come from.""" @@ -581,12 +544,14 @@ def _missing_files(emulator_gaps: list[tuple[str, dict]]) -> _MissingFiles: "emu_keys": [emu_name], "required": g["required"], "source_ref": g["source_ref"], + "platforms": set(g.get("platforms") or ()), } found.rows.append(row) elif emu_name not in row["emu_keys"]: row["emulators"].append(data["emulator"]) row["emu_keys"].append(emu_name) row["required"] = row["required"] or g["required"] + row["platforms"].update(g.get("platforms") or ()) return found @@ -601,14 +566,10 @@ class SourceListing: placer: sitewanted.Placer | None = None -def _source_row(m: dict, profiles: dict, coverages: dict, - emu_to_platforms: dict[str, set[str]], placer: sitewanted.Placer | None) -> str: - """The row of one file to source.""" - plats = sorted(set().union( - *(reading_platforms(key, profiles, m["name"], { - p: coverages[p]["config"] for p in emu_to_platforms.get(key, set()) - }) for key in m["emu_keys"]) - )) +def _source_row(m: dict, profiles: dict, placer: sitewanted.Placer | None) -> str: + """The row of one file to source, with the platforms the gap report + found needing it.""" + plats = sorted(m["platforms"]) plat_badges = ( " ".join( f'{p}' @@ -1004,12 +965,11 @@ def generate_gap_analysis( lines.extend(_complement_intro(src_totals, total_undeclared, emulator_gaps, listing.moved)) # List truly missing files with platform impact - emu_to_platforms = _emulator_platforms(profiles, coverages) missing = _missing_files(emulator_gaps) if missing.rows: counted = _source_counted(missing) rows = [ - _source_row(m, profiles, coverages, emu_to_platforms, listing.placer) + _source_row(m, profiles, listing.placer) for m in sorted(missing.rows, key=lambda x: (not x["required"], x["name"])) ] lines.extend(["### Files to source", "", counted, diff --git a/tests/test_gap_settlement.py b/tests/test_gap_settlement.py index 05204f08d..89c120a30 100644 --- a/tests/test_gap_settlement.py +++ b/tests/test_gap_settlement.py @@ -98,6 +98,62 @@ class TheRunningBuildPlacesTheGap(unittest.TestCase): self.assertEqual(self._gap_paths(set()), ["Cemu/keys.txt"]) +class MissingRowsNameTheirPlatforms(unittest.TestCase): + """The gaps page decided again which platforms a missing file affects, + without installed_on: lzdoom's doom1.wad, which RetroPie's package + downloads, was badged retropie.""" + + PROFILE = {"emulator": "Engine", "type": "standalone + libretro", "systems": ["doom"], + "files": [ + {"name": "a.wad", "installed_on": ["beta"]}, + {"name": "b.bin", "unread_on": ["alpha"]}, + {"name": "c.bin", "mode": "standalone"}, + {"name": "d.bin", "bundled": True, "not_bundled_on": ["alpha"]}, + ]} + + def platforms(self) -> dict[str, list[str]]: + from packs.crossref import whole_tree_gaps + + configs = [ + {"_key": "alpha", "cores": ["engine"], "systems": {}}, + {"_key": "beta", "cores": ["engine"], "systems": {}}, + {"_key": "gamma", "cores": ["engine"], "standalone_cores": ["engine"], + "systems": {}}, + {"_key": "delta", "cores": ["other"], "systems": {}}, + ] + report = whole_tree_gaps(configs, {"files": {}, "indexes": {}}, + {"engine": self.PROFILE}) + return {g["name"]: g["platforms"] for g in report["engine"]["gap_details"]} + + def test_each_platform_rule_is_applied(self): + self.assertEqual(self.platforms(), { + "a.wad": ["alpha", "gamma"], + "b.bin": ["beta", "gamma"], + "c.bin": ["gamma"], + "d.bin": ["alpha"], + }) + + def test_real_profiles_name_only_the_platforms_that_need_them(self): + """cdbios.bin, read by standalone BlastEm only and never on RetroBat, + was badged retroarch, lakka and retrobat.""" + import yaml + + from model.platforms import load_platform_config + from packs.crossref import whole_tree_gaps + + profiles = { + name: yaml.safe_load((REPO_ROOT / "emulators" / f"{name}.yml").read_text(encoding="utf-8")) + for name in ("blastem", "lzdoom") + } + configs = [load_platform_config(name, str(REPO_ROOT / "platforms")) + for name in ("retroarch", "lakka", "retrobat", "retropie")] + report = whole_tree_gaps(configs, {"files": {}, "indexes": {}}, profiles) + found = {(emu, g["name"]): set(g["platforms"]) + for emu, data in report.items() for g in data["gap_details"]} + self.assertFalse(found[("blastem", "cdbios.bin")] & {"retroarch", "lakka", "retrobat"}) + self.assertNotIn("retropie", found[("lzdoom", "doom1.wad")]) + + class EveryGapReportFoldsCase(unittest.TestCase): """The command line passed folded_slots and the site did not, so the gaps page listed RetroBat files the CLI report settled. Later the CLI diff --git a/tests/test_site_render.py b/tests/test_site_render.py index 774141b6f..e58bb5f92 100644 --- a/tests/test_site_render.py +++ b/tests/test_site_render.py @@ -104,25 +104,6 @@ class BundledFilesAreNotToSource(unittest.TestCase): self.assertIn("| [ZQuest Classic](emulators/zq.md) | 4 | 1 | 0 | 0 | 2 | " '1 |', page) - def test_a_row_names_only_the_platforms_that_read_it(self): - """cdbios.bin, read by standalone BlastEm only and never on RetroBat, - was badged retroarch, lakka and retrobat.""" - from sitegen import gaps - from model.platforms import load_platform_config - from resolve.cores import resolve_platform_cores - - root = Path(__file__).resolve().parents[1] - profile = yaml.safe_load((root / "emulators" / "blastem.yml").read_text(encoding="utf-8")) - configs = {} - for name in ("retroarch", "lakka", "retrobat", "batocera"): - config = load_platform_config(name, str(root / "platforms")) - if "blastem" in resolve_platform_cores(config, {"blastem": profile}): - configs[name] = config - self.assertIn("retroarch", configs) - self.assertIn("retrobat", configs) - found = gaps.reading_platforms("blastem", {"blastem": profile}, "cdbios.bin", configs) - self.assertFalse(found & {"retroarch", "lakka", "retrobat"}, found) - class StructuredBlocks(unittest.TestCase): PIN = "1e0de94dc7e669c0925a22c0fccf6cdc837af0a0"