feat: place standalone files through links

standalone_bindings maps each subfolder of a standalone layout to the
folder of the BIOS tree a platform's links and passed directories give
it, followed through a working directory. platform_layouts applies it,
so the pack, the manifest, verify and slots read one destination.

uae4all paths are now what the emulator reads, kickstarts/<name> below
its working directory, and RetroPie still receives them in amiga/.
This commit is contained in:
Abdessamad Derraz committed 2026-11-09 17:28:00 +01:00
1 parent a2bf1c6f8e
commit 6a9700489d
5 files changed
+308 -78

No files matched your search

+39 -27
View File
@@ -2729,33 +2729,48 @@ def _handed(standalone_cores: Iterable[str]) -> list:
return found
def standalone_destination(entry: dict, root: str | None) -> str:
"""Where a standalone build reads an entry, relative to the BIOS root.
def standalone_layout_path(entry: dict, profile: dict) -> str | None:
"""The path of an entry relative to the directories its standalone build declares.
``standalone_path`` is relative to the directories the build resolves
it against (``standalone_directories``). A platform that hands one of
them a folder of its BIOS tree puts the file under that folder:
RetroPie and ROCKNIX give Flycast bios/dc, EmuDeck bios/flycast/bios.
An entry with no ``standalone_path`` keeps ``path``, the layout both
builds share.
``standalone_path`` when the entry has one. A profile with no libretro
build has one layout, so its ``path`` is that layout: UAE4All2 reads
kickstarts/kick13.rom below its working directory.
"""
own = entry.get("standalone_path")
if own and root:
return f"{root}/{own}"
return own or entry.get("path") or entry.get("name", "")
if own:
return own
if "libretro" in str(profile.get("type", "")):
return None
return entry.get("path") or None
def standalone_root_for(
def standalone_destination(entry: dict, profile: dict, bindings: dict[str, str]) -> str | None:
"""Where a platform puts a standalone entry, relative to the BIOS root.
``bindings`` are the folders the platform's launchers give the layout
(launchers.standalone_bindings): RetroPie and ROCKNIX give Flycast bios/dc,
EmuDeck bios/flycast/bios, RetroPie gives UAE4All2's kickstarts/ bios/amiga.
None when no binding covers the entry: it keeps the profile's layout.
"""
layout = standalone_layout_path(entry, profile)
if layout is None or not bindings:
return None
from launchers import bound_path # noqa: PLC0415
return bound_path(layout, bindings)
def standalone_bindings_for(
emu_name: str, profile: dict, standalone_cores: Iterable[str]
) -> str | None:
"""The folder a platform gives this emulator's standalone layout, or None."""
) -> dict[str, str]:
"""The folders a platform gives this emulator's standalone layout, by subfolder."""
declared = profile.get("standalone_directories") or []
if not declared:
return None
from launchers import standalone_root # noqa: PLC0415
return {}
from launchers import standalone_bindings # noqa: PLC0415
names = {emu_name, *(str(c) for c in profile.get("cores") or [])}
return standalone_root(names, declared, _handed(standalone_cores))
return standalone_bindings(names, declared, _handed(standalone_cores))
def platform_layouts(
@@ -2774,19 +2789,16 @@ def platform_layouts(
return [(profile, False)]
return [(system_dir_view(profile, d), False) for d in directories]
standalone = profile
root = standalone_root_for(emu_name, profile, standalone_cores)
if root:
bindings = standalone_bindings_for(emu_name, profile, standalone_cores)
if bindings:
# The standalone view carries the platform's destination, so every
# reader of standalone_path (builder, manifest, verify, slots) places
# the file in the folder the platform hands the emulator.
standalone = {
**profile,
"files": [
{**f, "standalone_path": standalone_destination(f, root)}
if isinstance(f, dict) and f.get("standalone_path") else f
for f in profile.get("files") or []
],
}
files = []
for f in profile.get("files") or []:
placed = standalone_destination(f, profile, bindings) if isinstance(f, dict) else None
files.append({**f, "standalone_path": placed} if placed else f)
standalone = {**profile, "files": files}
dual = {c.removeprefix(DUAL_MODE_PREFIX) for c in standalone_cores
if c.startswith(DUAL_MODE_PREFIX)}
if "libretro" in str(profile.get("type", "")) and dual & {
+76 -29
View File
@@ -211,6 +211,12 @@ BIOS_ROOT_VARIABLES = ("$biosdir", "$home/RetroPie/BIOS", "${biosPath}", "$bios_
# The kinds that hand an emulator a whole directory.
HANDED_KINDS = ("links", "passes_path")
# How a launcher record says the platform starts the emulator in a directory
# (retropie_launchers._working_directory), and the handle a profile gives
# that directory in standalone_directories: the call its code reads it with.
WORKING_DIRECTORY_PASSED = "working directory of "
WORKING_DIRECTORY = "getcwd"
_HOME = re.compile(r"^(?:\$\{HOME\}|\$HOME|\$home|~)(?=/|$)")
# Flatpak sets XDG_DATA_HOME to ~/.var/app/<id>/data inside the sandbox.
_FLATPAK_DATA = re.compile(r"^~/\.var/app/[^/]+/data(?=/|$)")
@@ -278,11 +284,17 @@ def handed_directories(config: dict) -> list[HandedDirectory]:
if not raw or re.search(r"[\s,:;]", raw):
continue
directory = normalize_handle(raw)
handles = frozenset(
handle
for token in str(record.get("passes_to") or "").split()
if (handle := normalize_handle(token)) and handle != directory
)
passes_to = str(record.get("passes_to") or "")
if passes_to.startswith(WORKING_DIRECTORY_PASSED):
# The program runs from the directory: what its code reads
# through getcwd(), or relative to it, is below it.
handles = frozenset({WORKING_DIRECTORY})
else:
handles = frozenset(
handle
for token in passes_to.split()
if (handle := normalize_handle(token)) and handle != directory
)
for emulator in (e.strip() for e in str(record.get("emulator", "")).split(",")):
found.append(HandedDirectory(
emulator=emulator,
@@ -294,40 +306,75 @@ def handed_directories(config: dict) -> list[HandedDirectory]:
return found
def standalone_root(
def standalone_bindings(
names: Iterable[str], declared: Iterable[str], handed: Iterable[HandedDirectory]
) -> str | None:
"""The folder of the BIOS tree a platform gives a standalone build's layout.
) -> dict[str, str]:
"""The folders of the BIOS tree a platform gives a standalone build's layout.
``declared`` are the directories the build resolves ``standalone_path``
against, as its profile names them (``standalone_directories``). A
record handing a folder of the BIOS tree under one of them gives it
directly: RetroPie points Flycast's ~/.local/share/flycast at bios/dc. A
record handing a directory outside the tree under one of them is
followed through a link to the tree: ROCKNIX's patched Flycast uses
/storage/roms/dreamcast/data, which its start script links to bios/dc.
``declared`` are the directories the build resolves its paths against,
as its profile names them (``standalone_directories``). The result maps
a subfolder of that layout ("" for the whole of it) to the folder of the
BIOS tree the emulator reads it from.
None when nothing gives a folder, or when two records give two: the
layout is then the profile's, relative to the BIOS root.
A record handing a folder of the tree under a declared directory gives
it directly: RetroPie points Flycast's ~/.local/share/flycast at bios/dc.
A record handing a directory outside the tree is followed through the
links that put a folder of the tree at it or below it: ROCKNIX's patched
Flycast uses /storage/roms/dreamcast/data, which its start script links
to bios/dc, and RetroPie starts UAE4All2 in $md_inst, whose kickstarts
folder it links to bios/amiga.
A subfolder two records give two folders is left out: its files keep
the profile's layout, relative to the BIOS root.
"""
names = set(names)
wanted = {normalize_handle(d) for d in declared}
if not wanted:
return None
return {}
records = [h for h in handed if h.emulator in names]
folders: set[str] = set()
def below(handle: str, directory: str) -> str | None:
if handle == directory:
return ""
if handle.startswith(directory + "/"):
return handle[len(directory) + 1:]
return None
found: dict[str, set[str]] = {}
for record in records:
if not record.handles & wanted:
subs = {
sub for handle in record.handles for directory in wanted
if (sub := below(handle, directory)) is not None
}
for sub in subs:
if record.folder is not None:
found.setdefault(sub, set()).add(record.folder)
continue
for link in records:
if link.folder is None:
continue
for handle in link.handles:
rest = below(handle, record.directory)
if rest is not None:
key = "/".join(p for p in (sub, rest) if p)
found.setdefault(key, set()).add(link.folder)
return {sub: next(iter(folders)) for sub, folders in found.items() if len(folders) == 1}
def bound_path(path: str, bindings: dict[str, str]) -> str | None:
"""Where the BIOS tree holds a layout path, None when no binding covers it.
The longest subfolder that contains the path wins: a link of
kickstarts/ places kickstarts/kick13.rom even when the whole layout is
bound elsewhere.
"""
for sub in sorted(bindings, key=len, reverse=True):
if sub and not path.startswith(sub + "/"):
continue
if record.folder is not None:
folders.add(record.folder)
continue
folders.update(
link.folder
for link in records
if link.folder is not None and record.directory in link.handles
)
return next(iter(folders)) if len(folders) == 1 else None
rest = path[len(sub) + 1:] if sub else path
folder = bindings[sub]
return f"{folder}/{rest}" if folder else rest
return None
def held_record(report: dict, db: dict) -> dict | None: