mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
fix: accept only registered platforms
require_platform checks the registry instead of any platforms/<name>.yml: verify --platform _shared reported 0/0 present and exited 0. --all and --platform resolve through model.cliargs.selected_platforms in auto_fetch, generate_truth, diff_truth, export_native and verify. The truth directory is core.paths.TRUTH_DIR for its writer and its three readers, and the remaining literal database and profile paths read core.paths and add_repo_inputs.
This commit is contained in:
1 parent
a732e69251
commit
ed19ae4198
15 files changed
+69
-67
No files matched your search
+2
-12
@@ -21,9 +21,8 @@ import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from model.cliargs import platform_arg, require_platform
|
||||
from model.cliargs import platform_arg, selected_platforms
|
||||
from core.cli import add_repo_inputs, require_directory
|
||||
from model.registry import list_registered_platforms
|
||||
from model.database import load_database, load_optional_database
|
||||
from model.platforms import load_platform_config
|
||||
from model.safeparse import require_yaml
|
||||
@@ -59,16 +58,7 @@ def main() -> None:
|
||||
|
||||
db = load_database(args.db)
|
||||
|
||||
if args.all:
|
||||
platforms = list_registered_platforms(
|
||||
args.platforms_dir,
|
||||
)
|
||||
elif args.platform:
|
||||
require_platform(args.platform, args.platforms_dir)
|
||||
platforms = [args.platform]
|
||||
else:
|
||||
parser.error("Specify --platform or --all")
|
||||
return
|
||||
platforms = selected_platforms(args, parser)
|
||||
|
||||
all_still_missing = {}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from core.cli import add_repo_inputs
|
||||
from core.hashing import compute_hashes
|
||||
from core.sizes import size_text
|
||||
from resolve.directories import expand_directory_entries
|
||||
@@ -110,9 +111,7 @@ def other_copies(rows: list[dict], bios_dir: Path) -> list[dict]:
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(allow_abbrev=False, description=__doc__.splitlines()[0])
|
||||
parser.add_argument("--db", default="database.json", help="database to read (default: %(default)s)")
|
||||
parser.add_argument("--emulators-dir", default="emulators", help="profiles (default: %(default)s)")
|
||||
parser.add_argument("--platforms-dir", default="platforms", help="platform lists (default: %(default)s)")
|
||||
add_repo_inputs(parser, "db", "emulators", "platforms")
|
||||
parser.add_argument("--install-dir", default="install", type=Path,
|
||||
help="install manifests, whose files are shipped (default: %(default)s)")
|
||||
parser.add_argument("--json", action="store_true", help="print the list as JSON")
|
||||
|
||||
@@ -75,7 +75,7 @@ from resolve.reconcile import build_native_model
|
||||
from scripts.scraper import game_dat_importer
|
||||
from scripts.scraper.redump_dat_scraper import fetch_snapshot
|
||||
from scripts.scraper.targets import discover_target_scrapers
|
||||
from core.paths import REPO_ROOT
|
||||
from core.paths import REPO_ROOT, TRUTH_DIR
|
||||
|
||||
CORE_INFO_REPO = "https://github.com/libretro/libretro-core-info"
|
||||
# The git blob of every .info as last reviewed: `--record-coreinfo` writes it.
|
||||
@@ -1840,7 +1840,7 @@ def main() -> int:
|
||||
help="where the platforms' own files are cached (default: %(default)s)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--truth-dir", default="dist/truth",
|
||||
"--truth-dir", default=TRUTH_DIR,
|
||||
help="directory of the truth models generate_truth writes (default: "
|
||||
"%(default)s)",
|
||||
)
|
||||
|
||||
@@ -21,6 +21,7 @@ Usage:
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from core.paths import PLATFORMS_DIR
|
||||
import argparse
|
||||
import json
|
||||
import subprocess
|
||||
@@ -57,7 +58,7 @@ def main() -> int:
|
||||
f"the release must be these files (default: the list attached to the release)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--platforms-dir", default="platforms",
|
||||
"--platforms-dir", default=PLATFORMS_DIR,
|
||||
help="registry whose release_pack platforms each need a pack (default: %(default)s)",
|
||||
)
|
||||
parser.add_argument("--json", action="store_true", help="JSON output")
|
||||
|
||||
@@ -15,6 +15,8 @@ DB_FILE = "database.json"
|
||||
PLATFORMS_DIR = "platforms"
|
||||
EMULATORS_DIR = "emulators"
|
||||
BIOS_DIR = "bios"
|
||||
# Where generate_truth writes its models and diff_truth and export_native read them.
|
||||
TRUTH_DIR = "dist/truth"
|
||||
|
||||
|
||||
def sanitize_pack_path(raw: str) -> str:
|
||||
|
||||
+4
-10
@@ -10,6 +10,7 @@ Usage:
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from core.paths import TRUTH_DIR
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
@@ -17,8 +18,7 @@ import sys
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
from core.cli import add_repo_inputs
|
||||
from model.cliargs import platform_arg, require_platform
|
||||
from model.registry import list_registered_platforms
|
||||
from model.cliargs import platform_arg, selected_platforms
|
||||
from model.platforms import load_platform_config, native_layer
|
||||
from model.safeparse import require_yaml, yaml_load
|
||||
from model.targets import truth_target_dir
|
||||
@@ -203,7 +203,7 @@ def main() -> None:
|
||||
help="same as --format markdown, the spelling validate_pr uses",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--truth-dir", default="dist/truth",
|
||||
"--truth-dir", default=TRUTH_DIR,
|
||||
help="directory of the truth models generate_truth writes (default: "
|
||||
"%(default)s)",
|
||||
)
|
||||
@@ -215,13 +215,7 @@ def main() -> None:
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.all:
|
||||
platforms = list_registered_platforms(
|
||||
args.platforms_dir
|
||||
)
|
||||
else:
|
||||
require_platform(args.platform, args.platforms_dir)
|
||||
platforms = [args.platform]
|
||||
platforms = selected_platforms(args)
|
||||
|
||||
reports: list[dict] = []
|
||||
formatter = _format_markdown if args.format == "markdown" else _format_terminal
|
||||
|
||||
@@ -15,6 +15,7 @@ Usage:
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from core.paths import TRUTH_DIR
|
||||
import argparse
|
||||
import sys
|
||||
from pathlib import Path
|
||||
@@ -22,8 +23,8 @@ from pathlib import Path
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
|
||||
from core.cli import add_repo_inputs
|
||||
from model.cliargs import platform_arg, require_platform
|
||||
from model.registry import list_registered_platforms, load_data_dir_registry, load_platform_registry
|
||||
from model.cliargs import platform_arg, selected_platforms
|
||||
from model.registry import load_data_dir_registry, load_platform_registry
|
||||
from exporter import discover_exporters
|
||||
from exporter.native import export_platform, refresh_cache
|
||||
from exporter.originals import DEFAULT_CACHE
|
||||
@@ -100,7 +101,7 @@ def main() -> None:
|
||||
help="directory the updated platform files go to (default: %(default)s)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--truth-dir", default="dist/truth",
|
||||
"--truth-dir", default=TRUTH_DIR,
|
||||
help="directory of the truth models generate_truth writes (default: "
|
||||
"%(default)s)",
|
||||
)
|
||||
@@ -123,13 +124,7 @@ def main() -> None:
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.all:
|
||||
platforms = list_registered_platforms(
|
||||
args.platforms_dir,
|
||||
)
|
||||
else:
|
||||
require_platform(args.platform, args.platforms_dir)
|
||||
platforms = [args.platform]
|
||||
platforms = selected_platforms(args)
|
||||
|
||||
if not args.refresh_cache:
|
||||
import contextlib
|
||||
|
||||
@@ -33,7 +33,7 @@ import urllib.parse
|
||||
from pathlib import Path
|
||||
|
||||
from model.registry import load_platform_registry
|
||||
from core.paths import PLATFORMS_DIR, REPO_ROOT
|
||||
from core.paths import DB_FILE, PLATFORMS_DIR, REPO_ROOT
|
||||
from scraper.base_scraper import FetchError, fetch_bytes
|
||||
|
||||
sys.path.insert(0, str(REPO_ROOT / "scripts"))
|
||||
@@ -199,7 +199,7 @@ def fetch_icons() -> None:
|
||||
from model.collection import group_by_manufacturer
|
||||
from sitegen.render import SYSTEM_ICON_BASE, console_icon_name
|
||||
|
||||
db = load_database(str(REPO_ROOT / "database.json"))
|
||||
db = load_database(str(REPO_ROOT / DB_FILE))
|
||||
names = sorted({
|
||||
console_icon_name(manufacturer, console)
|
||||
for manufacturer, consoles in group_by_manufacturer(db).items()
|
||||
|
||||
@@ -19,6 +19,7 @@ import re
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from core.cli import add_repo_inputs
|
||||
from model.profiles import load_emulator_profiles
|
||||
from model.region import REGIONS, normalize_declared
|
||||
from model.safeparse import yaml_load
|
||||
@@ -243,8 +244,7 @@ def main() -> int:
|
||||
help=f"extra-file rules to check (default {EXTRAS_FILE})")
|
||||
parser.add_argument("--headers", type=Path, default=HEADERS_FILE,
|
||||
help=f"header readers the triggers name (default {HEADERS_FILE})")
|
||||
parser.add_argument("--emulators-dir", default="emulators",
|
||||
help="profiles the rules are checked against (default emulators)")
|
||||
add_repo_inputs(parser, "emulators")
|
||||
parser.add_argument("--json", action="store_true", help="print the summary as JSON")
|
||||
args = parser.parse_args()
|
||||
from model.cliargs import work_from_repo_root
|
||||
|
||||
@@ -8,14 +8,15 @@ Usage:
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from core.paths import TRUTH_DIR
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
from model.targets import target_scope, truth_target_dir
|
||||
from model.cliargs import platform_arg, require_platform
|
||||
from model.registry import list_registered_platforms, load_data_dir_registry, load_platform_registry
|
||||
from model.cliargs import platform_arg, selected_platforms
|
||||
from model.registry import load_data_dir_registry, load_platform_registry
|
||||
from model.database import load_optional_database
|
||||
from model.profiles import load_emulator_profiles
|
||||
from model.platforms import load_platform_config
|
||||
@@ -26,7 +27,7 @@ from resolve.truth import generate_platform_truth
|
||||
|
||||
yaml = require_yaml()
|
||||
|
||||
DEFAULT_OUTPUT_DIR = "dist/truth"
|
||||
DEFAULT_OUTPUT_DIR = TRUTH_DIR
|
||||
|
||||
|
||||
def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
|
||||
@@ -63,13 +64,7 @@ def main(argv: list[str] | None = None) -> None:
|
||||
|
||||
db = load_optional_database(args.db)
|
||||
|
||||
if args.all:
|
||||
platforms = list_registered_platforms(
|
||||
args.platforms_dir,
|
||||
)
|
||||
else:
|
||||
require_platform(args.platform, args.platforms_dir)
|
||||
platforms = [args.platform]
|
||||
platforms = selected_platforms(args)
|
||||
|
||||
# A named platform without that target is refused, as verify and
|
||||
# generate_pack refuse it: skipped, it printed Done. and exited 0 with
|
||||
|
||||
@@ -63,7 +63,9 @@ def platform_arg(value: str) -> str:
|
||||
|
||||
|
||||
def require_platform(name: str, platforms_dir: str = PLATFORMS_DIR) -> None:
|
||||
"""Exit with a usable message when no platform answers to a name.
|
||||
"""Exit with a usable message when no registered platform answers to a
|
||||
name. A file under platforms/ is not enough: _shared, _registry and the
|
||||
emulatorjs base config passed and reported 0/0 present.
|
||||
|
||||
A typo used to end in a traceback (verify, cross_reference) or in "no
|
||||
pack for batocra" after the whole build ran (generate_pack).
|
||||
@@ -75,11 +77,16 @@ def require_platform(name: str, platforms_dir: str = PLATFORMS_DIR) -> None:
|
||||
f"ERROR: --platform takes one platform, not '{name}'. "
|
||||
"Run once per platform, or use --all."
|
||||
)
|
||||
if os.path.exists(os.path.join(platforms_dir, f"{name}.yml")):
|
||||
if not os.path.exists(os.path.join(platforms_dir, "_registry.yml")):
|
||||
# A fixture directory without a registry names its platforms by file.
|
||||
if os.path.exists(os.path.join(platforms_dir, f"{name}.yml")):
|
||||
return
|
||||
raise SystemExit(f"ERROR: unknown platform '{name}' in {platforms_dir}")
|
||||
known = list_registered_platforms(platforms_dir)
|
||||
if name in known:
|
||||
return
|
||||
import difflib
|
||||
|
||||
known = list_registered_platforms(platforms_dir)
|
||||
close = difflib.get_close_matches(name, known, n=1)
|
||||
hint = f" Close match: '{close[0]}'." if close else ""
|
||||
raise SystemExit(
|
||||
@@ -87,6 +94,20 @@ def require_platform(name: str, platforms_dir: str = PLATFORMS_DIR) -> None:
|
||||
)
|
||||
|
||||
|
||||
def selected_platforms(
|
||||
args: argparse.Namespace, parser: argparse.ArgumentParser | None = None
|
||||
) -> list[str]:
|
||||
"""The platforms --all or --platform names, every one registered."""
|
||||
if args.all:
|
||||
return list_registered_platforms(args.platforms_dir)
|
||||
if args.platform:
|
||||
require_platform(args.platform, args.platforms_dir)
|
||||
return [args.platform]
|
||||
if parser is not None:
|
||||
parser.error("Specify --platform or --all")
|
||||
raise SystemExit("ERROR: specify --platform or --all")
|
||||
|
||||
|
||||
def list_emulator_profiles(emulators_dir: str, skip_aliases: bool = True) -> None:
|
||||
"""Print available emulator profiles."""
|
||||
profiles = load_emulator_profiles(emulators_dir, skip_aliases=False)
|
||||
|
||||
@@ -19,7 +19,7 @@ from typing import IO, TYPE_CHECKING, TypedDict
|
||||
from unattended import worktree
|
||||
import core_probe
|
||||
from core import childenv, hostguard
|
||||
from core.paths import REPO_ROOT
|
||||
from core.paths import DB_FILE, REPO_ROOT
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing_extensions import Unpack
|
||||
@@ -177,7 +177,7 @@ class Paths:
|
||||
def default(cls) -> Paths:
|
||||
main = worktree.main_checkout()
|
||||
return cls(root=REPO_ROOT, home=main / ".cache" / "campaign",
|
||||
content=main / ".cache" / "test-content", db=REPO_ROOT / "database.json")
|
||||
content=main / ".cache" / "test-content", db=REPO_ROOT / DB_FILE)
|
||||
|
||||
|
||||
ROMFETCH_PASSED = ("XDG_CONFIG_HOME", "XDG_CACHE_HOME", "XDG_DATA_HOME")
|
||||
|
||||
@@ -11,7 +11,7 @@ import tempfile
|
||||
from collections.abc import Callable, Iterable
|
||||
from pathlib import Path
|
||||
|
||||
from core.paths import REPO_ROOT
|
||||
from core.paths import DB_FILE, REPO_ROOT
|
||||
from model.profiles import entry_system_ids
|
||||
from core_probe import BUILTIN
|
||||
from probes.content import Content, load_content, load_file
|
||||
@@ -211,7 +211,7 @@ def pack_files(emulator: str, region: str, work: Path) -> dict[str, Path]:
|
||||
def local_resolver() -> Callable[[dict], Path | None]:
|
||||
from model.database import load_database
|
||||
|
||||
db = load_database(str(REPO_ROOT / "database.json"))
|
||||
db = load_database(str(REPO_ROOT / DB_FILE))
|
||||
return lambda entry: held_file(entry, db, REPO_ROOT)
|
||||
|
||||
|
||||
|
||||
+3
-8
@@ -44,6 +44,7 @@ from model.cliargs import (
|
||||
platform_arg,
|
||||
work_from_repo_root,
|
||||
require_platform,
|
||||
selected_platforms,
|
||||
list_platform_system_ids,
|
||||
list_emulator_profiles,
|
||||
list_system_ids,
|
||||
@@ -53,7 +54,7 @@ from model.systems import resolve_system_arg
|
||||
from model.profiles import (
|
||||
load_emulator_profiles,
|
||||
)
|
||||
from model.registry import list_registered_platforms, load_data_dir_registry
|
||||
from model.registry import load_data_dir_registry
|
||||
from resolve.grouping import group_identical_platforms
|
||||
from model.database import load_database
|
||||
from model.platforms import load_platform_config
|
||||
@@ -364,13 +365,7 @@ def _run_platform_mode(
|
||||
requested_regions: list[str],
|
||||
platform_systems: list[str] | None,
|
||||
) -> None:
|
||||
if args.all:
|
||||
platforms = list_registered_platforms(args.platforms_dir)
|
||||
elif args.platform:
|
||||
platforms = [args.platform]
|
||||
else:
|
||||
parser.error("Specify --platform or --all")
|
||||
return
|
||||
platforms = selected_platforms(args, parser)
|
||||
|
||||
# Load emulator profiles once for cross-reference (not per-platform)
|
||||
emu_profiles = load_emulator_profiles(args.emulators_dir)
|
||||
|
||||
@@ -607,6 +607,16 @@ class OnePlatformPerFlag(unittest.TestCase):
|
||||
require_platform("batocra", str(ROOT / "platforms"))
|
||||
self.assertIn("batocera", str(caught.exception))
|
||||
|
||||
def test_a_file_that_is_no_platform_is_refused(self):
|
||||
"""_shared and the emulatorjs base config are YAML files under
|
||||
platforms/, not platforms: verify --platform _shared reported 0/0."""
|
||||
from model.cliargs import require_platform
|
||||
|
||||
for name in ("_shared", "_registry", "emulatorjs"):
|
||||
with self.subTest(name=name), self.assertRaises(SystemExit) as caught:
|
||||
require_platform(name, str(ROOT / "platforms"))
|
||||
self.assertIn("unknown platform", str(caught.exception))
|
||||
|
||||
|
||||
class APackIsSwappedInWhole(unittest.TestCase):
|
||||
"""Packs were opened on their final name: a rebuild truncated the good
|
||||
|
||||
Reference in new issue
Block a user