refactor: name the platform's own core build

The Recalbox and RetroPie exporters each rebuilt the folded core-name
index that model.profiles provides, and kept one claimant of a contested
name by load order (Recalbox the first, RetroPie the last). Neither read
built_by.

Both now read core_key_index through BaseExporter.core_profiles, and
model.profiles.platform_core_profiles chooses: the builds the platform
ships itself (built_by), all of them, else the claimants no platform
builds on its own, the profile keyed by the name first. platform_builds
carries the first half, shared with resolve.launchers.

Recalbox names that change: amiberry and libretro/amiberry
(amiberry-5.6.5, ROCKNIX's build, to amiberry-8.2.2), libretro/pcsx2
(lrps2-416291a, Batocera's, to pcsx2-libretro-408e3b2), bare pcsx2 (to
the standalone pcsx2), libretro/px68k (px68k-sdl, RetroPie's standalone,
to px68k), libretro/dosbox_pure (dosbox-pure-unleashed to dosbox_pure),
libretro/vice_x64, x64sc, x128, xvic (vice to each own core). A name no
profile of the written build claims falls back to either build:
es_bios.xml writes libretro/fba2x for piFBA, a standalone binary.

RetroPie: the amiberry package now stands for Amiberry 5.7.2 and 6.3.3,
the two builds RetroPie compiles, instead of the generic profile.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 10:30:51 +01:00
1 parent 3518e1c53c
commit b6bd585ee4
8 files changed
+241 -81

No files matched your search

+20
View File
@@ -11,6 +11,8 @@ from __future__ import annotations
from abc import ABC, abstractmethod
from typing import Generic, TypeVar, Union
from core.paths import EMULATORS_DIR, REPO_ROOT
from model.profiles import core_key_index, load_emulator_profiles, platform_core_profiles
from resolve.reconcile import NativeFile, NativeSystem, Report
# What a produced file holds: text for every format, bytes besides for one
@@ -222,6 +224,24 @@ class BaseExporter(ABC, Generic[Content]):
reads as one value the checker never compares."""
return None
def core_profiles(self, name: str, mode: str | None) -> set[str]:
"""The profiles a core name in the platform's own file stands for,
in the build ``mode`` it names (libretro or standalone, None for
either).
The platform's own build of a name is what the name means there:
Recalbox's libretro/pcsx2 is its PCSX2 1.7 fork, not the LRPS2
revision Batocera builds under that name, and load order picked
either one.
"""
cached = getattr(self, "_core_profiles", None)
if cached is None:
profiles = load_emulator_profiles(str(REPO_ROOT / EMULATORS_DIR))
cached = (profiles, core_key_index(profiles, include_aliases=True))
self._core_profiles = cached
profiles, index = cached
return platform_core_profiles(index, profiles, name, self.platform_name(), mode)
def required_value(self, fe: NativeFile) -> bool:
"""The requirement the render writes for an entry.
+8 -19
View File
@@ -20,7 +20,6 @@ from xml.sax.saxutils import quoteattr
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from model.profiles import load_emulator_profiles
from core.hashing import parse_hash_list
from model.safeparse import parse_untrusted_xml
@@ -33,8 +32,6 @@ SOURCE_URL = (
"https://gitlab.com/recalbox/recalbox/-/raw/master/board/recalbox/fsoverlay"
"/recalbox/share_init/system/.emulationstation/es_bios.xml"
)
# Resolved from the file: the profiles say which names each core answers to.
EMULATORS_DIR = Path(__file__).resolve().parents[2] / "emulators"
SCHEMA_URL = (
"https://gitlab.com/recalbox/recalbox/-/raw/master/board/recalbox/fsoverlay"
"/recalbox/share_init/system/.emulationstation/es_bios.xsd"
@@ -185,17 +182,6 @@ class Exporter(BaseExporter[str]):
return path
return fe.destination or fe.name
def _profile_keys(self) -> dict[str, str]:
"""Each name a core answers to, as Recalbox writes it, to its profile."""
index = getattr(self, "_keys", None)
if index is None:
index = {}
for key, profile in load_emulator_profiles(str(EMULATORS_DIR)).items():
for name in (key, *(str(c) for c in profile.get("cores") or [])):
index.setdefault(name.replace("-", "_").lower(), key)
self._keys = index
return index
def required_value(self, fe: NativeFile) -> bool:
"""Whether the cores the element names need the file.
@@ -216,11 +202,14 @@ class Exporter(BaseExporter[str]):
]
if not entries:
return fe.required
index = self._profile_keys()
named = {
index.get(core.rsplit("/", 1)[-1].replace("-", "_").lower(), "")
for core in fe.cores()
} - {""}
# Recalbox writes a libretro core under libretro/ and a standalone
# emulator bare, mostly: its own list writes libretro/fba2x for
# piFBA, a standalone binary. A name no profile of the build written
# claims is the emulator of either build.
named: set[str] = set()
for core in fe.cores():
mode, _, name = core.rpartition("/")
named |= self.core_profiles(name, mode or "standalone") or self.core_profiles(name, None)
readers: set[str] = set()
requirers: set[str] = set()
set_readers: set[str] = set()
+19 -28
View File
@@ -19,7 +19,6 @@ from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from model.profiles import load_emulator_profiles
from scraper.retropie_scraper import script_members
from .base_exporter import BaseExporter
@@ -29,9 +28,6 @@ SOURCE_URL = (
"https://codeload.github.com/RetroPie/RetroPie-Setup/tar.gz/refs/heads/master"
)
ARCHIVE = "RetroPie-Setup.tar.gz"
# Resolved from the file rather than the working directory: the profiles
# are what say which files a package needs.
EMULATORS_DIR = Path(__file__).resolve().parents[2] / "emulators"
# The longest list RetroPie writes is six names (lr-atari800). Past that the
# sentence stops being something a reader uses, so the names are reported
@@ -97,24 +93,17 @@ class Exporter(BaseExporter[str]):
if relative.startswith("scriptmodules/") and "bios" in text.lower()
}
def _core_index(self) -> dict[str, dict[str, str]]:
"""Module id (without its lr- prefix) to the profile it stands for,
per build.
def _module_cores(self, module_id: str) -> frozenset[str]:
"""The profiles a package stands for.
An lr- package is a libretro core and a bare one a standalone
emulator: the standalone minivmac package matched the libretro
profile, which reads MacII.ROM where Mini vMac 37 reads vMac.ROM.
A build RetroPie compiles itself is what its name means there, all
of them: the amiberry package is Amiberry 5.7.2 or 6.3.3 by board.
"""
index: dict[str, dict[str, str]] = {"libretro": {}, "standalone": {}}
for key, profile in load_emulator_profiles(str(EMULATORS_DIR)).items():
kind = str(profile.get("type", ""))
for build in ("libretro", "standalone"):
if build not in kind:
continue
index[build][key.replace("-", "_").lower()] = key
for name in profile.get("cores", []) or []:
index[build][str(name).replace("-", "_").lower()] = key
return index
build = "libretro" if module_id.startswith("lr-") else "standalone"
return frozenset(self.core_profiles(module_id.removeprefix("lr-"), build))
@staticmethod
def _files_by_core(systems: dict[str, NativeSystem]) -> dict[str, list[NativeFile]]:
@@ -246,8 +235,8 @@ class Exporter(BaseExporter[str]):
return kept
@staticmethod
def _required_for(fe: NativeFile, core: str | None) -> bool:
"""Whether the package's own core needs the file.
def _required_for(fe: NativeFile, cores: frozenset[str]) -> bool:
"""Whether the package's own cores need the file.
The merged `required` is true when any core needs it: pcsx_rearmed
runs in HLE without a BIOS, yet four were proposed as required for
@@ -257,12 +246,14 @@ class Exporter(BaseExporter[str]):
# A file the package installs is not one to copy: gngeopi's
# gngeo_data.zip lands in its data directory with make install.
brought = truth.get("_brought_by")
if brought is not None and not any(b.startswith(f"{core}:") for b in brought):
if brought is not None and not any(
b.startswith(f"{core}:") for b in brought for core in cores
):
return False
required_by = truth.get("_required_by")
if required_by is None:
return fe.required
return core in required_by
return bool(cores.intersection(required_by))
@staticmethod
def _join(names: list[str], serial: bool = False) -> str:
@@ -316,7 +307,6 @@ class Exporter(BaseExporter[str]):
"repository: the BIOS list is a sentence inside a shell script"
)
index = self._core_index()
# A sentence grows no longer than the longest RetroPie writes itself:
# past that it stops reading as one, and the names are reported.
self._longest = max(len(self._listed(help_text)) for _, help_text in modules.values())
@@ -335,13 +325,14 @@ class Exporter(BaseExporter[str]):
produced: dict[str, str] = {}
for relative, (module_id, help_text) in sorted(modules.items()):
build = "libretro" if module_id.startswith("lr-") else "standalone"
core = index[build].get(module_id.removeprefix("lr-").replace("-", "_").lower())
files = by_core.get(core or "", [])
cores = self._module_cores(module_id)
files = list({
id(fe): fe for core in sorted(cores) for fe in by_core.get(core, [])
}.values())
if not files:
self._skip("which no profiled core matches", module_id)
continue
new_help = self._new_help(module_id, help_text, files, core, systems_of)
new_help = self._new_help(module_id, help_text, files, cores, systems_of)
if new_help is None:
continue
produced[relative] = originals[relative].replace(
@@ -360,7 +351,7 @@ class Exporter(BaseExporter[str]):
module_id: str,
help_text: str,
files: list[NativeFile],
core: str | None,
cores: frozenset[str],
systems_of: dict[str, set[str]],
) -> str | None:
"""The help sentence with the files it lacks, None when left as is."""
@@ -381,7 +372,7 @@ class Exporter(BaseExporter[str]):
fe
for fe in files
if not fe.foreign_system
and self._required_for(fe, core)
and self._required_for(fe, cores)
and not (
{fe.name.lower()}
| {str(a).lower() for a in _aliases(fe)}
+44
View File
@@ -4,6 +4,7 @@ from __future__ import annotations
import os
import sys
from collections.abc import Iterable, Mapping
from pathlib import Path
from core.cli import InputMissing, suggest_names
@@ -327,3 +328,46 @@ def preferred_profile(index: dict[str, set[str]], name: str) -> str | None:
if not claimants:
return None
return name if name in claimants else sorted(claimants)[0]
def platform_builds(
claimants: Iterable[str], profiles: Mapping[str, dict], platform: str
) -> set[str]:
"""The claimants of a core name that a platform runs.
The builds the platform ships itself (``built_by``) when it names one,
else every claimant no platform builds on its own: a revision only
another platform compiles is not on this one. Recalbox's pcsx2 core is
its PCSX2 1.7 fork, not the LRPS2 revision Batocera builds under that
name.
"""
claimed = set(claimants)
own = {k for k in claimed if platform in (profiles[k].get("built_by") or [])}
return own or {k for k in claimed if not profiles[k].get("built_by")}
def platform_core_profiles(
index: Mapping[str, set[str]],
profiles: Mapping[str, dict],
name: str,
platform: str,
mode: str | None,
) -> set[str]:
"""The profiles a core name designates in a platform's own list.
``index`` is a ``core_key_index``, ``mode`` the build the list names
(``libretro`` or ``standalone``, None for either). The platform's own builds answer
first, all of them: RetroPie builds Amiberry 5.7.2 and 6.3.3 under one
package, one per board. Without one, the profile whose key is the name
does: Recalbox's vice_x64 is the vice_x64 core, not the vice profile
that also lists it.
"""
key = core_key(name)
claimants = {
k for k in index.get(key, ())
if mode is None or mode in str(profiles[k].get("type", ""))
}
builds = platform_builds(claimants, profiles, platform)
if any(platform in (profiles[k].get("built_by") or []) for k in builds):
return builds
return {k for k in builds if core_key(k) == key} or builds
+2 -3
View File
@@ -23,7 +23,7 @@ from dataclasses import dataclass
from core.hashing import HASH_FIELDS, declared_hashes
from model.database import record_at
from model.declarations import CONFIGS_ROOT, ROMS_ROOT, declared_root, declared_slot, outer_layout
from model.profiles import lists_files, profile_names
from model.profiles import lists_files, platform_builds, profile_names
from resolve.content import name_match_size_ok
from resolve.localfile import resolve_local_file
from core.paths import comparable_destination, sanitize_pack_path
@@ -435,8 +435,7 @@ def _named_profiles(record: dict, profiles: Mapping[str, dict], platform: str) -
key for key, profile in profiles.items()
if lists_files(profile) and part in profile_names(key, profile)
]
own = [k for k in named if platform in (profiles[k].get("built_by") or [])]
found.extend(own or [k for k in named if not profiles[k].get("built_by")])
found.extend(platform_builds(named, profiles, platform))
return sorted(set(found))