mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
fix: read targets from the config's own tree
resolve_platform_cores and offer_boards read the RetroArch and platform targets under the repository, whatever --platforms-dir a run was given, behind a process-long cache. load_platform_config now records the directory it read (_platforms_dir), the resolver reads targets from it, the cache is keyed on that directory, and downloadable_on takes it from its callers. The key is kept out of the published registry export.
This commit is contained in:
1 parent
6aca93231a
commit
8780398518
7 files changed
+69
-22
No files matched your search
@@ -4,13 +4,23 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
from core.paths import PLATFORMS_DIR, comparable_destination
|
||||
from core.paths import PLATFORMS_DIR, REPO_ROOT, comparable_destination
|
||||
from model.sources import source_yaml_file
|
||||
|
||||
|
||||
_shared_yml_cache: dict[str, dict] = {}
|
||||
_platform_config_cache: dict[tuple[str, str], dict] = {}
|
||||
|
||||
# The directory a config was loaded from, read by the steps that consult
|
||||
# its other files (the RetroArch targets of a downloaded-only core).
|
||||
PLATFORMS_DIR_KEY = "_platforms_dir"
|
||||
|
||||
|
||||
def config_platforms_dir(config: dict) -> str:
|
||||
"""The directory a config was loaded from, the repository's for a config
|
||||
built by hand."""
|
||||
return str(config.get(PLATFORMS_DIR_KEY) or REPO_ROOT / PLATFORMS_DIR)
|
||||
|
||||
|
||||
def _inherited_yaml(platform_name: str, platforms_dir: str) -> tuple[dict, list[str]]:
|
||||
"""The platform's YAML merged over its parents', and the chain of names.
|
||||
@@ -233,6 +243,7 @@ def load_platform_config(platform_name: str, platforms_dir: str = PLATFORMS_DIR)
|
||||
# The registry key, which per-platform profile fields (installed_on,
|
||||
# not_bundled_on) name: the display name differs (MiSTer FPGA).
|
||||
config["_key"] = platform_name
|
||||
config[PLATFORMS_DIR_KEY] = platforms_dir
|
||||
_attach_rom_folders(config, platform_name, platforms_dir)
|
||||
_platform_config_cache[cache_key] = config
|
||||
return config
|
||||
|
||||
@@ -405,7 +405,7 @@ def downloaded_cores(
|
||||
if cores is None:
|
||||
continue
|
||||
for profile, names in reached.items():
|
||||
if downloadable_on(cores, names):
|
||||
if downloadable_on(cores, names, platforms_dir):
|
||||
boards[profile] += [target["name"], *target.get("aliases", [])]
|
||||
return {profile: sorted(names) for profile, names in sorted(boards.items())}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ from resolve.layout import (
|
||||
standalone_layout_path,
|
||||
)
|
||||
from model.declarations import ROMS_ROOT, outer_layout
|
||||
from model.platforms import config_platforms_dir
|
||||
from model.profiles import core_key, profile_names
|
||||
from core.paths import REPO_ROOT
|
||||
|
||||
@@ -63,12 +64,13 @@ def offer_boards(config: dict) -> dict[tuple[str, str], frozenset[str] | None]:
|
||||
|
||||
ROCKNIX writes a core under a `case "${DEVICE}"` branch for the devices
|
||||
it builds (`when`), and a default for a named device in board_defaults
|
||||
(DEVICE=RK3326). Boards are the platform's targets, aliases included.
|
||||
(DEVICE=RK3326). Boards are the platform's targets, aliases included,
|
||||
read from the directory the config was loaded from.
|
||||
"""
|
||||
platform = str(config.get("_key") or "")
|
||||
targets = list_available_targets(
|
||||
platform, str(REPO_ROOT / "platforms")
|
||||
) if platform else []
|
||||
targets = (
|
||||
list_available_targets(platform, config_platforms_dir(config)) if platform else []
|
||||
)
|
||||
names = {t["name"]: [t["name"], *t.get("aliases", [])] for t in targets}
|
||||
|
||||
def admitted(test: Callable[[str], bool]) -> set[str]:
|
||||
|
||||
+17
-13
@@ -3,17 +3,17 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import functools
|
||||
import os
|
||||
from collections.abc import Collection
|
||||
from dataclasses import dataclass
|
||||
|
||||
from core.cli import suggest_names
|
||||
from core.paths import sanitize_pack_path
|
||||
from model.declarations import declared_slot
|
||||
from model.platforms import load_platform_config
|
||||
from model.platforms import config_platforms_dir, load_platform_config
|
||||
from model.profiles import preferred_profile, profile_names, upstream_profile_index
|
||||
from model.systems import norm_system_id, select_systems
|
||||
from model.targets import list_available_targets, load_target_config
|
||||
from core.paths import REPO_ROOT
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -79,14 +79,17 @@ def resolve_platform_cores(
|
||||
3. cores: absent, fallback to systems intersection
|
||||
|
||||
Alias profiles are always excluded (they point to another profile).
|
||||
If target_cores is provided, result is intersected with it.
|
||||
If target_cores is provided, result is intersected with it, and a core
|
||||
only the RetroArch downloader brings is checked against the RetroArch
|
||||
targets of the directory the config was loaded from.
|
||||
"""
|
||||
result, downloaded_only = _platform_profiles(config, profiles)
|
||||
if target_cores is not None:
|
||||
result = result & designated_profiles(profiles, target_cores)
|
||||
platforms_dir = config_platforms_dir(config)
|
||||
result -= {
|
||||
profile for profile, names in downloaded_only.items()
|
||||
if not downloadable_on(target_cores, names)
|
||||
if not downloadable_on(target_cores, names, platforms_dir)
|
||||
}
|
||||
return result
|
||||
|
||||
@@ -236,19 +239,20 @@ def _platform_profiles(
|
||||
return result, {p: frozenset(names) for p, names in downloaded_only.items()}
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=1)
|
||||
def _retroarch_target_sets() -> tuple[frozenset[str], ...]:
|
||||
platforms = str(REPO_ROOT / "platforms")
|
||||
@functools.lru_cache(maxsize=8)
|
||||
def _retroarch_target_sets(platforms_dir: str) -> tuple[frozenset[str], ...]:
|
||||
return tuple(
|
||||
frozenset(found)
|
||||
for t in list_available_targets("retroarch", platforms)
|
||||
if (found := load_target_config("retroarch", t["name"], platforms))
|
||||
for t in list_available_targets("retroarch", platforms_dir)
|
||||
if (found := load_target_config("retroarch", t["name"], platforms_dir))
|
||||
)
|
||||
|
||||
|
||||
def downloadable_on(target_cores: set[str], names: Collection[str]) -> bool:
|
||||
"""Whether a board's core set holds a RetroArch download list offering
|
||||
one of `names`.
|
||||
def downloadable_on(
|
||||
target_cores: set[str], names: Collection[str], platforms_dir: str
|
||||
) -> bool:
|
||||
"""Whether a board's core set holds a RetroArch download list of
|
||||
`platforms_dir` offering one of `names`.
|
||||
|
||||
A board with a downloader carries a whole RetroArch targets entry in its
|
||||
set (load_target_config, `downloads`), a board without one only what it
|
||||
@@ -256,7 +260,7 @@ def downloadable_on(target_cores: set[str], names: Collection[str]) -> bool:
|
||||
"""
|
||||
return any(
|
||||
found <= target_cores and not found.isdisjoint(names)
|
||||
for found in _retroarch_target_sets()
|
||||
for found in _retroarch_target_sets(os.path.realpath(platforms_dir))
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ from core.hashing import file_digest
|
||||
from model import retired as model_retired
|
||||
from model.database import sha1_at
|
||||
from model.dumpcatalog import load_provenance_snapshots
|
||||
from model.platforms import PLATFORMS_DIR_KEY
|
||||
from model.profiles import is_emulator
|
||||
from packs.crossref import FileConsumers, SupplementalIndex
|
||||
from acquire.provenance import build_report
|
||||
@@ -157,7 +158,7 @@ def _split_contract(config: dict) -> tuple[dict, dict]:
|
||||
for sys_id, system in contract["systems"].items()
|
||||
}
|
||||
registry = {key: value for key, value in config.items()
|
||||
if key not in allowed and key != "_key"}
|
||||
if key not in allowed and key not in ("_key", PLATFORMS_DIR_KEY)}
|
||||
# The merged config gives a child its parent's release_pack: Lakka and
|
||||
# RetroPie said true in the API while every page said they had no ZIP.
|
||||
# The registry's own entry decides, as it does for the pages.
|
||||
|
||||
@@ -645,7 +645,7 @@ class TheContractsValidate(unittest.TestCase):
|
||||
self.skipTest("jsonschema is a tooling dependency")
|
||||
|
||||
from model.registry import list_registered_platforms
|
||||
from model.platforms import load_platform_config
|
||||
from model.platforms import PLATFORMS_DIR_KEY, load_platform_config
|
||||
|
||||
schema = json.loads((REPO_ROOT / "schemas" / "platform.schema.json").read_text())
|
||||
validator = Draft202012Validator(schema)
|
||||
@@ -658,7 +658,11 @@ class TheContractsValidate(unittest.TestCase):
|
||||
self.assertEqual(errors, [])
|
||||
self.assertIn("install", registry)
|
||||
self.assertNotIn("_key", registry)
|
||||
self.assertEqual(set(contract) | set(registry) | {"_key"}, set(config) | {"_key"})
|
||||
# The directory a run loaded the config from is no published field.
|
||||
self.assertNotIn(PLATFORMS_DIR_KEY, registry)
|
||||
unpublished = {"_key", PLATFORMS_DIR_KEY}
|
||||
self.assertEqual(set(contract) | set(registry) | unpublished,
|
||||
set(config) | unpublished)
|
||||
|
||||
def test_every_schema_id_is_the_address_it_is_served_at(self):
|
||||
for path in sorted((REPO_ROOT / "schemas").glob("*.schema.json")):
|
||||
|
||||
@@ -373,6 +373,31 @@ class DownloadedCoresReachTheirBoards(unittest.TestCase):
|
||||
self.assertIn("x86_64", boards["amiberry"])
|
||||
self.assertNotIn("bcm2711", boards["amiberry"])
|
||||
|
||||
def test_the_downloader_lists_come_from_the_configs_own_tree(self):
|
||||
"""A downloaded-only core was checked against the repository's
|
||||
RetroArch targets whatever --platforms-dir the run was given."""
|
||||
import tempfile
|
||||
|
||||
from model.platforms import load_platform_config
|
||||
from resolve.cores import resolve_platform_cores
|
||||
|
||||
profiles = {"amiberry": {"type": "libretro", "cores": ["amiberry"],
|
||||
"systems": ["amiga"]}}
|
||||
resolved = {}
|
||||
for offered in ("amiberry", "amiberry, mgba"):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
(Path(root) / "targets").mkdir()
|
||||
(Path(root) / "demo.yml").write_text(
|
||||
"platform: Demo\ncores: [mgba]\ninstallable_cores: [amiberry]\n"
|
||||
"systems: {}\n")
|
||||
(Path(root) / "targets" / "retroarch.yml").write_text(
|
||||
f"targets:\n board:\n cores: [{offered}]\n")
|
||||
config = load_platform_config("demo", root)
|
||||
resolved[offered] = resolve_platform_cores(config, profiles, {"amiberry"})
|
||||
# The board builds amiberry, and only the first tree's downloader
|
||||
# list fits inside what it holds.
|
||||
self.assertEqual(resolved, {"amiberry": {"amiberry"}, "amiberry, mgba": set()})
|
||||
|
||||
|
||||
class KnulliPerBoard(unittest.TestCase):
|
||||
"""KNULLI builds per board on Batocera's model from its own tree:
|
||||
|
||||
Reference in new issue
Block a user