diff --git a/scripts/model/targets.py b/scripts/model/targets.py index 646629489..98d6a2aaf 100644 --- a/scripts/model/targets.py +++ b/scripts/model/targets.py @@ -248,10 +248,11 @@ def build_target_cores_cache( target: str, platforms_dir: str, is_all: bool = False, -) -> tuple[dict[str, set[str] | None], list[str]]: +) -> tuple[dict[str, set[str] | None], list[str], list[str]]: """Build target cores cache for a list of platforms. - Returns (cache dict, list of platforms to keep after skipping failures). + Returns (cache dict, platforms kept after skipping failures, one note per + skipped platform for a command line to print). 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 @@ -282,10 +283,7 @@ def build_target_cores_cache( # The seventeen per-platform lines buried the one suggestion that # mattered: the refusal names the closest target across them all. raise ValueError(_unknown_target_message(target, platforms, platforms_dir)) - # On stderr: slots --json printed them ahead of its document. - for note in notes: - print(note, file=sys.stderr) - return cache, kept + return cache, kept, notes def target_scope( @@ -299,10 +297,16 @@ def target_scope( if not target: return {}, platforms try: - return build_target_cores_cache(platforms, target, platforms_dir, is_all=is_all) + cache, kept, notes = build_target_cores_cache( + platforms, target, platforms_dir, is_all=is_all + ) except (FileNotFoundError, ValueError) as exc: print(f"ERROR: {exc}", file=sys.stderr) sys.exit(1) + # On stderr: slots --json printed them ahead of its document. + for note in notes: + print(note, file=sys.stderr) + return cache, kept def _unknown_target_message(target: str, platforms: list[str], platforms_dir: str) -> str: diff --git a/scripts/packs/naming.py b/scripts/packs/naming.py index a897be272..a0b98adfe 100644 --- a/scripts/packs/naming.py +++ b/scripts/packs/naming.py @@ -242,7 +242,7 @@ def expected_pack_names( cache = None if target_name: try: - cache, pool = build_target_cores_cache( + cache, pool, _notes = build_target_cores_cache( pool, target_name, platforms_dir, is_all=True ) except ValueError: diff --git a/tests/test_audit_regressions.py b/tests/test_audit_regressions.py index 5ea139bf2..6769eb71d 100644 --- a/tests/test_audit_regressions.py +++ b/tests/test_audit_regressions.py @@ -6957,12 +6957,11 @@ class AnUnknownTargetIsRefusedUnderAll(unittest.TestCase): from scripts.model.registry import 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 - ) + with self.assertRaises(ValueError): + build_target_cores_cache(platforms, "swtich", str(ROOT / "platforms"), is_all=True) + _cache, kept, _notes = build_target_cores_cache( + platforms, "switch", str(ROOT / "platforms"), is_all=True + ) self.assertNotIn("bizhawk", kept) self.assertIn("retroarch", kept) diff --git a/tests/test_target_verify.py b/tests/test_target_verify.py index 294fbe1a3..6fcf3019b 100644 --- a/tests/test_target_verify.py +++ b/tests/test_target_verify.py @@ -30,8 +30,7 @@ class CheckReadsTheTargetLikeTheBuild(unittest.TestCase): def test_a_platform_without_a_target_file(self): # Left out of a targeted --all run rather than built unfiltered, and # a run where no platform has the target is refused. - with tempfile.TemporaryDirectory() as platforms, \ - contextlib.redirect_stdout(io.StringIO()), self.assertRaises(ValueError): + with tempfile.TemporaryDirectory() as platforms, self.assertRaises(ValueError): build_target_cores_cache(["recalbox"], "x86_64", platforms, is_all=True) # The build never packs such a platform under the target, so the # check refuses it too instead of reading the full pack. @@ -262,9 +261,9 @@ class CrossReferenceReadsTheTargetAcrossPlatforms(unittest.TestCase): profiles = load_emulator_profiles(str(REPO_ROOT / "emulators")) with contextlib.redirect_stderr(io.StringIO()): tree = tree_scope(None, "switch", platforms_dir, profiles) - cache, kept = build_target_cores_cache( - list_registered_platforms(platforms_dir), "switch", platforms_dir, is_all=True, - ) + cache, kept, _notes = build_target_cores_cache( + list_registered_platforms(platforms_dir), "switch", platforms_dir, is_all=True, + ) self.assertEqual(tree.selected, kept) self.assertIsNone(tree.platform) expected: set[str] = set() diff --git a/tests/test_tool_messages.py b/tests/test_tool_messages.py index 8949360b3..9659e53c6 100644 --- a/tests/test_tool_messages.py +++ b/tests/test_tool_messages.py @@ -19,7 +19,7 @@ from core.cli import SourceUnreadable from core.github import github_token, _gh_cli_token from model.profiles import select_emulator_profiles, ProfileSelectionError from model.registry import list_registered_platforms -from model.targets import load_target_config, build_target_cores_cache +from model.targets import load_target_config, build_target_cores_cache, target_scope from exporter import diffreport import pipeline from orchestrate import guards, labels, prepare, runner @@ -312,7 +312,13 @@ class AMistypedTargetEndsEveryToolAlike(unittest.TestCase): platforms = list_registered_platforms(str(REPO_ROOT / "platforms")) out, err = io.StringIO(), io.StringIO() with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err): - build_target_cores_cache(platforms, "switch", str(REPO_ROOT / "platforms"), is_all=True) + _cache, _kept, notes = build_target_cores_cache( + platforms, "switch", str(REPO_ROOT / "platforms"), is_all=True + ) + self.assertEqual(out.getvalue() + err.getvalue(), "") + self.assertTrue(any(n.startswith("INFO: Skipping") for n in notes)) + with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err): + target_scope(platforms, "switch", str(REPO_ROOT / "platforms"), is_all=True) self.assertEqual(out.getvalue(), "") self.assertIn("INFO: Skipping", err.getvalue())