diff --git a/scripts/generate_pack.py b/scripts/generate_pack.py index 9e2a2684..28961749 100644 --- a/scripts/generate_pack.py +++ b/scripts/generate_pack.py @@ -490,7 +490,8 @@ def _select_variants( for sys_id, members in region_groups.items() } slot_drops, slot_undecidable = slot_mod.resolve_slot_drops( - slot_groups, slot_mod.build_slot_index(emu_profiles or {}) + slot_groups, + slot_mod.platform_slot_index(config, emu_profiles or {}, target_cores), ) region_drops = region_drops | slot_drops if slot_undecidable: diff --git a/scripts/slot.py b/scripts/slot.py index bae36afa..f08049ad 100644 --- a/scripts/slot.py +++ b/scripts/slot.py @@ -30,6 +30,21 @@ from __future__ import annotations BIOS_CATEGORY = "bios" +def platform_slot_index( + config: dict, profiles: dict, target_cores: set[str] | None = None +) -> dict[str, dict]: + """The slot index of the emulators a platform runs, nothing else. + + Built over every profile, DuckStation, ePSXe and Rustation ranked the + PlayStation BIOS of RomM, whose cores rank none of them, and + `--one-per-slot` dropped four images RomM declares. + """ + from common import resolve_platform_cores # noqa: PLC0415 + + cores = resolve_platform_cores(config, profiles, target_cores=target_cores) + return build_slot_index({n: profiles[n] for n in cores if n in profiles}) + + def build_slot_index(profiles: dict) -> dict[str, dict]: """Map a file key to its slot metadata, keyed by path then name.""" index: dict[str, dict] = {} diff --git a/tests/test_region_platform_index.py b/tests/test_region_platform_index.py index a91bf96f..4d2be7cb 100644 --- a/tests/test_region_platform_index.py +++ b/tests/test_region_platform_index.py @@ -40,5 +40,34 @@ class OnlyThePlatformsCores(unittest.TestCase): self.assertIn("platform_region_index(", source, module) + +class OnlyThePlatformsCoresRankASlot(unittest.TestCase): + """RomM runs beetle_psx and pcsx_rearmed, which rank no PlayStation + BIOS; DuckStation's ranks dropped four images RomM declares.""" + + PROFILES = { + "beetle_psx": {"emulator": "Beetle", "type": "libretro", + "systems": ["sony-playstation"], + "files": [{"name": "scph100.bin"}, {"name": "scph5501.bin"}]}, + "duckstation": {"emulator": "DuckStation", "type": "standalone", + "systems": ["sony-playstation"], + "files": [{"name": "scph100.bin", "priority": 10}, + {"name": "scph5501.bin", "priority": 5}]}, + } + + def test_a_foreign_rank_orders_nothing(self): + import slot as slot_mod # noqa: PLC0415 + + config = {"cores": ["beetle_psx"], "systems": {"sony-playstation": {"files": []}}} + index = slot_mod.platform_slot_index(config, self.PROFILES) + self.assertIsNone(index["scph100.bin"]["rank"]) + self.assertEqual(slot_mod.build_slot_index(self.PROFILES)["scph100.bin"]["rank"], 10) + + def test_the_pack_reads_it(self): + source = (REPO_ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8") + self.assertNotIn("build_slot_index(", source) + self.assertIn("platform_slot_index(", source) + + if __name__ == "__main__": unittest.main()