fix: give retropie modules the platform name flag

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 06:01:53 +01:00
1 parent b80fc1919d
commit 0f602d5914
7 files changed
+68 -66

No files matched your search

+1 -1
View File
@@ -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
+2 -1
View File
@@ -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
+46
View File
@@ -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
+3 -16
View File
@@ -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, `!<platform flag>` 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})
@@ -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)
+6 -6
View File
@@ -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):
+8 -1
View File
@@ -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):