mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-15 22:43:48 -06:00
chore: merge integ-2026-11-09 placement round
Both binding sides kept: roms_place, named handles and environment variable directories from integ run through the pool and per-system binding of this branch. Batocera, KNULLI and RetroBat launcher records regenerated from the merged extractors.
This commit is contained in:
commit
339297c75c
26 files changed
+1018
-137
No files matched your search
+49
-2
@@ -509,6 +509,14 @@ def load_platform_config(platform_name: str, platforms_dir: str = "platforms") -
|
||||
# The registry key, which per-platform profile fields (installed_on,
|
||||
# not_bundled_on) name: the display name differs (MiSTer FPGA).
|
||||
config["_key"] = platform_name
|
||||
# Where the platform's games live, as its rom folders file records it
|
||||
# from the OS's own source (platforms/romfolders/<key>.yml, roms_root).
|
||||
romfolders = os.path.join(platforms_dir, "romfolders", f"{platform_name}.yml")
|
||||
if os.path.exists(romfolders):
|
||||
with open(romfolders) as f:
|
||||
roms_root = (source_yaml(f) or {}).get("roms_root")
|
||||
if isinstance(roms_root, dict):
|
||||
config["_roms_root"] = roms_root
|
||||
_platform_config_cache[cache_key] = config
|
||||
return config
|
||||
|
||||
@@ -2761,7 +2769,7 @@ def standalone_set(config: dict) -> set[str]:
|
||||
names |= {
|
||||
HANDED_PREFIX + json.dumps(
|
||||
[position, h.emulator, h.folder, h.directory, sorted(h.handles), h.source_ref,
|
||||
h.roms_folder, sorted(h.systems), h.holds_declared]
|
||||
h.roms_place, sorted(h.systems), h.holds_declared]
|
||||
)
|
||||
for position, h in enumerate(handed)
|
||||
}
|
||||
@@ -2808,7 +2816,8 @@ def _handed(standalone_cores: Iterable[str]) -> list:
|
||||
tag[len(HANDED_PREFIX):]
|
||||
)
|
||||
found.append(((position, tag), HandedDirectory(
|
||||
emulator, folder, directory, frozenset(handles), ref, roms, frozenset(systems), held
|
||||
emulator, folder, directory, frozenset(handles), ref,
|
||||
tuple(roms) if roms else None, frozenset(systems), held,
|
||||
)))
|
||||
return [h for _key, h in sorted(found, key=lambda pair: pair[0])]
|
||||
|
||||
@@ -2862,6 +2871,39 @@ EMULATORS_ROOT = "emulators"
|
||||
OUTER_ROOTS = (ROMS_ROOT, EMULATORS_ROOT)
|
||||
|
||||
|
||||
def outer_layout(config: dict, root: str) -> dict | None:
|
||||
"""Where a platform keeps the folder an outer root names, or None.
|
||||
|
||||
roms: the roms root its rom folders file records (``path``, the OS's
|
||||
spelling, and ``from_bios``, relative to the BIOS folder), with the
|
||||
BIOS folder's own name, base_destination, that a run's folder must
|
||||
carry before ``from_bios`` is followed from it. emulators: the
|
||||
registry's ``emulators_directory``, the folders a launcher searches
|
||||
for an emulator by key, which no rom folders file describes.
|
||||
"""
|
||||
if root == ROMS_ROOT:
|
||||
found = config.get("_roms_root") or {}
|
||||
base = str(config.get("base_destination") or "")
|
||||
path, relation = found.get("path"), found.get("from_bios")
|
||||
if not (path and relation) or "<" in str(path):
|
||||
return None
|
||||
if base:
|
||||
return {"path": str(path), "from_bios": str(relation), "bios_folder": base}
|
||||
# A list whose dests start above the BIOS folder (AmberELEC's
|
||||
# bios/...) installs into the folder holding it: a roms root there
|
||||
# or below is part of the install tree, written as a plain dest.
|
||||
declared = declared_root(config)
|
||||
if not declared:
|
||||
return None
|
||||
inside = os.path.normpath(f"{declared}/{relation}")
|
||||
if inside == ".." or inside.startswith("../"):
|
||||
return None
|
||||
return {"path": str(path), "install_prefix": "" if inside == "." else inside}
|
||||
if root == EMULATORS_ROOT:
|
||||
return config.get("emulators_directory") or None
|
||||
return None
|
||||
|
||||
|
||||
def standalone_layout_path(entry: dict, profile: dict) -> str | None:
|
||||
"""The path of an entry relative to the directories its standalone build declares.
|
||||
|
||||
@@ -2991,6 +3033,11 @@ def platform_layouts(
|
||||
tree, path = placed
|
||||
moved = {**f, "standalone_path": path,
|
||||
"layout_path": standalone_layout_path(f, profile)}
|
||||
if tree == "install":
|
||||
# Below the roms root inside the install tree (AmberELEC's
|
||||
# /storage/roms): a plain dest the platform prefix skips.
|
||||
files.append({**moved, "unprefixed": True})
|
||||
continue
|
||||
# A file the launcher runs from the roms directory (ROCKNIX's
|
||||
# roms/pico-8) or an emulator folder (RetroBat's emulators/pico8)
|
||||
# is relative to it, and says so.
|
||||
|
||||
@@ -40,6 +40,7 @@ from alternatives import core_file_spares, settle_sets, slot_set_keys
|
||||
from common import resolve_platform_cores as _platform_cores
|
||||
from common import (
|
||||
OUTER_ROOTS,
|
||||
outer_layout,
|
||||
installed_data_refs,
|
||||
platform_arg,
|
||||
require_directory,
|
||||
@@ -4686,11 +4687,12 @@ def _record_absent(
|
||||
)
|
||||
|
||||
|
||||
# What a manifest's roms_directory and emulators_directory carry from the
|
||||
# registry: the BIOS folder's name, and for emulator folders the places the
|
||||
# What a manifest's roms_directory and emulators_directory carry: the BIOS
|
||||
# folder's name, for the roms root its place relative to the BIOS folder
|
||||
# (romfolders roms_root.from_bios), and for emulator folders the places the
|
||||
# launcher searches, the one a missing folder is created at, and the config
|
||||
# file whose key moves a folder.
|
||||
MANIFEST_OUTER_FIELDS = ("bios_folder", "searched", "default", "config")
|
||||
MANIFEST_OUTER_FIELDS = ("bios_folder", "from_bios", "searched", "default", "config")
|
||||
|
||||
|
||||
def _record_unplaceable(unplaceable: list[dict], record_omission: Callable[..., None]) -> None:
|
||||
@@ -5259,7 +5261,7 @@ def generate_manifest(
|
||||
if data_directories:
|
||||
result["data_directories"] = data_directories
|
||||
for root in OUTER_ROOTS:
|
||||
layout = config.get(f"{root}_directory") or {}
|
||||
layout = outer_layout(config, root) or {}
|
||||
if layout and any(entry.get("root") == root
|
||||
for entry in [*manifest_files, *result["omitted_files"]]):
|
||||
# Where the installer finds the folder: relative to the folder
|
||||
|
||||
+83
-28
@@ -331,6 +331,9 @@ BIOS_TREE = ""
|
||||
ROMS_TREE = "roms"
|
||||
# The emulator folders of a platform whose registry describes them.
|
||||
EMULATORS_TREE = "emulators"
|
||||
# The tree a platform's list installs into when it starts above the BIOS
|
||||
# folder: a plain dest, with no prefix.
|
||||
INSTALL_TREE = "install"
|
||||
# A folder of neither tree, which no pack and no installer can fill.
|
||||
OUTSIDE_TREE = "outside"
|
||||
Place = tuple[str, str]
|
||||
@@ -382,7 +385,7 @@ class HandedDirectory:
|
||||
directory: str
|
||||
handles: frozenset[str]
|
||||
source_ref: str
|
||||
roms_folder: str | None = None
|
||||
roms_place: Place | None = None
|
||||
# The platform systems, by our ids, the record applies to. Empty when
|
||||
# the launcher hands the directory whatever the system.
|
||||
systems: frozenset[str] = frozenset()
|
||||
@@ -393,9 +396,7 @@ class HandedDirectory:
|
||||
"""The folder as a place, None when it lies outside both roots."""
|
||||
if self.folder is not None:
|
||||
return (BIOS_TREE, self.folder)
|
||||
if self.roms_folder is not None:
|
||||
return (ROMS_TREE, self.roms_folder)
|
||||
return None
|
||||
return self.roms_place
|
||||
|
||||
|
||||
# The placeholder a launcher record writes for the system it is launched
|
||||
@@ -491,7 +492,10 @@ def handed_directories(config: dict) -> list[HandedDirectory]:
|
||||
directory=directory,
|
||||
handles=handles,
|
||||
source_ref=str(record.get("source_ref", "")),
|
||||
roms_folder=None if folder is not None else folder_in_roms(part, config),
|
||||
roms_place=None if folder is not None else (
|
||||
_roms_place(config, folder_in_roms(part, config))
|
||||
or _emulators_place(folder_in_emulators(part, config))
|
||||
),
|
||||
systems=systems,
|
||||
holds_declared=bool(folder) and any(
|
||||
d.startswith(f"{folder.lower()}/") for d in declared
|
||||
@@ -500,14 +504,35 @@ def handed_directories(config: dict) -> list[HandedDirectory]:
|
||||
return found
|
||||
|
||||
|
||||
def _emulators_place(path: str | None) -> Place | None:
|
||||
"""A folder an emulator key names, as a place of the emulators tree."""
|
||||
return None if path is None else (EMULATORS_TREE, path)
|
||||
|
||||
|
||||
def _roms_place(config: dict, path: str | None) -> Place | None:
|
||||
"""A path below the roms root as a place: in the install tree when the
|
||||
platform installs above its BIOS folder (AmberELEC), else the roms tree."""
|
||||
if path is None:
|
||||
return None
|
||||
from common import ROMS_ROOT, outer_layout # noqa: PLC0415
|
||||
|
||||
layout = outer_layout(config, ROMS_ROOT) or {}
|
||||
if "install_prefix" in layout:
|
||||
prefix = layout["install_prefix"]
|
||||
return (INSTALL_TREE, sanitize_pack_path(f"{prefix}/{path}" if prefix else path))
|
||||
return (ROMS_TREE, path)
|
||||
|
||||
|
||||
def folder_in_roms(directory: str, config: dict) -> str | None:
|
||||
"""A directory relative to the platform's roms directory, None outside it.
|
||||
|
||||
Only a platform whose registry names the roms directory has one
|
||||
(``roms_directory.path``): ROCKNIX's /storage/roms, which holds its BIOS
|
||||
Only a platform whose rom folders file records its roms root has one
|
||||
(``roms_root.path``): ROCKNIX's /storage/roms, which holds its BIOS
|
||||
folder and the folders its launchers run programs from.
|
||||
"""
|
||||
roms = str((config.get("roms_directory") or {}).get("path") or "").rstrip("/")
|
||||
from common import ROMS_ROOT, outer_layout # noqa: PLC0415
|
||||
|
||||
roms = str((outer_layout(config, ROMS_ROOT) or {}).get("path") or "").rstrip("/")
|
||||
directory = directory.strip().rstrip("/")
|
||||
if not roms or not directory.startswith(roms + "/"):
|
||||
return None
|
||||
@@ -526,9 +551,11 @@ def folder_in_emulators(directory: str, config: dict) -> str | None:
|
||||
spelling = str((config.get("emulators_directory") or {}).get("launcher_spelling") or "")
|
||||
if "{key}" not in spelling:
|
||||
return None
|
||||
pattern = re.escape(spelling).replace(re.escape("{key}"), r"([\w.-]+)")
|
||||
# The key, then any folder below it: Citron's generator creates
|
||||
# <folder>/user, its portable data folder.
|
||||
pattern = re.escape(spelling).replace(re.escape("{key}"), r"([\w.-]+)") + r"((?:/[\w.-]+)*)"
|
||||
found = re.fullmatch(pattern, directory.strip())
|
||||
return found.group(1) if found else None
|
||||
return found.group(1) + found.group(2) if found else None
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -568,7 +595,7 @@ def executed_files(config: dict) -> list[ExecutedFile]:
|
||||
f"{directories[0]}/{name}" if directories[0] else name
|
||||
))
|
||||
elif roms is not None:
|
||||
place = (ROMS_TREE, sanitize_pack_path(f"{roms}/{name}" if roms else name))
|
||||
place = _roms_place(config, sanitize_pack_path(f"{roms}/{name}" if roms else name))
|
||||
elif emulator_folder is not None:
|
||||
place = (EMULATORS_TREE, sanitize_pack_path(f"{emulator_folder}/{name}"))
|
||||
else:
|
||||
@@ -618,8 +645,9 @@ def _record_places(
|
||||
up = _below(base, handle) if inner else None
|
||||
if up:
|
||||
found.append(("", (target[0], _join(target[1], up))))
|
||||
if not found and record.roms_folder is not None:
|
||||
found.append(("", (ROMS_TREE, _join(record.roms_folder, inner))))
|
||||
if not found and record.roms_place is not None:
|
||||
root, folder = record.roms_place
|
||||
found.append(("", (root, _join(folder, inner))))
|
||||
return found
|
||||
|
||||
|
||||
@@ -627,14 +655,19 @@ def _bind(
|
||||
records: list[HandedDirectory],
|
||||
links: list[HandedDirectory],
|
||||
wanted: set[str],
|
||||
named: Mapping[str, str],
|
||||
pools: Mapping[str, str],
|
||||
) -> dict[str, set[Place]]:
|
||||
"""The places each subfolder of the layout is given by ``records``.
|
||||
|
||||
A record whose handle is a declared directory, or lies below one, gives
|
||||
that subfolder. One whose handle lies above a declared directory gives
|
||||
the declared directory where it lands: RetroPie configures XRoar with
|
||||
--prefix=$md_inst, so ${prefix}/share/xroar/roms is $md_inst/share/xroar/roms.
|
||||
that subfolder, and a handle ``named`` gives the one folder it stands
|
||||
for. One whose handle lies above a declared directory, or is the
|
||||
environment variable the declared directory is spelled from
|
||||
($XDG_DATA_HOME/suyu), gives the declared directory where it lands:
|
||||
RetroPie configures XRoar with --prefix=$md_inst, so
|
||||
${prefix}/share/xroar/roms is $md_inst/share/xroar/roms. When it lands
|
||||
in no folder a pack fills, the layout is read outside the trees.
|
||||
``links`` are the records followed from a directory outside the trees.
|
||||
|
||||
A handle in ``pools`` names a list of directories the program searches
|
||||
@@ -653,16 +686,27 @@ def _bind(
|
||||
(record.holds_declared, place)
|
||||
)
|
||||
continue
|
||||
if handle in named:
|
||||
for rest, place in _record_places(record, "", links):
|
||||
found.setdefault(_join(named[handle], rest), set()).add(place)
|
||||
for directory in wanted:
|
||||
sub = _below(handle, directory)
|
||||
inner = ""
|
||||
if sub is None:
|
||||
up = _below(directory, handle)
|
||||
if not up:
|
||||
continue
|
||||
sub, inner = "", up
|
||||
for rest, place in _record_places(record, inner, links):
|
||||
found.setdefault(_join(sub, rest), set()).add(place)
|
||||
if sub is not None:
|
||||
for rest, place in _record_places(record, "", links):
|
||||
found.setdefault(_join(sub, rest), set()).add(place)
|
||||
continue
|
||||
if handle == directory:
|
||||
continue
|
||||
inner = next(
|
||||
(up for spelled in (f"${handle}", handle)
|
||||
if (up := _below(directory, spelled)) is not None),
|
||||
None,
|
||||
)
|
||||
if inner is None:
|
||||
continue
|
||||
places = _record_places(record, inner, links)
|
||||
for rest, place in places or [("", (OUTSIDE_TREE, ""))]:
|
||||
found.setdefault(rest, set()).add(place)
|
||||
for sub, entries in pooled.items():
|
||||
# The directory the platform's own list fills, else the first of the
|
||||
# BIOS tree, else the first a pack fills.
|
||||
@@ -714,17 +758,28 @@ def standalone_bindings(
|
||||
"""
|
||||
names = set(names)
|
||||
pools = {normalize_handle(k): str(v).strip("/") for k, v in (pools or {}).items()}
|
||||
wanted = {normalize_handle(d) for d in declared} - set(pools)
|
||||
if not wanted and not pools:
|
||||
# "<handle> = <subfolder>" names the code's handle for one folder of the
|
||||
# layout: Citron's CitronPath::KeysDir is its keys/ folder, and a patch
|
||||
# that rewrites the handle moves that folder alone.
|
||||
named: dict[str, str] = {}
|
||||
wanted: set[str] = set()
|
||||
for raw in declared:
|
||||
handle, sep, sub = str(raw).partition(" = ")
|
||||
if sep:
|
||||
named[normalize_handle(handle)] = sanitize_pack_path(sub.strip())
|
||||
else:
|
||||
wanted.add(normalize_handle(handle))
|
||||
wanted -= set(pools)
|
||||
if not wanted and not named and not pools:
|
||||
return {}
|
||||
systems = set(systems)
|
||||
records = [h for h in handed if h.emulator in names]
|
||||
generic = [h for h in records if not h.systems]
|
||||
specific = [h for h in records if h.systems & systems]
|
||||
|
||||
found = _bind(generic, generic, wanted, pools)
|
||||
found = _bind(generic, generic, wanted, named, pools)
|
||||
# A link is followed whatever system it was written for.
|
||||
found.update(_bind(specific, specific + generic, wanted, pools))
|
||||
found.update(_bind(specific, specific + generic, wanted, named, pools))
|
||||
if EXECUTABLE_DIRECTORY in wanted:
|
||||
paths = list(layout)
|
||||
for run in executed:
|
||||
|
||||
+13
-7
@@ -18,7 +18,7 @@ from common import resolve_local_file
|
||||
from common import resolve_platform_cores
|
||||
from common import core_system_dirs, platform_layouts, system_dir_path
|
||||
from common import standalone_set as platform_standalone_set
|
||||
from common import OUTER_ROOTS, sanitize_pack_path
|
||||
from common import OUTER_ROOTS, outer_layout, sanitize_pack_path
|
||||
from common import size_fits
|
||||
from validation import deliverable, read_from_save_dir, read_from_system_dir
|
||||
from packpaths import libretro_systems, save_destination, save_layout
|
||||
@@ -44,6 +44,10 @@ def extra_full_destination(fe: dict, prefix: str) -> str:
|
||||
"""
|
||||
if fe.get("root") == "save":
|
||||
return str(fe.get("pack_path") or "")
|
||||
if fe.get("unprefixed"):
|
||||
# A path of the install tree outside the BIOS folder (AmberELEC's
|
||||
# pico-8/ beside bios/): no platform prefix in front.
|
||||
return sanitize_pack_path(fe.get("destination", fe.get("name", "")))
|
||||
if fe.get("root") in OUTER_ROOTS:
|
||||
return outer_destination(
|
||||
fe["root"], sanitize_pack_path(fe.get("destination", fe.get("name", "")))
|
||||
@@ -573,7 +577,7 @@ def _agnostic_scan_extras(
|
||||
# The scan walks the BIOS tree: a file read below the save
|
||||
# directory is placed by the gap report's pass.
|
||||
if (read_from_save_dir(f, standalone) or f.get("unplaced")
|
||||
or f.get("root") in OUTER_ROOTS):
|
||||
or f.get("root") in OUTER_ROOTS or f.get("unprefixed")):
|
||||
continue
|
||||
# An agnostic BIOS mode says the BIOS filename is free, not that
|
||||
# every file the emulator loads is. A free filename still has a
|
||||
@@ -1024,12 +1028,10 @@ class ExtraPlacement:
|
||||
self.native_systems = native_slug_systems(config)
|
||||
self.flat = bool(config.get("firmware_folder_flat"))
|
||||
self.save = save_layout(config)
|
||||
# The roms directory and emulator folders the registry describes,
|
||||
# The roms root and emulator folders the platform's files describe,
|
||||
# for a file a launcher runs from them (ROCKNIX's roms/pico-8,
|
||||
# RetroBat's emulators/pico8).
|
||||
self.outer = {
|
||||
root for root in OUTER_ROOTS if config.get(f"{root}_directory")
|
||||
}
|
||||
self.outer = {root for root in OUTER_ROOTS if outer_layout(config, root)}
|
||||
self.config = config
|
||||
self.norm_map = (
|
||||
{_norm_system_id(sid): sid for sid in self.platform_systems}
|
||||
@@ -1050,6 +1052,8 @@ class ExtraPlacement:
|
||||
"""
|
||||
if entry.get("unplaced"):
|
||||
return None
|
||||
if entry.get("unprefixed"):
|
||||
return dest, dest
|
||||
if entry.get("root") in OUTER_ROOTS:
|
||||
root = entry["root"]
|
||||
return (dest, outer_destination(root, dest)) if root in self.outer else None
|
||||
@@ -1339,7 +1343,7 @@ def _collect_emulator_extras(
|
||||
# covered elsewhere belongs to another program's file.
|
||||
# Nor is one placed outside the BIOS tree by the layout.
|
||||
if (fname not in covered_names or f.get("unsourceable") or f.get("unplaced")
|
||||
or f.get("root") in OUTER_ROOTS):
|
||||
or f.get("root") in OUTER_ROOTS or f.get("unprefixed")):
|
||||
continue
|
||||
# Installed with the emulator or by the platform's package,
|
||||
# as the first pass already decided for the same entry.
|
||||
@@ -1586,6 +1590,8 @@ def _report_extra(u: dict, name: str, dest: str) -> dict:
|
||||
extra["system_dir"] = u["system_dir"]
|
||||
if u.get("layout_path"):
|
||||
extra["layout_path"] = u["layout_path"]
|
||||
if u.get("unprefixed"):
|
||||
extra["unprefixed"] = True
|
||||
# The archive layout the core opens ranks same-named copies by what
|
||||
# they hold. Without it the first copy indexed won.
|
||||
if u.get("contents"):
|
||||
|
||||
@@ -105,9 +105,10 @@ def _path_value(node: ast.AST | None, constants: dict[str, str]) -> str | None:
|
||||
and isinstance(node.func, ast.Name)
|
||||
and node.func.id == "Path"
|
||||
and len(node.args) == 1
|
||||
and isinstance(node.args[0], ast.Constant)
|
||||
):
|
||||
return str(node.args[0].value)
|
||||
if isinstance(node.args[0], ast.Constant):
|
||||
return str(node.args[0].value)
|
||||
return _path_value(node.args[0], constants)
|
||||
if isinstance(node, ast.BinOp) and isinstance(node.op, ast.Div):
|
||||
left = _path_value(node.left, constants)
|
||||
right = node.right.value if isinstance(node.right, ast.Constant) else None
|
||||
@@ -954,6 +955,44 @@ def config_directories(
|
||||
return launchers
|
||||
|
||||
|
||||
# Generators that start the emulator from a folder they enter with os.chdir.
|
||||
WORKING_DIRECTORY_GENERATORS = ("shadps4.shadps4Generator",)
|
||||
|
||||
|
||||
def working_directories(cg: Configgen) -> list[Launcher]:
|
||||
"""os.chdir(<folder>) in the generators above, before the command runs.
|
||||
|
||||
shadPS4 reads its user folder below the working directory first
|
||||
(std::filesystem::current_path() / "user"): Batocera enters
|
||||
/userdata/system/configs/shadps4.
|
||||
"""
|
||||
launchers = []
|
||||
for module in WORKING_DIRECTORY_GENERATORS:
|
||||
src = cg.generator(module)
|
||||
calls = _calls(src.tree, attr="chdir")
|
||||
if len(calls) != 1 or len(calls[0].args) != 1:
|
||||
src.fail("one os.chdir(folder) call")
|
||||
call = calls[0]
|
||||
argument = call.args[0]
|
||||
constants = dict(cg.paths)
|
||||
spans = [(call.lineno, call.end_lineno or call.lineno)]
|
||||
if isinstance(argument, ast.Name):
|
||||
scope = _innermost_function(src, call)
|
||||
assigned = src.assignment(argument.id, scope)
|
||||
spans.append((assigned.lineno, assigned.end_lineno or assigned.lineno))
|
||||
folder = _path_value(assigned.value, constants)
|
||||
else:
|
||||
folder = _path_value(argument, constants)
|
||||
if folder is None:
|
||||
src.fail("os.chdir names no folder")
|
||||
launchers.append(Launcher(
|
||||
emulator=cg.emulator(module), build="standalone", kind="passes_path", names=[],
|
||||
search_dir=folder, passes_to=f"working directory of {src.path.rsplit('/', 1)[-1]}",
|
||||
source_ref=src.ref(spans),
|
||||
))
|
||||
return launchers
|
||||
|
||||
|
||||
# libretro core options whose value names the BIOS file the core opens.
|
||||
FILE_OPTIONS = (("_o2em_options", "o2em_bios"), ("_neocd_options", "neocd_bios"))
|
||||
|
||||
@@ -1006,14 +1045,64 @@ def core_file_options(cg: Configgen) -> list[Launcher]:
|
||||
return launchers
|
||||
|
||||
|
||||
# Batocera's patches to an emulator's own path code. Each rewrites one of
|
||||
# the folders the emulator derives (yuzu's family generates every user
|
||||
# folder through Generate<Name>Path) to a fixed folder of /userdata.
|
||||
PATH_PATCHES = ("package/batocera/emulators/citron/002-adjust-paths.patch",)
|
||||
_PATH_REMOVED = re.compile(r"^-\s*Generate\w+Path\((\w+Path::\w+),\s*(.+?)\);\s*$")
|
||||
_PATH_ADDED = re.compile(r'^\+\s*Generate\w+Path\((\w+Path::\w+),\s*"(/userdata/bios[^"]*)"\);\s*$')
|
||||
|
||||
|
||||
def patched_paths(read: Callable[[str], str], patches: tuple[str, ...] = PATH_PATCHES) -> list[Launcher]:
|
||||
"""The emulator folders a path patch points at the BIOS tree.
|
||||
|
||||
A patch line replacing `GenerateCitronPath(CitronPath::KeysDir,
|
||||
citron_path / KEYS_DIR)` with a literal /userdata/bios folder hands
|
||||
that folder to the emulator under the handle the code names it by.
|
||||
The emulator is the package the patch belongs to.
|
||||
"""
|
||||
launchers: list[Launcher] = []
|
||||
for path in patches:
|
||||
lines = read(path).splitlines()
|
||||
target = ""
|
||||
removed: dict[str, tuple[int, str]] = {}
|
||||
found = 0
|
||||
for number, line in enumerate(lines, 1):
|
||||
if line.startswith("+++ b/"):
|
||||
target = line[len("+++ b/"):]
|
||||
continue
|
||||
if (old := _PATH_REMOVED.match(line)):
|
||||
removed[old.group(1)] = (number, old.group(2))
|
||||
continue
|
||||
if not (new := _PATH_ADDED.match(line)):
|
||||
continue
|
||||
handle, folder = new.groups()
|
||||
if handle not in removed or not target:
|
||||
raise LauncherShapeError(f"{path}:{number}: {handle} added with no line it replaces")
|
||||
first, original = removed[handle]
|
||||
found += 1
|
||||
launchers.append(Launcher(
|
||||
emulator=path.split("/")[-2], build="standalone", kind="passes_path", names=[],
|
||||
search_dir=folder,
|
||||
passes_to=f"{handle} in {target} returns it, in place of {original}",
|
||||
fails_when_missing=False,
|
||||
source_ref=f"{path}:{first}-{number}",
|
||||
))
|
||||
if not found:
|
||||
raise LauncherShapeError(f"{path}: no path rewritten to /userdata/bios")
|
||||
return launchers
|
||||
|
||||
|
||||
EXTRACTORS: tuple[Callable[[Configgen], list[Launcher]], ...] = (
|
||||
duckstation, duckstation_legacy, hatari, xemu, melonds, mupen64plus,
|
||||
x16emu, gsplus, lexaloffle, environment_directories, config_directories,
|
||||
core_file_options,
|
||||
core_file_options, working_directories,
|
||||
)
|
||||
|
||||
|
||||
def extract_launchers(read: Callable[[str], str]) -> list[dict[str, Any]]:
|
||||
"""Every launcher record, read through `read(repo-relative path)`."""
|
||||
cg = Configgen(read)
|
||||
return [launcher.entry() for extractor in EXTRACTORS for launcher in extractor(cg)]
|
||||
launchers = [launcher for extractor in EXTRACTORS for launcher in extractor(cg)]
|
||||
launchers += patched_paths(read)
|
||||
return [launcher.entry() for launcher in launchers]
|
||||
@@ -30,6 +30,7 @@ import yaml
|
||||
|
||||
try:
|
||||
from .batocera_launchers import (
|
||||
PATH_PATCHES,
|
||||
Configgen,
|
||||
config_directories,
|
||||
_path_value,
|
||||
@@ -41,11 +42,14 @@ try:
|
||||
hatari,
|
||||
melonds,
|
||||
mupen64plus,
|
||||
patched_paths,
|
||||
x16emu,
|
||||
working_directories,
|
||||
xemu,
|
||||
)
|
||||
from .configgen_launchers import (
|
||||
Launcher,
|
||||
_calls,
|
||||
LauncherShapeError,
|
||||
Source,
|
||||
_assigned_name,
|
||||
@@ -53,6 +57,7 @@ try:
|
||||
from .shell_launchers import LauncherPatternMissing, Script, source_ref
|
||||
except ImportError:
|
||||
from batocera_launchers import ( # type: ignore[no-redef]
|
||||
PATH_PATCHES,
|
||||
Configgen,
|
||||
config_directories,
|
||||
_path_value,
|
||||
@@ -64,11 +69,14 @@ except ImportError:
|
||||
hatari,
|
||||
melonds,
|
||||
mupen64plus,
|
||||
patched_paths,
|
||||
x16emu,
|
||||
working_directories,
|
||||
xemu,
|
||||
)
|
||||
from configgen_launchers import ( # type: ignore[no-redef]
|
||||
Launcher,
|
||||
_calls,
|
||||
LauncherShapeError,
|
||||
Source,
|
||||
_assigned_name,
|
||||
@@ -85,7 +93,6 @@ LIBRETRO_OPTIONS = f"{GENERATORS}/libretro/libretroOptions.py"
|
||||
PICO8_INSTALLER = "board/fsoverlay/usr/bin/knulli-install-pico8"
|
||||
ES_FEATURES = "package/emulationstation/knulli-es-system/es_features.yml"
|
||||
|
||||
# Batocera's extractors that read KNULLI's generators unchanged.
|
||||
# The generators of Batocera's config_directories that KNULLI keeps in the
|
||||
# same shape: openMSX's filepool lines and amiberry's rom_path.
|
||||
CONFIG_DIRECTORY_GENERATORS = ("openmsx.openmsxGenerator", "amiberry.amiberryGenerator")
|
||||
@@ -95,9 +102,10 @@ def knulli_config_directories(cg: Configgen) -> list[Launcher]:
|
||||
return config_directories(cg, CONFIG_DIRECTORY_GENERATORS)
|
||||
|
||||
|
||||
# Batocera's extractors that read KNULLI's generators unchanged.
|
||||
SHARED = (
|
||||
duckstation, duckstation_legacy, hatari, xemu, melonds, mupen64plus, x16emu,
|
||||
environment_directories, knulli_config_directories,
|
||||
environment_directories, working_directories, knulli_config_directories,
|
||||
)
|
||||
|
||||
|
||||
@@ -1063,14 +1071,65 @@ EXTRACTORS: tuple[Callable[[Configgen], list[Launcher]], ...] = (
|
||||
)
|
||||
|
||||
|
||||
def extract_launchers(read: Callable[[str], str]) -> list[dict[str, Any]]:
|
||||
"""Every launcher record, read through `read(repo-relative path)`."""
|
||||
# Generators whose command sets the emulator's XDG data folder, the parent
|
||||
# of every user folder a yuzu-family emulator derives.
|
||||
DATA_HOME_GENERATORS = ("suyu.suyuGenerator",)
|
||||
|
||||
|
||||
def data_homes(cg: Configgen) -> list[Launcher]:
|
||||
"""Command(..., env={"XDG_DATA_HOME": <path>}) in the generators above.
|
||||
|
||||
The path need not lie in /userdata/bios: KNULLI's suyu keeps its data
|
||||
in /userdata/saves/switch, which tells where its keys are not.
|
||||
"""
|
||||
launchers = []
|
||||
for module in DATA_HOME_GENERATORS:
|
||||
src = cg.generator(module)
|
||||
found = [
|
||||
(_path_value(item, cg.paths), key)
|
||||
for call in _calls(src.tree, attr="Command")
|
||||
for keyword in call.keywords
|
||||
if keyword.arg == "env" and isinstance(keyword.value, ast.Dict)
|
||||
for key, item in zip(keyword.value.keys, keyword.value.values)
|
||||
if isinstance(key, ast.Constant) and key.value == "XDG_DATA_HOME"
|
||||
]
|
||||
if not found or found[0][0] is None:
|
||||
src.fail("the command environment sets no XDG_DATA_HOME path")
|
||||
value, node = found[0]
|
||||
launchers.append(Launcher(
|
||||
emulator=cg.emulator(module), build="standalone", kind="passes_path", names=[],
|
||||
search_dir=value, passes_to="environment XDG_DATA_HOME",
|
||||
source_ref=src.ref([(node.lineno, node.end_lineno)]),
|
||||
))
|
||||
return launchers
|
||||
|
||||
|
||||
# KNULLI builds Batocera's emulator packages from this submodule, at the
|
||||
# batocera.linux commit it pins: Citron's path patch is there.
|
||||
BATOCERA_SUBMODULE = "batocera"
|
||||
|
||||
|
||||
def extract_launchers(
|
||||
read: Callable[[str], str], batocera: Callable[[str], str] | None = None
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Every launcher record, read through `read(repo-relative path)`.
|
||||
|
||||
`batocera` reads the batocera submodule at its pinned commit. The
|
||||
records it gives name the file by its path in KNULLI's repository.
|
||||
"""
|
||||
cg = configgen(read)
|
||||
launchers = [launcher for extractor in EXTRACTORS for launcher in extractor(cg)]
|
||||
launchers += pico8_installer(read, cg.bios)
|
||||
launchers += boot_disks(cg, read)
|
||||
for spec in GENERIC_SITES:
|
||||
launchers += bios_sites(cg, spec)
|
||||
launchers += data_homes(cg)
|
||||
if batocera is not None:
|
||||
prefix = f"{BATOCERA_SUBMODULE}/"
|
||||
launchers += patched_paths(
|
||||
lambda path: batocera(path.removeprefix(prefix)),
|
||||
tuple(prefix + patch for patch in PATH_PATCHES),
|
||||
)
|
||||
return [launcher.entry() for launcher in launchers]
|
||||
|
||||
|
||||
|
||||
@@ -45,12 +45,15 @@ from .batocera_scraper import (
|
||||
requirements_from_systems,
|
||||
)
|
||||
from .es_emulators import attach_system_cores
|
||||
from .knulli_launchers import extract_launchers
|
||||
from .knulli_launchers import BATOCERA_SUBMODULE, extract_launchers
|
||||
|
||||
PLATFORM_NAME = "knulli"
|
||||
|
||||
REPO = "knulli-cfw/knulli-linux"
|
||||
_RAW = "https://raw.githubusercontent.com/knulli-cfw/knulli-linux/{ref}/"
|
||||
# The batocera.linux revision KNULLI's submodule pins, and its files.
|
||||
_SUBMODULE = "https://api.github.com/repos/knulli-cfw/knulli-linux/contents/{path}?ref={ref}"
|
||||
_BATOCERA_RAW = "https://raw.githubusercontent.com/batocera-linux/batocera.linux/{ref}/"
|
||||
SOURCE_TEMPLATE = _RAW + "package/system/knulli-scripts/scripts/knulli-systems"
|
||||
CONFIGGEN_DEFAULTS_TEMPLATE = (
|
||||
_RAW + "package/system/knulli-configgen/configs/configgen-defaults.yml"
|
||||
@@ -83,6 +86,23 @@ class Scraper(BaseScraper):
|
||||
except urllib.error.URLError as e:
|
||||
raise ConnectionError(f"Failed to fetch {url}: {e}") from e
|
||||
|
||||
def submodule_revision(self) -> str:
|
||||
"""The batocera.linux commit KNULLI's batocera submodule pins at the tag."""
|
||||
import json # noqa: PLC0415
|
||||
|
||||
from .base_scraper import github_headers # noqa: PLC0415
|
||||
|
||||
url = _SUBMODULE.format(path=BATOCERA_SUBMODULE, ref=self.tag)
|
||||
req = urllib.request.Request(url, headers=github_headers())
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=30) as resp:
|
||||
found = json.loads(resp.read().decode("utf-8"))
|
||||
except urllib.error.URLError as e:
|
||||
raise ConnectionError(f"Failed to fetch {url}: {e}") from e
|
||||
if not isinstance(found, dict) or found.get("type") != "submodule" or not found.get("sha"):
|
||||
raise RuntimeError(f"{url}: {BATOCERA_SUBMODULE} is not a submodule")
|
||||
return str(found["sha"])
|
||||
|
||||
def validate_format(self, raw_data: str) -> bool:
|
||||
has_dict = re.search(r"^systems\s*=\s*\{", raw_data, re.MULTILINE) is not None
|
||||
return has_dict and "def checkBios" in raw_data and '"biosFiles"' in raw_data
|
||||
@@ -126,8 +146,10 @@ class Scraper(BaseScraper):
|
||||
# configgen hands a libretro core /userdata/saves/<system>, as
|
||||
# Batocera's does: the systems each core runs for are its save folders.
|
||||
result["libretro_systems"] = es_systems_libretro_systems(es_systems, dropped)
|
||||
revision = self.submodule_revision()
|
||||
result["launchers"] = extract_launchers(
|
||||
lambda path: self._fetch_text(_RAW.format(ref=self.tag) + path)
|
||||
lambda path: self._fetch_text(_RAW.format(ref=self.tag) + path),
|
||||
lambda path: self._fetch_text(_BATOCERA_RAW.format(ref=revision) + path),
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ SOURCE_FILES = (
|
||||
f"{GENERATORS}/Bizhawk.CoreOptions.cs",
|
||||
f"{GENERATORS}/Bizhawk.Generator.cs",
|
||||
f"{GENERATORS}/Blastem.Generator.cs",
|
||||
f"{GENERATORS}/Citron.Generator.cs",
|
||||
f"{GENERATORS}/Demul.Generator.cs",
|
||||
f"{GENERATORS}/Desmume.Generator.cs",
|
||||
f"{GENERATORS}/Dolphin.Generator.cs",
|
||||
@@ -58,6 +59,7 @@ SOURCE_FILES = (
|
||||
f"{GENERATORS}/Rpcs3.Generator.cs",
|
||||
f"{GENERATORS}/SSF.Generator.cs",
|
||||
f"{GENERATORS}/ScummVm.Generator.cs",
|
||||
f"{GENERATORS}/ShadPS4.Generator.cs",
|
||||
f"{GENERATORS}/Snes9x.Generator.cs",
|
||||
f"{GENERATORS}/Tsugaru.Generator.cs",
|
||||
f"{GENERATORS}/Uae.Generator.cs",
|
||||
@@ -3038,6 +3040,48 @@ def _per_system(src: Source, record: Record) -> list[Record]:
|
||||
return out
|
||||
|
||||
|
||||
# Generators that create a portable user folder beside the emulator's binary,
|
||||
# and the emulator each one starts: the folder AppConfig.GetFullPath gives.
|
||||
PORTABLE_USERS = (
|
||||
("Citron.Generator.cs", "citron", "citron.exe"),
|
||||
("ShadPS4.Generator.cs", "shadps4", "shadPS4.exe"),
|
||||
)
|
||||
_EMULATOR_FOLDER = (
|
||||
r"GetEmulatorPathAndExe\(emulator, out string path, out string exe, \"[^\"]+\"\)"
|
||||
r"|string path = AppConfig\.GetFullPath\(emulator\);"
|
||||
)
|
||||
|
||||
|
||||
def portable_users(sources: dict[str, Source]) -> list[Record]:
|
||||
"""The portable user folder a generator creates beside the binary.
|
||||
|
||||
The emulator folder comes from AppConfig.GetFullPath(emulator), and the
|
||||
generator creates <folder>/user before launching: the emulator then
|
||||
keeps its data there (keys/, sys_modules/) in place of %APPDATA%.
|
||||
"""
|
||||
records = []
|
||||
for name, emulator, binary in PORTABLE_USERS:
|
||||
src = sources[f"{GENERATORS}/{name}"]
|
||||
found = src.find(_EMULATOR_FOLDER, f"{emulator} folder")
|
||||
user = src.find(r'string userFolder = Path\.Combine\(path, "(\w+)"\);', "user folder")
|
||||
create = src.find(
|
||||
r"Directory\.CreateDirectory\(userFolder\)", "user folder creation", user.end()
|
||||
)
|
||||
records.append(_record(
|
||||
emulator,
|
||||
"standalone",
|
||||
"passes_path",
|
||||
[],
|
||||
source_ref((src.path, [
|
||||
src.lines(found.start(), found.end()), src.lines(user.start(), create.end()),
|
||||
])),
|
||||
search_dir=f'<AppConfig.GetFullPath("{emulator}")>/{user.group(1)}',
|
||||
passes_to=f"PORTABLE_DIR, the user folder beside {binary}",
|
||||
fails_when_missing=False,
|
||||
))
|
||||
return records
|
||||
|
||||
|
||||
def pico8(sources: dict[str, Source]) -> list[Record]:
|
||||
"""The PICO-8 binary the generator runs, from an emulator folder.
|
||||
|
||||
@@ -3345,6 +3389,7 @@ EXTRACTORS: tuple[Callable[[dict[str, Source]], list[Record]], ...] = (
|
||||
pcsx2,
|
||||
pcsx2_libretro,
|
||||
pico8,
|
||||
portable_users,
|
||||
psx_cascades,
|
||||
psxmame,
|
||||
raine,
|
||||
|
||||
@@ -794,6 +794,8 @@ def find_undeclared_files(
|
||||
entry["members"] = members
|
||||
if f.get("layout_path"):
|
||||
entry["layout_path"] = f["layout_path"]
|
||||
if f.get("unprefixed"):
|
||||
entry["unprefixed"] = True
|
||||
if f.get("unplaced"):
|
||||
entry["unplaced"] = f["unplaced"]
|
||||
elif f.get("root") in OUTER_ROOTS:
|
||||
|
||||
Reference in new issue
Block a user