diff --git a/scripts/scraper/recalbox_scraper.py b/scripts/scraper/recalbox_scraper.py index 84ef8dfbc..3d12876bd 100644 --- a/scripts/scraper/recalbox_scraper.py +++ b/scripts/scraper/recalbox_scraper.py @@ -211,25 +211,34 @@ def system_ini_cores(text: str) -> tuple[set[str], set[str]]: return cores, standalone +# romfs2 systemholder.py reads core.0 to core.19. +CORE_SLOTS = 20 + + def board_cores(text: str, board: str, enabled: set[str]) -> set[str]: """The cores of one system.ini a board's image builds. - A core is built when the Buildroot package its section names is enabled - in the board's defconfig. ``[core.N.]`` replaces the section on - that board and ``package.`` its package. + romfs2 builds each board's list as systemholder.py does: a slot exists + as ``[core.N]`` or as ``[core.N.]`` alone (gb's bsnes on x86_64), + each key is read from the board's section, then as ``.``, + then plain, and a core is kept when the Buildroot package it names is + enabled in the board's defconfig. """ - import re - sections = _ini_sections(text) cores: set[str] = set() - for section, values in sections.items(): - match = re.fullmatch(r"core\.(\d+)", section) - if not match: + for slot in range(CORE_SLOTS): + plain, own = f"core.{slot}", f"core.{slot}.{board}" + if plain not in sections and own not in sections: continue - values = sections.get(f"{section}.{board}", values) - package = values.get(f"package.{board}", values.get("package", "")) - if package in enabled: - cores |= _core_names(values)[0] + + def read(key: str, plain: str = plain, own: str = own) -> str: + for where, name in ((own, key), (plain, f"{key}.{board}"), (plain, key)): + if name in sections.get(where, {}): + return sections[where][name] + return "" + + if read("package") in enabled: + cores |= _core_names({"emulator": read("emulator"), "core": read("core")})[0] return cores diff --git a/tests/test_target_scrapers.py b/tests/test_target_scrapers.py index 0bfdd60c6..4f5428e1b 100644 --- a/tests/test_target_scrapers.py +++ b/tests/test_target_scrapers.py @@ -266,6 +266,20 @@ class RecalboxPerBoard(unittest.TestCase): self.assertEqual(defconfig_arch("BR2_arm=y\n"), "armhf") self.assertEqual(defconfig_arch("BR2_aarch64=y\n"), "aarch64") + def test_board_sections_read_key_by_key_as_romfs_does(self): + from scraper.recalbox_scraper import board_cores # noqa: PLC0415 + + ini = ( + "[core.0]\npackage = BR2_PACKAGE_LIBRETRO_GAMBATTE\nemulator = \"libretro\"\n" + "core = \"gambatte\"\n" + "[core.0.x86_64]\npriority = 2\n" + "[core.5.x86_64]\npackage = BR2_PACKAGE_LIBRETRO_BSNES\nemulator = \"libretro\"\n" + "core = \"bsnes\"\n" + ) + enabled = {"BR2_PACKAGE_LIBRETRO_GAMBATTE", "BR2_PACKAGE_LIBRETRO_BSNES"} + self.assertEqual(board_cores(ini, "x86_64", enabled), {"gambatte", "bsnes"}) + self.assertEqual(board_cores(ini, "rpi3", enabled), {"gambatte"}) + class RetroPieModuleFlags(unittest.TestCase): """The RetroPie target list read flags as requirements and libretro alone.