diff --git a/scripts/common.py b/scripts/common.py index ad7f944c..48ea95b6 100644 --- a/scripts/common.py +++ b/scripts/common.py @@ -2609,6 +2609,10 @@ def build_target_cores_cache( """Build target cores cache for a list of platforms. Returns (cache dict, list of platforms to keep after skipping failures). + A platform without a targets file cannot honour the target and is left + out with the others, never run unfiltered, and a target no platform knows + is refused: `--all --target swtich` checked BizHawk and MiSTer whole and + exited 0, a green run that said nothing about the Switch. """ cache: dict[str, set[str] | None] = {} skip: list[str] = [] @@ -2616,10 +2620,10 @@ def build_target_cores_cache( try: cache[p] = load_target_config(p, target, platforms_dir) except FileNotFoundError: - if is_all: - cache[p] = None - else: + if not is_all: raise + print(f"INFO: Skipping {p}: no hardware targets") + skip.append(p) except ValueError as e: if is_all: print(f"INFO: Skipping {p}: {e}") @@ -2627,6 +2631,8 @@ def build_target_cores_cache( else: raise kept = [p for p in platforms if p not in skip] + if is_all and platforms and not kept: + raise ValueError(f"unknown target '{target}': no platform has it") return cache, kept diff --git a/scripts/generate_pack.py b/scripts/generate_pack.py index c709700b..7f615122 100644 --- a/scripts/generate_pack.py +++ b/scripts/generate_pack.py @@ -4442,10 +4442,10 @@ def _target_cores_for( """ if not target_name: return None - cache, _kept = build_target_cores_cache( - [platform_name], target_name, platforms_dir, is_all=True - ) - return cache.get(platform_name) + try: + return load_target_config(platform_name, target_name, platforms_dir) + except (FileNotFoundError, ValueError): + return None def _expected_pack_names( @@ -4479,9 +4479,13 @@ def _expected_pack_names( ) cache = None if target_name: - cache, pool = build_target_cores_cache( - pool, target_name, platforms_dir, is_all=True - ) + try: + cache, pool = build_target_cores_cache( + pool, target_name, platforms_dir, is_all=True + ) + except ValueError: + # No platform has the target: no pack was built under it. + continue for group, representative in group_identical_platforms( pool, platforms_dir, cache ): diff --git a/tests/test_audit_regressions.py b/tests/test_audit_regressions.py index ac385869..f85d1eb5 100644 --- a/tests/test_audit_regressions.py +++ b/tests/test_audit_regressions.py @@ -5438,5 +5438,23 @@ class AForcedRehashIsCheckedAgainstTheLastOne(unittest.TestCase): ) +class AnUnknownTargetIsRefusedUnderAll(unittest.TestCase): + """--all --target swtich skipped every platform with targets and checked + BizHawk and MiSTer unfiltered: a green run about no Switch at all.""" + + def test_a_typo_is_refused_and_targetless_platforms_are_left_out(self): + from scripts.common import build_target_cores_cache, list_registered_platforms + + platforms = list_registered_platforms(str(ROOT / "platforms")) + with contextlib.redirect_stdout(io.StringIO()): + with self.assertRaises(ValueError): + build_target_cores_cache(platforms, "swtich", str(ROOT / "platforms"), is_all=True) + _cache, kept = build_target_cores_cache( + platforms, "switch", str(ROOT / "platforms"), is_all=True + ) + self.assertNotIn("bizhawk", kept) + self.assertIn("retroarch", kept) + + if __name__ == "__main__": unittest.main()