diff --git a/scripts/model/profiles.py b/scripts/model/profiles.py index fdb62611a..648e37b19 100644 --- a/scripts/model/profiles.py +++ b/scripts/model/profiles.py @@ -16,7 +16,6 @@ from model.profilekinds import reads_own_files as reads_own_files from model.safeparse import require_yaml from model.sources import source_yaml_file from model.systems import norm_system_id, system_index -from core.paths import REPO_ROOT # The content tests a profile can declare in ``validation:``, each run by @@ -180,7 +179,7 @@ def source_yaml_paths(directory: str | Path) -> list[Path]: ] -def installed_data_refs(platform: str, emulators_dir: str = "") -> frozenset[str]: +def installed_data_refs_in(platform: str, profiles: Mapping[str, dict]) -> frozenset[str]: """Data directories a platform's own packages install beside the cores. The platform layer names trees for its systems (retroarch.yml carries @@ -188,11 +187,9 @@ def installed_data_refs(platform: str, emulators_dir: str = "") -> frozenset[str core packages put both into the system directory themselves. A profile records that with installed_on on its data directory reference. """ - emulators_dir = emulators_dir or os.path.join( - REPO_ROOT, "emulators") return frozenset( str(tree.get("ref", "")) - for profile in load_emulator_profiles(emulators_dir, skip_aliases=False).values() + for profile in profiles.values() for tree in profile.get("data_directories") or [] if isinstance(tree, dict) and platform in (tree.get("installed_on") or []) ) diff --git a/scripts/orchestrate/compare.py b/scripts/orchestrate/compare.py index 976457320..0d2b305d5 100644 --- a/scripts/orchestrate/compare.py +++ b/scripts/orchestrate/compare.py @@ -13,7 +13,7 @@ def tree_members( ) -> dict[str, int]: """Archive path -> size of every file the platform's data trees can add.""" from packs import datatrees - from model.profiles import load_emulator_profiles + 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 @@ -21,14 +21,13 @@ def tree_members( config = load_platform_config(platform, platforms_dir) base_dest = config.get("base_destination", "") registry = load_data_dir_registry(platforms_dir) - core_trees = datatrees.core_data_trees( - config, load_emulator_profiles(emulators_dir), platform, registry, - ) + 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, + core_trees=core_trees, installed=installed_data_refs_in(platform, profiles), ): members[flat_arcname(full, base_dest, True)] = os.path.getsize(src) return members diff --git a/scripts/packs/datatrees.py b/scripts/packs/datatrees.py index 508494e0b..e5c5a169c 100644 --- a/scripts/packs/datatrees.py +++ b/scripts/packs/datatrees.py @@ -13,7 +13,7 @@ from core.hashing import compute_hashes from core.options import reject_unknown from model.declarations import declared_root from model.registry import load_versions -from model.profiles import entry_system_ids, installed_data_refs +from model.profiles import entry_system_ids, installed_data_refs_in from model.systems import norm_system_id from packs.archive import PackRecord, Placed, add_pack_member from packs.datadirs import cache_lock, revisioned @@ -55,7 +55,7 @@ def core_data_trees( the core (and the build's own folder, ``pack_structure``), as the emulator pack lays them out. Left out: a tree the platform's package installs, for this core or another reading the same tree - (``installed_data_refs``), one the build bundles or the platform never + (``installed_data_refs_in``), one the build bundles or the platform never opens (``deliverable``), and one whose registry entry names the platforms it serves (``for_platforms``) without this one. A standalone build reads its data below its own folder, which a tree's destination does not describe, so its trees stay out, as does a @@ -66,7 +66,7 @@ def core_data_trees( """ if not data_registry: return [] - installed = installed_data_refs(platform_name) + installed = installed_data_refs_in(platform_name, profiles) 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 @@ -146,15 +146,18 @@ class _TreeWalkOptions(TypedDict, total=False): required_only: bool core_trees: Iterable[dict] reclaim: dict[str, str] | None + installed: frozenset[str] -def _carried_tree(dd: dict, data_registry: dict | None, platform_name: str) -> str | None: +def _carried_tree( + dd: dict, data_registry: dict | None, platform_name: str, installed: frozenset[str], +) -> str | None: """The cache folder of a tree reference the pack carries ("" when the cache does not hold it), or None for a tree the pack does not carry.""" ref_key = dd.get("ref", "") if not ref_key or not data_registry or ref_key not in data_registry: return None - if ref_key in installed_data_refs(platform_name): + if ref_key in installed: return None entry = data_registry[ref_key] allowed = entry.get("for_platforms") @@ -202,6 +205,10 @@ def data_directory_members( each tree the pack carries and the cache does not hold: the caller reports it and counts its run incomplete. + ``installed`` names the trees the platform's packages install + (installed_data_refs_in over the run's profiles): the walk leaves them + out. + These are not BIOS and carry no hash of their own: they are whole trees an emulator reads, refreshed from upstream, so what ships is whatever the cache holds. The pack and the install manifest both read @@ -215,12 +222,13 @@ def data_directory_members( reclaim = options.get("reclaim") required_only = options.get("required_only", False) core_trees = options.get("core_trees", ()) + installed = options.get("installed", frozenset()) # Data directories from _data_dirs.yml for systems, dd in _tree_references(pack_systems, core_trees): needed = dd.get("required") is not False if required_only and not needed: continue - local_path = _carried_tree(dd, data_registry, platform_name) + local_path = _carried_tree(dd, data_registry, platform_name, installed) if local_path is None: continue ref_key = dd.get("ref", "") diff --git a/scripts/packs/manifest.py b/scripts/packs/manifest.py index 95640d27e..23e778d37 100644 --- a/scripts/packs/manifest.py +++ b/scripts/packs/manifest.py @@ -12,7 +12,7 @@ from core.options import reject_unknown from core.paths import EMULATORS_DIR, REPO_ROOT, declared_destination, sanitize_pack_path from model.declarations import OUTER_ROOTS, declared_root, outer_layout from model.platforms import load_platform_config -from model.profiles import load_emulator_profiles +from model.profiles import installed_data_refs_in, load_emulator_profiles from model.registry import load_data_dir_registry, platform_registry_at from model.systems import platform_system_names from packs import slots @@ -474,6 +474,7 @@ class _ManifestBuild: self.pack_systems, self.data_registry, self.platform_name, self.base_dest, self.placed, refs_out=data_refs, required_only=required_only, core_trees=core_trees, + installed=installed_data_refs_in(self.platform_name, self.emu_profiles), reclaim=reclaim, uncached_out=uncached, )) if opts.uncached_out is not None: diff --git a/scripts/packs/platformpack.py b/scripts/packs/platformpack.py index 8033cfb37..d290f6962 100644 --- a/scripts/packs/platformpack.py +++ b/scripts/packs/platformpack.py @@ -18,7 +18,7 @@ from core.ziptools import is_archive_path from model.alternatives import core_file_spares from model.declarations import OUTER_ROOTS, declared_root from model.platforms import load_platform_config -from model.profiles import load_emulator_profiles +from model.profiles import installed_data_refs_in, load_emulator_profiles from model.releaserecord import PACK_SUFFIX from packs import slots from packs.archive import ( @@ -936,6 +936,7 @@ class _PlatformPackBuild: pack_systems, plan.opts.data_registry, plan.platform_name, plan.base_dest, self.placed, required_only=required_only, core_trees=core_trees, uncached_out=uncached, + installed=installed_data_refs_in(plan.platform_name, plan.emu_profiles or {}), ): # The installer writes a data tree member without the bit. add_pack_member(self.zf, src, self._flat(full), executable=False) diff --git a/tests/test_audit_regressions.py b/tests/test_audit_regressions.py index f03d200be..4a19090bd 100644 --- a/tests/test_audit_regressions.py +++ b/tests/test_audit_regressions.py @@ -5641,20 +5641,16 @@ class BundledFilesAreNotToSource(unittest.TestCase): def test_a_tree_the_platform_installs_leaves_its_pack(self): """retroarch.yml names dolphin-sys and ppsspp-assets and Lakka inherits them, while Lakka's core packages install both trees.""" - import tempfile + from model.profiles import installed_data_refs_in - import yaml as _yaml - - from model.profiles import installed_data_refs - - with tempfile.TemporaryDirectory() as tmp: - Path(tmp, "dolphin.yml").write_text(_yaml.safe_dump({ - "emulator": "Dolphin", "type": "libretro", "files": [], - "data_directories": [{"ref": "dolphin-sys", "installed_on": ["lakka"]}]})) - self.assertEqual(installed_data_refs("lakka", tmp), frozenset({"dolphin-sys"})) - self.assertEqual(installed_data_refs("retroarch", tmp), frozenset()) + profiles = {"dolphin": { + "emulator": "Dolphin", "type": "libretro", "files": [], + "data_directories": [{"ref": "dolphin-sys", "installed_on": ["lakka"]}]}} + self.assertEqual(installed_data_refs_in("lakka", profiles), frozenset({"dolphin-sys"})) + self.assertEqual(installed_data_refs_in("retroarch", profiles), frozenset()) source = script_source("generate_pack.py") - self.assertIn("if ref_key in installed_data_refs(platform_name):", source) + self.assertIn("if ref_key in installed:", source) + self.assertIn("installed=installed_data_refs_in(plan.platform_name", source) def test_the_pack_builder_skips_it(self): source = (ROOT / "scripts" / "packs" / "extras.py").read_text(encoding="utf-8") diff --git a/tests/test_core_data_trees.py b/tests/test_core_data_trees.py index 2ae3b0d91..d6c3adc30 100644 --- a/tests/test_core_data_trees.py +++ b/tests/test_core_data_trees.py @@ -13,12 +13,13 @@ from __future__ import annotations import tests import os +import tempfile import unittest from pathlib import Path from model.database import load_database from model.platforms import load_platform_config -from model.profiles import load_emulator_profiles, installed_data_refs +from model.profiles import load_emulator_profiles, installed_data_refs_in from model.registry import load_data_dir_registry, list_registered_platforms from resolve.cores import resolve_platform_cores from resolve.standalone import platform_layouts, standalone_set @@ -29,7 +30,7 @@ from resolve.validation import deliverable, read_from_system_dir REPO_ROOT = Path(__file__).resolve().parent.parent -PROFILES = { +PROFILES: dict[str, dict] = { "demo": { "emulator": "Demo", "type": "libretro", @@ -124,6 +125,25 @@ class CoreDataTreesTest(unittest.TestCase): def test_no_registry_no_tree(self) -> None: self.assertEqual(datatrees.core_data_trees(CONFIG, PROFILES, "plat", None), []) + def test_the_run_profiles_decide_an_installed_tree(self) -> None: + """installed_on read from the repository's emulators/: a pack built + from other profiles dropped a tree the platform's systems declare.""" + installed = installed_data_refs_in("plat", PROFILES) + self.assertEqual(installed, frozenset({"installed"})) + self.assertEqual(installed_data_refs_in("plat", {}), frozenset()) + with tempfile.TemporaryDirectory() as tmp: + Path(tmp, "f.bin").write_bytes(b"x") + registry = {"installed": {"local_cache": tmp}} + systems = {"demo-system": {"data_directories": [{"ref": "installed"}]}} + + def walk(refs: frozenset[str]) -> list[str]: + return [full for _src, full in datatrees.data_directory_members( + systems, registry, "lakka", "", archive.Placed(False), installed=refs, + )] + + self.assertEqual(walk(frozenset()), ["f.bin"]) + self.assertEqual(walk(installed), []) + class EveryReaderHasTheTreeOrAReason(unittest.TestCase): """Reads the repository: platforms/_data_dirs.yml against the profiles.""" @@ -142,7 +162,7 @@ class EveryReaderHasTheTreeOrAReason(unittest.TestCase): in platform_layouts(core, profile, handed)): continue trees = [t for t in profile.get("data_directories") or [] if isinstance(t, dict)] - installed = installed_data_refs(platform) + installed = installed_data_refs_in(platform, profiles) for tree in deliverable(trees, False, platform): allowed = registry.get(tree.get("ref"), {}).get("for_platforms") if tree.get("ref") in installed or not read_from_system_dir(tree):