mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-28 04:18:52 -06:00
fix: scope --target the same way in every tool
slots and cross_reference go through model.targets.target_scope, so a mistyped target ends with ERROR and exit 1 as in verify, where they exited 2. The platforms --all skips are noted on stderr, which kept slots --json from printing them ahead of its document. slots reads the mode through platform_mode and builds the ZIP index and data-directory registry once per run instead of twice per platform.
This commit is contained in:
1 parent
3467b80b38
commit
ee66aa4e66
4 files changed
+50
-34
No files matched your search
@@ -206,22 +206,15 @@ class _PlatformScope:
|
|||||||
run_anywhere: set[str]
|
run_anywhere: set[str]
|
||||||
|
|
||||||
|
|
||||||
def _platform_scope(
|
def _platform_scope(args: argparse.Namespace, profiles: dict[str, dict]) -> _PlatformScope:
|
||||||
args: argparse.Namespace, parser: argparse.ArgumentParser, profiles: dict[str, dict],
|
from model.targets import target_scope
|
||||||
) -> _PlatformScope:
|
|
||||||
from model.targets import load_target_config
|
|
||||||
from resolve.cores import resolve_platform_cores
|
from resolve.cores import resolve_platform_cores
|
||||||
|
|
||||||
try:
|
# A typo ended in a traceback where verify and slots name the closest
|
||||||
target_cores = (
|
# target, and is refused the way they refuse it.
|
||||||
load_target_config(args.platform, args.target, args.platforms_dir)
|
target_cores = target_scope(
|
||||||
if args.target
|
[args.platform], args.target, args.platforms_dir
|
||||||
else None
|
)[0].get(args.platform)
|
||||||
)
|
|
||||||
except (FileNotFoundError, ValueError) as exc:
|
|
||||||
# A typo ended in a traceback where verify and slots name the
|
|
||||||
# closest target.
|
|
||||||
parser.error(str(exc))
|
|
||||||
config = load_platform_config(args.platform, args.platforms_dir)
|
config = load_platform_config(args.platform, args.platforms_dir)
|
||||||
relevant = resolve_platform_cores(config, profiles, target_cores=target_cores)
|
relevant = resolve_platform_cores(config, profiles, target_cores=target_cores)
|
||||||
run_anywhere = (
|
run_anywhere = (
|
||||||
@@ -321,7 +314,7 @@ def main() -> None:
|
|||||||
platform_scope: _PlatformScope | None = None
|
platform_scope: _PlatformScope | None = None
|
||||||
standalone_cores: set[str] = set()
|
standalone_cores: set[str] = set()
|
||||||
if args.platform:
|
if args.platform:
|
||||||
platform_scope = _platform_scope(args, parser, profiles)
|
platform_scope = _platform_scope(args, profiles)
|
||||||
profiles = platform_scope.profiles
|
profiles = platform_scope.profiles
|
||||||
standalone_cores = platform_scope.standalone_cores
|
standalone_cores = platform_scope.standalone_cores
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -272,8 +272,9 @@ def build_target_cores_cache(
|
|||||||
# The seventeen per-platform lines buried the one suggestion that
|
# The seventeen per-platform lines buried the one suggestion that
|
||||||
# mattered: the refusal names the closest target across them all.
|
# mattered: the refusal names the closest target across them all.
|
||||||
raise ValueError(_unknown_target_message(target, platforms, platforms_dir))
|
raise ValueError(_unknown_target_message(target, platforms, platforms_dir))
|
||||||
|
# On stderr: slots --json printed them ahead of its document.
|
||||||
for note in notes:
|
for note in notes:
|
||||||
print(note)
|
print(note, file=sys.stderr)
|
||||||
return cache, kept
|
return cache, kept
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+17
-18
@@ -28,8 +28,9 @@ from model.platforms import load_platform_config
|
|||||||
from core.ziptools import build_zip_contents_index
|
from core.ziptools import build_zip_contents_index
|
||||||
from model.profiles import load_emulator_profiles
|
from model.profiles import load_emulator_profiles
|
||||||
from model.registry import list_registered_platforms, load_data_dir_registry
|
from model.registry import list_registered_platforms, load_data_dir_registry
|
||||||
from model.targets import build_target_cores_cache
|
from model.targets import target_scope
|
||||||
from resolve.localfile import resolution_is_hash_exact
|
from resolve.localfile import resolution_is_hash_exact
|
||||||
|
from resolve.nativemode import platform_mode
|
||||||
from resolve.standalone import standalone_set as platform_standalone_set
|
from resolve.standalone import standalone_set as platform_standalone_set
|
||||||
|
|
||||||
from packs.slots import ADDRESSEE, Claim, Conflict, Decision, arbitrate, find_conflicts
|
from packs.slots import ADDRESSEE, Claim, Conflict, Decision, arbitrate, find_conflicts
|
||||||
@@ -120,7 +121,8 @@ def format_conflict(conflict: Conflict) -> str:
|
|||||||
|
|
||||||
def scan_platform(
|
def scan_platform(
|
||||||
platform: str, profiles: dict, db: dict, platforms_dir: str = PLATFORMS_DIR,
|
platform: str, profiles: dict, db: dict, platforms_dir: str = PLATFORMS_DIR,
|
||||||
target_cores: set[str] | None = None,
|
target_cores: set[str] | None = None, zip_index: dict | None = None,
|
||||||
|
data_registry: dict | None = None,
|
||||||
) -> list[Conflict]:
|
) -> list[Conflict]:
|
||||||
"""Conflicts on one platform, using the cores that platform actually runs."""
|
"""Conflicts on one platform, using the cores that platform actually runs."""
|
||||||
from model.platforms import load_platform_config
|
from model.platforms import load_platform_config
|
||||||
@@ -138,8 +140,8 @@ def scan_platform(
|
|||||||
db,
|
db,
|
||||||
config.get("base_destination", ""),
|
config.get("base_destination", ""),
|
||||||
platform_standalone_set(config),
|
platform_standalone_set(config),
|
||||||
build_zip_contents_index(db),
|
build_zip_contents_index(db) if zip_index is None else zip_index,
|
||||||
load_data_dir_registry(platforms_dir),
|
load_data_dir_registry(platforms_dir) if data_registry is None else data_registry,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -174,13 +176,13 @@ def main() -> int:
|
|||||||
|
|
||||||
import contextlib
|
import contextlib
|
||||||
|
|
||||||
from model.registry import load_data_dir_registry
|
|
||||||
from packs.datadirs import hold_data_dirs
|
from packs.datadirs import hold_data_dirs
|
||||||
|
|
||||||
# Claims resolve against data/: the trees stay put until the process
|
# Claims resolve against data/: the trees stay put until the process
|
||||||
# ends, which releases the hold.
|
# ends, which releases the hold.
|
||||||
held = contextlib.ExitStack()
|
held = contextlib.ExitStack()
|
||||||
hold_data_dirs(held, load_data_dir_registry(args.platforms_dir))
|
data_registry = load_data_dir_registry(args.platforms_dir)
|
||||||
|
hold_data_dirs(held, data_registry)
|
||||||
|
|
||||||
db = load_database(args.db)
|
db = load_database(args.db)
|
||||||
profiles = load_emulator_profiles(args.emulators_dir)
|
profiles = load_emulator_profiles(args.emulators_dir)
|
||||||
@@ -191,28 +193,25 @@ def main() -> int:
|
|||||||
if args.platform
|
if args.platform
|
||||||
else list_registered_platforms(args.platforms_dir)
|
else list_registered_platforms(args.platforms_dir)
|
||||||
)
|
)
|
||||||
target_cores: dict[str, set[str] | None] = {}
|
target_cores, names = target_scope(
|
||||||
if args.target:
|
names, args.target, args.platforms_dir, is_all=not args.platform
|
||||||
try:
|
)
|
||||||
target_cores, names = build_target_cores_cache(
|
|
||||||
names, args.target, args.platforms_dir, is_all=not args.platform
|
|
||||||
)
|
|
||||||
except (FileNotFoundError, ValueError) as exc:
|
|
||||||
parser.error(str(exc))
|
|
||||||
|
|
||||||
|
zip_index = build_zip_contents_index(db)
|
||||||
found: dict[str, list[Conflict]] = {}
|
found: dict[str, list[Conflict]] = {}
|
||||||
collided: dict[str, list[Collision]] = {}
|
collided: dict[str, list[Collision]] = {}
|
||||||
for name in names:
|
for name in names:
|
||||||
conflicts = scan_platform(
|
conflicts = scan_platform(
|
||||||
name, profiles, db, args.platforms_dir, target_cores.get(name)
|
name, profiles, db, args.platforms_dir, target_cores.get(name),
|
||||||
|
zip_index, data_registry,
|
||||||
)
|
)
|
||||||
if conflicts:
|
if conflicts:
|
||||||
found[name] = conflicts
|
found[name] = conflicts
|
||||||
collisions = find_collisions(
|
collisions = find_collisions(
|
||||||
load_platform_config(name, args.platforms_dir),
|
load_platform_config(name, args.platforms_dir),
|
||||||
db,
|
db,
|
||||||
build_zip_contents_index(db),
|
zip_index,
|
||||||
load_data_dir_registry(args.platforms_dir),
|
data_registry,
|
||||||
)
|
)
|
||||||
if collisions:
|
if collisions:
|
||||||
collided[name] = collisions
|
collided[name] = collisions
|
||||||
@@ -247,7 +246,7 @@ def main() -> int:
|
|||||||
fixable = 0
|
fixable = 0
|
||||||
for platform, conflicts in found.items():
|
for platform, conflicts in found.items():
|
||||||
config = load_platform_config(platform, args.platforms_dir)
|
config = load_platform_config(platform, args.platforms_dir)
|
||||||
mode = config.get("verification_mode", "existence")
|
mode = platform_mode(config)
|
||||||
print(f"{platform}: {len(conflicts)} contradicted [{mode}]")
|
print(f"{platform}: {len(conflicts)} contradicted [{mode}]")
|
||||||
for conflict in conflicts:
|
for conflict in conflicts:
|
||||||
decision = arbitrate(conflict, mode, rule=config.get("hash_rule", ""))
|
decision = arbitrate(conflict, mode, rule=config.get("hash_rule", ""))
|
||||||
|
|||||||
@@ -292,6 +292,29 @@ class AMistypedTargetAcrossAllPlatforms(unittest.TestCase):
|
|||||||
self.assertEqual(out.getvalue(), "")
|
self.assertEqual(out.getvalue(), "")
|
||||||
|
|
||||||
|
|
||||||
|
class AMistypedTargetEndsEveryToolAlike(unittest.TestCase):
|
||||||
|
"""--target swtich: verify exited 1, slots and cross_reference 2."""
|
||||||
|
|
||||||
|
def test_one_exit_status(self):
|
||||||
|
for script in ("verify.py", "slots.py", "cross_reference.py"):
|
||||||
|
with self.subTest(script=script):
|
||||||
|
proc = subprocess.run(
|
||||||
|
[sys.executable, f"scripts/{script}", "--platform", "retroarch",
|
||||||
|
"--target", "swtich"],
|
||||||
|
cwd=REPO_ROOT, capture_output=True, text=True, check=False, timeout=300,
|
||||||
|
)
|
||||||
|
self.assertEqual(proc.returncode, 1, proc.stderr)
|
||||||
|
self.assertIn("ERROR:", proc.stderr)
|
||||||
|
|
||||||
|
def test_skipped_platforms_are_noted_on_stderr(self):
|
||||||
|
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)
|
||||||
|
self.assertEqual(out.getvalue(), "")
|
||||||
|
self.assertIn("INFO: Skipping", err.getvalue())
|
||||||
|
|
||||||
|
|
||||||
class AMistypedDataKeyGetsTheClosestName(unittest.TestCase):
|
class AMistypedDataKeyGetsTheClosestName(unittest.TestCase):
|
||||||
"""`--key dolphin-sis` printed all 27 keys on one line."""
|
"""`--key dolphin-sis` printed all 27 keys on one line."""
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user