diff --git a/scripts/scraper/recalbox_romfs.py b/scripts/scraper/recalbox_romfs.py index c0a50dea1..5d1517b12 100644 --- a/scripts/scraper/recalbox_romfs.py +++ b/scripts/scraper/recalbox_romfs.py @@ -14,6 +14,7 @@ TARGET_PREFIX = "BR2_PACKAGE_RECALBOX_TARGET_" # romfs2 inisettings.py loadFile: a key line is tried first, then a section. _INI_KEY = re.compile(r'^([^#;].*?)\s?=\s?"?(.*?)"?$') _INI_SECTION = re.compile(r"^\[(.*)\]") +_CORE_SECTION = re.compile(r"core\.(\d+)(?:\.[\w-]+)?") # romfs2 keyvaluesettings.py loadFile, the reader configin.py uses. _CONFIG_KEY = re.compile(r"^([^#;].*?)\s?=\s?(.+)$") @@ -25,6 +26,13 @@ class SystemIni: sections: dict[str, dict[str, str]] lines: dict[str, int] + def core_sections(self) -> Iterator[dict[str, str]]: + """Every `[core.N]` and `[core.N.]` section some board builds.""" + for name, values in self.sections.items(): + slot = _CORE_SECTION.fullmatch(name) + if slot and int(slot.group(1)) < CORE_SLOTS: + yield values + def slots(self, board: str) -> Iterator[str]: """The `core.N` sections a board builds: `[core.N]` or `[core.N.]` alone.""" for slot in range(CORE_SLOTS): diff --git a/scripts/scraper/recalbox_scraper.py b/scripts/scraper/recalbox_scraper.py index 501b8d350..f68a3fbc9 100644 --- a/scripts/scraper/recalbox_scraper.py +++ b/scripts/scraper/recalbox_scraper.py @@ -155,13 +155,10 @@ def _core_names(values: dict[str, str]) -> tuple[set[str], set[str]]: def system_ini_libretro(text: str) -> set[str]: """The libretro cores one Recalbox system.ini offers.""" - import re - return { values.get("core", "") - for section, values in read_system_ini(text).sections.items() - if re.fullmatch(r"core\.\d+(\.[\w-]+)?", section) - and values.get("emulator") == "libretro" and values.get("core") + for values in read_system_ini(text).core_sections() + if values.get("emulator") == "libretro" and values.get("core") } @@ -196,13 +193,9 @@ def system_ini_cores(text: str) -> tuple[set[str], set[str]]: or a standalone emulator. es_bios.xml only names the cores that need a BIOS, so read alone it left most of Recalbox's cores outside the pack. """ - import re - cores: set[str] = set() standalone: set[str] = set() - for section, values in read_system_ini(text).sections.items(): - if not re.fullmatch(r"core\.\d+(\.[\w-]+)?", section): - continue + for values in read_system_ini(text).core_sections(): found, alone = _core_names(values) cores |= found standalone |= alone diff --git a/tests/test_target_scrapers.py b/tests/test_target_scrapers.py index 2d4d73b23..613f6c177 100644 --- a/tests/test_target_scrapers.py +++ b/tests/test_target_scrapers.py @@ -672,6 +672,18 @@ class RecalboxPerBoard(unittest.TestCase): path, config = found["rpi3"] self.assertEqual((path, config.enabled["BR2_arm"]), ("configs/recalbox-pi3_defconfig", 2)) + def test_core_slots_stop_where_systemholder_stops(self): + """systemholder.py reads core.0 to core.19: a later section is + neither built on a board nor offered by the platform.""" + from scraper.recalbox_scraper import board_cores, system_ini_cores + + ini = ("[core.20]\npackage = BR2_PACKAGE_PCSX2\nemulator = \"pcsx2\"\ncore = \"pcsx2\"\n" + "[core.19]\npackage = BR2_PACKAGE_LIBRETRO_GAMBATTE\nemulator = \"libretro\"\n" + "core = \"gambatte\"\n") + enabled = {"BR2_PACKAGE_PCSX2", "BR2_PACKAGE_LIBRETRO_GAMBATTE"} + self.assertEqual(board_cores(ini, "x86_64", enabled), {"gambatte"}) + self.assertEqual(system_ini_cores(ini), ({"gambatte"}, set())) + class RetroPieModuleFlags(unittest.TestCase): """The RetroPie target list read flags as requirements and libretro alone.