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

+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)