fix: prove launcher records against run profiles

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 21:42:19 +01:00
1 parent e36516f3b0
commit 1839916ca2
35 files changed
+179 -160

No files matched your search

+1 -1
View File
@@ -78,7 +78,7 @@ def doubled_destinations(
collisions = find_collisions(scraped, db, zip_contents, data_registry)
if not collisions:
return []
standalone = standalone_set(scraped)
standalone = standalone_set(scraped, profiles)
named: dict[str, list[tuple[str, dict, dict, bool]]] = {}
for key in sorted(resolve_platform_cores(scraped, profiles)):
profile = profiles[key]
+2 -2
View File
@@ -66,7 +66,7 @@ def platform_configs(platforms_dir: str, platforms: list[str] | None = None) ->
def global_report_scope(
configs: list[dict], db: dict,
configs: list[dict], db: dict, profiles: dict[str, 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.
@@ -101,7 +101,7 @@ def global_report_scope(
))
return declared, {
"all_declared": merged_platform_declarations(configs, db),
"standalone_cores": merged_standalone_set(configs),
"standalone_cores": merged_standalone_set(configs, profiles),
"folded_slots": folded,
"declared_contents": merged_platform_declared_contents(configs, db),
}
+2 -2
View File
@@ -70,13 +70,13 @@ def run_gap_report(args: argparse.Namespace, parser: argparse.ArgumentParser) ->
raise SystemExit(f"ERROR: {exc}") from None
profiles = {k: v for k, v in profiles.items() if k == emulator}
tree = tree_scope(args.platform, args.target, args.platforms_dir, profiles)
tree = tree_scope(args.platform, args.target, args.platforms_dir, profiles, all_profiles)
if not tree.profiles:
refuse_empty_scope(args, emulator, tree)
return
db = load_database(args.db)
report = scope_gaps(tree, db, args.platforms_dir, args.platform)
report = scope_gaps(tree, db, args.platforms_dir, args.platform, all_profiles)
launcher_reads, unproven = launcher_rows(
tree.selected, args.platforms_dir, db, all_profiles, registry, emulator,
)
+5 -2
View File
@@ -12,11 +12,14 @@ from packs.crossrefscope import TreeScope
from resolve.launchers import LauncherLayer, declared_destinations
def scope_gaps(tree: TreeScope, db: dict, platforms_dir: str, platform: str | None) -> dict:
def scope_gaps(
tree: TreeScope, db: dict, platforms_dir: str, platform: str | None,
all_profiles: dict[str, dict],
) -> dict:
"""Each profile of the scope with the files its platforms leave undeclared."""
platform_scope = tree.platform
declared, global_scope = global_report_scope(
platform_configs(platforms_dir, tree.selected), db)
platform_configs(platforms_dir, tree.selected), db, all_profiles)
global_scope["standalone_cores"] = tree.standalone_cores
data_names = build_supplemental_index()
return cross_reference(
+16 -8
View File
@@ -26,8 +26,12 @@ class PlatformScope:
def platform_scope(
platform: str, target: str | None, platforms_dir: str, profiles: dict[str, dict],
all_profiles: dict[str, dict],
) -> PlatformScope:
"""The scope of a --platform run, narrowed to its --target cores."""
"""The scope of a --platform run, narrowed to its --target cores.
*all_profiles* is every profile of the run, whatever --emulator keeps:
the launcher records are proven against them."""
# A typo ended in a traceback where verify and slots name the closest
# target, and is refused the way they refuse it.
target_cores = target_scope(
@@ -40,7 +44,7 @@ def platform_scope(
)
return PlatformScope(
{k: v for k, v in profiles.items() if k in relevant},
standalone_set(config),
standalone_set(config, all_profiles),
config,
relevant,
run_anywhere,
@@ -60,7 +64,7 @@ class TreeScope:
def target_platforms_scope(
target: str, platforms_dir: str, profiles: dict[str, dict],
target: str, platforms_dir: str, profiles: dict[str, dict], all_profiles: dict[str, dict],
) -> TreeScope:
"""--target without --platform: every platform that has the target, each
with the cores it builds for it, the way verify and generate_pack read
@@ -75,28 +79,32 @@ def target_platforms_scope(
relevant |= set(resolve_platform_cores(config, profiles, target_cores=cache.get(name)))
return TreeScope(
{k: v for k, v in profiles.items() if k in relevant},
merged_standalone_set(configs.values()),
merged_standalone_set(configs.values(), all_profiles),
kept,
)
def tree_scope(
platform: str | None, target: str | None, platforms_dir: str, profiles: dict[str, dict],
all_profiles: dict[str, dict],
) -> TreeScope:
"""The scope --platform, --target or neither asks for."""
if platform:
scope = platform_scope(platform, target, platforms_dir, profiles)
scope = platform_scope(platform, target, platforms_dir, profiles, all_profiles)
return TreeScope(scope.profiles, scope.standalone_cores, [platform], scope)
if target:
return target_platforms_scope(target, platforms_dir, profiles)
return target_platforms_scope(target, platforms_dir, profiles, all_profiles)
# The tree as every platform runs it: a profile some platform runs
# standalone keeps its standalone entries. Laid out as libretro only,
# eka2l1, dolphin and xenia-edge lost 133 files no platform declares.
return TreeScope(
profiles,
merged_standalone_set(
load_platform_config(name, platforms_dir)
for name in list_registered_platforms(platforms_dir)
(
load_platform_config(name, platforms_dir)
for name in list_registered_platforms(platforms_dir)
),
all_profiles,
),
None,
)
+1 -1
View File
@@ -67,7 +67,7 @@ def core_data_trees(
if not data_registry:
return []
installed = installed_data_refs(platform_name)
handed = standalone_set(config)
handed = standalone_set(config, profiles)
# Relative to base_destination, which the members are written under. A
# platform with none writes its BIOS folder into every destination, and
# the trees go there as the core extras do.
+1 -1
View File
@@ -1535,7 +1535,7 @@ def collect_emulator_extras(
return extras
relevant = resolve_platform_cores(config, profiles, target_cores=target_cores)
standalone_set = platform_standalone_set(config)
standalone_set = platform_standalone_set(config, profiles)
by_name = db.get("indexes", {}).get("by_name", {})
# Build set of filenames already covered (platform baseline + first pass extras)
+2 -2
View File
@@ -484,7 +484,7 @@ def find_undeclared_files(
)
relevant = resolve_platform_cores(config, profiles, target_cores=target_cores)
standalone_set = platform_standalone_set(config)
standalone_set = platform_standalone_set(config, profiles)
# What the platform's own launchers open, matched to the cores it runs:
# the one decision the builder and this report both read.
launcher_layer = LauncherLayer(
@@ -647,6 +647,7 @@ def find_exclusion_notes(
platform_systems.add(sys_id)
relevant = resolve_platform_cores(config, profiles, target_cores=target_cores)
standalone_set = platform_standalone_set(config, profiles)
notes = []
for emu_name, profile in sorted(profiles.items()):
emu_systems = set(profile.get("systems", []))
@@ -682,7 +683,6 @@ def find_exclusion_notes(
# Count standalone-only files, but only report as excluded if the
# platform does NOT use this emulator in standalone mode
standalone_set = platform_standalone_set(config)
is_standalone = runs_standalone(emu_name, profile, standalone_set)
if not is_standalone:
standalone_files = [
+1 -1
View File
@@ -544,7 +544,7 @@ def slot_choices(
platform_profiles,
db,
config.get("base_destination", ""),
platform_standalone_set(config),
platform_standalone_set(config, profiles),
zip_contents,
data_dir_registry,
)
+1 -1
View File
@@ -29,7 +29,7 @@ def scan_platform(
relevant,
db,
config.get("base_destination", ""),
platform_standalone_set(config),
platform_standalone_set(config, profiles),
build_zip_contents_index(db) if zip_index is None else zip_index,
load_data_dir_registry(platforms_dir) if data_registry is None else data_registry,
)
+5 -3
View File
@@ -68,12 +68,14 @@ def platform_system(config: dict, system: str) -> str | None:
return matches[0] if matches else None
def libretro_build_runs(name: str, profile: dict, config: dict) -> bool:
def libretro_build_runs(
name: str, profile: dict, config: dict, profiles: dict[str, dict]
) -> bool:
"""The platform launches this profile's libretro build: it has one, and
the platform does not run the emulator standalone only."""
if "libretro" not in str(profile.get("type", "")) or profile.get("type") == "alias":
return False
standalone = standalone_set(config)
standalone = standalone_set(config, profiles)
if not runs_standalone(name, profile, standalone):
return True
dual = {c.removeprefix(DUAL_MODE_PREFIX) for c in standalone if c.startswith(DUAL_MODE_PREFIX)}
@@ -102,7 +104,7 @@ def choose_cores(config: dict, profiles: dict[str, dict], system: str, buildbot:
profile = profiles[name]
if wanted not in {norm_system_id(s) for s in profile.get("systems") or ()}:
continue
if not libretro_build_runs(name, profile, config):
if not libretro_build_runs(name, profile, config, profiles):
continue
out.extend(CoreChoice(name, so) for so in so_names(name, profile, buildbot, target))
return out
+2 -5
View File
@@ -8,8 +8,7 @@ import os
from model.platforms import load_platform_config
from model.sources import source_yaml_file
from resolve.layout import CORE_DIR_PREFIX
from resolve.standalone import standalone_set
from resolve.standalone import core_dir_tags
def group_identical_platforms(
@@ -66,9 +65,7 @@ def group_identical_platforms(
bool(config.get("case_insensitive_fs")),
# Where each core's files go: the same cores handed other
# folders make another pack.
sorted(
tag for tag in standalone_set(config) if tag.startswith(CORE_DIR_PREFIX)
),
sorted(core_dir_tags(config)),
]
fp = hashlib.sha1(f"{fp}|{emulators}".encode()).hexdigest()
if target_cores_cache:
+7 -28
View File
@@ -27,7 +27,6 @@ from model.profiles import lists_files, platform_builds, profile_names
from resolve.content import name_match_size_ok
from resolve.localfile import resolve_local_file
from core.paths import comparable_destination, sanitize_pack_path
from core.paths import REPO_ROOT
# The kinds whose names say which file the launcher opens. A link of a named
# file is one too: ROCKNIX links /storage/roms/bios/nds_bios_arm9.bin into
@@ -502,46 +501,27 @@ def config_evidence(
return ConfigEvidence(tuple(cited or [choices]), tuple(missing), tuple(readers))
_DEFAULT_PROFILES: dict[str, dict] | None = None
def _profiles_or_repo(profiles: Mapping[str, dict] | None) -> Mapping[str, dict]:
"""The profiles given, else this repository's, read once."""
global _DEFAULT_PROFILES
if profiles is not None:
return profiles
if _DEFAULT_PROFILES is None:
from model.profiles import load_emulator_profiles
_DEFAULT_PROFILES = load_emulator_profiles(
str(REPO_ROOT / "emulators")
)
return _DEFAULT_PROFILES
def _cites_config(record: dict) -> bool:
from resolve.launcherrefs import config_ref
return bool(record.get("choices_from")) or bool(config_ref(str(record.get("source_ref") or "")))
def bound_launchers(config: dict, profiles: Mapping[str, dict] | None = None) -> list[dict]:
def bound_launchers(config: dict, profiles: Mapping[str, dict]) -> list[dict]:
"""The launcher records a platform's packs, manifests and reports consume.
A record resting on a config file binds only when config_evidence holds
for it. The repository's profiles are read only when a record cites one.
for it against the run's profiles.
"""
records = [r for r in config.get("launchers") or [] if isinstance(r, dict)]
if not any(_cites_config(r) for r in records):
return records
known = _profiles_or_repo(profiles)
platform = str(config.get("_key") or "")
return [r for r in records if config_evidence(r, known, platform).proven]
return [r for r in records if config_evidence(r, profiles, platform).proven]
def launcher_unproven(
configs: Mapping[str, dict], profiles: Mapping[str, dict] | None = None
configs: Mapping[str, dict], profiles: Mapping[str, dict]
) -> list[dict]:
"""The records resting on a config file whose evidence does not hold.
@@ -553,9 +533,8 @@ def launcher_unproven(
records = [r for r in config.get("launchers") or [] if isinstance(r, dict)]
if not any(_cites_config(r) for r in records):
continue
known = _profiles_or_repo(profiles)
for index, record in enumerate(records):
evidence = config_evidence(record, known, str(config.get("_key") or platform))
evidence = config_evidence(record, profiles, str(config.get("_key") or platform))
if evidence.proven:
continue
rows.append({
@@ -582,7 +561,7 @@ def _place_paths(name: str, directories: list[str] | None) -> tuple[str, ...]:
def launcher_places(
config: dict, profiles: Mapping[str, dict] | None = None
config: dict, profiles: Mapping[str, dict]
) -> list[LauncherPlace]:
"""Every place a platform's launchers open a named file from."""
base = str(config.get("base_destination") or "bios")
@@ -810,7 +789,7 @@ def _listed_directories(raw: str) -> list[str] | None:
def handed_directories(
config: dict, profiles: Mapping[str, dict] | None = None
config: dict, profiles: Mapping[str, dict]
) -> list[HandedDirectory]:
"""Every whole directory a platform links or passes to a standalone build.
+1 -1
View File
@@ -765,8 +765,8 @@ def _attach_runners(systems: dict[str, NativeSystem], scraped: dict | None) -> N
standalone = {str(c) for c in scraped.get("standalone_cores") or []}
# The build decision reads the tagged set (own builds, twins), as the
# pack does. The runner's name is looked up among the plain names.
layout_set = standalone_set(scraped)
profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
layout_set = standalone_set(scraped, profiles)
for system in systems.values():
for fe in system.files:
if fe.platform is not None or not fe.truth:
+17 -10
View File
@@ -78,12 +78,23 @@ def twin_build_names(config: dict) -> set[str]:
return found
def standalone_set(config: dict) -> set[str]:
def core_dir_tags(config: dict) -> set[str]:
"""The system directory a platform hands each core, tagged."""
return {
CORE_DIR_PREFIX + json.dumps([str(core), directory])
for directory, entry in (config.get("core_system_dirs") or {}).items()
for core in entry.get("cores") or []
}
def standalone_set(config: dict, profiles: Mapping[str, dict]) -> set[str]:
"""The emulators a platform launches standalone, with its dual-mode ones.
``dual_mode_cores`` names those it offers both ways (Batocera lists
libretro:dolphin and standalone dolphin for GameCube). They travel in the
same set, tagged, so every reader of standalone_cores sees them.
same set, tagged, so every reader of standalone_cores sees them. A
launcher record resting on a config file is proven against *profiles*,
the run's, as cross-reference proves it.
"""
names = {str(c) for c in config.get("standalone_cores") or []}
names |= {DUAL_MODE_PREFIX + str(c) for c in config.get("dual_mode_cores") or []}
@@ -100,15 +111,11 @@ def standalone_set(config: dict) -> set[str]:
names |= {DUAL_MODE_PREFIX + n for n in twin_build_names(config)}
# The system directory each core is handed travels the same way, so
# platform_layouts places a core's files below it for every reader.
names |= {
CORE_DIR_PREFIX + json.dumps([str(core), directory])
for directory, entry in (config.get("core_system_dirs") or {}).items()
for core in entry.get("cores") or []
}
names |= core_dir_tags(config)
if names - {n for n in names if n.startswith(CORE_DIR_PREFIX)}:
from resolve.launchers import executed_files, handed_directories
handed = handed_directories(config)
handed = handed_directories(config, profiles)
# The record's position travels too: a search list is read in order.
names |= {
HANDED_PREFIX + json.dumps(
@@ -144,7 +151,7 @@ def standalone_set(config: dict) -> set[str]:
return names | content_folder_tags(config)
def merged_standalone_set(configs: Iterable[dict]) -> set[str]:
def merged_standalone_set(configs: Iterable[dict], profiles: Mapping[str, dict]) -> set[str]:
"""The standalone set of several platforms read as one tree.
A per-core directory marker says which cores one platform hands a folder
@@ -155,7 +162,7 @@ def merged_standalone_set(configs: Iterable[dict]) -> set[str]:
return {
tag
for config in configs
for tag in standalone_set(config)
for tag in standalone_set(config, profiles)
if not tag.startswith((CORE_DIR_PREFIX, *CONTENT_TAG_PREFIXES))
}
+1 -1
View File
@@ -806,7 +806,7 @@ def generate_platform_truth(
# The layout rule verify and the pack builder apply: truth guessed its
# own from the profile type where the platform names no standalone
# emulator, and kept files the pack never carries.
standalone_set = platform_standalone_set(config)
standalone_set = platform_standalone_set(config, profiles)
resolved = resolve_platform_cores(config, profiles, target_cores)
+1 -1
View File
@@ -250,7 +250,7 @@ def build_emulator_gap_report(
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)
[cov["config"] for cov in coverages.values()], db, profiles)
unique_profiles = {
k: v
for k, v in profiles.items()
+7 -4
View File
@@ -346,18 +346,21 @@ PER_EMULATOR_STEM = "gaps-per-emulator"
NOT_COLLECTED_STEM = "gaps-not-collected"
def reading_platforms(emu_name: str, profile: dict, name: str,
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."""
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))
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))
}
@@ -575,7 +578,7 @@ 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[key], m["name"], {
*(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"])
))
+5 -3
View File
@@ -11,6 +11,7 @@ from collections import Counter
from core.text import series
from model import siteinputs
from model.collection import profiles_in
from model.guides import GUIDES, TERMINALS, install_command
from model.platforms import load_platform_config
from model.registry import list_release_pack_platforms
@@ -186,13 +187,14 @@ def emulator_install_route(name: str, profile: dict) -> tuple[str, list[str], tu
def _standalone_cores(platform: str) -> frozenset[str]:
"""The emulators a setup launches as apps, by its platform file."""
return _standalone_cores_in(str(siteinputs.current().platforms), platform)
inputs = siteinputs.current()
return _standalone_cores_in(str(inputs.platforms), str(inputs.emulators), platform)
@functools.cache
def _standalone_cores_in(platforms_dir: str, platform: str) -> frozenset[str]:
def _standalone_cores_in(platforms_dir: str, emulators_dir: str, platform: str) -> frozenset[str]:
config = load_platform_config(platform, platforms_dir)
return frozenset(standalone_set(config))
return frozenset(standalone_set(config, profiles_in(emulators_dir, skip_aliases=True)))
def install_block(name: str, profile: dict) -> list[str]:
+2 -2
View File
@@ -121,7 +121,7 @@ def _launcher_refs(config: dict) -> dict[str, list[str]]:
# config file does not prove opens nothing: it is listed apart.
source = list_source(str(config.get("source") or ""))
found: dict[str, list[str]] = {}
for record in bound_launchers(config):
for record in bound_launchers(config, _site_profiles()):
if not isinstance(record, dict) or not record.get("source_ref"):
continue
text = (f"{escape_tags(str(record.get('emulator', '')))} at "
@@ -145,7 +145,7 @@ def launcher_unproven_section(config: dict) -> list[str]:
from resolve.launchers import launcher_unproven
from sitegen.sources import launcher_ref_markdown, list_source
rows = launcher_unproven({str(config.get("_key") or ""): config})
rows = launcher_unproven({str(config.get("_key") or ""): config}, _site_profiles())
if not rows:
return []
source = list_source(str(config.get("source") or ""))
+1 -1
View File
@@ -199,7 +199,7 @@ def wanted_declarations(profiles: dict, coverages: dict, gap_report: dict) -> li
found: list[dict] = []
for key, coverage in sorted(coverages.items()):
systems = coverage.get("config", {}).get("systems") or {}
standalone_cores = standalone_set(coverage.get("config", {}))
standalone_cores = standalone_set(coverage.get("config", {}), profiles)
by_system: dict[str, list[dict]] = {}
for detail in coverage.get("details", []):
by_system.setdefault(detail.get("system", ""), []).append(detail)