fix: share the gap report scope with the site

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 06:03:37 +01:00
1 parent a119efc149
commit a34949d9e4
7 files changed
+70 -130

No files matched your search

+6 -16
View File
@@ -24,7 +24,6 @@ from model.cliargs import platform_arg, list_emulator_profiles, require_platform
from model.profiles import ProfileSelectionError, load_emulator_profiles, select_emulator_profiles
from model.database import load_database
from model.registry import list_registered_platforms, load_data_dir_registry
from model.declarations import merged_platform_declared_contents
from model.platforms import load_platform_config
from model.safeparse import require_yaml
from resolve.standalone import standalone_set
@@ -37,10 +36,9 @@ from resolve.launchers import (
from packs.crossref import (
build_supplemental_index,
cross_reference,
declared_names,
folded_declared_slots,
global_report_scope,
launcher_reads_not_held,
load_platform_files,
platform_configs,
profile_breakdown,
)
@@ -351,21 +349,13 @@ def main() -> None:
return
selected = [args.platform] if args.platform else None
declared, plat_data_dirs = load_platform_files(args.platforms_dir, selected)
db = load_database(args.db)
declared, global_scope = global_report_scope(
platform_configs(args.platforms_dir, selected), db)
global_scope["standalone_cores"] = standalone_cores
data_names = build_supplemental_index()
report = cross_reference(
profiles, declared, db, plat_data_dirs, data_names,
all_declared=declared_names(args.platforms_dir, selected, db),
standalone_cores=standalone_cores,
folded_slots=folded_declared_slots(args.platforms_dir, selected, db),
declared_contents=merged_platform_declared_contents(
[
load_platform_config(name, args.platforms_dir)
for name in selected or list_registered_platforms(args.platforms_dir)
],
db,
),
profiles, declared, db, data_names, **global_scope,
platform=(
platform_scope.config.get("_key", args.platform) if platform_scope else ""
),
+40 -63
View File
@@ -56,75 +56,54 @@ if TYPE_CHECKING:
from typing_extensions import Unpack
def load_platform_files(
platforms_dir: str,
platforms: list[str] | None = None,
) -> tuple[dict[str, set[str]], dict[str, set[str]]]:
"""Collect declared filenames + data_directories per system.
def platform_configs(platforms_dir: str, platforms: list[str] | None = None) -> list[dict]:
"""The configs of *platforms*, otherwise of every registered platform."""
return [
load_platform_config(platform_name, platforms_dir)
for platform_name in platforms or list_registered_platforms(platforms_dir)
]
Restricted to *platforms* when given, otherwise every registered platform.
Keyed by the normalized system ID: a profile writes `sega-megacd` where
RetroArch writes `sega-mega-cd`, and an exact match called 924 declared
files undeclared.
def global_report_scope(
configs: list[dict], db: dict,
) -> tuple[dict[str, set[str]], ReportScope]:
"""What a gap report over *configs* compares against: the names each
system declares, and the scope cross_reference reads.
The declared names are keyed by the normalized system ID: a profile
writes `sega-megacd` where RetroArch writes `sega-mega-cd`, and an exact
match called 924 declared files undeclared. `all_declared` is every name
with each declaration's size and slot: judged per normalized system id,
646 entries whose exact name a platform declares (bk and elektronika-bk,
nintendo-sgb and nintendo-super-game-boy) were counted undeclared.
`folded_slots` holds the slots a case-folding filesystem fills under any
spelling (RetroBat's 32X_G_BIOS.BIN is BlastEm's 32X_G_BIOS.bin), and
`declared_contents` the members of a declared archive. The command line
and the site's gap page read this one scope.
"""
from model.declarations import (
merged_platform_declarations,
merged_platform_declared_contents,
platform_declarations,
)
from resolve.standalone import merged_standalone_set
declared: dict[str, set[str]] = {}
platform_data_dirs: dict[str, set[str]] = {}
for platform_name in platforms or list_registered_platforms(
platforms_dir
):
config = load_platform_config(platform_name, platforms_dir)
for config in configs:
for sys_id, system in config.get("systems", {}).items():
for fe in system.get("files", []):
name = fe.get("name", "")
if name:
declared.setdefault(norm_system_id(sys_id), set()).add(name)
for dd in system.get("data_directories", []):
ref = dd.get("ref", "")
if ref:
platform_data_dirs.setdefault(norm_system_id(sys_id), set()).add(ref)
return declared, platform_data_dirs
def declared_names(
platforms_dir: str, platforms: list[str] | None, db: dict
) -> dict[str, list[tuple[int | None, str]]]:
"""Every name the platforms declare, with each declaration's size and slot.
The report judged "undeclared" per normalized system id, which does not
bring bk and elektronika-bk, or nintendo-sgb and nintendo-super-game-boy,
together: 646 entries whose exact name a platform declares were counted
undeclared, while verify and the site read one flat index.
"""
from model.declarations import merged_platform_declarations
return merged_platform_declarations(
[
load_platform_config(platform_name, platforms_dir)
for platform_name in platforms or list_registered_platforms(
platforms_dir
)
],
db,
)
def folded_declared_slots(
platforms_dir: str, platforms: list[str] | None, db: dict
) -> frozenset[str]:
"""The slots platforms whose filesystem folds case fill, any spelling.
RetroBat's 32X_G_BIOS.BIN is the file BlastEm opens as 32X_G_BIOS.bin,
and the exact-case name test called it undeclared.
"""
from model.declarations import platform_declarations
slots: set[str] = set()
for platform_name in platforms or list_registered_platforms(
platforms_dir
):
config = load_platform_config(platform_name, platforms_dir)
slots |= case_folded_slots(config, platform_declarations(config, db))
return frozenset(slots)
folded: frozenset[str] = frozenset().union(*(
case_folded_slots(config, platform_declarations(config, db)) for config in configs
))
return declared, {
"all_declared": merged_platform_declarations(configs, db),
"standalone_cores": merged_standalone_set(configs),
"folded_slots": folded,
"declared_contents": merged_platform_declared_contents(configs, db),
}
def build_supplemental_index(
@@ -1387,7 +1366,6 @@ def cross_reference(
profiles: dict[str, dict],
declared: dict[str, set[str]],
db: dict,
platform_data_dirs: dict[str, set[str]] | None = None,
data_names: set[str] | None = None,
**scope: Unpack[ReportScope],
) -> dict:
@@ -1415,7 +1393,6 @@ def cross_reference(
platform = scope.get("platform", "")
launcher_layer = scope.get("launcher_layer")
declared_contents = scope.get("declared_contents")
platform_data_dirs = platform_data_dirs or {}
report: dict[str, dict] = {}
index = {
+4 -35
View File
@@ -249,47 +249,16 @@ def build_emulator_gap_report(
The gap analysis page and the published gaps export must not compute this
twice and drift. Both read this one report.
"""
from model.systems import norm_system_id
from model.declarations import merged_platform_declarations
from packs.crossref import cross_reference as run_cross_reference
# Enriched with alias resolution, with each declaration's size and slot:
# a name alone settled DOSBox's 32 KiB SC-55 ROM1.BIN on Galaksija's.
all_declared = merged_platform_declarations(
[cov["config"] for cov in coverages.values()], db
)
declared: dict[str, set[str]] = {}
for cov in coverages.values():
config = cov["config"]
for sys_id, system in config.get("systems", {}).items():
for fe in system.get("files", []):
fname = fe.get("name", "")
if fname:
declared.setdefault(norm_system_id(sys_id), set()).add(fname)
from packs.crossref import cross_reference as run_cross_reference, global_report_scope
declared, scope = global_report_scope(
[cov["config"] for cov in coverages.values()], db)
unique_profiles = {
k: v
for k, v in profiles.items()
if is_emulator(v)
}
from resolve.standalone import merged_standalone_set
from model.declarations import platform_declarations
from resolve.validation import case_folded_slots
# The command line passes these too: without them a RetroBat file named
# 32X_G_BIOS.BIN read as missing for a core opening 32X_G_BIOS.bin.
folded = frozenset().union(*(
case_folded_slots(cov["config"], platform_declarations(cov["config"], db))
for cov in coverages.values()
))
return run_cross_reference(
unique_profiles, declared, db,
data_names=data_names, all_declared=all_declared,
standalone_cores=merged_standalone_set(
cov["config"] for cov in coverages.values()
),
folded_slots=folded,
)
return run_cross_reference(unique_profiles, declared, db, data_names=data_names, **scope)
def _gap_export_rows(
+5 -6
View File
@@ -13,7 +13,7 @@ import tests
import unittest
from pathlib import Path
from packs.crossref import cross_reference, declared_names, load_platform_files
from packs.crossref import cross_reference, global_report_scope, platform_configs
REPO_ROOT = Path(__file__).resolve().parent.parent
@@ -39,11 +39,10 @@ class FlatDeclaredSet(unittest.TestCase):
}}
db = {"files": {}, "indexes": {"by_name": {}, "by_md5": {}, "by_crc32": {},
"by_path_suffix": {}}}
declared, data_dirs = load_platform_files(str(platforms), ["fx"])
per_system = cross_reference(profiles, declared, db, data_dirs, set())
declared, scope = global_report_scope(platform_configs(str(platforms), ["fx"]), db)
per_system = cross_reference(profiles, declared, db, set())
flat = cross_reference(
profiles, declared, db, data_dirs, set(),
all_declared=declared_names(str(platforms), ["fx"], db),
profiles, declared, db, set(), all_declared=scope["all_declared"],
)
self.assertEqual([g["name"] for g in per_system["sgbcore"]["gap_details"]],
["sgb.boot.rom"])
@@ -62,7 +61,7 @@ class AnAliasIsADeclaration(unittest.TestCase):
db = {"files": {}, "indexes": {"by_name": {}, "by_md5": {}, "by_crc32": {},
"by_path_suffix": {}}}
report = cross_reference(
profiles, {}, db, {}, {"by_name": {}},
profiles, {}, db, {"by_name": {}},
all_declared={"kick40060.CD32"},
)
self.assertEqual(report["amiberry"]["gap_details"], [])
+4 -3
View File
@@ -5792,7 +5792,7 @@ struct BurnDriver BurnDrvneogeo = {
def test_226_cross_reference_platform_filter(self):
"""--platform restricts declarations to that platform alone."""
from packs.crossref import load_platform_files
from packs.crossref import global_report_scope, platform_configs
with tempfile.TemporaryDirectory() as tmpdir:
plat_dir = os.path.join(tmpdir, "platforms")
@@ -5816,10 +5816,11 @@ struct BurnDriver BurnDrvneogeo = {
# Keyed by the normalized system ID, as profiles spell systems
# differently from platforms.
everything, _ = load_platform_files(plat_dir)
db = {"files": {}, "indexes": {}}
everything, _ = global_report_scope(platform_configs(plat_dir), db)
self.assertEqual(everything["sharedsystem"], {"a.bin", "b.bin"})
only_alpha, _ = load_platform_files(plat_dir, ["alpha"])
only_alpha, _ = global_report_scope(platform_configs(plat_dir, ["alpha"]), db)
self.assertEqual(only_alpha["sharedsystem"], {"a.bin"})
+6 -3
View File
@@ -100,9 +100,11 @@ class TheRunningBuildPlacesTheGap(unittest.TestCase):
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."""
gaps page listed RetroBat files the CLI report settled; later the CLI
passed declared_contents and the site did not, 20 gaps apart. Both
take their scope from packs.crossref.global_report_scope."""
def test_each_cross_reference_call_passes_the_folded_slots(self):
def test_each_cross_reference_call_reads_the_shared_scope(self):
import ast
for script in ("cross_reference.py", "generate_site.py"):
@@ -114,8 +116,9 @@ class EveryGapReportFoldsCase(unittest.TestCase):
]
with self.subTest(script=script):
self.assertTrue(calls)
self.assertIn("global_report_scope(", source)
for call in calls:
self.assertIn("folded_slots", {kw.arg for kw in call.keywords})
self.assertIn(None, {kw.arg for kw in call.keywords})
if __name__ == "__main__":
+5 -4
View File
@@ -430,18 +430,19 @@ class LauncherLayerTest(unittest.TestCase):
"""cross_reference --platform batocera listed duckstation's
scph1002a.bin as packed while the PAL slot was filled by the
launcher's scph5502.bin, which verify and the builder both knew."""
from packs.crossref import cross_reference, declared_names, load_platform_files
from packs.crossref import cross_reference, global_report_scope, platform_configs
from resolve.launchers import declared_destinations
selected = ["launchertest"]
declared, data_dirs = load_platform_files(self.platforms_dir, selected)
declared, scope = global_report_scope(
platform_configs(self.platforms_dir, selected), self.db)
layer = LauncherLayer(
self.config, self.profiles, self.profiles, self.db,
declared_destinations(self.config),
)
report = cross_reference(
self.profiles, declared, self.db, data_dirs, set(),
all_declared=declared_names(self.platforms_dir, selected, self.db),
self.profiles, declared, self.db, set(),
all_declared=scope["all_declared"],
standalone_cores={"psxemu", "fixemu"},
platform="launchertest", launcher_layer=layer,
)