diff --git a/scripts/common.py b/scripts/common.py index cfacf831..75fbff95 100644 --- a/scripts/common.py +++ b/scripts/common.py @@ -363,21 +363,20 @@ def list_available_targets( with open(target_file) as f: data = yaml_load(f) or {} - overrides_file = os.path.join(targets_dir, "_overrides.yml") - overrides = {} - if os.path.exists(overrides_file): - with open(overrides_file) as f: - all_overrides = yaml_load(f) or {} - overrides = all_overrides.get(platform_name, {}).get("targets", {}) + # The count --target filters on: overrides applied, as load_target_config + # applies them. The scraped list counted Batocera's machine variants and + # launchers, 198 cores shown for 187 used. + overrides = _target_overrides(platform_name, targets_dir) result = [] for tname, tdata in sorted(data.get("targets", {}).items()): - aliases = overrides.get(tname, {}).get("aliases", []) + aliases = (overrides.get(tname) or {}).get("aliases", []) + cores = {str(c) for c in tdata.get("cores", [])} result.append( { "name": tname, "architecture": tdata.get("architecture", ""), - "core_count": len(tdata.get("cores", [])), + "core_count": len(apply_target_overrides(cores, overrides, tname)), "aliases": aliases, } ) diff --git a/tests/test_target_names.py b/tests/test_target_names.py index e0804947..a0721946 100644 --- a/tests/test_target_names.py +++ b/tests/test_target_names.py @@ -54,5 +54,26 @@ class TheBuilderNamesByTheCanonicalTarget(unittest.TestCase): ) + +class TheListingCountsWhatTheFilterUses(unittest.TestCase): + """--list-targets showed Batocera x86_64 with 198 cores; --target x86_64 + filters on 187 once _overrides.yml removes machine variants and launchers.""" + + def test_every_listed_count_is_the_filtered_set(self): + from common import list_available_targets, load_target_config # noqa: PLC0415 + + platforms = str(REPO_ROOT / "platforms") + checked = 0 + for target_file in sorted((REPO_ROOT / "platforms" / "targets").glob("[!_]*.yml")): + platform = target_file.stem + for row in list_available_targets(platform, platforms): + with self.subTest(platform=platform, target=row["name"]): + self.assertEqual( + row["core_count"], + len(load_target_config(platform, row["name"], platforms)), + ) + checked += 1 + self.assertGreater(checked, 0) + if __name__ == "__main__": unittest.main()