refactor: let the extractor name bios programs

boards_build matched passes_to exec and a literal /userdata/bios on the
serialized records to know which emulators the user supplies. The
Batocera and KNULLI extractors now report them, read against the BIOS
root configgen's batoceraPaths gives.
This commit is contained in:
Abdessamad Derraz committed 2026-11-23 21:02:27 +01:00
1 parent 0757698063
commit 888799e24c
5 files changed
+72 -27

No files matched your search

+32 -3
View File
@@ -17,9 +17,10 @@ from __future__ import annotations
import ast
import re
from collections.abc import Callable, Iterable
from dataclasses import dataclass
from typing import Any
from model.launcherrecords import join_emulators
from model.launcherrecords import emulator_names, join_emulators
from .configgen_launchers import (
Launcher,
LauncherShapeError,
@@ -1020,9 +1021,37 @@ EXTRACTORS: tuple[Callable[[Configgen], list[Launcher]], ...] = (
)
def extract_launchers(read: Callable[[str], str]) -> list[dict[str, Any]]:
@dataclass(frozen=True)
class Extraction:
"""A configgen's launcher records, and the emulators it runs from the BIOS folder."""
records: list[dict[str, Any]]
# The emulators whose program the launcher runs from the BIOS folder
# (lexaloffle, /userdata/bios/pico-8/pico8): the user supplies it, no
# package builds it.
bios_programs: frozenset[str]
def extraction(launchers: list[Launcher], bios: str) -> Extraction:
"""The records of `launchers`, and those that run a program from `bios`."""
root = bios.rstrip("/")
return Extraction(
records=[launcher.entry() for launcher in launchers],
bios_programs=frozenset(
name
for launcher in launchers
if launcher.passes_to == "exec"
and launcher.search_dir is not None
and (launcher.search_dir.rstrip("/") == root
or launcher.search_dir.startswith(f"{root}/"))
for name in emulator_names(launcher.emulator)
),
)
def extract_launchers(read: Callable[[str], str]) -> Extraction:
"""Every launcher record, read through `read(repo-relative path)`."""
cg = Configgen(read)
launchers = [launcher for extractor in EXTRACTORS for launcher in extractor(cg)]
launchers += patched_paths(read)
return [launcher.entry() for launcher in launchers]
return extraction(launchers, cg.bios)
+10 -14
View File
@@ -11,7 +11,7 @@ from __future__ import annotations
import ast
import re
import sys
from collections.abc import Callable
from collections.abc import Callable, Iterable
from model.database import load_database
@@ -412,7 +412,9 @@ def configgen_cores(
return sorted(cores - dropped), sorted(standalone - dropped), sorted(dual)
def boards_build(selection: BuildSelection, launchers: list[dict]) -> Callable[[str], bool]:
def boards_build(
selection: BuildSelection, bios_programs: Iterable[str]
) -> Callable[[str], bool]:
"""Whether some board of a build runs an emulator.
es_systems.yml ties each name to the packages that build it
@@ -422,16 +424,10 @@ def boards_build(selection: BuildSelection, launchers: list[dict]) -> Callable[[
configgen-defaults.yml gives is built when a board selects the package
of that name: the symbol its Config.in defines, else the one Buildroot
derives from the folder (BR2_PACKAGE_<NAME>, package/pkg-generic.mk). A
program the launcher runs from the BIOS folder (lexaloffle,
/userdata/bios/pico-8/pico8) needs no package.
program the launcher runs from the BIOS folder (`bios_programs`, as
extract_launchers reports them) needs no package.
"""
supplied = {
name
for record in launchers
if record.get("passes_to") == "exec"
and str(record.get("search_dir") or "").startswith("/userdata/bios")
for name in record_emulators(record)
}
supplied = frozenset(bios_programs)
def built(name: str) -> bool:
if name in selection.emulators or name in supplied:
@@ -537,12 +533,12 @@ class Scraper(CheckBiosScraper):
"""Generate a platform YAML config dict from scraped data."""
systems = self.platform_systems()
launchers = extract_launchers(
extracted = extract_launchers(
lambda path: fetch_text(f"{_RAW_BASE}/{self.tag}/{path}")
)
selection = BoardTargets().build_selection(self.tag)
built = boards_build(selection, launchers)
launchers = records_run(launchers, built)
built = boards_build(selection, extracted.bios_programs)
launchers = records_run(extracted.records, built)
cores, standalone, dual = self._fetch_cores(built)
installable = installable_cores(selection, cores, standalone, dual)
libretro_systems = es_systems_libretro_systems(
+4 -3
View File
@@ -24,13 +24,14 @@ import posixpath
import re
from collections.abc import Callable
from dataclasses import dataclass
from typing import Any
import yaml
from model.launcherrecords import emulator_names, join_emulators
from .batocera_launchers import (
PATH_PATCHES,
Extraction,
extraction,
config_directories,
_render,
_system_branches,
@@ -562,7 +563,7 @@ BATOCERA_SUBMODULE = "batocera"
def extract_launchers(
read: Callable[[str], str], batocera: Callable[[str], str] | None = None
) -> list[dict[str, Any]]:
) -> Extraction:
"""Every launcher record, read through `read(repo-relative path)`.
`batocera` reads the batocera submodule at its pinned commit. The
@@ -580,7 +581,7 @@ def extract_launchers(
lambda path: batocera(path.removeprefix(prefix)),
tuple(prefix + patch for patch in PATH_PATCHES),
)
return [launcher.entry() for launcher in launchers]
return extraction(launchers, cg.bios)
__all__ = [
+3 -3
View File
@@ -95,7 +95,7 @@ class Scraper(CheckBiosScraper):
dropped = not_cores("batocera") | not_cores(PLATFORM_NAME)
# The batocera.linux commit KNULLI's batocera submodule pins at the tag.
revision = submodule_commit(REPO, BATOCERA_SUBMODULE, self.tag)
launchers = extract_launchers(
extracted = extract_launchers(
lambda path: fetch_text(_RAW.format(ref=self.tag) + path),
lambda path: fetch_text(_BATOCERA_RAW.format(ref=revision) + path),
)
@@ -103,8 +103,8 @@ class Scraper(CheckBiosScraper):
# scraper from the Kconfig of KNULLI's tree and its batocera and
# buildroot submodules (boards_build).
selection = BoardTargets().build_selection(self.tag)
built = boards_build(selection, launchers)
launchers = records_run(launchers, built)
built = boards_build(selection, extracted.bios_programs)
launchers = records_run(extracted.records, built)
cores, standalone, dual = configgen_cores(defaults, es_systems, dropped, built)
installable = installable_cores(selection, cores, standalone, dual)
# Each system's own list (psx, es_systems.yml:640-653: libretro
+23 -4
View File
@@ -254,8 +254,7 @@ class OnlyWhatABoardBuildsIsRun(unittest.TestCase):
emulator: mpv
core: mpv
""")
LAUNCHERS = [{"emulator": "lexaloffle", "kind": "fixed_name", "passes_to": "exec",
"search_dir": "/userdata/bios"}]
BIOS_PROGRAMS = frozenset({"lexaloffle"})
def selection(self, symbols: set[str]):
from scraper.targets.batocera_targets_scraper import BuildSelection
@@ -275,7 +274,7 @@ class OnlyWhatABoardBuildsIsRun(unittest.TestCase):
# not count for it.
built = bs.boards_build(
self.selection({"BR2_PACKAGE_KODI", "BR2_PACKAGE_MPV", "BR2_PACKAGE_CITRON_X"}),
self.LAUNCHERS,
self.BIOS_PROGRAMS,
)
cores, standalone, _dual = bs.configgen_cores(self.DEFAULTS, self.ES, set(), built)
self.assertEqual(sorted(cores), ["kodi", "mgba", "mpv", "vox_official"])
@@ -297,10 +296,30 @@ class OnlyWhatABoardBuildsIsRun(unittest.TestCase):
# Without a selection, every name counts, as before.
self.assertIn("suyu", bs.configgen_cores(self.DEFAULTS, self.ES, set())[0])
def test_the_extractor_reports_programs_run_from_its_own_bios_root(self):
from scraper.batocera_launchers import Launcher, extraction
# A fork whose batoceraPaths puts the BIOS folder elsewhere: the
# report follows the root its code gives, not Batocera's.
launchers = [
Launcher(emulator="lexaloffle", build="standalone", kind="fixed_name",
names=["pico-8/pico8"], source_ref="g.py:1",
search_dir="/storage/bios", passes_to="exec"),
Launcher(emulator="flycast", build="standalone", kind="passes_path",
names=[], source_ref="g.py:2", search_dir="/storage/bios/dc",
passes_to="environment FLYCAST_BIOS_PATH"),
Launcher(emulator="other", build="standalone", kind="fixed_name",
names=["x"], source_ref="g.py:3", search_dir="/userdata/bios",
passes_to="exec"),
]
found = extraction(launchers, "/storage/bios")
self.assertEqual(found.bios_programs, frozenset({"lexaloffle"}))
self.assertEqual([r["emulator"] for r in found.records], ["lexaloffle", "flycast", "other"])
def test_a_record_for_several_emulators_runs_when_one_is_built(self):
from scraper import batocera_scraper as bs
built = bs.boards_build(self.selection(set()), [])
built = bs.boards_build(self.selection(set()), frozenset())
for field in ("citron, mgba", "citron,mgba"):
with self.subTest(field=field):
self.assertEqual(len(bs.records_run([{"emulator": field}], built)), 1)