From 0f602d59148593a04eaf461351c7fc70ec8ead2c Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 04:33:25 +0100 Subject: [PATCH] fix: give retropie modules the platform name flag --- platforms/romfolders/_sources/retropie.yml | 2 +- platforms/targets/retropie.yml | 3 +- scripts/scraper/retropie_modules.py | 46 +++++++++++++++++++ scripts/scraper/romfolders/es.py | 19 ++------ .../targets/retropie_targets_scraper.py | 43 +---------------- tests/test_romfolders_es.py | 12 ++--- tests/test_target_scrapers.py | 9 +++- 7 files changed, 68 insertions(+), 66 deletions(-) create mode 100644 scripts/scraper/retropie_modules.py diff --git a/platforms/romfolders/_sources/retropie.yml b/platforms/romfolders/_sources/retropie.yml index 9bd4cd3b2..78234273f 100644 --- a/platforms/romfolders/_sources/retropie.yml +++ b/platforms/romfolders/_sources/retropie.yml @@ -5,7 +5,7 @@ params: platforms_cfg: platforms.cfg module_dirs: [emulators, libretrocores] install_sections: [core, main, opt, exp] - platform_flags: [native, 64bit, gl, vulkan, x11, x86] + platform: x86_64 sources: os: repo: https://github.com/RetroPie/RetroPie-Setup diff --git a/platforms/targets/retropie.yml b/platforms/targets/retropie.yml index 972a74a1a..ce2e2a4aa 100644 --- a/platforms/targets/retropie.yml +++ b/platforms/targets/retropie.yml @@ -1,6 +1,6 @@ platform: retropie source: https://api.github.com/repos/RetroPie/RetroPie-Setup/contents/scriptmodules?ref=427e76216633591861791cfb28807ac1039c5ea8 -scraped_at: '2026-11-09T16:03:30Z' +scraped_at: '2026-11-21T03:32:27Z' targets: rpi1: architecture: armv6 @@ -1125,6 +1125,7 @@ targets: - px68k - quasi88 - quicknes + - redream - reicast - retro8 - retroarch diff --git a/scripts/scraper/retropie_modules.py b/scripts/scraper/retropie_modules.py new file mode 100644 index 000000000..84a03bf27 --- /dev/null +++ b/scripts/scraper/retropie_modules.py @@ -0,0 +1,46 @@ +"""Which RetroPie scriptmodules a platform enables, as RetroPie-Setup decides.""" + +from __future__ import annotations + +from collections.abc import Iterable + +# scriptmodules/system.sh: set_platform_defaults starts each platform's flags +# with its own name and getconf LONG_BIT (`x86_64`, `64bit`), then the cpu_* +# and platform_* functions add theirs. A PC takes platform_native, which adds +# the x86 flag on i686 and x86_64. The video stacks are those of the images +# RetroPie ships: videocore and dispmanx on rpi1-3, kms with fkms dispmanx on +# rpi4 (buster), kms on rpi5. +PLATFORM_FLAGS: dict[str, set[str]] = { + "rpi1": {"rpi1", "32bit", "arm", "armv6", "rpi", "gles", "videocore", "dispmanx"}, + "rpi2": {"rpi2", "32bit", "arm", "armv7", "neon", "rpi", "gles", "videocore", + "dispmanx"}, + "rpi3": {"rpi3", "32bit", "arm", "armv8", "neon", "rpi", "gles", "videocore", + "dispmanx"}, + "rpi4": {"rpi4", "32bit", "arm", "armv8", "neon", "rpi", "gles", "gles3", "gles31", + "mesa", "kms", "dispmanx"}, + "rpi5": {"rpi5", "32bit", "arm", "armv8", "neon", "rpi", "gles", "gles3", "gles31", + "mesa", "kms"}, + "x86": {"i686", "x86", "32bit", "gl", "vulkan", "x11"}, + "x86_64": {"x86_64", "x86", "64bit", "gl", "vulkan", "x11"}, +} + + +def module_enabled(flags: Iterable[str], platform_flags: set[str]) -> bool: + """Whether RetroPie enables a module whose rp_module_flags are `flags`. + + Port of rp_registerModule (scriptmodules/packages.sh): flags are read in + order from an enabled default; !all disables, a flag the platform has + enables, !flag disables when the platform has it. A flag the platform + does not know (sdl1, nodistcc) changes nothing, and a comparison against + the build host (:$__gcc_version:-lt:7) cannot be decided here, so it + leaves the module as it was. + """ + enabled = True + for flag in flags: + if flag == "!all": + enabled = False + elif flag in platform_flags: + enabled = True + elif flag.startswith("!") and flag[1:] in platform_flags: + enabled = False + return enabled diff --git a/scripts/scraper/romfolders/es.py b/scripts/scraper/romfolders/es.py index 893f7da23..2ef7d7725 100644 --- a/scripts/scraper/romfolders/es.py +++ b/scripts/scraper/romfolders/es.py @@ -33,6 +33,7 @@ from collections.abc import Iterator from model.safeparse import parse_untrusted_xml, yaml_load_upstream +from ..retropie_modules import PLATFORM_FLAGS, module_enabled from . import Fetcher, SourceError, register @@ -922,20 +923,6 @@ _LIST = re.compile(r'(?:local\s+)?(\w+)=\(([^)]*)\)') _LOOP = re.compile(r'for (\w+) in (.+?); do') -def _module_valid(flags: list[str], platform: set[str]) -> bool: - """packages.sh rp_registerModule: flags read in order, `!all` drops - the module, a platform flag keeps it, `!` drops it.""" - valid = True - for flag in flags: - if flag == "!all": - valid = False - elif flag in platform: - valid = True - elif flag.startswith("!") and flag[1:] in platform: - valid = False - return valid - - def _emulator_calls(text: str) -> Iterator[tuple[int, str, str, list[str]]]: """(line, default flag, emulator id, systems) of each addEmulator call, a system variable expanded through the loop or array that sets it.""" @@ -985,7 +972,7 @@ def retropie(spec: dict, fetcher: Fetcher) -> list[dict]: match = re.match(r'^([\w-]+)_exts="([^"]*)"', cfg_line) if match: exts[match.group(1)] = (match.group(2), number) - platform = set(params["platform_flags"]) + platform = PLATFORM_FLAGS[params["platform"]] modules: list[dict] = [] for kind in params["module_dirs"]: for path in fetcher.tree(key, f"scriptmodules/{kind}/"): @@ -993,7 +980,7 @@ def retropie(spec: dict, fetcher: Fetcher) -> list[dict]: continue text = fetcher.text(key, path) fields = dict(_MODULE_FIELD.findall(text)) - if not _module_valid(fields.get("flags", "").split(), platform): + if not module_enabled(fields.get("flags", "").split(), platform): continue modules.append({"path": path, "id": fields.get("id", ""), "section": fields.get("section", ""), "text": text}) diff --git a/scripts/scraper/targets/retropie_targets_scraper.py b/scripts/scraper/targets/retropie_targets_scraper.py index 415979515..7c423c588 100644 --- a/scripts/scraper/targets/retropie_targets_scraper.py +++ b/scripts/scraper/targets/retropie_targets_scraper.py @@ -14,6 +14,7 @@ import sys import tarfile from datetime import datetime, timezone +from ..retropie_modules import PLATFORM_FLAGS, module_enabled from ..retropie_scraper import SOURCE_URL, core_name, fetch_archive, script_members from . import BaseTargetScraper, target_cli @@ -27,24 +28,6 @@ GITHUB_API_URL = ( # is filtered out of every targeted pack. PACKAGE_DIRS = ("emulators", "libretrocores", "ports") -# The flags RetroPie's set_platform_defaults, cpu_* and platform_* functions -# give each platform (scriptmodules/system.sh), with the video stack of the -# images it ships: videocore and dispmanx on rpi1-3, kms with fkms dispmanx -# on rpi4 (buster), kms on rpi5. -PLATFORM_FLAGS: dict[str, set[str]] = { - "rpi1": {"rpi1", "32bit", "arm", "armv6", "rpi", "gles", "videocore", "dispmanx"}, - "rpi2": {"rpi2", "32bit", "arm", "armv7", "neon", "rpi", "gles", "videocore", - "dispmanx"}, - "rpi3": {"rpi3", "32bit", "arm", "armv8", "neon", "rpi", "gles", "videocore", - "dispmanx"}, - "rpi4": {"rpi4", "32bit", "arm", "armv8", "neon", "rpi", "gles", "gles3", "gles31", - "mesa", "kms", "dispmanx"}, - "rpi5": {"rpi5", "32bit", "arm", "armv8", "neon", "rpi", "gles", "gles3", "gles31", - "mesa", "kms"}, - "x86": {"x86", "32bit", "gl", "vulkan", "x11"}, - "x86_64": {"x86", "64bit", "gl", "vulkan", "x11"}, -} - ARCH_MAP: dict[str, str] = { "rpi1": "armv6", "rpi2": "armv7", @@ -66,28 +49,6 @@ def _fetch_archive(url: str) -> bytes: raise RuntimeError(str(exc)) from exc -def _is_available(flags_str: str, platform: str) -> bool: - """Whether RetroPie enables a module on *platform*. - - Port of rp_registerModule (scriptmodules/packages.sh): flags are read in - order from an enabled default; !all disables, a flag the platform has - enables, !flag disables when the platform has it. A flag the platform - does not know (sdl1, nodistcc) changes nothing, and a comparison against - the build host (:$__gcc_version:-lt:7) cannot be decided here, so it - leaves the module as it was. - """ - platform_has = PLATFORM_FLAGS.get(platform, set()) - enabled = True - for token in flags_str.split(): - if token == "!all": - enabled = False - elif token in platform_has: - enabled = True - elif token.startswith("!") and token[1:] in platform_has: - enabled = False - return enabled - - def _parse_module(content: str) -> tuple[str | None, str]: """Return (module_id, flags_string) from a scriptmodule file.""" id_match = _MODULE_ID_RE.search(content) @@ -144,7 +105,7 @@ class Scraper(BaseTargetScraper): continue # The platform scraper names the package the same way. for platform in PLATFORM_FLAGS: - if _is_available(flags, platform): + if module_enabled(flags.split(), PLATFORM_FLAGS[platform]): platform_cores[platform].add(core_name(module_id)) print(f" parsed {len(modules)} scriptmodules", file=sys.stderr) diff --git a/tests/test_romfolders_es.py b/tests/test_romfolders_es.py index a50b24ea7..e8e1fcff4 100644 --- a/tests/test_romfolders_es.py +++ b/tests/test_romfolders_es.py @@ -24,7 +24,7 @@ from scraper.romfolders import ( scrape_setup, ) from scraper.romfolders.__main__ import dump_setup -from scraper.romfolders.es import _module_valid +from scraper.retropie_modules import module_enabled ROOT = Path(__file__).resolve().parent.parent @@ -300,7 +300,7 @@ class RetroPieFormat(unittest.TestCase): self.rows = by_folder(scrape("retropie", "retropie", { "platforms_cfg": "platforms.cfg", "module_dirs": ["emulators", "libretrocores"], "install_sections": ["core", "main", "opt", "exp"], - "platform_flags": ["native", "64bit", "gl", "vulkan", "x11", "x86"]})) + "platform": "x86_64"})) def test_folders_and_loop_systems(self) -> None: self.assertEqual(sorted(self.rows), ["nes", "psx", "vectrex"]) @@ -314,10 +314,10 @@ class RetroPieFormat(unittest.TestCase): def test_module_flags_read_in_order(self) -> None: x86 = {"x86", "64bit"} - self.assertFalse(_module_valid(["!all"], x86)) - self.assertTrue(_module_valid(["!all", "x86"], x86)) - self.assertFalse(_module_valid(["!x86"], x86)) - self.assertTrue(_module_valid(["!arm"], x86)) + self.assertFalse(module_enabled(["!all"], x86)) + self.assertTrue(module_enabled(["!all", "x86"], x86)) + self.assertFalse(module_enabled(["!x86"], x86)) + self.assertTrue(module_enabled(["!arm"], x86)) class Determinism(unittest.TestCase): diff --git a/tests/test_target_scrapers.py b/tests/test_target_scrapers.py index b2b61d8b3..c0279ccfb 100644 --- a/tests/test_target_scrapers.py +++ b/tests/test_target_scrapers.py @@ -19,6 +19,7 @@ import urllib.error from pathlib import Path from unittest import mock +from scripts.scraper.retropie_modules import PLATFORM_FLAGS, module_enabled from scripts.scraper.targets import ( batocera_targets_scraper, emudeck_targets_scraper, @@ -643,7 +644,9 @@ class RetroPieModuleFlags(unittest.TestCase): """ def test_flags_follow_rp_register_module(self): - available = retropie_targets_scraper._is_available + def available(flags: str, platform: str) -> bool: + return module_enabled(flags.split(), PLATFORM_FLAGS[platform]) + cases = { ("sdl1 !mali", "rpi4"): True, ("!all videocore", "rpi3"): True, @@ -653,6 +656,10 @@ class RetroPieModuleFlags(unittest.TestCase): ("!all x86", "rpi4"): False, ("!all x86", "x86_64"): True, ("!all arm rpi3 rpi4 rpi5 x86", "rpi1"): True, + # system.sh:541 puts the platform name first: redream.sh + # declares `!all gles31 aarch64 x86_64` and runs on a PC. + ("noinstclean !all gles31 aarch64 x86_64", "x86_64"): True, + ("noinstclean !all gles31 aarch64 x86_64", "x86"): False, } for (flags, platform), expected in cases.items(): with self.subTest(flags=flags, platform=platform):