From 6e44a93156a71cfdfcbb7624ef2980d126a7238a Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 24 Nov 2026 02:17:58 +0100 Subject: [PATCH] refactor: carry platform launches as a dataclass standalone_set returned one string set mixing standalone names with ten JSON-tagged record kinds that every reader re-decoded. platform_launches now returns a frozen PlatformLaunches (resolve/launches.py) with typed fields, runs_standalone, is_dual, system_file_index and merged, which _build_layouts and packprobe share. --- .github/workflows/deploy-site.yml | 1 + scripts/exporter/doubled.py | 4 +- scripts/packs/crossref.py | 15 ++- scripts/packs/crossrefscope.py | 13 +- scripts/packs/datatrees.py | 8 +- scripts/packs/extras.py | 23 ++-- scripts/packs/gaps.py | 12 +- scripts/packs/slots.py | 13 +- scripts/packs/slotscan.py | 4 +- scripts/probes/packprobe.py | 10 +- scripts/resolve/contentlayout.py | 107 ++++++++-------- scripts/resolve/grouping.py | 4 +- scripts/resolve/launches.py | 159 +++++++++++++++++++++++ scripts/resolve/layout.py | 136 ++------------------ scripts/resolve/reconcile.py | 9 +- scripts/resolve/standalone.py | 206 +++++++++++++----------------- scripts/resolve/truth.py | 17 +-- scripts/sitegen/install.py | 13 +- scripts/sitegen/wanted.py | 10 +- tests/test_audit_regressions.py | 10 +- tests/test_batocera_cores.py | 9 +- tests/test_core_data_trees.py | 4 +- tests/test_e2e.py | 18 +-- tests/test_gap_settlement.py | 3 +- tests/test_launcher_evidence.py | 18 +-- tests/test_launcher_layer.py | 3 +- tests/test_launcher_paths.py | 4 +- tests/test_launcher_placement.py | 32 ++--- tests/test_minui_platform.py | 12 +- tests/test_pack_probe.py | 2 +- tests/test_slots.py | 13 +- tests/test_standalone_links.py | 50 ++++---- tests/test_standalone_mode.py | 13 +- tests/test_target_scrapers.py | 5 +- 34 files changed, 493 insertions(+), 467 deletions(-) create mode 100644 scripts/resolve/launches.py diff --git a/.github/workflows/deploy-site.yml b/.github/workflows/deploy-site.yml index dc8ecdb1a..970031bee 100644 --- a/.github/workflows/deploy-site.yml +++ b/.github/workflows/deploy-site.yml @@ -110,6 +110,7 @@ on: - "scripts/resolve/grouping.py" - "scripts/resolve/launcherrefs.py" - "scripts/resolve/launchers.py" + - "scripts/resolve/launches.py" - "scripts/resolve/layout.py" - "scripts/resolve/localfile.py" - "scripts/resolve/nativemode.py" diff --git a/scripts/exporter/doubled.py b/scripts/exporter/doubled.py index bd9dc133d..8bd435280 100644 --- a/scripts/exporter/doubled.py +++ b/scripts/exporter/doubled.py @@ -16,7 +16,7 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from resolve.archives import contents_members, holds_required_members -from resolve.standalone import platform_layouts, standalone_set +from resolve.standalone import platform_layouts, platform_launches from resolve.cores import resolve_platform_cores from core.hashing import declared_hash_lists, lists_hashes from model.declarations import declared_components @@ -78,7 +78,7 @@ def doubled_destinations( collisions = find_collisions(scraped, db, zip_contents, data_registry) if not collisions: return [] - standalone = standalone_set(scraped, profiles) + standalone = platform_launches(scraped, profiles) named: dict[str, list[tuple[str, dict, dict, bool]]] = {} for key in sorted(resolve_platform_cores(scraped, profiles)): profile = profiles[key] diff --git a/scripts/packs/crossref.py b/scripts/packs/crossref.py index b8c1c4554..936f75918 100644 --- a/scripts/packs/crossref.py +++ b/scripts/packs/crossref.py @@ -23,6 +23,7 @@ from resolve.launchers import LauncherLayer, held_record from resolve.layout import system_dir_path from resolve.localfile import held_record_for from resolve.ownership import foreign_tree, owner_tokens +from resolve.launches import PlatformLaunches from resolve.standalone import platform_layouts from resolve.validation import ( case_folded_slots, @@ -68,7 +69,7 @@ def global_report_scope( merged_platform_declared_contents, platform_declarations, ) - from resolve.standalone import merged_standalone_set + from resolve.standalone import merged_launches declared: dict[str, set[str]] = {} for config in configs: @@ -82,7 +83,7 @@ def global_report_scope( )) return declared, { "all_declared": merged_platform_declarations(configs, db), - "standalone_cores": merged_standalone_set(configs, profiles), + "standalone_cores": merged_launches(configs, profiles), "folded_slots": folded, "declared_contents": merged_platform_declared_contents(configs, db), } @@ -125,7 +126,7 @@ def _record_needing_platforms( 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.standalone import platform_launches from resolve.validation import filter_files_by_mode missing = [ @@ -138,7 +139,7 @@ def _record_needing_platforms( runnable = emulator_profiles(profiles) for config in configs: platform = str(config.get("_key") or "") - standalone = standalone_set(config, profiles) + standalone = platform_launches(config, profiles) for emu_name in resolve_platform_cores(config, runnable): runners.setdefault(emu_name, []).append((platform, standalone)) for emu_name, gap in missing: @@ -653,7 +654,7 @@ def _cross_reference_profile( declared: dict[str, set[str]], report: dict, index: dict, - standalone_cores: set[str] | None = None, + standalone_cores: PlatformLaunches | None = None, platform: str = "", ) -> None: """Compare one emulator profile against what the platforms declare. @@ -684,7 +685,7 @@ def _cross_reference_profile( # The build a platform runs decides which entries it reads, as in # find_undeclared_files: without a platform, the libretro build. - layouts = platform_layouts(emu_name, profile, standalone_cores or set()) + layouts = platform_layouts(emu_name, profile, standalone_cores or PlatformLaunches()) comparison = _ProfileComparison(emu_name, profile, index, platform_names, platform, layouts) # Each file under each layout the platform gives the emulator: both, for # one it launches as a libretro core and standalone. @@ -770,7 +771,7 @@ class ReportScope(TypedDict, total=False): """What a cross_reference run compares against and answers for.""" all_declared: dict[str, list[tuple[int | None, str]]] | None - standalone_cores: set[str] | None + standalone_cores: PlatformLaunches | None folded_slots: frozenset[str] platform: str launcher_layer: LauncherLayer | None diff --git a/scripts/packs/crossrefscope.py b/scripts/packs/crossrefscope.py index abf0e8bf9..b4dbcc8a6 100644 --- a/scripts/packs/crossrefscope.py +++ b/scripts/packs/crossrefscope.py @@ -10,7 +10,8 @@ from model.platforms import load_platform_config from model.registry import list_registered_platforms from model.targets import target_scope from resolve.cores import resolve_platform_cores -from resolve.standalone import merged_standalone_set, standalone_set +from resolve.launches import PlatformLaunches +from resolve.standalone import merged_launches, platform_launches @dataclass(frozen=True) @@ -18,7 +19,7 @@ class PlatformScope: """The profiles a --platform run compares, and how the platform runs them.""" profiles: dict[str, dict] - standalone_cores: set[str] + standalone_cores: PlatformLaunches config: dict relevant: set[str] run_anywhere: set[str] @@ -44,7 +45,7 @@ def platform_scope( ) return PlatformScope( {k: v for k, v in profiles.items() if k in relevant}, - standalone_set(config, all_profiles), + platform_launches(config, all_profiles), config, relevant, run_anywhere, @@ -58,7 +59,7 @@ class TreeScope: standalone layout of those platforms.""" profiles: dict[str, dict] - standalone_cores: set[str] + standalone_cores: PlatformLaunches selected: list[str] | None platform: PlatformScope | None = None @@ -79,7 +80,7 @@ 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(), all_profiles), + merged_launches(configs.values(), all_profiles), kept, ) @@ -99,7 +100,7 @@ def tree_scope( # eka2l1, dolphin and xenia-edge lost 133 files no platform declares. return TreeScope( profiles, - merged_standalone_set( + merged_launches( ( load_platform_config(name, platforms_dir) for name in list_registered_platforms(platforms_dir) diff --git a/scripts/packs/datatrees.py b/scripts/packs/datatrees.py index 4233730ab..c75f9169a 100644 --- a/scripts/packs/datatrees.py +++ b/scripts/packs/datatrees.py @@ -20,7 +20,7 @@ from packs.extras import prefixed_destination from packs.paths import MEDIA_MARKER, lands_on_android from resolve.cores import resolve_platform_cores as _platform_cores from resolve.layout import core_system_dirs -from resolve.standalone import platform_layouts, standalone_set +from resolve.standalone import platform_layouts, platform_launches from resolve.validation import deliverable, read_from_system_dir if TYPE_CHECKING: @@ -66,7 +66,7 @@ def core_data_trees( if not data_registry: return [] installed = installed_data_refs_in(platform_name, profiles) - handed = standalone_set(config, profiles) + launches = platform_launches(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. @@ -75,10 +75,10 @@ def core_data_trees( seen: dict[tuple[str, str], int] = {} for core in sorted(_platform_cores(config, profiles, target_cores)): profile = profiles[core] - if all(standalone for _view, standalone in platform_layouts(core, profile, handed)): + if all(standalone for _view, standalone in platform_layouts(core, profile, launches)): continue declared = [t for t in profile.get("data_directories") or [] if isinstance(t, dict)] - directories = core_system_dirs(core, profile, handed) + directories = core_system_dirs(core, profile, launches) structure = str((profile.get("pack_structure") or {}).get("libretro") or "") for tree in deliverable(declared, False, platform_name): if not read_from_system_dir(tree): diff --git a/scripts/packs/extras.py b/scripts/packs/extras.py index 9f4016218..feb6a0d0b 100644 --- a/scripts/packs/extras.py +++ b/scripts/packs/extras.py @@ -22,9 +22,10 @@ from resolve.localfile import resolution_is_hash_exact from resolve.localfile import resolve_local_file from resolve.nativemode import platform_mode from resolve.cores import resolve_platform_cores +from resolve.launches import PlatformLaunches from resolve.layout import core_system_dirs, system_dir_path from resolve.standalone import platform_layouts -from resolve.standalone import standalone_set as platform_standalone_set +from resolve.standalone import platform_launches from model.declarations import OUTER_ROOTS, outer_layout from core.paths import declared_destination, sanitize_pack_path from resolve.content import declares_shape, shape_fits, size_fits @@ -592,7 +593,7 @@ def _agnostic_scan_extras( by_name: dict, seen_dests: set, extras_prefix: str, - standalone_set: set[str] | None = None, + launches: PlatformLaunches | None = None, taken: dict[str, dict] | None = None, ) -> list[dict]: """Every interchangeable candidate a filename-agnostic core accepts. @@ -620,7 +621,7 @@ def _agnostic_scan_extras( ): continue resolved = _resolved_dirs(emu_name, profile, db) - for layout, standalone in platform_layouts(emu_name, profile, standalone_set or set()): + for layout, standalone in platform_layouts(emu_name, profile, launches or PlatformLaunches()): # A layout copies each entry in order (a launcher's folder, a # system directory): its files are looked up as the profile's # own, or a bound layout scans nothing (KNULLI's bios/ps2). @@ -962,7 +963,7 @@ def expand_agnostic_entries( scanned = _agnostic_scan_extras( {emu_name: {**profile, "files": files}}, {emu_name}, db, db.get("indexes", {}).get("by_name", {}), set(), "", - {emu_name} if standalone else set(), + PlatformLaunches(standalone=frozenset({emu_name})) if standalone else PlatformLaunches(), ) # A placeholder is answered by the files its own scan found in its own @@ -1167,7 +1168,7 @@ def _archive_prefix_extras( extras_prefix: str, by_name: dict, taken: dict[str, dict] | None = None, - standalone_set: set[str] | None = None, + launches: PlatformLaunches | None = None, ) -> list[dict]: """A second copy of an archive under the subdirectory a core reads. @@ -1188,10 +1189,10 @@ def _archive_prefix_extras( # A platform that hands each core its own system directory moves the # subfolder with it, once per directory. views = [profile] - if core_system_dirs(emu_name, profile, standalone_set or set()) is not None: + if core_system_dirs(emu_name, profile, launches or PlatformLaunches()) is not None: views = [ view for view, standalone - in platform_layouts(emu_name, profile, standalone_set or set()) + in platform_layouts(emu_name, profile, launches or PlatformLaunches()) if not standalone ] for view in views: @@ -1535,7 +1536,7 @@ def collect_emulator_extras( return extras relevant = resolve_platform_cores(config, profiles, target_cores=target_cores) - standalone_set = platform_standalone_set(config, profiles) + launches = platform_launches(config, profiles) by_name = db.get("indexes", {}).get("by_name", {}) # Build set of filenames already covered (platform baseline + first pass extras) @@ -1556,7 +1557,7 @@ def collect_emulator_extras( continue if emu_name not in relevant: continue - for layout, is_standalone in platform_layouts(emu_name, profile, standalone_set): + for layout, is_standalone in platform_layouts(emu_name, profile, launches): for f in layout.get("files", []): copy = _second_pass_copy(scope, emu_name, layout, is_standalone, f) if copy is not None: @@ -1581,14 +1582,14 @@ def collect_emulator_extras( extras.extend( _archive_prefix_extras( profiles, relevant, covered_names, state.seen_dests, extras_prefix, - by_name, state.taken, standalone_set, + by_name, state.taken, launches, ) ) extras.extend( _agnostic_scan_extras( profiles, relevant, db, by_name, state.seen_dests, extras_prefix, - standalone_set, state.taken, + launches, state.taken, ) ) diff --git a/scripts/packs/gaps.py b/scripts/packs/gaps.py index d631365d8..cc339cb06 100644 --- a/scripts/packs/gaps.py +++ b/scripts/packs/gaps.py @@ -14,11 +14,11 @@ from resolve.archives import archive_entry, archive_members from resolve.cores import resolve_platform_cores from resolve.directories import expand_directory_entries from resolve.launchers import LauncherLayer, declared_destinations, held_record -from resolve.layout import runs_standalone, system_dir_path +from resolve.layout import system_dir_path from resolve.localfile import resolve_local_file from resolve.nativemode import hash_mismatch_excludes_file, platform_mode from resolve.ownership import foreign_tree, owner_tokens -from resolve.standalone import platform_layouts, standalone_set as platform_standalone_set +from resolve.standalone import platform_layouts, platform_launches from resolve.validation import ( parse_validation, case_folded_slots, @@ -484,7 +484,7 @@ def find_undeclared_files( ) relevant = resolve_platform_cores(config, profiles, target_cores=target_cores) - standalone_set = platform_standalone_set(config, profiles) + launches = platform_launches(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( @@ -509,7 +509,7 @@ def find_undeclared_files( # (ARMSX2's arcade/proverb.zip once ROCKNIX binds bios/armsx2). agnostic = profile.get("bios_mode") == "agnostic" - for layout, is_standalone in platform_layouts(emu_name, profile, standalone_set): + for layout, is_standalone in platform_layouts(emu_name, profile, launches): for f in expand_directory_entries( layout.get("files", []), db, is_standalone ): @@ -647,7 +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) + launches = platform_launches(config, profiles) notes = [] for emu_name, profile in sorted(profiles.items()): emu_systems = set(profile.get("systems", [])) @@ -683,7 +683,7 @@ def find_exclusion_notes( # Count standalone-only files, but only report as excluded if the # platform does NOT use this emulator in standalone mode - is_standalone = runs_standalone(emu_name, profile, standalone_set) + is_standalone = launches.runs_standalone(emu_name, profile) if not is_standalone: standalone_files = [ f for f in profile.get("files", []) if f.get("mode") == "standalone" diff --git a/scripts/packs/slots.py b/scripts/packs/slots.py index f0f3227b2..90a3bfb48 100644 --- a/scripts/packs/slots.py +++ b/scripts/packs/slots.py @@ -18,7 +18,8 @@ from resolve.cores import resolve_platform_cores from resolve.layout import system_dir_path from resolve.localfile import resolution_is_hash_exact, resolve_local_file from resolve.packfiles import preferred_entries -from resolve.standalone import platform_layouts, standalone_set as platform_standalone_set +from resolve.launches import PlatformLaunches +from resolve.standalone import platform_layouts, platform_launches from resolve.validation import ( content_alternatives, outside_gap_scope, @@ -146,7 +147,7 @@ def profile_claims( profiles: dict, db: dict, base_dest: str = "", - standalone_cores: set[str] | None = None, + standalone_cores: PlatformLaunches | None = None, zip_contents: dict | None = None, data_dir_registry: dict | None = None, config: dict | None = None, @@ -165,7 +166,7 @@ def profile_claims( running that emulator as a core, and where it does, the destination is ``standalone_path``. This is the gate verify already applies. """ - standalone_cores = standalone_cores or set() + standalone_cores = standalone_cores or PlatformLaunches() placement = None if config is not None: from packs.extras import ExtraPlacement @@ -353,7 +354,7 @@ def _slot_claims( profiles: dict, db: dict, base_dest: str, - standalone_cores: set[str] | None, + standalone_cores: PlatformLaunches | None, zip_contents: dict | None, data_dir_registry: dict | None, ) -> tuple[dict[str, Claim], dict[str, list[Claim]]]: @@ -427,7 +428,7 @@ def find_conflicts( profiles: dict, db: dict, base_dest: str = "", - standalone_cores: set[str] | None = None, + standalone_cores: PlatformLaunches | None = None, zip_contents: dict | None = None, data_dir_registry: dict | None = None, ) -> list[Conflict]: @@ -544,7 +545,7 @@ def slot_choices( platform_profiles, db, config.get("base_destination", ""), - platform_standalone_set(config, profiles), + platform_launches(config, profiles), zip_contents, data_dir_registry, ) diff --git a/scripts/packs/slotscan.py b/scripts/packs/slotscan.py index 00044e39b..b7962fb97 100644 --- a/scripts/packs/slotscan.py +++ b/scripts/packs/slotscan.py @@ -10,7 +10,7 @@ from packs.slots import Conflict, Decision, arbitrate, find_conflicts from resolve.collisions import Collision, find_collisions from resolve.cores import resolve_platform_cores from resolve.nativemode import platform_mode -from resolve.standalone import standalone_set as platform_standalone_set +from resolve.standalone import platform_launches def scan_platform( @@ -30,7 +30,7 @@ def scan_platform( relevant, db, config.get("base_destination", ""), - platform_standalone_set(config, profiles), + platform_launches(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, ) diff --git a/scripts/probes/packprobe.py b/scripts/probes/packprobe.py index 0b2dab8f8..f60991d46 100644 --- a/scripts/probes/packprobe.py +++ b/scripts/probes/packprobe.py @@ -35,8 +35,7 @@ from probes.packlayout import ( pack_layout, ) from resolve.cores import resolve_platform_cores -from resolve.layout import DUAL_MODE_PREFIX, runs_standalone -from resolve.standalone import standalone_set +from resolve.standalone import platform_launches from resolve.validation import filter_files_by_mode @@ -76,11 +75,10 @@ def libretro_build_runs( 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, profiles) - if not runs_standalone(name, profile, standalone): + standalone = platform_launches(config, profiles) + if not standalone.runs_standalone(name, profile): return True - dual = {c.removeprefix(DUAL_MODE_PREFIX) for c in standalone if c.startswith(DUAL_MODE_PREFIX)} - return bool(dual & ({name} | {str(c) for c in profile.get("cores") or ()})) + return standalone.is_dual({name} | {str(c) for c in profile.get("cores") or ()}) def so_names(name: str, profile: dict, buildbot: set[str], target: set[str] | None) -> list[str]: diff --git a/scripts/resolve/contentlayout.py b/scripts/resolve/contentlayout.py index 846b5eb3f..298e16757 100644 --- a/scripts/resolve/contentlayout.py +++ b/scripts/resolve/contentlayout.py @@ -7,13 +7,9 @@ import json from collections.abc import Callable, Iterable from model.targets import list_available_targets +from resolve.launches import ContentFolder, ContentLaunches, PlatformLaunches, RomSearch from resolve.layout import ( - CONTENT_FOLDER_PREFIX, - CONTENT_SCOPE_TAG, - CONTENT_SYSTEM_TAG, - CONTENT_TAG_PREFIXES, OUTSIDE_BIOS_FOLDER, - ROM_SEARCH_PREFIX, placed_entry, standalone_layout_path, ) @@ -128,9 +124,9 @@ def content_folder_boards(config: dict) -> dict[tuple[str, str], frozenset[str] } -def content_folder_tags(config: dict) -> set[str]: +def content_launches(config: dict) -> ContentLaunches: """The roms folders a platform launches each libretro core for, and the - ROM search paths its commands hand emulators and cores, as tags. + ROM search paths its commands hand emulators and cores. A core reading its BIOS sets beside the game (MAME 2003's osd_get_path gives FILETYPE_ROM the content directory) reads them in the folder of @@ -145,10 +141,9 @@ def content_folder_tags(config: dict) -> set[str]: # EmulatorJS writes the BIOS a frontend hands it and the game to # the root of one filesystem (data/src/emulator.js:845, 990, 1054): # RomM's firmware folder is beside the content. - return {CONTENT_SYSTEM_TAG} - tags = {CONTENT_SCOPE_TAG} + return ContentLaunches(beside=True) if outer_layout(config, ROMS_ROOT) is None: - return tags + return ContentLaunches(scoped=True) rows = config.get("_rom_folders") or [] folders = {str(r.get("folder")) for r in rows if r.get("folder")} boards = content_folder_boards(config) @@ -156,29 +151,32 @@ def content_folder_tags(config: dict) -> set[str]: pairs = {pair for pair, on in boards.items() if not target or on is None or target in on} from resolve.launchers import roms_place_of - def place(folder: str) -> list: - return list(roms_place_of(config, folder) or ()) + def place(folder: str) -> tuple[str, ...]: + return tuple(roms_place_of(config, folder) or ()) # Without a board, a core a folder offers on some boards only carries # them, for a manifest the installer narrows to one. - tags |= { - CONTENT_FOLDER_PREFIX + json.dumps([ + content_folders = frozenset( + ContentFolder( c, f, place(f), - None if target or (offered_on := boards.get((c, f))) is None else sorted(offered_on), - ]) + None if target or (offered_on := boards.get((c, f))) is None + else tuple(sorted(offered_on)), + ) for c, f in pairs if f in folders - } - for row in rows: - for search in row.get("searched_by") or []: - for read in search.get("reads") or []: - if read in folders: - tags.add(ROM_SEARCH_PREFIX + json.dumps([ - str(search.get("core") or search["emulator"]), place(read), - str(row["folder"]), sorted(search.get("machines") or []), - bool(search.get("any_machine")), str(search.get("source_ref", "")), - "libretro" if search.get("core") else "standalone", - ])) - return tags + ) + searches = frozenset( + RomSearch( + str(search.get("core") or search["emulator"]), place(read), + str(row["folder"]), tuple(sorted(search.get("machines") or [])), + bool(search.get("any_machine")), str(search.get("source_ref", "")), + "libretro" if search.get("core") else "standalone", + ) + for row in rows + for search in row.get("searched_by") or [] + for read in search.get("reads") or [] + if read in folders + ) + return ContentLaunches(scoped=True, folders=content_folders, searches=searches) # The machines ES-DE runs from a folder whose command starts the game itself @@ -257,12 +255,12 @@ def _rom_search_sets( return frozenset(found | members) -def _search_reads(emu_name: str, searches: list, name: str) -> list[tuple[str, str]]: +def _search_reads(emu_name: str, searches: list[RomSearch], name: str) -> list[tuple[str, str]]: """The (tree, folder) places a passed ROM search reads this set from.""" stem = name.rsplit(".", 1)[0] return sorted({ - tuple(where) for _emu, where, system, machines, any_machine, _ref, _build in searches - if where and stem in rom_search_sets(emu_name, system, machines, any_machine) + (s.place[0], s.place[1]) for s in searches + if s.place and stem in rom_search_sets(emu_name, s.folder, s.machines, s.any_machine) }) @@ -277,28 +275,29 @@ def _roms_entry(entry: dict, tree: str, folder: str, rel: str) -> dict: return {**entry, **where, "path": f"{folder}/{rel}", "layout_path": rel} -def _content_folder_boards(tags: list[str], names: set[str]) -> dict[tuple, set[str] | None]: +def _content_folder_boards( + folders: Iterable[ContentFolder], names: set[str], +) -> dict[tuple, set[str] | None]: """Each roms folder the platform launches the core from, with its boards.""" # A place keeps the boards its core is offered on there, every board # when one folder offers it everywhere. on_boards: dict[tuple, set[str] | None] = {} - for core, _folder, where, on in ( - json.loads(t[len(CONTENT_FOLDER_PREFIX):]) - for t in tags if t.startswith(CONTENT_FOLDER_PREFIX) - ): - if core not in names or not where: + for folder in folders: + if folder.core not in names or not folder.place: continue - place = tuple(where) - known = on_boards.get(place, set()) - on_boards[place] = None if on is None or known is None else known | set(on) + known = on_boards.get(folder.place, set()) + on_boards[folder.place] = ( + None if folder.boards is None or known is None else known | set(folder.boards) + ) return on_boards def _libretro_content_layout( - emu_name: str, view: dict, tags: list[str], names: set[str], searches: list, + emu_name: str, view: dict, content: ContentLaunches, names: set[str], + searches: list[RomSearch], ) -> dict: """The libretro layout with each file read beside the content placed there.""" - on_boards = _content_folder_boards(tags, names) + on_boards = _content_folder_boards(content.folders, names) folders = sorted(on_boards) # The folders a passed `-rompath` replaces the build's own search # path with stand for these: libretro MAME hands MAME @@ -336,7 +335,7 @@ def _libretro_content_layout( return {**view, "files": out} if changed else view -def _standalone_content_layout(emu_name: str, view: dict, searches: list) -> dict: +def _standalone_content_layout(emu_name: str, view: dict, searches: list[RomSearch]) -> dict: """The standalone layout with each set a passed search reads placed there.""" pools = {str(v).strip("/") for v in (view.get("standalone_pools") or {}).values()} if not searches or "" not in pools: @@ -377,7 +376,7 @@ def _standalone_content_layout(emu_name: str, view: dict, searches: list) -> dic def content_layout( - emu_name: str, view: dict, standalone: bool, standalone_cores: Iterable[str], + emu_name: str, view: dict, standalone: bool, launches: PlatformLaunches, ) -> dict: """The layout with each file read in a roms folder placed in that folder. @@ -387,11 +386,11 @@ def content_layout( entry in the folder a passed ROM search path stands for (the root of a standalone layout, a ``libretro_pools`` folder) also goes to each folder a command passes for a machine that reads it, and a standalone entry no - launcher record places goes there only. Outside a platform (no - CONTENT_SCOPE_TAG) the view is left as it is. + launcher record places goes there only. Outside a platform (not + ContentLaunches.scoped) the view is left as it is. """ - tags = [t for t in standalone_cores if t.startswith(CONTENT_TAG_PREFIXES)] - if CONTENT_SYSTEM_TAG in tags and not standalone: + content = launches.content + if content.beside and not standalone: files = [ _without_libretro_load(f) if isinstance(f, dict) and _content_load(f) == "content_dir" @@ -399,17 +398,15 @@ def content_layout( for f in view.get("files") or [] ] return {**view, "files": files} - if CONTENT_SCOPE_TAG not in tags: + if not content.scoped: return view names = {core_key(n) for n in profile_names(emu_name, view)} - searches = [ - json.loads(t[len(ROM_SEARCH_PREFIX):]) - for t in tags if t.startswith(ROM_SEARCH_PREFIX) - ] build = "standalone" if standalone else "libretro" - searches = [s for s in searches if core_key(s[0]) in names and s[6] == build] + searches = [ + s for s in content.searches if core_key(s.emulator) in names and s.build == build + ] if not standalone: - return _libretro_content_layout(emu_name, view, tags, names, searches) + return _libretro_content_layout(emu_name, view, content, names, searches) return _standalone_content_layout(emu_name, view, searches) diff --git a/scripts/resolve/grouping.py b/scripts/resolve/grouping.py index 4ce7dc0b3..5d72f7179 100644 --- a/scripts/resolve/grouping.py +++ b/scripts/resolve/grouping.py @@ -8,7 +8,7 @@ import os from model.platforms import load_platform_config from model.sources import source_yaml_file -from resolve.standalone import core_dir_tags +from resolve.standalone import core_dirs def group_identical_platforms( @@ -65,7 +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(core_dir_tags(config)), + sorted(core_dirs(config)), ] fp = hashlib.sha1(f"{fp}|{emulators}".encode()).hexdigest() if target_cores_cache: diff --git a/scripts/resolve/launches.py b/scripts/resolve/launches.py new file mode 100644 index 000000000..4ed3a0d5b --- /dev/null +++ b/scripts/resolve/launches.py @@ -0,0 +1,159 @@ +"""What a platform's launch code says about the emulators it runs.""" + +from __future__ import annotations + +import json +from collections.abc import Hashable, Iterable +from dataclasses import dataclass, field +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from resolve.launchers import ExecutedFile, HandedDirectory + + +@dataclass(frozen=True) +class ContentFolder: + """A roms folder a platform launches a libretro core for, which reads beside the content.""" + + core: str + folder: str + # The folder as a (tree, path) place, empty when the platform gives none. + place: tuple[str, ...] + # The boards the folder offers the core on, None for every board. + boards: tuple[str, ...] | None + + +@dataclass(frozen=True) +class RomSearch: + """A roms folder a system's launch command hands as ROM search path. + + ``emulator`` is a standalone emulator, or a libretro core in the command + line it is handed as content (``build``). + """ + + emulator: str + place: tuple[str, ...] + folder: str + machines: tuple[str, ...] + any_machine: bool + source_ref: str + build: str + + +@dataclass(frozen=True) +class ContentLaunches: + """Where a platform puts the files a core reads beside the content.""" + + # The platform is known: an entry read beside the content is placed in + # the roms folders a core is launched for, or named as read outside the + # BIOS folder. + scoped: bool = False + # The frontend writes the BIOS it hands a core beside the content: the + # folder it gives the BIOS is the content's. + beside: bool = False + folders: frozenset[ContentFolder] = frozenset() + searches: frozenset[RomSearch] = frozenset() + + +def frozen_source(source: object) -> Hashable: + """A profile's ``source`` in a form a set can hold: a dict by build mode, or a URL.""" + if isinstance(source, dict): + return tuple(sorted((str(k), frozen_source(v)) for k, v in source.items())) + if isinstance(source, list): + return tuple(frozen_source(v) for v in source) + return source # type: ignore[return-value] + + +def _handed_order(position: int, handed: HandedDirectory) -> tuple[int, str]: + """Where a record of one platform's search lists sorts among several platforms'.""" + return position, json.dumps([ + position, handed.emulator, handed.folder, handed.directory, sorted(handed.handles), + handed.source_ref, handed.roms_place, sorted(handed.systems), handed.holds_declared, + ]) + + +@dataclass(frozen=True) +class PlatformLaunches: + """The emulators a platform launches standalone and how its launchers lay them out.""" + + # The names the platform runs standalone (standalone_cores). + standalone: frozenset[str] = frozenset() + # The names it also launches as libretro cores. + dual: frozenset[str] = frozenset() + # (standalone name, profile, source): a build the platform compiles + # itself (built_by) answers to that name there. + own_builds: frozenset[tuple[str, str, Hashable]] = frozenset() + # The directories its launchers hand standalone emulators, a search list + # read in order. + handed: tuple[HandedDirectory, ...] = () + # The files its launchers execute. + executed: tuple[ExecutedFile, ...] = () + # (libretro core, system directory the platform hands it). + core_dirs: frozenset[tuple[str, str]] = frozenset() + # (system, lower-case file name or MACHINE_KEY + machine): a name the + # platform declares under a system a launcher record is written for. + system_files: frozenset[tuple[str, str]] = frozenset() + content: ContentLaunches = field(default_factory=ContentLaunches) + + def runs_standalone(self, emu_name: str, profile: dict) -> bool: + """Whether the platform lays this emulator's files out for its standalone build. + + A platform names the emulators it launches standalone in + ``standalone_cores``, by profile key or by any name in ``cores:``. The + name alone is not enough: Recalbox and Batocera call their standalone + ScummVM ``scummvm``, which is also the key of the libretro core's + profile, and that profile documents no standalone build. Laid out + "standalone" it would lose every ``path:`` and drop its files at the + root, so a profile whose ``type`` has no standalone build keeps its + libretro layout whatever the platform calls it. + """ + if not self.standalone: + return False + if "standalone" not in str(profile.get("type", "")): + return False + names = {emu_name, *(str(c) for c in profile.get("cores", []))} + # A name a build the platform compiles itself answers to means that + # build there: RetroBat's standalone amiberry is 8.3.0, and the 8.5.0 + # profile, run there as the buildbot core, keeps its libretro layout. + source = frozen_source(profile.get("source")) + owners: dict[str, set[str]] = {} + for name, owner, built in self.own_builds: + if built == source: + owners.setdefault(name, set()).add(owner) + if any(emu_name not in owners[n] for n in names & owners.keys()): + return False + return emu_name in self.standalone or bool(self.standalone & names) + + def is_dual(self, names: Iterable[str]) -> bool: + """Whether the platform also launches, as a libretro core, an emulator of these names.""" + return not self.dual.isdisjoint(names) + + def system_file_index(self) -> dict[str, set[str]]: + """File name, lower case -> the platform systems declaring it.""" + index: dict[str, set[str]] = {} + for slug, name in self.system_files: + index.setdefault(name, set()).add(slug) + return index + + @classmethod + def merged(cls, launches: Iterable[PlatformLaunches]) -> PlatformLaunches: + """Several platforms' launches read as one tree. + + A per-core directory marker says which cores one platform hands a + folder and that it hands the others none. Carried into the union, + MinUI's 86 markers left every core they do not list without a layout: + the global gap report lost 238 profiles and 1201 files without a word. + Core directories and content folders stay with their platform. + """ + each = list(launches) + handed = { + (position, h) for one in each for position, h in enumerate(one.handed) + } + return cls( + standalone=frozenset().union(*(one.standalone for one in each)), + dual=frozenset().union(*(one.dual for one in each)), + own_builds=frozenset().union(*(one.own_builds for one in each)), + handed=tuple(h for _p, h in sorted(handed, key=lambda pair: _handed_order(*pair))), + executed=tuple(dict.fromkeys(run for one in each for run in one.executed)), + system_files=frozenset().union(*(one.system_files for one in each)), + ) diff --git a/scripts/resolve/layout.py b/scripts/resolve/layout.py index eaa9e3de7..faa43e7c2 100644 --- a/scripts/resolve/layout.py +++ b/scripts/resolve/layout.py @@ -1,90 +1,22 @@ -"""Where a platform's launch code puts a file: tag prefixes and standalone layout paths.""" +"""Where a platform's launch code puts a file: system directories and standalone layout paths.""" from __future__ import annotations -import json from collections.abc import Iterable, Mapping +from typing import TYPE_CHECKING from model.profiles import profile_names +if TYPE_CHECKING: + from resolve.launches import PlatformLaunches -def runs_standalone( - emu_name: str, profile: dict, standalone_cores: set[str] -) -> bool: - """Whether a platform lays this emulator's files out for its standalone build. - - A platform names the emulators it launches standalone in - ``standalone_cores``, by profile key or by any name in ``cores:``. The - name alone is not enough: Recalbox and Batocera call their standalone - ScummVM ``scummvm``, which is also the key of the libretro core's - profile, and that profile documents no standalone build. Laid out - "standalone" it would lose every ``path:`` and drop its files at the - root, so a profile whose ``type`` has no standalone build keeps its - libretro layout whatever the platform calls it. - """ - if not standalone_cores: - return False - if "standalone" not in str(profile.get("type", "")): - return False - names = {emu_name, *(str(c) for c in profile.get("cores", []))} - # A name a build the platform compiles itself answers to means that - # build there: RetroBat's standalone amiberry is 8.3.0, and the 8.5.0 - # profile, run there as the buildbot core, keeps its libretro layout. - owners: dict[str, set[str]] = {} - for tag in standalone_cores: - if tag.startswith(OWN_BUILD_PREFIX): - name, owner, source = json.loads(tag[len(OWN_BUILD_PREFIX):]) - if source == profile.get("source"): - owners.setdefault(name, set()).add(owner) - if any(emu_name not in owners[n] for n in names & owners.keys()): - return False - return emu_name in standalone_cores or bool(standalone_cores & names) - - -# Marks, in a platform's standalone set, an emulator it also launches as a -# libretro core. No core name starts with it. -DUAL_MODE_PREFIX = "dual:" -# Marks, in the same set, a whole directory the platform's launcher hands a -# standalone emulator (launchers.handed_directories), as JSON. -HANDED_PREFIX = "handed:" -# Marks, in the same set, a libretro core and the system directory the -# platform hands it (``core_system_dirs``), as JSON. -CORE_DIR_PREFIX = "coredir:" -# Marks, in the same set, a file the platform's launcher executes -# (launchers.executed_files), as JSON. -EXECUTED_PREFIX = "exec:" -# Marks, in the same set, a standalone name a build the platform compiles -# itself (built_by) answers to, as JSON [name, profile, source]. -OWN_BUILD_PREFIX = "ownbuild:" -# Marks, in the same set, a file name the platform declares under one of the -# systems a launcher record is written for, as JSON [system, name]: it says -# which launch reads a profile entry of that name. -SYSTEM_FILE_PREFIX = "sysfile:" -# The key, in that index, of a machine a launcher record offers. +# The key, in a platform's system file index, of a machine a launcher record offers. MACHINE_KEY = "machine:" -# The platform is known: an entry read beside the content is placed in the -# roms folders a core is launched for, or named as read outside the BIOS -# folder. The tags below carry those folders. -CONTENT_SCOPE_TAG = "contentscope:" -# [core name, roms folder, (tree, path)]: a libretro core the platform -# launches for the games of that folder, which it reads beside. -CONTENT_FOLDER_PREFIX = "contentdir:" -# [emulator or core, (tree, path), system, machines, any machine, -# source_ref, build]: a standalone emulator, or a libretro core in the -# command line it is handed as content, given a roms folder as its ROM -# search path by a system's launch command. -ROM_SEARCH_PREFIX = "romsearch:" -# The frontend writes the BIOS it hands a core beside the content: the -# folder it gives the BIOS is the content's. -CONTENT_SYSTEM_TAG = "contentsystem:" -CONTENT_TAG_PREFIXES = ( - CONTENT_SCOPE_TAG, CONTENT_FOLDER_PREFIX, ROM_SEARCH_PREFIX, CONTENT_SYSTEM_TAG, -) def core_system_dirs( - emu_name: str, profile: dict, standalone_cores: Iterable[str] + emu_name: str, profile: dict, launches: PlatformLaunches ) -> list[str] | None: """The system directories a platform hands this libretro core, or None. @@ -93,14 +25,10 @@ def core_system_dirs( them (MinUI hands each launch tag its own Bios//) gives a core it lists no directory at all, so the list is then empty. """ - pairs = [ - json.loads(tag[len(CORE_DIR_PREFIX):]) - for tag in standalone_cores if tag.startswith(CORE_DIR_PREFIX) - ] - if not pairs: + if not launches.core_dirs: return None names = set(profile_names(emu_name, profile)) - return sorted({directory for core, directory in pairs if core in names}) + return sorted({directory for core, directory in launches.core_dirs if core in names}) def system_dir_view(profile: dict, directory: str) -> dict: @@ -129,40 +57,12 @@ def system_dir_path(entry: dict, path: str) -> str: return f"{directory}/{path}" if directory else path -def handed_from_tags(standalone_cores: Iterable[str]) -> list: - """The directories a standalone set carries, as launchers built them.""" - from resolve.launchers import HandedDirectory - - found = [] - for tag in standalone_cores: - if not tag.startswith(HANDED_PREFIX): - continue - position, emulator, folder, directory, handles, ref, roms, systems, held = json.loads( - tag[len(HANDED_PREFIX):] - ) - found.append(((position, tag), HandedDirectory( - emulator, folder, directory, frozenset(handles), ref, - tuple(roms) if roms else None, frozenset(systems), held, - ))) - return [h for _key, h in sorted(found, key=lambda pair: pair[0])] - - -def system_file_index(standalone_cores: Iterable[str]) -> dict[str, set[str]]: - """File name, lower case -> the platform systems declaring it (SYSTEM_FILE_PREFIX).""" - index: dict[str, set[str]] = {} - for tag in standalone_cores: - if tag.startswith(SYSTEM_FILE_PREFIX): - slug, name = json.loads(tag[len(SYSTEM_FILE_PREFIX):]) - index.setdefault(name, set()).add(slug) - return index - - def entry_launch_systems(entry: dict, index: Mapping[str, set[str]]) -> frozenset[str]: """The platform systems, by our ids, that launch the emulator for an entry. The systems the entry names, and those under which the platform declares - a file of one of its names (``index``, system_file_index): Recalbox lists - XRoar's coco3.rom under trs80coco, which our coco is. + a file of one of its names (``index``, PlatformLaunches.system_file_index): + Recalbox lists XRoar's coco3.rom under trs80coco, which our coco is. """ systems = {str(s) for s in entry.get("systems") or []} if entry.get("system"): @@ -173,18 +73,6 @@ def entry_launch_systems(entry: dict, index: Mapping[str, set[str]]) -> frozense return frozenset(systems) -def _executed(standalone_cores: Iterable[str]) -> list: - """The files a standalone set's launchers execute, as launchers read them.""" - from resolve.launchers import ExecutedFile - - found = [] - for tag in standalone_cores: - if tag.startswith(EXECUTED_PREFIX): - emulator, name, place, ref = json.loads(tag[len(EXECUTED_PREFIX):]) - found.append(ExecutedFile(emulator, name, tuple(place) if place else None, ref)) - return found - - # Why a standalone entry has no destination on a platform that relocates its # layout: the manifest's omission reason, named as the installer words it. OUTSIDE_BIOS_FOLDER = "outside_bios_folder" @@ -266,7 +154,7 @@ def standalone_destination( def standalone_bindings_for( - emu_name: str, profile: dict, standalone_cores: Iterable[str], + emu_name: str, profile: dict, launches: PlatformLaunches, systems: Iterable[str] = (), ) -> dict[str, tuple[str, str]]: """The places a platform gives this emulator's standalone layout, by subfolder. @@ -286,7 +174,7 @@ def standalone_bindings_for( if isinstance(f, dict) and (path := standalone_layout_path(f, profile)) ] return standalone_bindings( - names, declared, handed_from_tags(standalone_cores), _executed(standalone_cores), layout, + names, declared, launches.handed, launches.executed, layout, pools, systems, ) diff --git a/scripts/resolve/reconcile.py b/scripts/resolve/reconcile.py index a53fab3f9..0a2bb5278 100644 --- a/scripts/resolve/reconcile.py +++ b/scripts/resolve/reconcile.py @@ -762,15 +762,14 @@ def _attach_runners( """ if not scraped: return - from resolve.layout import runs_standalone - from resolve.standalone import standalone_set + from resolve.standalone import platform_launches declared = scraped.get("cores") libretro = {str(c) for c in declared} if isinstance(declared, list) else set() standalone = {str(c) for c in scraped.get("standalone_cores") or []} - # The build decision reads the tagged set (own builds, twins), as the + # The build decision reads the platform launches (own builds, twins), as the # pack does. The runner's name is looked up among the plain names. - layout_set = standalone_set(scraped, profiles) + launches = platform_launches(scraped, profiles) for system in systems.values(): for fe in system.files: if fe.platform is not None or not fe.truth: @@ -781,7 +780,7 @@ def _attach_runners( sorted((key, build == "standalone") for key, _, build in (b.partition(":") for b in brought)) if brought is not None - else [(key, runs_standalone(key, profiles.get(key, {}), layout_set)) + else [(key, launches.runs_standalone(key, profiles.get(key, {}))) for key in sorted(fe.truth.get("_cores") or ())] ) for key, as_standalone in layers: diff --git a/scripts/resolve/standalone.py b/scripts/resolve/standalone.py index 46775e619..ee52c19e0 100644 --- a/scripts/resolve/standalone.py +++ b/scripts/resolve/standalone.py @@ -3,50 +3,40 @@ from __future__ import annotations import dataclasses -import json -from collections.abc import Iterable, Mapping +from collections.abc import Hashable, Iterable, Mapping from dataclasses import dataclass from model.profiles import profile_names from model.systems import norm_system_id -from resolve.contentlayout import content_folder_tags, content_layout +from resolve.contentlayout import content_launches, content_layout +from resolve.launches import PlatformLaunches, frozen_source from resolve.layout import ( - CONTENT_TAG_PREFIXES, - CORE_DIR_PREFIX, - DUAL_MODE_PREFIX, - EXECUTED_PREFIX, - HANDED_PREFIX, MACHINE_KEY, OUTSIDE_BIOS_FOLDER, - OWN_BUILD_PREFIX, - SYSTEM_FILE_PREFIX, - handed_from_tags, placed_entry, core_system_dirs, entry_launch_systems, - runs_standalone, standalone_bindings_for, standalone_destination, standalone_layout_path, system_dir_view, - system_file_index, ) -def own_build_tags( - config: dict, standalone: set[str], profiles: Mapping[str, dict] -) -> set[str]: - """The standalone names the platform's own builds answer to, tagged, - read from the run's profiles.""" +def own_builds( + config: dict, standalone: frozenset[str], profiles: Mapping[str, dict] +) -> frozenset[tuple[str, str, Hashable]]: + """The standalone names the platform's own builds answer to, as + (name, profile, source), read from the run's profiles.""" platform = str(config.get("_key") or "") if not platform or not standalone: - return set() - return { - OWN_BUILD_PREFIX + json.dumps([n, key, p.get("source")]) + return frozenset() + return frozenset( + (n, key, frozen_source(p.get("source"))) for key, p in profiles.items() if platform in (p.get("built_by") or []) and "standalone" in str(p.get("type", "")) for n in set(profile_names(key, p)) & standalone - } + ) def twin_build_names(config: dict, profiles: Mapping[str, dict]) -> set[str]: @@ -74,104 +64,92 @@ def twin_build_names(config: dict, profiles: Mapping[str, dict]) -> set[str]: return found -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]) +def core_dirs(config: dict) -> frozenset[tuple[str, str]]: + """The system directory a platform hands each core, as (core, directory).""" + return frozenset( + (str(core), directory) for directory, entry in (config.get("core_system_dirs") or {}).items() for core in entry.get("cores") or [] + ) + + +def _system_files(config: dict, handed: Iterable) -> frozenset[tuple[str, str]]: + """The file names a platform declares under the systems its launcher + records name, and the machines a record offers under its systems.""" + named = {system for h in handed for system in h.systems} + found = { + (slug, str(f["name"]).lower()) + for slug, system in (config.get("systems") or {}).items() + if slug in named + for f in system.get("files") or [] + if f.get("name") } + # The machines a record offers under its systems, by normalized id. + from resolve.launchers import native_systems + + natives = native_systems(config) + found |= { + (natives.get(str(native), str(native)), MACHINE_KEY + norm_system_id(str(m))) + for record in config.get("launchers") or [] + for native in record.get("systems") or [] + for m in record.get("machines") or [] + } + return frozenset(found) -def standalone_set(config: dict, profiles: Mapping[str, dict]) -> set[str]: +def platform_launches(config: dict, profiles: Mapping[str, dict]) -> PlatformLaunches: """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. A - launcher record resting on a config file is proven against *profiles*, - the run's, as cross-reference proves it, and the platform's own and twin - builds are read from them. + libretro:dolphin and standalone dolphin for GameCube). A launcher record + resting on a config file is proven against *profiles*, the run's, as + cross-reference proves it, and the platform's own and twin builds are + read from them. """ - 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 []} + standalone = frozenset(str(c) for c in config.get("standalone_cores") or []) + dual = {str(c) for c in config.get("dual_mode_cores") or []} # A buildbot core the platform's RetroArch installs under the name of an # emulator it runs standalone is that emulator's libretro build: run # both ways, as Batocera runs amiberry standalone and can fetch # amiberry_libretro. - names |= { - DUAL_MODE_PREFIX + str(c) - for c in set(map(str, config.get("installable_cores") or [])) - & set(map(str, config.get("standalone_cores") or [])) - } - names |= own_build_tags(config, names, profiles) - names |= {DUAL_MODE_PREFIX + n for n in twin_build_names(config, profiles)} - # 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_tags(config) - if names - {n for n in names if n.startswith(CORE_DIR_PREFIX)}: - from resolve.launchers import executed_files, handed_directories + dual |= set(map(str, config.get("installable_cores") or [])) & standalone + builds = own_builds(config, standalone, profiles) + dual |= twin_build_names(config, profiles) + launches = PlatformLaunches( + standalone=standalone, dual=frozenset(dual), own_builds=builds, + # The system directory each core is handed: platform_layouts places + # a core's files below it for every reader. + core_dirs=core_dirs(config), content=content_launches(config), + ) + if not (standalone or dual or builds): + return launches + from resolve.launchers import executed_files, handed_directories - handed = handed_directories(config, profiles) - # The record's position travels too: a search list is read in order. - names |= { - HANDED_PREFIX + json.dumps( - [position, h.emulator, h.folder, h.directory, sorted(h.handles), h.source_ref, - h.roms_place, sorted(h.systems), h.holds_declared] - ) - for position, h in enumerate(handed) - } - named = {system for h in handed for system in h.systems} - names |= { - SYSTEM_FILE_PREFIX + json.dumps([slug, str(f["name"]).lower()]) - for slug, system in (config.get("systems") or {}).items() - if slug in named - for f in system.get("files") or [] - if f.get("name") - } - # The machines a record offers under its systems, by normalized id. - from resolve.launchers import native_systems - - natives = native_systems(config) - names |= { - SYSTEM_FILE_PREFIX + json.dumps( - [natives.get(str(native), str(native)), MACHINE_KEY + norm_system_id(str(m))] - ) - for record in config.get("launchers") or [] - for native in record.get("systems") or [] - for m in record.get("machines") or [] - } - names |= { - EXECUTED_PREFIX + json.dumps([run.emulator, run.name, run.place, run.source_ref]) - for run in executed_files(config, profiles) - } - return names | content_folder_tags(config) + # The record's order travels too: a search list is read in order. + handed = tuple(handed_directories(config, profiles)) + return dataclasses.replace( + launches, + handed=handed, + system_files=_system_files(config, handed), + executed=tuple(dict.fromkeys(executed_files(config, profiles))), + ) -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 - and that it hands the others none. Carried into the union, MinUI's 86 - markers left every core they do not list without a layout: the global - gap report lost 238 profiles and 1201 files without a word. - """ - return { - tag - for config in configs - for tag in standalone_set(config, profiles) - if not tag.startswith((CORE_DIR_PREFIX, *CONTENT_TAG_PREFIXES)) - } +def merged_launches( + configs: Iterable[dict], profiles: Mapping[str, dict] +) -> PlatformLaunches: + """The launches of several platforms read as one tree (PlatformLaunches.merged).""" + return PlatformLaunches.merged(platform_launches(config, profiles) for config in configs) def platform_layouts( - emu_name: str, profile: dict, standalone_cores: set[str] + emu_name: str, profile: dict, launches: PlatformLaunches ) -> list[tuple[dict, bool]]: """The layouts a platform gives an emulator: (profile, standalone?) each, with the files read in a roms folder placed there (content_layout).""" return [ - (content_layout(emu_name, view, standalone, standalone_cores), standalone) - for view, standalone in _build_layouts(emu_name, profile, standalone_cores) + (content_layout(emu_name, view, standalone, launches), standalone) + for view, standalone in _build_layouts(emu_name, profile, launches) ] @@ -181,7 +159,7 @@ class _StandaloneLaunches: emu_name: str profile: dict - standalone_cores: set[str] + launches: PlatformLaunches per_system: bool index: Mapping[str, set[str]] # A profile system the platform launches under a system of its own, as @@ -196,12 +174,12 @@ class _StandaloneLaunches: by_systems: dict[frozenset[str], dict[str, tuple[str, str]]] = dataclasses.field(default_factory=dict) @classmethod - def of(cls, emu_name: str, profile: dict, standalone_cores: set[str]) -> _StandaloneLaunches: + def of(cls, emu_name: str, profile: dict, launches: PlatformLaunches) -> _StandaloneLaunches: names = set(profile_names(emu_name, profile)) per_system = bool( profile.get("standalone_directories") or profile.get("standalone_pools") - ) and any(h.systems and h.emulator in names for h in handed_from_tags(standalone_cores)) - index = system_file_index(standalone_cores) if per_system else {} + ) and any(h.systems and h.emulator in names for h in launches.handed) + index = launches.system_file_index() if per_system else {} # A profile system the platform launches under a system of its own, as # its list says for one entry, is launched there for every entry: # Recalbox lists mc10.rom under trs80coco, so alice.rom is read there. @@ -216,7 +194,7 @@ class _StandaloneLaunches: # the folder its record gives, every other launch the folder the records # naming none give. named_systems = frozenset().union(*( - h.systems for h in handed_from_tags(standalone_cores) if h.emulator in names + h.systems for h in launches.handed if h.emulator in names )) if per_system else frozenset() # The layout folders a search setting stands for (standalone_pools): @@ -225,7 +203,7 @@ class _StandaloneLaunches: pool_folders = {v.strip("/") for v in _pool_folders(profile).values()} - {""} return cls( - emu_name, profile, standalone_cores, per_system, index, family, + emu_name, profile, launches, per_system, index, family, named_systems, pool_folders, ) @@ -248,7 +226,7 @@ class _StandaloneLaunches: def bindings_for(self, systems: frozenset[str]) -> dict[str, tuple[str, str]]: if systems not in self.by_systems: self.by_systems[systems] = standalone_bindings_for( - self.emu_name, self.profile, self.standalone_cores, systems + self.emu_name, self.profile, self.launches, systems ) return self.by_systems[systems] @@ -307,7 +285,7 @@ class _StandaloneLaunches: def _build_layouts( - emu_name: str, profile: dict, standalone_cores: set[str] + emu_name: str, profile: dict, launches: PlatformLaunches ) -> list[tuple[dict, bool]]: """The layouts a platform gives an emulator: (profile, standalone?) each. @@ -316,19 +294,19 @@ def _build_layouts( Dolphin found dolphin-emu/Sys/GC/ empty. Each layout keeps its own rules (what the build reads from the system directory, where it reads it). """ - if not runs_standalone(emu_name, profile, standalone_cores): - directories = core_system_dirs(emu_name, profile, standalone_cores) + if not launches.runs_standalone(emu_name, profile): + directories = core_system_dirs(emu_name, profile, launches) if directories is None: return [(profile, False)] return [(system_dir_view(profile, d), False) for d in directories] standalone = profile - launches = _StandaloneLaunches.of(emu_name, profile, standalone_cores) + placing = _StandaloneLaunches.of(emu_name, profile, launches) layout_entries = [ f for f in profile.get("files") or [] if isinstance(f, dict) and standalone_layout_path(f, profile) is not None ] - if any(launches.bindings_of(f) for f in layout_entries): + if any(placing.bindings_of(f) for f in layout_entries): # The standalone view carries the platform's destination, so every # reader of standalone_path (builder, manifest, verify, slots) places # the file in the folder the platform hands the emulator. @@ -336,11 +314,9 @@ def _build_layouts( # platform keeps outside the BIOS tree: UAE4All2's kick.rom in # RetroPie's $md_inst. It is marked, never left at the BIOS root # where the emulator does not read it. - standalone = {**profile, "files": launches.placed_files()} - dual = {c.removeprefix(DUAL_MODE_PREFIX) for c in standalone_cores - if c.startswith(DUAL_MODE_PREFIX)} - if "libretro" in str(profile.get("type", "")) and dual & { - emu_name, *(str(c) for c in profile.get("cores", [])) - }: + standalone = {**profile, "files": placing.placed_files()} + if "libretro" in str(profile.get("type", "")) and launches.is_dual( + {emu_name, *(str(c) for c in profile.get("cores", []))} + ): return [(profile, False), (standalone, True)] return [(standalone, True)] diff --git a/scripts/resolve/truth.py b/scripts/resolve/truth.py index 17e1387c8..02d08fcc5 100644 --- a/scripts/resolve/truth.py +++ b/scripts/resolve/truth.py @@ -13,7 +13,8 @@ from dataclasses import dataclass from model.declarations import OUTER_ROOTS from model.systems import norm_system_id -from resolve.standalone import platform_layouts, standalone_set as platform_standalone_set +from resolve.launches import PlatformLaunches +from resolve.standalone import platform_layouts, platform_launches from resolve.cores import resolve_platform_cores from resolve.reconcile import contradicts, shares_hash from model.alternatives import groups_of @@ -542,7 +543,7 @@ def _fold_data_directory_readers( systems: dict, profiles: dict, cores: list[str], - standalone_set: set[str], + launches: PlatformLaunches, platform_name: str, data_registry: dict, ) -> None: @@ -565,7 +566,7 @@ def _fold_data_directory_readers( return for emu_name in cores: for view, standalone in platform_layouts( - emu_name, profiles[emu_name], standalone_set + emu_name, profiles[emu_name], launches ): trees = [ tree for tree in filter_files_by_mode( @@ -729,7 +730,7 @@ def _cover( def _platform_entries( - emu_name: str, profile: dict, standalone_set: set[str], platform_name: str, + emu_name: str, profile: dict, launches: PlatformLaunches, platform_name: str, ) -> list[dict]: # The pack's rule (validation.deliverable), per build: a file the # emulator installs is kept and marked, one the launcher never opens @@ -741,7 +742,7 @@ def _platform_entries( "_brought": None if installed_with_emulator(fe, platform_name) else f"{emu_name}:{'standalone' if standalone else 'libretro'}", } - for view, standalone in platform_layouts(emu_name, profile, standalone_set) + for view, standalone in platform_layouts(emu_name, profile, launches) for fe in _system_dir_files(view, standalone) if not unread_on(fe, platform_name) ]) @@ -802,7 +803,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, profiles) + launches = platform_launches(config, profiles) resolved = resolve_platform_cores(config, profiles, target_cores) @@ -830,7 +831,7 @@ def generate_platform_truth( on_platform = { mapping.map_sys_id(sid) for sid in profile.get("systems", []) } & mapping.platform_sys_ids - for fe in _platform_entries(emu_name, profile, standalone_set, platform_name): + for fe in _platform_entries(emu_name, profile, launches, platform_name): sys_targets = mapping.targets(fe, profile, on_platform) if not sys_targets: unattributed[emu_name] = unattributed.get(emu_name, 0) + 1 @@ -859,7 +860,7 @@ def generate_platform_truth( _cover(system_cores, sys_id, "unprofiled", emu_name) _fold_data_directory_readers( - systems, profiles, sorted(cores_profiled), standalone_set, platform_name, + systems, profiles, sorted(cores_profiled), launches, platform_name, data_registry, ) diff --git a/scripts/sitegen/install.py b/scripts/sitegen/install.py index 44dfd2d11..e615d45c9 100644 --- a/scripts/sitegen/install.py +++ b/scripts/sitegen/install.py @@ -17,8 +17,9 @@ from sitegen.guidedata import platform_guides, terminals, install_command from model.platforms import load_platform_config from model.registry import list_release_pack_platforms from model.profiles import reads_own_files -from resolve.layout import data_root_place, runs_standalone -from resolve.standalone import standalone_set +from resolve.launches import PlatformLaunches +from resolve.layout import data_root_place +from resolve.standalone import platform_launches from resolve.validation import installed_everywhere, installed_with_emulator from sitegen import markup from installer_build.module import installer_module @@ -165,7 +166,7 @@ def emulator_install_route(name: str, profile: dict) -> tuple[str, list[str], tu # package leaves out the 667 files every other setup's install brings. if all(installed_with_emulator(f, platform) for f in files): continue - if standalone and not runs_standalone(name, profile, _standalone_cores(platform)): + if standalone and not _standalone_cores(platform).runs_standalone(name, profile): continue if any("--dest" in args for args in platform_args(platform, platform_guides()[platform]).values()): continue @@ -194,16 +195,16 @@ def emulator_install_route(name: str, profile: dict) -> tuple[str, list[str], tu return command, setups, oses -def _standalone_cores(platform: str) -> frozenset[str]: +def _standalone_cores(platform: str) -> PlatformLaunches: """The emulators a setup launches as apps, by its platform file.""" inputs = siteinputs.current() return _standalone_cores_in(str(inputs.platforms), str(inputs.emulators), platform) @functools.cache -def _standalone_cores_in(platforms_dir: str, emulators_dir: str, platform: str) -> frozenset[str]: +def _standalone_cores_in(platforms_dir: str, emulators_dir: str, platform: str) -> PlatformLaunches: config = load_platform_config(platform, platforms_dir) - return frozenset(standalone_set(config, profiles_in(emulators_dir, skip_aliases=True))) + return platform_launches(config, profiles_in(emulators_dir, skip_aliases=True)) def install_block(name: str, profile: dict) -> list[str]: diff --git a/scripts/sitegen/wanted.py b/scripts/sitegen/wanted.py index e632e20af..860ba31de 100644 --- a/scripts/sitegen/wanted.py +++ b/scripts/sitegen/wanted.py @@ -21,8 +21,8 @@ from collections.abc import Callable, Iterable from pathlib import Path from romrecipes import ledger as romrecipes_ledger -from resolve.layout import runs_standalone -from resolve.standalone import standalone_set +from resolve.launches import PlatformLaunches +from resolve.standalone import platform_launches from model.profiles import unique_emulator_profiles from packs.crossref import first_hash from core.hashing import cut_md5_owner, declared_hash_lists, parse_hash_list @@ -160,7 +160,7 @@ def paired_declarations(files: list, details: list[dict]) -> Iterable[tuple[dict def _brought_by_readers( - detail: dict, standalone_cores: set[str], platform: str, profiles: dict, + detail: dict, standalone_cores: PlatformLaunches, platform: str, profiles: dict, ) -> bool: """Whether every core that reads a platform entry installs it itself. @@ -179,7 +179,7 @@ def _brought_by_readers( names = {str(e.get("name")) for e in reader.get("entries") or []} read = [f for f in profile.get("files") or [] if isinstance(f, dict) and str(f.get("name")) in names] - standalone = runs_standalone(reader["emulator"], profile, standalone_cores) + standalone = standalone_cores.runs_standalone(reader["emulator"], profile) if filter_files_by_mode(read, standalone): verdicts.append(not deliverable(read, standalone, platform)) return bool(verdicts) and all(verdicts) @@ -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", {}), profiles) + standalone_cores = platform_launches(coverage.get("config", {}), profiles) by_system: dict[str, list[dict]] = {} for detail in coverage.get("details", []): by_system.setdefault(detail.get("system", ""), []).append(detail) diff --git a/tests/test_audit_regressions.py b/tests/test_audit_regressions.py index 2dde6a4a7..d74a63f12 100644 --- a/tests/test_audit_regressions.py +++ b/tests/test_audit_regressions.py @@ -4544,7 +4544,7 @@ class OpenMsxRomsSitInItsSystemroms(unittest.TestCase): def test_every_entry_is_under_share_systemroms(self): from scripts.model.profiles import load_emulator_profiles from scripts.model.platforms import load_platform_config - from scripts.resolve.standalone import platform_layouts, standalone_set + from scripts.resolve.standalone import platform_layouts, platform_launches profiles = load_emulator_profiles(str(ROOT / "emulators")) profile = profiles["openmsx"] @@ -4557,7 +4557,7 @@ class OpenMsxRomsSitInItsSystemroms(unittest.TestCase): } self.assertEqual(declared_dirs, {"openmsx/share/systemroms"}) config = load_platform_config("retrobat", str(ROOT / "platforms")) - ((view, _standalone),) = platform_layouts("openmsx", profile, standalone_set(config, profiles)) + ((view, _standalone),) = platform_layouts("openmsx", profile, platform_launches(config, profiles)) placed = {f["name"]: f for f in view["files"]} for entry in profile["files"]: with self.subTest(name=entry["name"]): @@ -5385,7 +5385,7 @@ class EmuDeckRunsItsEmulatorsStandalone(unittest.TestCase): def test_every_emuscripts_emulator_is_standalone(self): from scripts.model.platforms import load_platform_config - from scripts.resolve.layout import runs_standalone + from scripts.resolve.launches import PlatformLaunches from scripts.model.profiles import load_emulator_profiles config = load_platform_config("emudeck", str(ROOT / "platforms")) @@ -5394,10 +5394,10 @@ class EmuDeckRunsItsEmulatorsStandalone(unittest.TestCase): sorted(c for c in config["cores"] if c != "retroarch"), ) profiles = load_emulator_profiles(str(ROOT / "emulators")) - standalone = set(config["standalone_cores"]) + standalone = PlatformLaunches(standalone=frozenset(config["standalone_cores"])) for name in ("dolphin", "cemu", "armsx2", "supermodel"): with self.subTest(emulator=name): - self.assertTrue(runs_standalone(name, profiles[name], standalone)) + self.assertTrue(standalone.runs_standalone(name, profiles[name])) def test_retroarch_brings_its_libretro_cores(self): """The scraper dropped RetroArch's own script: np2kai, neocd and diff --git a/tests/test_batocera_cores.py b/tests/test_batocera_cores.py index fd190da99..453604fbf 100644 --- a/tests/test_batocera_cores.py +++ b/tests/test_batocera_cores.py @@ -112,13 +112,16 @@ class AnEmulatorLaunchedBothWaysGetsBothLayouts(unittest.TestCase): self.assertEqual(standalone & es_systems_libretro(text), {"dolphin"}) def test_the_layouts_are_both(self): - from resolve.layout import DUAL_MODE_PREFIX + from resolve.launches import PlatformLaunches from resolve.standalone import platform_layouts profile = {"type": "standalone + libretro", "cores": ["dolphin"], "files": []} - both = platform_layouts("dolphin", profile, {"dolphin", DUAL_MODE_PREFIX + "dolphin"}) + dolphin = frozenset({"dolphin"}) + both = platform_layouts( + "dolphin", profile, PlatformLaunches(standalone=dolphin, dual=dolphin) + ) self.assertEqual([standalone for _view, standalone in both], [False, True]) - only = platform_layouts("dolphin", profile, {"dolphin"}) + only = platform_layouts("dolphin", profile, PlatformLaunches(standalone=dolphin)) self.assertEqual([standalone for _view, standalone in only], [True]) def test_the_batocera_manifest_carries_both(self): diff --git a/tests/test_core_data_trees.py b/tests/test_core_data_trees.py index d6c3adc30..c1cf40a9e 100644 --- a/tests/test_core_data_trees.py +++ b/tests/test_core_data_trees.py @@ -22,7 +22,7 @@ from model.platforms import load_platform_config 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 +from resolve.standalone import platform_layouts, platform_launches from packs import archive from packs import datatrees from packs import platformpack @@ -155,7 +155,7 @@ class EveryReaderHasTheTreeOrAReason(unittest.TestCase): unexplained = [] for platform in list_registered_platforms(platforms_dir): config = load_platform_config(platform, platforms_dir) - handed = standalone_set(config, profiles) + handed = platform_launches(config, profiles) for core in sorted(resolve_platform_cores(config, profiles)): profile = profiles[core] if all(standalone for _view, standalone diff --git a/tests/test_e2e.py b/tests/test_e2e.py index 331d3fc98..50c0ddc4e 100644 --- a/tests/test_e2e.py +++ b/tests/test_e2e.py @@ -6872,18 +6872,20 @@ class StandaloneModeRequiresAStandaloneBuild(unittest.TestCase): profile loses every ``path:`` and drops its files at the root.""" def test_libretro_only_profile_keeps_its_layout(self): - from resolve.layout import runs_standalone + from resolve.launches import PlatformLaunches libretro_only = {"type": "libretro", "cores": ["scummvm"]} dual = {"type": "standalone + libretro", "cores": ["dolphin"]} standalone = {"type": "standalone", "cores": ["xemu"]} - named = {"scummvm", "dolphin", "xemu", "hatari"} - self.assertFalse(runs_standalone("scummvm", libretro_only, named)) - self.assertTrue(runs_standalone("dolphin", dual, named)) - self.assertTrue(runs_standalone("xemu", standalone, named)) - self.assertTrue(runs_standalone("other-key", {"type": "standalone", "cores": ["hatari"]}, named)) - self.assertFalse(runs_standalone("dolphin", dual, set())) - self.assertFalse(runs_standalone("dolphin", dual, {"pcsx2"})) + named = PlatformLaunches(standalone=frozenset({"scummvm", "dolphin", "xemu", "hatari"})) + self.assertFalse(named.runs_standalone("scummvm", libretro_only)) + self.assertTrue(named.runs_standalone("dolphin", dual)) + self.assertTrue(named.runs_standalone("xemu", standalone)) + self.assertTrue(named.runs_standalone("other-key", {"type": "standalone", "cores": ["hatari"]})) + self.assertFalse(PlatformLaunches().runs_standalone("dolphin", dual)) + self.assertFalse( + PlatformLaunches(standalone=frozenset({"pcsx2"})).runs_standalone("dolphin", dual) + ) diff --git a/tests/test_gap_settlement.py b/tests/test_gap_settlement.py index 89c120a30..f84f40350 100644 --- a/tests/test_gap_settlement.py +++ b/tests/test_gap_settlement.py @@ -14,6 +14,7 @@ import unittest from pathlib import Path from packs.crossref import cross_reference +from resolve.launches import PlatformLaunches from resolve.validation import case_folded_slots, declaration_settles REPO_ROOT = Path(__file__).resolve().parents[1] @@ -87,7 +88,7 @@ class TheRunningBuildPlacesTheGap(unittest.TestCase): "systems": ["nintendo-wiiu"], "files": [self.KEYS]}} report = cross_reference( profiles, {}, {"files": {}, "indexes": {}}, all_declared={}, - standalone_cores=standalone, + standalone_cores=PlatformLaunches(standalone=frozenset(standalone)), ) return [g["path"] for g in report["cemu"]["gap_details"]] diff --git a/tests/test_launcher_evidence.py b/tests/test_launcher_evidence.py index e6b23b345..fa22d72fb 100644 --- a/tests/test_launcher_evidence.py +++ b/tests/test_launcher_evidence.py @@ -18,8 +18,7 @@ import yaml from model.platforms import load_platform_config from model.profiles import load_emulator_profiles from resolve.categories import EntryCategories -from resolve.layout import EXECUTED_PREFIX, HANDED_PREFIX -from resolve.standalone import standalone_set +from resolve.standalone import platform_launches from resolve.launchers import ( bound_launchers, config_evidence, @@ -209,26 +208,23 @@ class Gate(unittest.TestCase): self.assertEqual(len(bound_launchers(config, {"duck": profile(config_reads=[])})), 1) def test_the_layout_is_proven_against_the_profiles_given(self) -> None: - """The pack's tag set and cross_reference judge with the same profiles: + """The pack's launches and cross_reference judge with the same profiles: an --emulators-dir whose profile lacks config_reads hands nothing.""" config = {**self.config(record()), "standalone_cores": ["duck"]} - handed = [t for t in standalone_set(config, {"duck": profile()}) if t.startswith(HANDED_PREFIX)] - self.assertEqual(len(handed), 1) - self.assertFalse([t for t in standalone_set(config, {"duck": profile(config_reads=[])}) - if t.startswith(HANDED_PREFIX)]) + self.assertEqual(len(platform_launches(config, {"duck": profile()}).handed), 1) + self.assertFalse(platform_launches(config, {"duck": profile(config_reads=[])}).handed) def test_an_unproven_record_executes_nothing(self) -> None: code = {"emulator": "duck", "kind": "fixed_name", "names": ["run.sh"], "passes_to": "exec", "search_dir": "/storage/roms/bios", "source_ref": "start.sh:3"} cited = {**code, "source_ref": "duck/config/settings.ini:4, start.sh:3"} - def executed(launcher: dict) -> list[str]: + def executed(launcher: dict) -> tuple: config = {**self.config(launcher), "standalone_cores": ["duck"]} - return [t for t in standalone_set(config, {"duck": profile()}) - if t.startswith(EXECUTED_PREFIX)] + return platform_launches(config, {"duck": profile()}).executed self.assertEqual(len(executed(code)), 1) - self.assertEqual(executed(cited), []) + self.assertEqual(executed(cited), ()) def test_an_unproven_record_proves_no_read(self) -> None: named = record(kind="fixed_name", names=["tos.img"], passes_to="settings.ini [BIOS] PathPAL") diff --git a/tests/test_launcher_layer.py b/tests/test_launcher_layer.py index b57095c6c..9c85bc183 100644 --- a/tests/test_launcher_layer.py +++ b/tests/test_launcher_layer.py @@ -23,6 +23,7 @@ import yaml from model.profiles import emulator_profiles_cache, load_emulator_profiles from model.platforms import load_platform_config +from resolve.launches import PlatformLaunches from resolve.launchers import LauncherLayer, launcher_places, suffixed_stem from packs.gaps import find_undeclared_files from packs.coverage import verify_platform @@ -443,7 +444,7 @@ class LauncherLayerTest(unittest.TestCase): report = cross_reference( self.profiles, declared, self.db, set(), all_declared=scope["all_declared"], - standalone_cores={"psxemu", "fixemu"}, + standalone_cores=PlatformLaunches(standalone=frozenset({"psxemu", "fixemu"})), platform="launchertest", launcher_layer=layer, ) gaps = sorted( diff --git a/tests/test_launcher_paths.py b/tests/test_launcher_paths.py index 70b9eb1da..f6904e052 100644 --- a/tests/test_launcher_paths.py +++ b/tests/test_launcher_paths.py @@ -349,7 +349,7 @@ class AUserFolderInTheConfigsFolder(unittest.TestCase): from model.profiles import load_emulator_profiles from model.platforms import load_platform_config from resolve.standalone import platform_layouts - from resolve.standalone import standalone_set + from resolve.standalone import platform_launches profiles = load_emulator_profiles(str(REPO_ROOT / "emulators")) profile = profiles["shadps4"] @@ -357,7 +357,7 @@ class AUserFolderInTheConfigsFolder(unittest.TestCase): for platform in ("batocera",): config = load_platform_config(platform, str(REPO_ROOT / "platforms")) ((view, _standalone),) = platform_layouts( - "shadps4", profile, standalone_set(config, profiles) + "shadps4", profile, platform_launches(config, profiles) ) with self.subTest(platform=platform): self.assertEqual( diff --git a/tests/test_launcher_placement.py b/tests/test_launcher_placement.py index 222afed45..a9f525f2c 100644 --- a/tests/test_launcher_placement.py +++ b/tests/test_launcher_placement.py @@ -13,7 +13,6 @@ import tests import hashlib import io -import json import shutil import tempfile import unittest @@ -25,7 +24,7 @@ import yaml from model.profiles import emulator_profiles_cache, load_emulator_profiles from model.platforms import load_platform_config -from resolve.standalone import platform_layouts, standalone_set +from resolve.standalone import platform_layouts, platform_launches from packs.manifest import generate_manifest from packs.platformpack import build_platform_pack from packs.coverage import verify_platform @@ -204,7 +203,7 @@ class ALinkMovesTheDestination(unittest.TestCase): config = {"standalone_cores": ["kick"], "launchers": [LINK]} profiles = load_emulator_profiles(str(self.emulators)) profile = profiles["kick"] - (view, standalone), = platform_layouts("kick", profile, standalone_set(config, profiles)) + (view, standalone), = platform_layouts("kick", profile, platform_launches(config, profiles)) self.assertTrue(standalone) self.assertNotIn("standalone_path", view["files"][0]) @@ -216,7 +215,7 @@ class UAE4AllOnRetroPie(unittest.TestCase): profiles = load_emulator_profiles(str(REPO_ROOT / "emulators")) profile = profiles["uae4all"] config = load_platform_config("retropie", str(REPO_ROOT / "platforms")) - (view, standalone), = platform_layouts("uae4all", profile, standalone_set(config, profiles)) + (view, standalone), = platform_layouts("uae4all", profile, platform_launches(config, profiles)) self.assertTrue(standalone) for entry in view["files"]: if entry["path"].startswith("kickstarts/"): @@ -689,7 +688,7 @@ class AetherSX2OnKnulli(unittest.TestCase): profiles = load_emulator_profiles(str(REPO_ROOT / "emulators")) profile = profiles["aethersx2"] config = load_platform_config("knulli", str(REPO_ROOT / "platforms")) - (view, standalone), = platform_layouts("aethersx2", profile, standalone_set(config, profiles)) + (view, standalone), = platform_layouts("aethersx2", profile, platform_launches(config, profiles)) self.assertTrue(standalone) for entry in view["files"]: path = entry.get("path") or "" @@ -706,7 +705,7 @@ class Quasi88OnRetroPie(unittest.TestCase): profiles = load_emulator_profiles(str(REPO_ROOT / "emulators")) profile = profiles["quasi88kai"] config = load_platform_config("retropie", str(REPO_ROOT / "platforms")) - (view, standalone), = platform_layouts("quasi88kai", profile, standalone_set(config, profiles)) + (view, standalone), = platform_layouts("quasi88kai", profile, platform_launches(config, profiles)) self.assertTrue(standalone) paths = [e["path"] for e in view["files"]] self.assertTrue(paths and all(p.startswith("rom/") for p in paths)) @@ -736,7 +735,7 @@ class FlycastOnEmuELEC(unittest.TestCase): profiles = load_emulator_profiles(str(REPO_ROOT / "emulators")) profile = profiles["flycast"] config = load_platform_config("emuelec", str(REPO_ROOT / "platforms")) - layouts = platform_layouts("flycast", profile, standalone_set(config, profiles)) + layouts = platform_layouts("flycast", profile, platform_launches(config, profiles)) (view,) = [v for v, standalone in layouts if standalone] self.assertTrue(view["files"]) for entry in view["files"]: @@ -747,7 +746,7 @@ def standalone_view(emulator: str, platform: str) -> dict: profiles = load_emulator_profiles(str(REPO_ROOT / "emulators")) profile = profiles[emulator] config = load_platform_config(platform, str(REPO_ROOT / "platforms")) - (view,) = [v for v, standalone in platform_layouts(emulator, profile, standalone_set(config, profiles)) + (view,) = [v for v, standalone in platform_layouts(emulator, profile, platform_launches(config, profiles)) if standalone] return view @@ -939,7 +938,7 @@ class LibretroMameSetsInMameBios(unittest.TestCase): profiles = load_emulator_profiles(str(REPO_ROOT / "emulators")) profile = profiles["mame"] config = load_platform_config("retrobat", str(REPO_ROOT / "platforms")) - builds = sorted(s for _v, s in platform_layouts("mame", profile, standalone_set(config, profiles))) + builds = sorted(s for _v, s in platform_layouts("mame", profile, platform_launches(config, profiles))) self.assertEqual(builds, [False, True]) @@ -1041,7 +1040,7 @@ def libretro_view(emulator: str, platform: str) -> dict: profiles = load_emulator_profiles(str(REPO_ROOT / "emulators")) profile = profiles[emulator] config = load_platform_config(platform, str(REPO_ROOT / "platforms")) - (view,) = [v for v, standalone in platform_layouts(emulator, profile, standalone_set(config, profiles)) + (view,) = [v for v, standalone in platform_layouts(emulator, profile, platform_launches(config, profiles)) if not standalone] return view @@ -1232,12 +1231,12 @@ class AdvanceMameOnRetroPie(unittest.TestCase): def test_the_sets_go_to_the_first_folder_searched(self) -> None: config = load_platform_config("retropie", str(REPO_ROOT / "platforms")) profiles = load_emulator_profiles(str(REPO_ROOT / "emulators")) - tags = standalone_set(config, profiles) + launches = platform_launches(config, profiles) for emu in ("advmame", "advmame-1.4", "advmame-0.94"): with self.subTest(emu=emu): placed = [ (f.get("root"), f.get("standalone_path")) - for view, standalone in platform_layouts(emu, profiles[emu], tags) + for view, standalone in platform_layouts(emu, profiles[emu], launches) if standalone for f in view["files"] if isinstance(f, dict) and f["name"] == "neogeo.zip" ] @@ -1282,16 +1281,13 @@ class CoreOfferedOnSomeBoards(unittest.TestCase): self.assertIsNone(boards[("puae2021", "amiga")]) def test_a_board_pack_places_the_core_where_the_board_offers_it(self) -> None: - from resolve.layout import CONTENT_FOLDER_PREFIX - from resolve.contentlayout import TARGET_KEY, content_folder_tags + from resolve.contentlayout import TARGET_KEY, content_launches def placed(config: dict) -> dict: - rows = [json.loads(t[len(CONTENT_FOLDER_PREFIX):]) for t in content_folder_tags(config) - if t.startswith(CONTENT_FOLDER_PREFIX)] - return {core: on for core, _folder, _where, on in rows} + return {row.core: row.boards for row in content_launches(config).folders} every = placed(self.config()) - self.assertEqual(every["uae4arm"], ["h700", "rk3326"]) + self.assertEqual(every["uae4arm"], ("h700", "rk3326")) self.assertIsNone(every["puae"]) self.assertIn("uae4arm", placed(self.config(**{TARGET_KEY: "rk3326"}))) self.assertNotIn("uae4arm", placed(self.config(**{TARGET_KEY: "s922x"}))) diff --git a/tests/test_minui_platform.py b/tests/test_minui_platform.py index 1cbd3abfb..38d68f9ed 100644 --- a/tests/test_minui_platform.py +++ b/tests/test_minui_platform.py @@ -439,16 +439,16 @@ class TheSitePageOfACardPlatform(unittest.TestCase): class TheWholeTreeKeepsCoresMinUILeavesOut(unittest.TestCase): """Without --platform, cross_reference and the site's gap report merge - every platform's standalone set. MinUI's per-core folders came along and + every platform's launches. MinUI's per-core folders came along and left every core MinUI does not list with no layout: px68k showed 0 files and the global report lost 238 profiles.""" def test_a_core_minui_does_not_list_keeps_its_files(self): - from resolve.standalone import merged_standalone_set, platform_layouts + from resolve.standalone import merged_launches, platform_layouts minui = {"core_system_dirs": {"Bios/FC": {"cores": ["fceumm"]}}} retroarch = {} - merged = merged_standalone_set([minui, retroarch], {}) + merged = merged_launches([minui, retroarch], {}) profile = {"type": "libretro", "files": [{"name": "cgrom.tmp"}]} layouts = platform_layouts("px68k", profile, merged) self.assertEqual(layouts, [(profile, False)]) @@ -460,10 +460,10 @@ class TheWholeTreeKeepsCoresMinUILeavesOut(unittest.TestCase): source = script_source(script) with self.subTest(script=script): self.assertTrue( - "merged_standalone_set(" in source or "global_report_scope(" in source + "merged_launches(" in source or "global_report_scope(" in source ) - self.assertNotIn("set().union(*(\n standalone_set(", source) - self.assertNotIn("*(standalone_set(cov", source) + self.assertNotIn("set().union(*(\n platform_launches(", source) + self.assertNotIn("*(platform_launches(cov", source) if __name__ == "__main__": diff --git a/tests/test_pack_probe.py b/tests/test_pack_probe.py index 9f5ac82eb..a0431fb67 100644 --- a/tests/test_pack_probe.py +++ b/tests/test_pack_probe.py @@ -94,7 +94,7 @@ class CoreChoice(unittest.TestCase): self.assertTrue(packprobe.libretro_build_runs("duckstation", both, { "standalone_cores": ["duckstation"], "dual_mode_cores": ["duckstation-sa"]}, {})) # A buildbot core installable under the standalone name is its - # libretro build, run both ways (standalone_set). + # libretro build, run both ways (platform_launches). self.assertTrue(packprobe.libretro_build_runs("duckstation", both, { "standalone_cores": ["duckstation"], "installable_cores": ["duckstation"]}, {})) self.assertFalse(packprobe.libretro_build_runs("x", {"type": "standalone"}, {}, {})) diff --git a/tests/test_slots.py b/tests/test_slots.py index 77a9b330f..fc1d874c6 100644 --- a/tests/test_slots.py +++ b/tests/test_slots.py @@ -16,10 +16,13 @@ from pathlib import Path from packs import slotreport from packs import slots as packs_slots from resolve import collisions as resolve_collisions +from resolve.launches import PlatformLaunches from packs.slots import Claim, Conflict, arbitrate from packs.slotreport import format_decision from tests.sources import script_source +ARES = PlatformLaunches(standalone=frozenset({"ares"})) + def _db(entries: dict[str, dict]) -> dict: """Minimal database shaped like the generated one, keyed by sha1. @@ -699,7 +702,7 @@ class TestBuildModeDecidesWhoClaims(unittest.TestCase): self._config(standalone=["ares"]), self._profile(mode="standalone"), REGIONS_DB, - standalone_cores={"ares"}, + standalone_cores=ARES, ) self.assertEqual(len(conflicts), 1) @@ -708,7 +711,7 @@ class TestBuildModeDecidesWhoClaims(unittest.TestCase): self._config(standalone=["ares"]), self._profile(mode="libretro"), REGIONS_DB, - standalone_cores={"ares"}, + standalone_cores=ARES, ) self.assertEqual(conflicts, []) @@ -716,7 +719,7 @@ class TestBuildModeDecidesWhoClaims(unittest.TestCase): claims = packs_slots.profile_claims( self._profile(standalone_path="elsewhere/IPL.bin"), REGIONS_DB, - standalone_cores={"ares"}, + standalone_cores=ARES, ) self.assertEqual(claims[0].destination, "elsewhere/IPL.bin") @@ -728,7 +731,7 @@ class TestBuildModeDecidesWhoClaims(unittest.TestCase): "mode": "standalone"}]}} conflicts = packs_slots.find_conflicts( self._config(standalone=["ares"]), profile, REGIONS_DB, - standalone_cores={"ares"}, + standalone_cores=ARES, ) self.assertEqual(len(conflicts), 1) @@ -738,7 +741,7 @@ class TestBuildModeDecidesWhoClaims(unittest.TestCase): "path": "GC/JAP/IPL.bin", "standalone_path": "elsewhere/IPL.bin"}]}} claims = packs_slots.profile_claims( - profile, REGIONS_DB, standalone_cores={"ares"} + profile, REGIONS_DB, standalone_cores=ARES ) self.assertEqual(claims[0].destination, "GC/JAP/IPL.bin") diff --git a/tests/test_standalone_links.py b/tests/test_standalone_links.py index 0061d22af..60d47a232 100644 --- a/tests/test_standalone_links.py +++ b/tests/test_standalone_links.py @@ -22,11 +22,11 @@ from resolve.layout import ( entry_launch_systems, standalone_bindings_for, standalone_destination, - system_file_index, ) from model.profiles import load_emulator_profiles from model.platforms import load_platform_config -from resolve.standalone import platform_layouts, standalone_set +from resolve.launches import PlatformLaunches +from resolve.standalone import platform_layouts, platform_launches from resolve.launchers import ( SEARCHED_FILES, bound_path, @@ -70,7 +70,7 @@ def config(*launchers: dict, base: str = "bios") -> dict: def standalone_view(cfg: dict) -> dict: - views = platform_layouts("emu", PROFILE, standalone_set(cfg, {})) + views = platform_layouts("emu", PROFILE, platform_launches(cfg, {})) return next(view for view, standalone in views if standalone) @@ -309,7 +309,7 @@ class PerSystem(unittest.TestCase): **config({**passes("emu", "bios/coco", "-rompath"), "systems": ["coco"]}), "systems": {"coco": {"files": [{"name": "coco3.rom", "native_system": "coco"}]}}, } - index = system_file_index(standalone_set(cfg, {})) + index = platform_launches(cfg, {}).system_file_index() self.assertEqual( entry_launch_systems({"name": "COCO3.ROM", "system": "coco3"}, index), frozenset({"coco3", "coco"}), @@ -332,7 +332,7 @@ class SystemFamily(unittest.TestCase): "systems": {"coco": {"native_id": "trs80coco", "files": [{"name": "mc10.rom"}]}}, } - ((view, _standalone),) = platform_layouts("emu", profile, standalone_set(cfg, {})) + ((view, _standalone),) = platform_layouts("emu", profile, platform_launches(cfg, {})) self.assertEqual( [f.get("standalone_path") for f in view["files"]], ["trs80coco/mc10.rom", "trs80coco/alice.rom"], @@ -356,7 +356,7 @@ class OfferedMachine(unittest.TestCase): ), "systems": {"coco": {"files": [{"name": "x.zip", "native_system": "coco"}]}}, } - ((view, _standalone),) = platform_layouts("emu", profile, standalone_set(cfg, {})) + ((view, _standalone),) = platform_layouts("emu", profile, platform_launches(cfg, {})) self.assertEqual( [f.get("standalone_path") for f in view["files"]], ["coco/coco3.rom", "dragon/mc10.rom"] ) @@ -382,7 +382,7 @@ class Layout(unittest.TestCase): def test_libretro_view_keeps_path(self) -> None: cfg = {**config(self.LINKED, base="BIOS"), "dual_mode_cores": ["emu"]} - views = platform_layouts("emu", PROFILE, standalone_set(cfg, {})) + views = platform_layouts("emu", PROFILE, platform_launches(cfg, {})) libretro = next(view for view, standalone in views if not standalone) self.assertIs(libretro, PROFILE) @@ -392,7 +392,7 @@ class Layout(unittest.TestCase): cfg = {**config(link("emu", "$biosdir/emu", "$home/.local/share/emu is a symlink to it"), base="BIOS"), "dual_mode_cores": ["emu"]} views = dict((standalone, view) for view, standalone in - platform_layouts("emu", PROFILE, standalone_set(cfg, {}))) + platform_layouts("emu", PROFILE, platform_launches(cfg, {}))) self.assertEqual( [f["path"] for f in views[False]["files"]], ["dc/boot.bin", "dc/set.zip", "dc/shared.bin"] ) @@ -401,9 +401,9 @@ class Layout(unittest.TestCase): ) def test_union_of_platforms_with_two_folders_keeps_the_profile_layout(self) -> None: - union = standalone_set(config(self.LINKED, base="BIOS"), {}) | standalone_set(config( + union = PlatformLaunches.merged([platform_launches(config(self.LINKED, base="BIOS"), {}), platform_launches(config( link("emu", "${biosPath}/emu/bios", "symlink ${biosPath}/emu/bios -> ${HOME}/.local/share/emu"), - ), {}) + ), {})]) self.assertEqual(standalone_bindings_for("emu", PROFILE, union), {}) def test_destination_function(self) -> None: @@ -434,7 +434,7 @@ class FlycastOnEachPlatform(unittest.TestCase): with self.subTest(platform=platform): cfg = load_platform_config(platform, str(REPO_ROOT / "platforms")) self.assertEqual( - standalone_bindings_for("flycast", self.profile, standalone_set(cfg, REPO_PROFILES)), + standalone_bindings_for("flycast", self.profile, platform_launches(cfg, REPO_PROFILES)), {"": ("", folder)}, ) @@ -445,7 +445,7 @@ class FlycastOnEachPlatform(unittest.TestCase): with self.subTest(platform=platform): cfg = load_platform_config(platform, str(REPO_ROOT / "platforms")) for view, standalone in platform_layouts( - "flycast", self.profile, standalone_set(cfg, REPO_PROFILES) + "flycast", self.profile, platform_launches(cfg, REPO_PROFILES) ): if not standalone: continue @@ -463,7 +463,7 @@ class FlycastOnEachPlatform(unittest.TestCase): self.assertIn("flycast", cfg.get("dual_mode_cores") or []) views = { standalone: view - for view, standalone in platform_layouts("flycast", self.profile, standalone_set(cfg, REPO_PROFILES)) + for view, standalone in platform_layouts("flycast", self.profile, platform_launches(cfg, REPO_PROFILES)) } self.assertEqual(set(views), {False, True}) for entry in views[False]["files"]: @@ -594,7 +594,7 @@ class OpenmsxOnEachPlatform(unittest.TestCase): with self.subTest(platform=platform): cfg = load_platform_config(platform, str(REPO_ROOT / "platforms")) self.assertEqual( - standalone_bindings_for("openmsx", self.profile, standalone_set(cfg, REPO_PROFILES)), + standalone_bindings_for("openmsx", self.profile, platform_launches(cfg, REPO_PROFILES)), expected, ) @@ -603,7 +603,7 @@ class OpenmsxOnEachPlatform(unittest.TestCase): with self.subTest(platform=platform): cfg = load_platform_config(platform, str(REPO_ROOT / "platforms")) (view, _standalone), = platform_layouts( - "openmsx", self.profile, standalone_set(cfg, REPO_PROFILES) + "openmsx", self.profile, platform_launches(cfg, REPO_PROFILES) ) for entry in view["files"]: self.assertNotIn("unplaced", entry) @@ -638,7 +638,7 @@ class XroarOnEachPlatform(unittest.TestCase): def test_each_rom_lands_where_its_launch_reads_it(self) -> None: for platform, folders in self.EXPECTED.items(): cfg = load_platform_config(platform, str(REPO_ROOT / "platforms")) - (view, _standalone), = platform_layouts("xroar", self.profile, standalone_set(cfg, REPO_PROFILES)) + (view, _standalone), = platform_layouts("xroar", self.profile, platform_launches(cfg, REPO_PROFILES)) for entry in view["files"]: with self.subTest(platform=platform, name=entry["name"]): self.assertNotIn("unplaced", entry) @@ -666,7 +666,7 @@ class AmiberryOnEachPlatform(unittest.TestCase): with self.subTest(platform=platform): cfg = load_platform_config(platform, str(REPO_ROOT / "platforms")) self.assertEqual( - standalone_bindings_for(name, self.profiles[name], standalone_set(cfg, REPO_PROFILES)), + standalone_bindings_for(name, self.profiles[name], platform_launches(cfg, REPO_PROFILES)), {"": ("", folder)}, ) @@ -674,7 +674,7 @@ class AmiberryOnEachPlatform(unittest.TestCase): for platform, (name, folder) in self.BOUND.items(): profile = self.profiles[name] cfg = load_platform_config(platform, str(REPO_ROOT / "platforms")) - views = platform_layouts(name, profile, standalone_set(cfg, REPO_PROFILES)) + views = platform_layouts(name, profile, platform_launches(cfg, REPO_PROFILES)) ((view, _standalone),) = [(v, s) for v, s in views if s] for own, entry in zip(profile["files"], view["files"]): if own.get("mode") == "libretro": @@ -692,10 +692,10 @@ class AmiberryOnEachPlatform(unittest.TestCase): profile = self.profiles[name] cfg = load_platform_config("retrobat", str(REPO_ROOT / "platforms")) self.assertEqual( - standalone_bindings_for(name, profile, standalone_set(cfg, REPO_PROFILES)), + standalone_bindings_for(name, profile, platform_launches(cfg, REPO_PROFILES)), {"": ("emulators", "amiberry/ROMs"), "WHDBoot": ("emulators", "amiberry/WHDBoot")}, ) - ((view, _standalone),) = platform_layouts(name, profile, standalone_set(cfg, REPO_PROFILES)) + ((view, _standalone),) = platform_layouts(name, profile, platform_launches(cfg, REPO_PROFILES)) for own, entry in zip(profile["files"], view["files"]): layout = own.get("standalone_path") or own.get("path") or own["name"] folder = "amiberry" if layout.startswith("WHDBoot/") else "amiberry/ROMs" @@ -746,7 +746,7 @@ class AmiberryBuildEachPlatformShips(unittest.TestCase): cfg = load_platform_config(platform, str(REPO_ROOT / "platforms")) if "amiberry" not in self.resolved(platform): continue - layouts = platform_layouts("amiberry", self.profiles["amiberry"], standalone_set(cfg, REPO_PROFILES)) + layouts = platform_layouts("amiberry", self.profiles["amiberry"], platform_launches(cfg, REPO_PROFILES)) with self.subTest(platform=platform): self.assertEqual([standalone for _view, standalone in layouts], [False]) @@ -774,10 +774,10 @@ class AmiberryBuildEachPlatformShips(unittest.TestCase): for name in ("amiberry-5.7.2", "amiberry-6.3.3"): profile = self.profiles[name] self.assertEqual( - standalone_bindings_for(name, profile, standalone_set(cfg, REPO_PROFILES)), + standalone_bindings_for(name, profile, platform_launches(cfg, REPO_PROFILES)), {"kickstarts": ("", "amiga")}, ) - ((view, _standalone),) = platform_layouts(name, profile, standalone_set(cfg, REPO_PROFILES)) + ((view, _standalone),) = platform_layouts(name, profile, platform_launches(cfg, REPO_PROFILES)) for entry in view["files"]: with self.subTest(name=name, file=entry["name"]): if entry["path"].startswith("kickstarts/"): @@ -793,10 +793,10 @@ class AmiberryBuildEachPlatformShips(unittest.TestCase): profile = self.profiles["amiberry-5.6.5"] cfg = load_platform_config("rocknix", str(REPO_ROOT / "platforms")) self.assertEqual( - standalone_bindings_for("amiberry-5.6.5", profile, standalone_set(cfg, REPO_PROFILES)), + standalone_bindings_for("amiberry-5.6.5", profile, platform_launches(cfg, REPO_PROFILES)), {"kickstarts": ("", "")}, ) - ((view, _standalone),) = platform_layouts("amiberry-5.6.5", profile, standalone_set(cfg, REPO_PROFILES)) + ((view, _standalone),) = platform_layouts("amiberry-5.6.5", profile, platform_launches(cfg, REPO_PROFILES)) for entry in view["files"]: with self.subTest(name=entry["name"]): if entry["path"].startswith("kickstarts/"): diff --git a/tests/test_standalone_mode.py b/tests/test_standalone_mode.py index cc50784c7..3631a0aef 100644 --- a/tests/test_standalone_mode.py +++ b/tests/test_standalone_mode.py @@ -19,6 +19,7 @@ from pathlib import Path import yaml from packs.crossref import cross_reference +from resolve.launches import PlatformLaunches REPO_ROOT = Path(__file__).resolve().parent.parent @@ -76,10 +77,11 @@ class CrossReferenceReadsTheBuildThePlatformRuns(unittest.TestCase): for Recalbox, which runs Dolphin standalone, it reported 12 Dolphin gaps where verify and the pack builder found 26.""" - def _gaps(self, standalone_cores): + def _gaps(self, standalone, dual=frozenset()): empty_db = {"files": {}, "indexes": {}} report = cross_reference( - {"dual": DUAL_PROFILE}, {}, empty_db, standalone_cores=standalone_cores + {"dual": DUAL_PROFILE}, {}, empty_db, + standalone_cores=PlatformLaunches(standalone=frozenset(standalone), dual=dual), ) return sorted(g["name"] for g in report["dual"]["gap_details"]) @@ -93,10 +95,8 @@ class CrossReferenceReadsTheBuildThePlatformRuns(unittest.TestCase): def test_a_platform_running_both_builds(self): # The dual layout keyed seen files by (path, slot) and then looked # the pair up in the slot table: KeyError on Batocera's dolphin. - from resolve.layout import DUAL_MODE_PREFIX - self.assertEqual( - self._gaps({"dual", DUAL_MODE_PREFIX + "dual"}), + self._gaps({"dual"}, dual=frozenset({"dual"})), ["both.bin", "libretro.bin", "standalone.bin"], ) @@ -111,7 +111,8 @@ class CrossReferenceReadsTheBuildThePlatformRuns(unittest.TestCase): ], } report = cross_reference( - {"b": profile}, {}, {"files": {}, "indexes": {}}, standalone_cores={"b"} + {"b": profile}, {}, {"files": {}, "indexes": {}}, + standalone_cores=PlatformLaunches(standalone=frozenset({"b"})), ) self.assertEqual(len(report["b"]["gap_details"]), 2) diff --git a/tests/test_target_scrapers.py b/tests/test_target_scrapers.py index 1bf15731a..f9fb4796c 100644 --- a/tests/test_target_scrapers.py +++ b/tests/test_target_scrapers.py @@ -308,9 +308,8 @@ class CoreDownloaderReach(unittest.TestCase): """Batocera runs amiberry standalone, and its x86_64 boards fetch amiberry_libretro: removing every name the image builds lost the libretro core to the name it shares with the standalone package.""" - from resolve.layout import DUAL_MODE_PREFIX from resolve.cores import resolve_platform_cores - from resolve.standalone import standalone_set + from resolve.standalone import platform_launches from scraper.batocera_scraper import installable_cores from scraper.targets.batocera_targets_scraper import BuildSelection @@ -335,7 +334,7 @@ class CoreDownloaderReach(unittest.TestCase): self.assertEqual(resolve_platform_cores(config, profiles), {"amiberry", "amiberry-7"}) self.assertEqual(resolve_platform_cores({**config, "installable_cores": []}, profiles), {"amiberry-7"}) - self.assertIn(DUAL_MODE_PREFIX + "amiberry", standalone_set(config, profiles)) + self.assertIn("amiberry", platform_launches(config, profiles).dual) class DownloadedCoresReachTheirBoards(unittest.TestCase):