diff --git a/scripts/truth.py b/scripts/truth.py index 76583741..d731dc54 100644 --- a/scripts/truth.py +++ b/scripts/truth.py @@ -310,6 +310,43 @@ def _system_dir_files(profile: dict, standalone: bool) -> list[dict]: ) +def _archives_not_members(files: list[dict]) -> list[dict]: + """A profile's entries with the members of each archive folded into it. + + fbneo declares bubsys.zip as the ROMs it holds, each carrying + `archive: bubsys.zip`. The platform reads the archive, never a member: + as loose files the members were added to RetroArch's System.dat, and + the 480-byte boot.bin was filed under the Dreamcast by its bare name. + The archive stands in their place with the members as its contents, + the shape a profile that declares the archive itself already has. + """ + out: list[dict] = [] + archives: dict[tuple[str, str], dict] = {} + for fe in files: + archive = fe.get("archive") + if not archive: + out.append(fe) + continue + key = (archive, fe.get("system", "")) + entry = archives.get(key) + if entry is None: + entry = {"name": archive, "category": "bios_zip", "contents": []} + if fe.get("system"): + entry["system"] = fe["system"] + if fe.get("source_ref") is not None: + entry["source_ref"] = fe["source_ref"] + archives[key] = entry + out.append(entry) + if fe.get("required"): + entry["required"] = True + entry["contents"].append({ + field: fe[field] + for field in ("name", "size", "crc32", "sha1", "md5") + if fe.get(field) is not None + }) + return out + + def generate_platform_truth( platform_name: str, config: dict, @@ -388,9 +425,9 @@ def generate_platform_truth( continue cores_profiled.add(emu_name) - filtered = _system_dir_files( + filtered = _archives_not_members(_system_dir_files( profile, runs_standalone(emu_name, profile, standalone_set) - ) + )) for fe in filtered: profile_sid = fe.get("system", "") diff --git a/tests/test_truth_layout.py b/tests/test_truth_layout.py index b87d3e89..f646ba2b 100644 --- a/tests/test_truth_layout.py +++ b/tests/test_truth_layout.py @@ -51,5 +51,49 @@ class TruthFollowsRunsStandalone(unittest.TestCase): self.assertEqual(_names(truth), {"both.bin", "only_sa.bin"}) + +class AnArchiveStandsForItsMembers(unittest.TestCase): + """fbneo declares bubsys.zip as the ROMs inside it. As loose truth files + the members were added to RetroArch's System.dat, and the 480-byte + boot.bin, filed under the Dreamcast by its bare name, merged with + RetroDream's 2 MB BIOS.""" + + PROFILES = { + "fbneo": { + "emulator": "FBNeo", "type": "libretro", "systems": ["konami-bubsys"], + "files": [ + {"name": "boot.bin", "archive": "bubsys.zip", "system": "konami-bubsys", + "required": True, "size": 480, "crc32": "f0774fc2"}, + {"name": "400b03.8g", "archive": "bubsys.zip", "system": "konami-bubsys", + "required": True, "size": 8192, "crc32": "85c2afc5"}, + ], + }, + "retrodream": { + "emulator": "RetroDream", "type": "libretro", "systems": ["sega-dreamcast"], + "files": [{"name": "boot.bin", "path": "boot.bin", "system": "sega-dreamcast", + "size": 2097152, "md5": "e10c53c2f8b90bab96ead2d368858623"}], + }, + } + CONFIG = { + "cores": ["fbneo", "retrodream"], + "systems": {"sega-dreamcast": {"files": [ + {"name": "boot.bin", "destination": "dc/boot.bin"}]}}, + } + + def test_the_archive_is_the_file(self): + truth = generate_platform_truth("p", self.CONFIG, {}, self.PROFILES) + bubsys = truth["systems"]["konami-bubsys"]["files"] + self.assertEqual([f["name"] for f in bubsys], ["bubsys.zip"]) + self.assertEqual( + sorted(m["name"] for m in bubsys[0]["contents"]), ["400b03.8g", "boot.bin"] + ) + self.assertTrue(bubsys[0]["required"]) + + def test_a_member_name_claims_no_other_system(self): + truth = generate_platform_truth("p", self.CONFIG, {}, self.PROFILES) + dreamcast = truth["systems"]["sega-dreamcast"]["files"] + self.assertEqual([(f["name"], f["size"]) for f in dreamcast], [("boot.bin", 2097152)]) + self.assertEqual(dreamcast[0]["_cores"], ["retrodream"]) + if __name__ == "__main__": unittest.main()