From 4246d9ec66e85121d542e78ef48655c44dea0745 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sun, 18 Oct 2026 19:44:47 +0200 Subject: [PATCH] fix: name a target only where it narrows the pack --- scripts/common.py | 11 +++++++++++ scripts/generate_pack.py | 7 +++++-- tests/test_target_verify.py | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/scripts/common.py b/scripts/common.py index 72c874d4..1a3fbe51 100644 --- a/scripts/common.py +++ b/scripts/common.py @@ -511,6 +511,17 @@ def _target_alias_index(targets: dict, overrides: dict) -> dict[str, str]: return alias_index +def platform_files_target(platform: str, target: str, platforms_dir: str = "platforms") -> bool: + """Whether the platform's targets file knows this target, by any alias.""" + targets_dir = os.path.join(platforms_dir, "targets") + target_file = os.path.join(targets_dir, f"{platform}.yml") + if not os.path.exists(target_file): + return False + with open(target_file) as f: + targets = (yaml_load(f) or {}).get("targets", {}) + return target in _target_alias_index(targets, _target_overrides(platform, targets_dir)) + + def canonical_target_name( platforms: list[str], target: str, platforms_dir: str = "platforms" ) -> str: diff --git a/scripts/generate_pack.py b/scripts/generate_pack.py index 97b77916..b5591495 100644 --- a/scripts/generate_pack.py +++ b/scripts/generate_pack.py @@ -53,6 +53,7 @@ from common import ( list_emulator_profiles, list_platform_system_ids, canonical_target_name, + platform_files_target, list_registered_platforms, list_system_ids, load_data_dir_registry, @@ -227,9 +228,11 @@ def _platform_target( Named once for the whole run, a target two platforms file differently (rpi4: Batocera's bcm2711, Recalbox's rpi4_64) kept the typed name under --all and took the platform's own under --platform, so --verify-packs - looked for a pack the --all build had named otherwise. + looked for a pack the --all build had named otherwise. A platform that + does not file the target is packed whole under --all, and its name + claims no narrowing: BizHawk_..._Switch_BIOS_Pack.zip was the full pack. """ - if not target: + if not target or not platform_files_target(platform_name, target, platforms_dir): return None return canonical_target_name([platform_name], target, platforms_dir) diff --git a/tests/test_target_verify.py b/tests/test_target_verify.py index 0da3a55f..d9157b38 100644 --- a/tests/test_target_verify.py +++ b/tests/test_target_verify.py @@ -35,5 +35,21 @@ class CheckReadsTheTargetLikeTheBuild(unittest.TestCase): self.assertTrue(cores) +class ANameClaimsOnlyANarrowingThatHappened(unittest.TestCase): + """--all --target switch packed BizHawk and MiSTer whole, and named them + BizHawk_..._Switch_BIOS_Pack.zip with a README saying 'cores available + on switch'.""" + + def test_a_platform_without_the_target_is_named_plainly(self): + from generate_pack import _narrowings, _platform_target + + platforms = str(REPO_ROOT / "platforms") + self.assertIsNone(_platform_target("bizhawk", "switch", platforms)) + self.assertEqual(_narrowings("full", None, None, False, False), []) + self.assertEqual( + _platform_target("retroarch", "nx", platforms), "nintendo-switch" + ) + + if __name__ == "__main__": unittest.main()