mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-25 02:57:52 -06:00
fix: let verify report on --all --system
verify refused --all --system as mutually exclusive while generate_pack builds a --system pack per platform. Both now resolve the list through model.cliargs.resolve_system_ids and scope the platforms through resolve.cores.platforms_with_systems: a platform without the system is skipped under --all and refused under --platform, with the note on stderr so verify --json stays a document.
This commit is contained in:
1 parent
b52c7cfafb
commit
96539e353c
6 files changed
+123
-127
No files matched your search
@@ -40,16 +40,13 @@ from model.cliargs import (
|
||||
refuse_beside_mode,
|
||||
requested_regions,
|
||||
require_platform,
|
||||
resolve_system_ids,
|
||||
run_listing,
|
||||
)
|
||||
from core.cli import add_emulator_selection, add_repo_inputs, require_directory
|
||||
from model.targets import (
|
||||
target_scope,
|
||||
)
|
||||
from model.systems import (
|
||||
resolve_system_arg,
|
||||
select_systems,
|
||||
)
|
||||
from core.artifacts import (
|
||||
write_if_changed,
|
||||
artifact_lock,
|
||||
@@ -58,8 +55,7 @@ from core.artifacts import (
|
||||
)
|
||||
from core.ziptools import build_zip_contents_index
|
||||
from resolve.cores import (
|
||||
platform_scope_systems,
|
||||
system_scope_error,
|
||||
platforms_with_systems,
|
||||
without_profile_blind,
|
||||
)
|
||||
from resolve.grouping import group_identical_platforms
|
||||
@@ -155,75 +151,6 @@ def _refuse_mixed_output(output_dir: str, writing: str) -> None:
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def _resolve_systems(args: argparse.Namespace, parser: argparse.ArgumentParser) -> None:
|
||||
"""Turn --system into the platform's system ids, before any work.
|
||||
|
||||
With --platform the platform's own names count too (Batocera's psx), the
|
||||
mapping the install manifest carries. With --all each name must be one
|
||||
of our ids some platform declares. Checked inside the build, a typo cost
|
||||
the lock and a refresh of every data directory first, then ended on a
|
||||
WARNING and exit 1, and a list with one known name ignored the others.
|
||||
"""
|
||||
if not args.system or not (args.platform or args.all):
|
||||
return
|
||||
if args.platform:
|
||||
config = load_platform_config(args.platform, args.platforms_dir)
|
||||
systems = list(config.get("systems", {}))
|
||||
listing = f"--platform {args.platform} --list-systems"
|
||||
else:
|
||||
config = None
|
||||
systems = sorted({
|
||||
sid
|
||||
for name in list_registered_platforms(args.platforms_dir)
|
||||
for sid in load_platform_config(name, args.platforms_dir).get("systems", {})
|
||||
})
|
||||
listing = "--platform <name> --list-systems"
|
||||
try:
|
||||
args.system_ids = resolve_system_arg(args.system, systems, config, listing)
|
||||
except ValueError as exc:
|
||||
parser.error(f"--system {args.system}: {exc}")
|
||||
|
||||
|
||||
def _platforms_with_systems(
|
||||
args: argparse.Namespace,
|
||||
platforms: list[str],
|
||||
system_filter: list[str],
|
||||
emu_profiles: dict,
|
||||
target_cores_cache: dict[str, set[str] | None],
|
||||
) -> list[str]:
|
||||
"""The platforms a --system list leaves a system to pack, before any lock.
|
||||
|
||||
Under --all a platform without one is out of scope, as a platform
|
||||
without the target is: `--all --system sony-playstation-2` built every
|
||||
PS2 pack and exited 1 on MiSTer, which has no PS2. Under --platform the
|
||||
request is refused here, with its reason.
|
||||
"""
|
||||
kept = []
|
||||
for name in platforms:
|
||||
config = load_platform_config(name, args.platforms_dir)
|
||||
tc = target_cores_cache.get(name) if args.target else None
|
||||
if platform_scope_systems(config, emu_profiles, tc, system_filter):
|
||||
kept.append(name)
|
||||
continue
|
||||
if not args.all:
|
||||
reason = system_scope_error(config, name, system_filter, args.target)
|
||||
print(f"ERROR: {reason}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
declared = select_systems(config.get("systems", {}), system_filter)
|
||||
reason = (
|
||||
system_scope_error(config, name, system_filter, args.target)
|
||||
if declared and args.target
|
||||
else f"no system {', '.join(system_filter)}"
|
||||
)
|
||||
print(f"INFO: Skipping {name}: {reason}")
|
||||
if not kept:
|
||||
where = f" on target {args.target}" if args.target else ""
|
||||
print(f"ERROR: no platform packed here runs {', '.join(system_filter)}{where}",
|
||||
file=sys.stderr)
|
||||
sys.exit(1)
|
||||
return kept
|
||||
|
||||
|
||||
def _refuse_for_verify_packs(args: argparse.Namespace, parser: argparse.ArgumentParser) -> None:
|
||||
"""What --verify-packs cannot be combined with, refused before any lock.
|
||||
|
||||
@@ -1276,8 +1203,9 @@ def _run_platform_mode(
|
||||
|
||||
emu_profiles = load_emulator_profiles(args.emulators_dir)
|
||||
if system_filter:
|
||||
platforms = _platforms_with_systems(
|
||||
args, platforms, system_filter, emu_profiles, target_cores_cache
|
||||
platforms = platforms_with_systems(
|
||||
platforms, system_filter, emu_profiles, target_cores_cache,
|
||||
args.platforms_dir, args.target, args.all,
|
||||
)
|
||||
platforms = without_profile_blind(
|
||||
platforms,
|
||||
@@ -1349,7 +1277,7 @@ def _main(held: contextlib.ExitStack) -> None:
|
||||
return
|
||||
|
||||
_validate_args(args, parser)
|
||||
_resolve_systems(args, parser)
|
||||
args.system_ids = resolve_system_ids(args, parser)
|
||||
# Unset until every refusal has run, so a typed default value is seen.
|
||||
args.source = args.source or "full"
|
||||
args.group_by = args.group_by or "system"
|
||||
|
||||
@@ -16,7 +16,7 @@ except ImportError:
|
||||
from model.platforms import load_platform_config
|
||||
from model.profiles import is_emulator, load_emulator_profiles
|
||||
from model.registry import list_registered_platforms, list_release_pack_platforms
|
||||
from model.systems import platform_system_names, system_index
|
||||
from model.systems import platform_system_names, resolve_system_arg, system_index
|
||||
from core.paths import PLATFORMS_DIR, REPO_ROOT
|
||||
|
||||
|
||||
@@ -109,6 +109,37 @@ def selected_platforms(
|
||||
raise SystemExit("ERROR: specify --platform or --all")
|
||||
|
||||
|
||||
def resolve_system_ids(
|
||||
args: argparse.Namespace, parser: argparse.ArgumentParser
|
||||
) -> list[str] | None:
|
||||
"""--system beside --platform or --all as system ids, before any work.
|
||||
|
||||
With --platform the platform's own names count too (Batocera's psx), the
|
||||
mapping the install manifest carries. With --all each name must be one
|
||||
of our ids some platform declares. Checked inside the build, a typo cost
|
||||
the lock and a refresh of every data directory first, then ended on a
|
||||
WARNING and exit 1, and a list with one known name ignored the others.
|
||||
"""
|
||||
if not args.system or not (args.platform or args.all):
|
||||
return None
|
||||
if args.platform:
|
||||
config = load_platform_config(args.platform, args.platforms_dir)
|
||||
systems = list(config.get("systems", {}))
|
||||
listing = f"--platform {args.platform} --list-systems"
|
||||
else:
|
||||
config = None
|
||||
systems = sorted({
|
||||
sid
|
||||
for name in list_registered_platforms(args.platforms_dir)
|
||||
for sid in load_platform_config(name, args.platforms_dir).get("systems", {})
|
||||
})
|
||||
listing = "--platform <name> --list-systems"
|
||||
try:
|
||||
return resolve_system_arg(args.system, systems, config, listing)
|
||||
except ValueError as exc:
|
||||
parser.error(f"--system {args.system}: {exc}")
|
||||
|
||||
|
||||
def comma_list(value: str) -> list[str]:
|
||||
"""The names of a comma-separated option, blanks dropped."""
|
||||
return [name.strip() for name in value.split(",") if name.strip()]
|
||||
|
||||
@@ -395,6 +395,50 @@ def platform_scope_systems(
|
||||
return select_systems(systems, system_filter) if system_filter else systems
|
||||
|
||||
|
||||
def platforms_with_systems(
|
||||
platforms: list[str],
|
||||
system_filter: list[str],
|
||||
profiles: dict[str, dict],
|
||||
target_cores_cache: dict[str, set[str] | None],
|
||||
platforms_dir: str,
|
||||
target: str | None,
|
||||
is_all: bool,
|
||||
) -> list[str]:
|
||||
"""The platforms a --system list leaves a system to cover, before any lock.
|
||||
|
||||
Under --all a platform without one is out of scope, as a platform
|
||||
without the target is: `--all --system sony-playstation-2` built every
|
||||
PS2 pack and exited 1 on MiSTer, which has no PS2. Under --platform the
|
||||
request is refused here, with its reason. verify.py and generate_pack.py
|
||||
scope a --system list through this one function.
|
||||
"""
|
||||
kept = []
|
||||
for name in platforms:
|
||||
config = load_platform_config(name, platforms_dir)
|
||||
tc = target_cores_cache.get(name) if target else None
|
||||
if platform_scope_systems(config, profiles, tc, system_filter):
|
||||
kept.append(name)
|
||||
continue
|
||||
if not is_all:
|
||||
reason = system_scope_error(config, name, system_filter, target)
|
||||
print(f"ERROR: {reason}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
declared = select_systems(config.get("systems", {}), system_filter)
|
||||
reason = (
|
||||
system_scope_error(config, name, system_filter, target)
|
||||
if declared and target
|
||||
else f"no system {', '.join(system_filter)}"
|
||||
)
|
||||
# On stderr: verify --json prints its document on stdout.
|
||||
print(f"INFO: Skipping {name}: {reason}", file=sys.stderr)
|
||||
if not kept:
|
||||
where = f" on target {target}" if target else ""
|
||||
print(f"ERROR: no platform here runs {', '.join(system_filter)}{where}",
|
||||
file=sys.stderr)
|
||||
sys.exit(1)
|
||||
return kept
|
||||
|
||||
|
||||
def system_scope_error(
|
||||
config: dict, platform_name: str, system_filter: list[str], target: str | None
|
||||
) -> str:
|
||||
|
||||
+16
-37
@@ -47,9 +47,9 @@ from model.cliargs import (
|
||||
run_listing,
|
||||
work_from_repo_root,
|
||||
require_platform,
|
||||
resolve_system_ids,
|
||||
selected_platforms,
|
||||
)
|
||||
from model.systems import resolve_system_arg
|
||||
from model.profiles import (
|
||||
load_emulator_profiles,
|
||||
)
|
||||
@@ -58,9 +58,8 @@ from resolve.grouping import group_identical_platforms
|
||||
from model.database import load_database
|
||||
from model.platforms import load_platform_config
|
||||
from resolve.cores import (
|
||||
platforms_with_systems,
|
||||
without_profile_blind,
|
||||
platform_scope_systems,
|
||||
system_scope_error,
|
||||
)
|
||||
from model.safeparse import require_yaml
|
||||
|
||||
@@ -116,7 +115,7 @@ def _refuse_mode_flags(args: argparse.Namespace, parser: argparse.ArgumentParser
|
||||
"--standalone is incompatible with --platform"),
|
||||
(args.target and not (args.platform or args.all),
|
||||
"--target requires --platform or --all"),
|
||||
(args.target and (args.emulator or (args.system and not args.platform)),
|
||||
(args.target and (args.emulator or (args.system and not (args.platform or args.all))),
|
||||
"--target is incompatible with --emulator and --system"),
|
||||
(args.destinations and args.system,
|
||||
"--destinations describes the full pack and is incompatible with --system"),
|
||||
@@ -198,8 +197,10 @@ def _build_parser() -> argparse.ArgumentParser:
|
||||
|
||||
def _check_mode(args: argparse.Namespace, parser: argparse.ArgumentParser) -> bool:
|
||||
"""Refuse a request naming no mode or several, and say if it is the system mode."""
|
||||
# --system beside --platform narrows that platform, as in generate_pack.
|
||||
system_mode = bool(args.system) and not args.platform
|
||||
# --system beside --platform or --all narrows each platform, as in
|
||||
# generate_pack: refused under --all, verify could not report on the
|
||||
# packs generate_pack --all --system builds.
|
||||
system_mode = bool(args.system) and not (args.platform or args.all)
|
||||
modes = sum(1 for x in (args.platform, args.all, args.emulator, system_mode) if x)
|
||||
if modes == 0:
|
||||
parser.error("Specify --platform, --all, --emulator, or --system")
|
||||
@@ -211,22 +212,6 @@ def _check_mode(args: argparse.Namespace, parser: argparse.ArgumentParser) -> bo
|
||||
return system_mode
|
||||
|
||||
|
||||
def _platform_system_filter(
|
||||
args: argparse.Namespace, parser: argparse.ArgumentParser,
|
||||
) -> list[str] | None:
|
||||
if not (args.platform and args.system):
|
||||
return None
|
||||
config = load_platform_config(args.platform, args.platforms_dir)
|
||||
try:
|
||||
return resolve_system_arg(
|
||||
args.system, list(config.get("systems", {})), config,
|
||||
f"--platform {args.platform} --list-systems",
|
||||
)
|
||||
except ValueError as exc:
|
||||
parser.error(f"--system {args.system}: {exc}")
|
||||
return None
|
||||
|
||||
|
||||
def _run_emulator_mode(args: argparse.Namespace, db: dict, requested_regions: list[str]) -> None:
|
||||
names = comma_list(args.emulator)
|
||||
result = verify_emulator(
|
||||
@@ -263,24 +248,18 @@ def _target_scope(
|
||||
emu_profiles: dict,
|
||||
platform_systems: list[str] | None,
|
||||
) -> tuple[dict[str, set[str] | None], list[str]]:
|
||||
"""The cores of each platform on --target, and the platforms that have it."""
|
||||
if not args.target:
|
||||
return {}, platforms
|
||||
"""The cores of each platform on --target, and the platforms that have
|
||||
it and a system of the --system list. A system the target leaves no
|
||||
core for was reported 0/0 with exit 0, where generate_pack refuses the
|
||||
same request."""
|
||||
target_cores_cache, platforms = target_scope(
|
||||
platforms, args.target, args.platforms_dir, is_all=args.all
|
||||
)
|
||||
# A system the target leaves no core for was reported 0/0 with exit 0,
|
||||
# where generate_pack refuses the same request.
|
||||
if platform_systems:
|
||||
config = load_platform_config(args.platform, args.platforms_dir)
|
||||
if not platform_scope_systems(
|
||||
config, emu_profiles, target_cores_cache.get(args.platform), platform_systems
|
||||
):
|
||||
reason = system_scope_error(
|
||||
config, args.platform, platform_systems, args.target
|
||||
)
|
||||
print(f"ERROR: {reason}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
platforms = platforms_with_systems(
|
||||
platforms, platform_systems, emu_profiles, target_cores_cache,
|
||||
args.platforms_dir, args.target, args.all,
|
||||
)
|
||||
return target_cores_cache, platforms
|
||||
|
||||
|
||||
@@ -402,7 +381,7 @@ def _main(held: contextlib.ExitStack) -> None:
|
||||
return
|
||||
|
||||
system_mode = _check_mode(args, parser)
|
||||
platform_systems = _platform_system_filter(args, parser)
|
||||
platform_systems = resolve_system_ids(args, parser)
|
||||
# The trees stay put while names resolve against them and files are read.
|
||||
from packs.datadirs import hold_data_dirs
|
||||
|
||||
|
||||
@@ -7677,15 +7677,14 @@ class AnUnknownSystemIsRefusedBeforeAnyWork(unittest.TestCase):
|
||||
def test_a_known_system_passes_the_early_check(self):
|
||||
import argparse
|
||||
|
||||
import generate_pack
|
||||
from model.cliargs import resolve_system_ids
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
args = argparse.Namespace(
|
||||
system="sony-playstation", platform="retroarch", all=False,
|
||||
platforms_dir=str(ROOT / "platforms"), manifest=False,
|
||||
)
|
||||
generate_pack._resolve_systems(args, parser)
|
||||
self.assertEqual(args.system_ids, ["sony-playstation"])
|
||||
self.assertEqual(resolve_system_ids(args, parser), ["sony-playstation"])
|
||||
|
||||
|
||||
class NoArchiveRepeatsAMemberName(unittest.TestCase):
|
||||
|
||||
@@ -170,20 +170,17 @@ class APlatformWithoutTheSystemIsOutOfScope(unittest.TestCase):
|
||||
exited 1 on 'no pack for misterfpga', which has no PS2."""
|
||||
|
||||
def _scope(self, **args):
|
||||
import argparse
|
||||
|
||||
import generate_pack
|
||||
from model.profiles import load_emulator_profiles
|
||||
from resolve.cores import platforms_with_systems
|
||||
|
||||
values = {"platforms_dir": str(REPO_ROOT / "platforms"), "target": None,
|
||||
"all": True}
|
||||
values = {"target": None, "all": True}
|
||||
values.update(args)
|
||||
out = io.StringIO()
|
||||
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(out):
|
||||
kept = generate_pack._platforms_with_systems(
|
||||
argparse.Namespace(**values), ["retroarch", "misterfpga"],
|
||||
["sony-playstation-2"],
|
||||
kept = platforms_with_systems(
|
||||
["retroarch", "misterfpga"], ["sony-playstation-2"],
|
||||
load_emulator_profiles(str(REPO_ROOT / "emulators")), {},
|
||||
str(REPO_ROOT / "platforms"), values["target"], values["all"],
|
||||
)
|
||||
return kept, out.getvalue()
|
||||
|
||||
@@ -197,6 +194,24 @@ class APlatformWithoutTheSystemIsOutOfScope(unittest.TestCase):
|
||||
self._scope(all=False)
|
||||
self.assertEqual(ctx.exception.code, 1)
|
||||
|
||||
def test_verify_reports_on_the_packs_generate_pack_builds(self):
|
||||
"""verify --all --system exited 2 'mutually exclusive' while
|
||||
generate_pack built a pack per platform for the same request."""
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
proc = subprocess.run(
|
||||
[sys.executable, "scripts/verify.py", "--all", "--system", "sony-playstation-2",
|
||||
"--json"],
|
||||
cwd=REPO_ROOT, capture_output=True, text=True, check=False, timeout=900,
|
||||
)
|
||||
self.assertIn(proc.returncode, (0, 1), proc.stderr[-500:])
|
||||
self.assertIn("INFO: Skipping misterfpga: no system sony-playstation-2", proc.stderr)
|
||||
report = json.loads(proc.stdout)
|
||||
self.assertIn("retroarch", report)
|
||||
self.assertNotIn("misterfpga", report)
|
||||
|
||||
|
||||
class TheSplitDirectoryReadsThePackStem(unittest.TestCase):
|
||||
"""The split prefix was assembled by hand: a version 'release/1.22' made
|
||||
|
||||
Reference in new issue
Block a user