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

+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)