chore: merge origin/main

# Conflicts:
#	install.ps1
#	install.sh
#	install/launchers/index.json
This commit is contained in:
Abdessamad Derraz committed 2026-11-10 07:39:26 +01:00
commit 8e15f94ed1
2865 files changed
+187255 -99594

No files matched your search

+122 -15
View File
@@ -2139,6 +2139,42 @@ class InstallerBoundaryRegressions(unittest.TestCase):
self.assertTrue(errors, "an invalid in-archive manifest must be reported")
self.assertTrue(any("sha1" in message for message in errors), errors)
@unittest.skipUnless(HAS_JSONSCHEMA, "validating a schema needs jsonschema")
def test_a_pack_carries_its_install_list_and_board_lists(self):
"""pack_systems puts the install list and the per-board core lists
in the pack's manifest.json, which install.py reads with the pack
alone. The pack schema refused both keys, and each is checked under
its own contract."""
import generate_pack
import validate_schemas
install_list = json.loads((ROOT / "install" / "romm.json").read_text(encoding="utf-8"))
targets = {"browser": None, "rpi4": {"cores": ["mgba"], "images": ["rpi4"]}}
document = {
"schema_version": 1, "version": 1,
"generator": "retrobios generate_pack.py",
"generated": "2026-08-10T00:00:00Z", "files": [],
"summary": {"total_files": 0, "verified": 0, "untracked": 0, "errors": 0},
"errors": [],
}
generate_pack.annotate_pack_systems(
document, generate_pack.pack_systems(install_list, targets))
self.assertIn("install_list", document)
self.assertIn("targets", document)
with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory:
dist = Path(directory)
with zipfile.ZipFile(dist / "Pack.zip", "w") as archive:
archive.writestr("manifest.json", json.dumps(document))
self.assertEqual(validate_schemas._validate_pack_manifests(dist), [])
broken = {**document, "targets": {"rpi4": [1]},
"install_list": {**install_list, "files": "none"}}
with zipfile.ZipFile(dist / "Pack.zip", "w") as archive:
archive.writestr("manifest.json", json.dumps(broken))
errors = validate_schemas._validate_pack_manifests(dist)
self.assertTrue(any(":targets:" in message for message in errors), errors)
self.assertTrue(any(":install_list:" in message for message in errors), errors)
def test_null_core_list_keeps_the_other_targets(self):
"""A target without a core inventory must not void the manifest.
@@ -4223,11 +4259,21 @@ class VerifyStrictAppliesInEveryMode(unittest.TestCase):
class OpenMsxRomsSitInItsSystemroms(unittest.TestCase):
"""openMSX entries had no path and landed at the BIOS root, where no
frontend points FilePool. RetroBat declares its ROMs under
openMSX/share/systemroms, and the profile's paths must agree."""
frontend points FilePool. The profile writes share/systemroms below
openMSX's user folder, the pool's first place (src/file/FilePool.cc,
FileOperations.cc), and RetroBat, which sets OPENMSX_HOME to
bios/openmsx and declares its ROMs under openMSX/share/systemroms, gets
them there."""
def test_every_entry_is_under_share_systemroms(self):
profile = yaml.safe_load((ROOT / "emulators" / "openmsx.yml").read_text())
from scripts.common import ( # noqa: PLC0415
load_emulator_profiles,
load_platform_config,
platform_layouts,
standalone_set,
)
profile = load_emulator_profiles(str(ROOT / "emulators"))["openmsx"]
retrobat = yaml.safe_load((ROOT / "platforms" / "retrobat.yml").read_text())
declared_dirs = {
fe["destination"].rsplit("/", 1)[0].lower()
@@ -4236,12 +4282,15 @@ class OpenMsxRomsSitInItsSystemroms(unittest.TestCase):
if "systemroms" in fe.get("destination", "")
}
self.assertEqual(declared_dirs, {"openmsx/share/systemroms"})
config = load_platform_config("retrobat", str(ROOT / "platforms"))
((view, _standalone),) = platform_layouts("openmsx", profile, standalone_set(config))
placed = {f["name"]: f for f in view["files"]}
for entry in profile["files"]:
with self.subTest(name=entry["name"]):
self.assertEqual(
entry.get("path", "").lower(),
f"openmsx/share/systemroms/{entry['name']}".lower(),
)
self.assertEqual(entry.get("path", "").lower(),
f"share/systemroms/{entry['name']}".lower())
self.assertEqual(placed[entry["name"]].get("standalone_path", "").lower(),
f"openmsx/share/systemroms/{entry['name']}".lower())
class ASameNamedMemberIsNotTheFile(unittest.TestCase):
@@ -6314,16 +6363,17 @@ class NoProfileHashFromASecondarySource(unittest.TestCase):
self.assertEqual(found, [])
class XeniosFollowsThePreviewBranch(unittest.TestCase):
"""The xenios pin 87b176a0 and tag v2.0.1 are ancestors of `preview`
(compare: ahead 129, behind 0) and diverged from the default `xenios`
branch (ahead 1784, behind 24). Without source_branch, profile_sync read
the pin as orphaned and 19 refs as moved by the branch divergence."""
class XeniosFollowsItsReleaseBranch(unittest.TestCase):
"""The xenios pin 87b176a0 sat on `preview`, which diverged from the
default `xenios` branch, and without source_branch profile_sync read the
pin as orphaned. Since November 2026 the releases (2.2 to 2.3.1) come from
`xenios` and `preview` stopped in June: the pin is release 2.3.1 on the
default branch, so the profile names no other branch."""
def test_the_profile_names_the_branch_its_pin_is_on(self):
def test_the_profile_follows_the_branch_its_pin_is_on(self):
profile = yaml.safe_load((ROOT / "emulators" / "xenios.yml").read_text(encoding="utf-8"))
self.assertEqual(profile.get("source_branch"), "preview")
self.assertNotIn("from the xenios branch", profile.get("notes", ""))
self.assertIn(profile.get("source_branch"), (None, "xenios"))
self.assertEqual(profile["source_commit"][:7], "cf7c7ee")
class PcemUpstreamPinIsTheLastSync(unittest.TestCase):
@@ -6361,6 +6411,8 @@ class AHashScanLabelNamesNoOtherDump(unittest.TestCase):
"share/machines/ColecoVision_SGM.xml:56 names it, tried beside the machine XML",
("openmsx", "fmpac.rom"):
"share/machines/Boosted_MSX2_EN.xml:83 names it, tried beside the machine XML",
("openmsx-libretro", "rs232.rom"):
"share/extensions/rs232.xml:18-22 names it, tried beside the extension XML",
}
@staticmethod
@@ -6918,6 +6970,10 @@ class WhatOnlyAnInstallProvidesIsListed(unittest.TestCase):
}
rows = bundled_only.bundled_only(db, profiles, tmp, Path(tmp))
self.assertEqual([row["path"] for row in rows], [str(Path(tmp, "icon.png"))])
# A platform whose package leaves the file out brings it from the
# collection: the copy stays.
profiles["app"]["files"][0]["not_bundled_on"] = ["someplatform"]
self.assertEqual(bundled_only.bundled_only(db, profiles, tmp, Path(tmp)), [])
def test_every_copy_of_the_listed_bytes_is_listed(self):
"""The database keeps one path per content: splitwolf's sprite
@@ -7749,5 +7805,56 @@ class AutoFetchIssueBodyReadsAsWritten(unittest.TestCase):
self.assertIn("posts nothing", auto_fetch.__doc__)
class EveryReaderOfACoreFileIsNamed(unittest.TestCase):
"""A requirement two cores read is reported once, the first profile
hosting the others' claims. Whatever drops the host must not drop the
claims with it."""
def test_a_host_its_emulator_installs_leaves_the_others_in_the_pack(self):
from verify import _split_bundled_claims
dsperate = {"profile": "dsperate", "name": "usrcheat.dat", "in_repo": True}
drastic = {"profile": "drastic", "name": "usrcheat.dat", "bundled": True,
"in_repo": True, "other_claims": [dsperate]}
out = _split_bundled_claims([drastic])
self.assertEqual([(u["profile"], u.get("other_claims")) for u in out],
[("drastic", None), ("dsperate", None)])
alone = {"profile": "drastic", "bundled": True, "other_claims": [
{"profile": "drastic-legacy", "bundled": True}]}
self.assertEqual(_split_bundled_claims([alone]), [alone])
def test_a_held_file_out_of_reach_names_every_core_reading_it(self):
"""harm1.wad is a release asset: a checkout without it omits the file,
and the omission named gzdoom alone where lzdoom reads it too."""
from generate_pack import _claim_cores
extra = {"source_profile": "gzdoom", "other_claims": [
{"source_profile": "uzdoom"}, {"source_profile": "lzdoom"}]}
self.assertEqual(_claim_cores(extra), ["gzdoom", "lzdoom", "uzdoom"])
def test_a_missing_file_names_every_core_reading_it(self):
from generate_pack import _record_absent
omitted: dict[str, dict] = {}
def record(full_dest, entry, system, reason, cores):
omitted[full_dest] = {"dest": full_dest, "reason": reason, "cores": cores}
absent = [
{"name": "NAPALM.GRP", "destination": "NAPALM.GRP", "source_profile": profile,
"source_system": system}
for profile, system in (("raze", "nam"), ("eduke32", "napalm"))
]
platform = {"dest": "SHARED.BIN", "reason": "not_found", "cores": None}
omitted["SHARED.BIN"] = platform
absent.append({"name": "SHARED.BIN", "destination": "SHARED.BIN",
"source_profile": "raze"})
_record_absent(absent, {}, "", set(), False, set(), omitted, record)
self.assertEqual(omitted["NAPALM.GRP"]["cores"], ["eduke32", "raze"])
# A platform's own omission stays the platform's.
self.assertIsNone(omitted["SHARED.BIN"]["cores"])
if __name__ == "__main__":
unittest.main()
+66
View File
@@ -0,0 +1,66 @@
"""A platform declaration that a content-found core entry accepts by hash.
atari800 identifies its ROMs by CRC32 in the folder it scans. RetroDECK
lists Atari BASIC Rev A as ROM_BASIC_A, a name atari800 never opens, and
the profile answered it with a false alias. Settled by content instead, the
declared file meets the entry and the label is not shipped a second time.
"""
from __future__ import annotations
import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache
import os
import sys
import unittest
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "scripts"))
from common import platform_declared_contents # noqa: E402
from validation import declaration_settles # noqa: E402
SHA1 = "70cdf57469a208528f78a14275837352e90e20f1"
DB = {
"files": {SHA1: {"path": "bios/Atari/ROM_BASIC_A", "name": "ROM_BASIC_A", "sha1": SHA1,
"md5": "a4dc52536d526ecc51ea857b9fa2b90f", "crc32": "4bec4de2",
"size": 8192}},
"indexes": {"by_md5": {"a4dc52536d526ecc51ea857b9fa2b90f": SHA1}},
}
CONFIG = {
"base_destination": "",
"systems": {"atari800": {"files": [
{"name": "ROM_BASIC_A", "destination": "bios/ROM_BASIC_A",
"md5": "a4dc52536d526ecc51ea857b9fa2b90f"},
]}},
}
ENTRY = {"name": "atari-basic-rev-a.rom", "found_by": "content", "crc32": "4bec4de2"}
class ContentDeclarationTest(unittest.TestCase):
def setUp(self) -> None:
self.contents = platform_declared_contents(CONFIG, DB)
def test_the_declared_file_is_indexed_by_each_hash(self) -> None:
self.assertEqual(self.contents["crc32:4bec4de2"], {""})
self.assertEqual(self.contents[f"sha1:{SHA1}"], {""})
def test_a_content_found_entry_is_met_by_its_hash(self) -> None:
self.assertTrue(declaration_settles(
ENTRY, ENTRY["name"], {}, ENTRY["name"], declared_contents=self.contents,
))
def test_an_entry_opened_by_name_is_not(self) -> None:
entry = {key: value for key, value in ENTRY.items() if key != "found_by"}
self.assertFalse(declaration_settles(
entry, entry["name"], {}, entry["name"], declared_contents=self.contents,
))
def test_another_folder_is_not_the_one_scanned(self) -> None:
self.assertFalse(declaration_settles(
ENTRY, ENTRY["name"], {}, "atari800/" + ENTRY["name"],
declared_contents=self.contents,
))
if __name__ == "__main__":
unittest.main()
-1
View File
@@ -258,7 +258,6 @@ class OneCommandRunsTheChecks(unittest.TestCase):
workflow = (REPO_ROOT / ".github" / "workflows" / "validate.yml").read_text(encoding="utf-8")
tolerated = set(re.findall(r"continue-on-error: true\n\s*run: (\S+ \S+)", workflow))
self.assertTrue(tolerated)
for step in pr_checks.STEPS:
with self.subTest(step=step.command):
self.assertEqual(step.may_fail, " ".join(step.command.split()[:2]) in tolerated)
+11 -3
View File
@@ -491,9 +491,13 @@ class CoreResolutionWrittenOnce(unittest.TestCase):
import common
self.assertNotIn("cores: [list]", _page("architecture.md"))
source = inspect.getsource(common.resolve_platform_cores)
# resolve_platform_cores narrows by target, _platform_profiles holds
# the strategies.
source = inspect.getsource(common._platform_profiles)
self.assertIn('not p.get("built_by")', source)
self.assertIn('"retroarch" in core_set', source)
self.assertIn('config.get("installable_cores")', source)
self.assertIn("downloadable_on", inspect.getsource(common.resolve_platform_cores))
naming = set()
for path in (ROOT / "platforms").glob("*.yml"):
config = yaml.safe_load(path.read_text(encoding="utf-8")) or {}
@@ -504,10 +508,14 @@ class CoreResolutionWrittenOnce(unittest.TestCase):
bullet = next(p for p in section.split("\n- ") if p.startswith("**Explicit list**"))
used_by = re.search(r"Used by ([^.]+)\.", bullet.replace("\n", " ")).group(1)
names = [n.strip().lower() for n in used_by.split(",")]
self.assertIn("the last\n four", bullet)
self.assertEqual(set(names[-4:]), naming)
words = {2: "two", 3: "three", 4: "four", 5: "five"}
counted = re.search(r"\(the last\s+(\w+)\)", bullet).group(1)
self.assertEqual(counted, words[len(naming)])
self.assertEqual(set(names[-len(naming):]), naming)
libretro = next(p for p in section.split("\n- ") if p.startswith("**all_libretro**"))
self.assertIn("built_by", libretro)
for name in ("installable_cores", "downloadable_on", "downloaded_cores"):
self.assertIn(f"`{name}`", bullet)
class ExitStatusTable(unittest.TestCase):
+6 -4
View File
@@ -450,7 +450,9 @@ class CoreCountsReadFromTheData(unittest.TestCase):
sitepages.require()
text = sitepages.page("cross-reference.md").read_text(encoding="utf-8")
profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
unique = {k: v for k, v in profiles.items() if v.get("type") not in ("alias", "test")}
# A test core says so in role, its type staying operational.
unique = {k: v for k, v in profiles.items()
if v.get("type") != "alias" and v.get("role") != "test"}
registry = yaml.safe_load((REPO_ROOT / "platforms" / "_registry.yml").read_text(
encoding="utf-8"))["platforms"]
run = set()
@@ -619,7 +621,7 @@ class ContributorChecksFetchThePlatformsFiles(unittest.TestCase):
def test_the_pr_checklist_fetches_them_before_the_tests(self):
workflow = _read(".github/workflows/validate.yml")
self.assertLess(
workflow.index("python scripts/export_native.py --all --fetch"),
workflow.index("python scripts/export_native.py --all --refresh-cache"),
workflow.index("python -m unittest discover"),
)
for text in (
@@ -627,13 +629,13 @@ class ContributorChecksFetchThePlatformsFiles(unittest.TestCase):
_read("CONTRIBUTING.md"),
):
block = _section(text, "## Before opening a PR")
self.assertIn("python scripts/export_native.py --all --fetch", block)
self.assertIn("python scripts/export_native.py --all --refresh-cache", block)
self.assertLess(
block.index("export_native.py"), block.index("unittest discover")
)
def test_the_testing_guide_names_the_command(self):
self.assertIn("export_native.py --all --fetch", _read("wiki/testing-guide.md"))
self.assertIn("export_native.py --all --refresh-cache", _read("wiki/testing-guide.md"))
class ArchiveRecipesAreCountedFromTheRecipes(unittest.TestCase):
+413
View File
@@ -64,6 +64,13 @@ from verify import (
verify_platform,
)
try:
import jsonschema # noqa: F401
except ImportError:
HAS_JSONSCHEMA = False
else:
HAS_JSONSCHEMA = True
def _h(data: bytes) -> dict:
"""Return sha1, md5, crc32 for test data."""
@@ -915,6 +922,40 @@ class TestE2E(unittest.TestCase):
c = result["severity_counts"]
self.assertGreater(c[Severity.WARNING], 0)
def test_24b_a_held_group_member_makes_the_others_optional(self):
"""RetroBat's group: one file held is enough (batocera-systems/Program.cs)."""
from common import _platform_config_cache
with open(os.path.join(self.platforms_dir, "test_md5.yml")) as fh:
config = yaml.safe_load(fh)
held_md5 = next(
f["md5"] for f in config["systems"]["sys-renamed"]["files"]
)
config["systems"] = {
"sys-group": {"files": [
{"name": "correct_hash.bin", "destination": "g/held.bin",
"md5": held_md5, "required": True, "group": "one"},
{"name": "absent_alt.bin", "destination": "g/absent_alt.bin",
"md5": "0" * 32, "required": True, "group": "one"},
{"name": "absent_a.bin", "destination": "g/absent_a.bin",
"md5": "1" * 32, "required": True, "group": "none"},
{"name": "absent_b.bin", "destination": "g/absent_b.bin",
"md5": "2" * 32, "required": True, "group": "none"},
]},
}
with open(os.path.join(self.platforms_dir, "grouped_md5.yml"), "w") as fh:
yaml.dump(config, fh)
_platform_config_cache.clear()
result = verify_platform(
load_platform_config("grouped_md5", self.platforms_dir), self.db, self.emulators_dir
)
by_name = {d["name"]: d for d in result["details"]}
self.assertEqual(by_name["correct_hash.bin"]["status"], Status.OK)
self.assertIs(by_name["absent_alt.bin"]["required"], False)
self.assertIs(by_name["absent_a.bin"]["required"], True)
self.assertIs(by_name["absent_b.bin"]["required"], True)
self.assertEqual(result["severity_counts"][Severity.CRITICAL], 2)
def test_25_verify_sha1_platform(self):
config = load_platform_config("test_sha1", self.platforms_dir)
result = verify_platform(config, self.db, self.emulators_dir)
@@ -1149,6 +1190,23 @@ class TestE2E(unittest.TestCase):
recalbox = {"cores": ["mame0278"], "systems": {}}
self.assertEqual(resolve_platform_cores(recalbox, profiles), {"mame0278"})
def test_a_platform_s_own_libretro_build_comes_with_its_retroarch(self):
"""ROCKNIX ships yabadabadoo with its RetroArch and names it nowhere
else: a list naming retroarch takes the libretro builds whose
built_by names that platform, and no other platform's."""
profiles = {
"yabause": {"type": "libretro", "systems": ["saturn"], "files": []},
"yabadabadoo": {"type": "libretro", "built_by": ["rocknix"],
"systems": ["saturn"], "files": []},
}
rocknix = {"_key": "rocknix", "cores": ["retroarch"], "systems": {}}
self.assertEqual(resolve_platform_cores(rocknix, profiles),
{"yabause", "yabadabadoo"})
other = {"_key": "batocera", "cores": ["retroarch"], "systems": {}}
self.assertEqual(resolve_platform_cores(other, profiles), {"yabause"})
everyone = {"_key": "retroarch", "cores": "all_libretro", "systems": {}}
self.assertEqual(resolve_platform_cores(everyone, profiles), {"yabause"})
def test_resolve_cores_explicit_list(self):
"""Explicit cores list matches against profile dict keys."""
config = {"cores": ["fbneo", "opera"], "systems": {"arcade": {"files": []}}}
@@ -6731,5 +6789,360 @@ class StandaloneModeRequiresAStandaloneBuild(unittest.TestCase):
self.assertFalse(runs_standalone("dolphin", dual, {"pcsx2"}))
class OneOfASearchList(unittest.TestCase):
"""Entries a core takes the first of are one need (``group:``).
Yabause tries saturn_bios.bin, sega_101.bin, mpr-17933.bin and loads the
first it finds. Written as required on the first name only, verify and
the gap report called saturn_bios.bin a missing required file while
sega_101.bin was held, and a set held through an optional-looking name
passed for the wrong reason. Synthetic: set ``first`` holds only its
second member, set ``none`` holds nothing.
"""
def setUp(self):
from common import _emulator_profiles_cache
_emulator_profiles_cache.clear()
repo = Path(__file__).resolve().parent.parent
(repo / "tmp").mkdir(exist_ok=True)
self.root = Path(tempfile.mkdtemp(dir=repo / "tmp"))
self.addCleanup(shutil.rmtree, self.root, True)
previous = os.getcwd()
os.chdir(self.root)
self.addCleanup(os.chdir, previous)
self.db = {"files": {}, "indexes": {"by_md5": {}, "by_name": {},
"by_crc32": {}, "by_path_suffix": {}}}
for name in ("second.bin", "third.bin", "plain.bin"):
data = name.encode() * 8
rel = f"bios/Test/Console/{name}"
Path(rel).parent.mkdir(parents=True, exist_ok=True)
Path(rel).write_bytes(data)
sha1 = hashlib.sha1(data).hexdigest()
self.db["files"][sha1] = {"path": rel, "name": name, "size": len(data),
"md5": hashlib.md5(data).hexdigest(), "crc32": ""}
self.db["indexes"]["by_name"][name] = [sha1]
Path("emulators").mkdir()
Path("platforms").mkdir()
def member(name: str, group: str, rank: int) -> dict:
return {"name": name, "system": "console-a", "group": group,
"priority": rank}
raw = {
"emulator": "Seq", "type": "libretro", "cores": ["seq"],
"systems": ["console-a"],
"groups": {"first": {"required": True}, "none": {"required": True}},
"files": [
member("first.bin", "first", 1),
member("second.bin", "first", 2),
member("third.bin", "first", 3),
member("none_a.bin", "none", 1),
member("none_b.bin", "none", 2),
{"name": "plain.bin", "system": "console-a", "required": True},
],
}
Path("emulators/seq.yml").write_text(yaml.safe_dump(raw))
self.raw = raw
# What every reader sees: the profile as load_emulator_profiles gives it.
self.profile = load_emulator_profiles("emulators")["seq"]
self.config = {
"platform": "Seqs", "verification_mode": "existence",
"base_destination": "system", "cores": ["seq"],
"systems": {"console-a": {"files": []}},
}
def _verify(self) -> dict:
return verify_emulator(["seq"], "emulators", self.db, platforms_dir="platforms")
def test_one_member_held_leaves_no_missing_report_for_its_set(self):
result = self._verify()
reported = {d["name"]: d["status"] for d in result["details"]}
self.assertEqual(reported["second.bin"], "ok")
self.assertEqual(reported["third.bin"], "ok")
self.assertNotIn("first.bin", reported)
self.assertEqual(
sorted(d["name"] for d in result["set_members"]),
["first.bin", "none_b.bin"],
)
def test_a_set_none_holds_is_one_gap(self):
result = self._verify()
missing = [d for d in result["details"] if d["status"] == "missing"]
self.assertEqual([d["name"] for d in missing], ["none_a.bin"])
self.assertEqual(missing[0]["alternatives"], ["none_b.bin"])
# Required and missing, judged as the core judges: one warning.
self.assertEqual(result["severity_counts"][Severity.WARNING], 1)
self.assertEqual(result["severity_counts"][Severity.INFO], 0)
self.assertEqual(result["status_counts"].get("missing"), 1)
self.assertEqual(result["total_files"], 4)
def test_a_required_set_held_through_a_later_member_is_satisfied(self):
"""second.bin used to read required: false beside a required
first.bin: the set is required and held, so nothing is critical
for it, and the strict exit names only the set nobody holds."""
from verify import _exit_if_strict_emulator
result = self._verify()
critical = [d["name"] for d in result["details"]
if d["status"] == "missing" and d["required"]]
self.assertEqual(critical, ["none_a.bin"])
with self.assertRaises(SystemExit), contextlib.redirect_stderr(io.StringIO()) as err:
_exit_if_strict_emulator(True, result)
self.assertIn("1 required file(s) missing: none_a.bin", err.getvalue())
def test_pack_and_verify_agree(self):
from generate_pack import generate_emulator_pack
result = self._verify()
out = io.StringIO()
with contextlib.redirect_stdout(out):
zip_path = generate_emulator_pack(
["seq"], "emulators", self.db, "bios", "out", offline=True,
platforms_dir="platforms",
)
with zipfile.ZipFile(zip_path) as zf:
packed = sorted(n for n in zf.namelist() if n != "README.txt")
self.assertEqual(packed, ["plain.bin", "second.bin", "third.bin"])
self.assertEqual(result["severity_counts"]["ok"], len(packed))
lines = out.getvalue().splitlines()
self.assertEqual(
[line.split(": ", 1)[1] for line in lines if line.strip().startswith("MISSING:")],
["none_a.bin"],
)
self.assertIn("3 files packed, 1 missing", out.getvalue())
def test_core_complement_reports_one_gap_per_set(self):
undeclared = find_undeclared_files(
self.config, "emulators", self.db, {"seq": self.profile}
)
by_name = {u["name"]: u for u in undeclared}
self.assertEqual(
sorted(by_name), ["none_a.bin", "plain.bin", "second.bin", "third.bin"]
)
self.assertTrue(by_name["second.bin"]["in_repo"])
self.assertFalse(by_name["none_a.bin"]["in_repo"])
self.assertEqual(by_name["none_a.bin"]["alternatives"], ["none_b.bin"])
def test_a_platform_declaration_speaks_for_the_set(self):
"""The platform declares first.bin and reports it in its own check:
the core's other names are not gaps on top of it."""
config = {**self.config, "systems": {"console-a": {"files": [
{"name": "first.bin", "destination": "first.bin", "required": True},
{"name": "none_b.bin", "destination": "none_b.bin", "required": True},
]}}}
undeclared = find_undeclared_files(
config, "emulators", self.db, {"seq": self.profile}
)
self.assertEqual(
sorted(u["name"] for u in undeclared), ["plain.bin", "second.bin", "third.bin"]
)
def test_gap_report_counts_the_set_once(self):
import cross_reference
index = {
"by_name": self.db["indexes"]["by_name"],
"by_name_lower": {k.lower(): k for k in self.db["indexes"]["by_name"]},
"by_path_suffix": {}, "by_md5": {}, "by_sha256": {}, "by_crc32": {},
"data_names": set(), "all_declared": set(), "db_files": self.db["files"],
}
report: dict = {}
cross_reference._cross_reference_profile("seq", self.profile, {}, report, index)
gaps = {g["name"]: g for g in report["seq"]["gap_details"]}
self.assertEqual(sorted(gaps), ["none_a.bin", "plain.bin", "second.bin", "third.bin"])
self.assertEqual(gaps["none_a.bin"]["alternatives"], ["none_b.bin"])
self.assertEqual(report["seq"]["set_aside"]["other_versions"], 2)
def test_truth_names_no_member_required_on_its_own(self):
from truth import _fold_into, _new_truth_entry
entry = _new_truth_entry(dict(self.profile["files"][0]), "seq", None)
self.assertNotIn("required", entry)
self.assertEqual(entry["_required_by"], set())
self.assertTrue(entry["one_of_required"])
_fold_into(entry, {"name": "first.bin", "required": True}, "other")
self.assertTrue(entry["required"])
self.assertEqual(entry["_required_by"], {"other"})
def test_ranks_order_one_set_and_never_two(self):
"""px68k-sdl ranks its IPL list and its font list each from 1:
--one-per-slot keeps the first of each, not one file of the two."""
from slot import build_slot_index, resolve_slot_drops
profile = {"type": "standalone", "files": [
{"name": "ipl_a.dat", "group": "ipl", "priority": 1},
{"name": "ipl_b.dat", "group": "ipl", "priority": 2},
{"name": "font_a.dat", "group": "font", "priority": 1},
{"name": "font_b.dat", "group": "font", "priority": 2},
]}
index = build_slot_index({"x68": profile})
groups = {"sharp-x68000": [(n, n) for n in
("ipl_a.dat", "ipl_b.dat", "font_a.dat", "font_b.dat")]}
drops, undecidable = resolve_slot_drops(groups, index)
self.assertEqual(drops, {"ipl_b.dat", "font_b.dat"})
self.assertEqual(undecidable, [])
def test_an_archive_needs_one_member_of_a_set(self):
import zlib
from common import holds_required_members
path = self.root / "set.zip"
with zipfile.ZipFile(path, "w") as zf:
zf.writestr("boot_b.ic94", b"B")
zf.writestr("eeprom.ic1", b"E")
crc = {n: f"{zlib.crc32(d):08x}" for n, d in (("a", b"A"), ("b", b"B"), ("e", b"E"))}
members = [
{"crc32": crc["a"], "required": True, "group": "boot"},
{"crc32": crc["b"], "required": True, "group": "boot"},
{"crc32": crc["e"], "required": True},
]
self.assertTrue(holds_required_members(str(path), members))
self.assertFalse(holds_required_members(str(path), members[:1] + members[2:]))
@unittest.skipUnless(HAS_JSONSCHEMA, "validate_schemas needs jsonschema")
def test_schema_refuses_a_set_split_on_required(self):
from validate_schemas import _group_requirement_split, ROOT
path = ROOT / "emulators" / "seq.yml"
own_value = {"groups": {"g": {"required": True}},
"files": [{"name": "a", "group": "g", "required": False},
{"name": "b", "group": "g"}]}
self.assertEqual(len(_group_requirement_split(path, own_value)), 1)
undeclared_set = {"files": [{"name": "a", "group": "g"}]}
self.assertEqual(len(_group_requirement_split(path, undeclared_set)), 1)
unused = {"groups": {"g": {"required": True}}, "files": [{"name": "a"}]}
self.assertEqual(len(_group_requirement_split(path, unused)), 1)
self.assertEqual(_group_requirement_split(path, self.raw), [])
def test_a_shared_fallback_takes_its_requirement_from_its_sets(self):
"""pom2 falls back on apple2e.rom for the //e it boots by default
and for the unenhanced //e it may be switched to. One value on the
file cannot say both: the sets carry it."""
from alternatives import derive_member_requirements
profile = {"groups": {"iie": {"required": True}, "iie-u": {"required": False}},
"files": [{"name": "apple2e_unenh.rom", "group": "iie-u"},
{"name": "apple2e.rom", "group": ["iie", "iie-u"]}]}
derive_member_requirements(profile)
self.assertEqual([f["required"] for f in profile["files"]], [False, True])
def test_required_only_keeps_one_held_member_per_required_set(self):
"""second.bin and third.bin are both held: a --required-only pack
carries second.bin, the first the code reads among those held, and
verify reports the same single file."""
from generate_pack import generate_emulator_pack
result = verify_emulator(["seq"], "emulators", self.db,
platforms_dir="platforms", required_only=True)
held = sorted(d["name"] for d in result["details"] if d["status"] == "ok")
self.assertEqual(held, ["plain.bin", "second.bin"])
with contextlib.redirect_stdout(io.StringIO()):
zip_path = generate_emulator_pack(
["seq"], "emulators", self.db, "bios", "out", offline=True,
platforms_dir="platforms", required_only=True,
)
with zipfile.ZipFile(zip_path) as zf:
packed = sorted(n for n in zf.namelist() if n != "README.txt")
self.assertEqual(packed, held)
def test_required_only_core_files_keep_one_member(self):
from alternatives import core_file_spares
undeclared = find_undeclared_files(
self.config, "emulators", self.db, {"seq": self.profile}
)
spares = core_file_spares(undeclared)
kept = sorted(u["name"] for u in undeclared if id(u) not in spares)
self.assertEqual(kept, ["none_a.bin", "plain.bin", "second.bin"])
class AnArchiveIsAMemberOfASet(unittest.TestCase):
"""Kronos reads kronos/stvbios.zip, else stvbios.zip at the root: one
archive under two paths, a first-found pair. The archive unit and the
root copy settle as members of one set, and a --required-only pack
carries the first, while the members inside still settle the archive
by its contents."""
def _fixture(self, held: bool) -> dict:
import zlib
from common import _emulator_profiles_cache
_emulator_profiles_cache.clear()
repo = Path(__file__).resolve().parent.parent
(repo / "tmp").mkdir(exist_ok=True)
root = Path(tempfile.mkdtemp(dir=repo / "tmp"))
self.addCleanup(shutil.rmtree, root, True)
previous = os.getcwd()
os.chdir(root)
self.addCleanup(os.chdir, previous)
self.db = {"files": {}, "indexes": {"by_md5": {}, "by_name": {},
"by_crc32": {}, "by_path_suffix": {}}}
rom = b"STV" * 64
if held:
rel = "bios/Sega/STV/set.zip"
Path(rel).parent.mkdir(parents=True)
with zipfile.ZipFile(rel, "w") as zf:
zf.writestr("epr.ic8", rom)
data = Path(rel).read_bytes()
sha1 = hashlib.sha1(data).hexdigest()
self.db["files"][sha1] = {"path": rel, "name": "set.zip", "size": len(data),
"md5": hashlib.md5(data).hexdigest(), "crc32": ""}
self.db["indexes"]["by_name"]["set.zip"] = [sha1]
Path("emulators").mkdir()
Path("platforms").mkdir()
Path("emulators/stv.yml").write_text(yaml.safe_dump({
"emulator": "Stv", "type": "libretro", "cores": ["stv"],
"systems": ["sega-stv"], "archive_prefix": "stv",
"groups": {"stv-bios": {"required": True}},
"files": [
{"name": "set.zip", "system": "sega-stv", "group": "stv-bios"},
{"name": "epr.ic8", "archive": "set.zip", "system": "sega-stv",
"required": True, "crc32": f"{zlib.crc32(rom):08x}"},
],
}))
return load_emulator_profiles("emulators")["stv"]
def test_the_archive_and_its_root_copy_are_one_need(self):
self._fixture(held=False)
result = verify_emulator(["stv"], "emulators", self.db, platforms_dir="platforms")
missing = [d for d in result["details"] if d["status"] == "missing"]
self.assertEqual([d["destination"] for d in missing], ["stv/set.zip"])
self.assertEqual(missing[0]["alternatives"], ["set.zip"])
self.assertEqual(result["status_counts"].get("missing"), 1)
def test_required_only_carries_the_archive_the_code_reads_first(self):
from generate_pack import generate_emulator_pack
self._fixture(held=True)
full = verify_emulator(["stv"], "emulators", self.db, platforms_dir="platforms")
self.assertEqual(
sorted(d["destination"] for d in full["details"] if d["status"] == "ok"),
["set.zip", "stv/set.zip"],
)
result = verify_emulator(["stv"], "emulators", self.db,
platforms_dir="platforms", required_only=True)
held = sorted(d["destination"] for d in result["details"] if d["status"] == "ok")
self.assertEqual(held, ["stv/set.zip"])
with contextlib.redirect_stdout(io.StringIO()):
zip_path = generate_emulator_pack(
["stv"], "emulators", self.db, "bios", "out", offline=True,
platforms_dir="platforms", required_only=True,
)
with zipfile.ZipFile(zip_path) as zf:
packed = sorted(n for n in zf.namelist() if n != "README.txt")
self.assertEqual(packed, held)
def test_core_files_report_the_pair_once(self):
profile = self._fixture(held=False)
config = {"platform": "Stvs", "verification_mode": "existence",
"base_destination": "system", "cores": ["stv"],
"systems": {"sega-stv": {"files": []}}}
undeclared = find_undeclared_files(config, "emulators", self.db, {"stv": profile})
self.assertEqual([u["name"] for u in undeclared], ["set.zip"])
self.assertTrue(undeclared[0].get("archive"))
if __name__ == "__main__":
unittest.main()
+9 -2
View File
@@ -284,7 +284,10 @@ class TheExportKeepsTheirShape(unittest.TestCase):
class TheCommittedListsAgree(unittest.TestCase):
"""A system's cores are a part of the platform's: a name only the system
carries would escape every reader of the platform list."""
carries would escape every reader of the platform list. A system keeps
the list its ES file writes, which says whose files its entries ask for,
so the one name it may carry beyond the platform's is one no device
image builds (EmuELEC's VVVVVV port engine, KNULLI's duckstation)."""
def test_system_cores_are_platform_cores(self):
import yaml
@@ -292,10 +295,14 @@ class TheCommittedListsAgree(unittest.TestCase):
for name in ("amberelec", "emuelec", "knulli"):
with self.subTest(platform=name):
config = yaml.safe_load((REPO_ROOT / "platforms" / f"{name}.yml").read_text())
targets = yaml.safe_load(
(REPO_ROOT / "platforms" / "targets" / f"{name}.yml").read_text())["targets"]
built = {c for entry in targets.values() for c in entry["cores"]}
platform = {str(c) for c in config["cores"]}
listed = {str(c) for s in config["systems"].values() for c in s.get("cores", [])}
self.assertTrue(listed, "no system carries its cores")
self.assertEqual(listed - platform, set())
self.assertEqual(listed - platform - (listed - built), set())
self.assertEqual(platform - built - {"lexaloffle", "mpv", "vox_official"}, set())
if __name__ == "__main__":
+2
View File
@@ -207,6 +207,8 @@ class APlatformEntryTakesNoOtherEmulatorsTree(unittest.TestCase):
config = load_platform_config("emuelec", str(REPO_ROOT / "platforms"))
entry = config["systems"]["vvvvvv"]["files"][0]
# No image builds the VVVVVV port engine, but es_systems.json still
# names it for the system: its tree is the one the entry asks for.
self.assertEqual(entry["platform_cores"], ["VVVVVV"])
db = load_database(str(REPO_ROOT / "database.json"))
path, _status = resolve_local_file(
+1 -1
View File
@@ -338,7 +338,7 @@ KNOWN_UNRESOLVED = {
"the program's profile lacks the system"),
# Not settled: two builds by host, a binary the OS tree lacks, a fork
# whose required files differ, a shell variable the scraper kept.
**dict.fromkeys(["pcsx2-nogui", "zx81", "yabadabadoo", "reicast-audio-${backend}"],
**dict.fromkeys(["pcsx2-nogui", "zx81", "reicast-audio-${backend}"],
"not proven"),
}
+102 -1
View File
@@ -433,7 +433,11 @@ class TheDataTreesCountInTheFreeSpace(unittest.TestCase):
member = os.urandom(4096)
results = []
with FakeRepository() as repo, unittest.mock.patch.dict(os.environ):
# The run is a Linux one whatever the host: under WSL main() reads
# the Windows side and keeps that in the module, where the Windows
# detection tests run after it found D:\ turned into /mnt/d.
with FakeRepository() as repo, unittest.mock.patch.dict(os.environ, RETROBIOS_OS="linux"), \
unittest.mock.patch.dict(install._WSL):
listed = json.loads((repo.root / "install" / "retroarch.json").read_text())
listed["data_directories"] = [{
"ref": "tree", "dest": "tree", "type": "zip", "archive_size": 50_000_000,
@@ -1145,6 +1149,103 @@ class StandaloneCopiesReadWhereThePackPutTheFile(unittest.TestCase):
install._validate_manifest(manifest, "emudeck")
class OuterRootsAreUntrusted(unittest.TestCase):
"""roms_directory and emulators_directory come from a downloaded list: each
path in them meets the rules a BIOS destination meets, and each folder
they resolve to stays where the platform's layout puts it."""
ROMS = {"bios_folder": "bios", "from_bios": ".."}
EMULATORS = {
"bios_folder": "bios", "searched": ["frontend/{key}", "emulators/{key}"],
"default": "emulators/{key}", "config": "frontend/launcher.cfg",
}
UNSAFE = ("..\\x", "C:", "C:/x", "..//x", "../", "../x\x01", "x" * 1025)
def test_unsafe_from_bios_is_refused(self):
for value in (*self.UNSAFE, "../../../x", "../x/..", "x", "./x", "/x", "..x", None):
with self.subTest(from_bios=value), self.assertRaises(ValueError):
install._check_relative_directories({"roms_directory": {**self.ROMS, "from_bios": value}})
def test_the_relations_the_rom_folders_files_use_are_accepted(self):
bios = Path("/card/system/bios")
expected = {
".": bios, "..": Path("/card/system"), "../roms": Path("/card/system/roms"),
"../Roms": Path("/card/system/Roms"), "../../Roms": Path("/card/Roms"),
"../../ROMS": Path("/card/ROMS"),
}
for value, root in expected.items():
with self.subTest(from_bios=value):
install._check_relative_directories({"roms_directory": {**self.ROMS, "from_bios": value}})
self.assertEqual(install._relative_root(bios, value), root)
self.assertEqual(install.MAX_ROMS_UPS, 2)
def test_a_list_without_a_roms_root_leaves_the_files_out(self):
files = [{"dest": "pico-8/pico8_64", "root": "roms", "cores": ["x"]}]
kept, left = install.place_relative_entries(files, Path("/card/roms/bios"), {}, "x", say=False)
self.assertEqual((kept, [o["reason"] for o in left]), ([], ["no_roms_directory"]))
def test_unsafe_emulator_folders_are_refused(self):
for field in ("searched", "default", "config"):
for value in self.UNSAFE + ("../{key}", "/abs/{key}"):
layout = dict(self.EMULATORS)
if field == "searched":
layout["searched"] = [value if "{key}" in value else value + "/{key}"]
layout["default"] = layout["searched"][0]
elif field == "default":
layout["default"] = value
else:
layout["config"] = value
with self.subTest(field=field, value=value), self.assertRaises(ValueError):
install._check_emulators_directory({"emulators_directory": layout})
def test_a_drive_or_colon_segment_is_refused_on_either_host(self):
from pathlib import PureWindowsPath
bios = PureWindowsPath("C:/RetroBat/bios")
for host in ("posix", "nt"):
with unittest.mock.patch.object(install.os, "name", host):
for value in ("../C:x", "..\\x", "../x:", "../Roms:x"):
with self.subTest(host=host, from_bios=value), self.assertRaises(ValueError):
install._check_relative_directories(
{"roms_directory": {**self.ROMS, "from_bios": value}})
for value in ("C:x/{key}", "x:/{key}", "emu:x/{key}"):
layout = {**self.EMULATORS, "searched": [value], "default": value}
with self.subTest(host=host, searched=value), self.assertRaises(ValueError):
install._check_emulators_directory({"emulators_directory": layout})
for dest in ("bios/C:x.bin", "bios/x:", "a:b/c.bin"):
with self.subTest(host=host, dest=dest), self.assertRaises(ValueError):
install._safe_relative_path(dest, "dest")
with self.subTest(host=host), self.assertRaises(ValueError):
install._safe_relative_path("pico8/x:y", "dest", colons=False)
# Each of these leaves the folder on Windows once joined.
self.assertEqual(PureWindowsPath(bios, "..", "D:x"), PureWindowsPath("D:x"))
self.assertEqual(PureWindowsPath("C:x").drive, "C:")
# RetroDECK's ares names are kept where the host is not Windows.
with unittest.mock.patch.object(install.os, "name", "posix"):
install._safe_relative_path("bios/snes:st018.data.rom", "dest")
with unittest.mock.patch.object(install.os, "name", "nt"), self.assertRaises(ValueError):
install._safe_relative_path("bios/snes:st018.data.rom", "dest")
def test_an_emulator_folder_stays_below_the_platform_folder(self):
with tempfile.TemporaryDirectory() as tmp:
home = Path(tmp)
(home / "bios").mkdir()
(home / "frontend").mkdir()
(home / "frontend" / "launcher.cfg").write_text("")
manifest = {"emulators_directory": self.EMULATORS}
for dest in ("../x/prog", "C:/prog", "prog\\..\\..\\x/a"):
with self.subTest(dest=dest), self.assertRaises(ValueError):
install.place_emulator_entries(
[{"dest": dest, "root": "emulators"}], home / "bios", manifest, "x",
say=False)
kept, left = install.place_emulator_entries(
[{"dest": "prog/prog.exe", "root": "emulators"}], home / "bios", manifest, "x",
say=False)
self.assertEqual((len(kept), left), (1, []))
folder, rest = install._entry_place(home / "bios", kept[0])
self.assertEqual((folder, rest), (home / "emulators" / "prog", "prog.exe"))
class DetectionFollowsTheRegistry(unittest.TestCase):
"""The registry declared RetroPie at ~/RetroPie/BIOS and BizHawk at
~/.config/BizHawk/Firmware, every manifest published it, and the
+95
View File
@@ -113,6 +113,83 @@ class NarrowToCores(unittest.TestCase):
)
class ACoreOnlyTheDownloaderBrings(unittest.TestCase):
"""Batocera builds amiberry standalone on every board, and only its
x86_64 RetroArch downloads the amiberry core: both answer to amiberry
in a board's core list. The builder reads the downloader's reach
(resolve_platform_cores) and the list carries it in downloaded_cores."""
MANIFEST = {
"core_names": {"amiberry": [], "amiberry-7": ["amiberry"]},
"downloaded_cores": {"amiberry": ["x86_64", "pc"]},
"system_cores": {"commodore-amiga": ["amiberry", "amiberry-7"]},
"files": [
{"dest": "kick31.rom", "cores": ["amiberry-7"], "systems": ["commodore-amiga"]},
{"dest": "roms/a4091.rom", "cores": ["amiberry"], "systems": ["commodore-amiga"]},
],
"omitted_files": [],
}
def test_a_board_without_the_download_keeps_its_own_build(self):
files, _ = install.narrow_to_cores(self.MANIFEST, ["amiberry"], target="bcm2711")
self.assertEqual([f["dest"] for f in files], ["kick31.rom"])
def test_a_board_or_its_alias_with_the_download_keeps_both(self):
for target in ("x86_64", "pc"):
with self.subTest(target=target):
files, _ = install.narrow_to_cores(self.MANIFEST, ["amiberry"], target=target)
self.assertEqual([f["dest"] for f in files], ["kick31.rom", "roms/a4091.rom"])
def test_an_installed_core_is_no_board(self):
files, _ = install.narrow_to_cores(self.MANIFEST, ["amiberry"])
self.assertEqual([f["dest"] for f in files], ["kick31.rom", "roms/a4091.rom"])
class ACoreTheListDoesNotKnow(unittest.TestCase):
"""A core newer than the list (parallel_dc, issue 87) loses nothing its .info declares."""
def setUp(self):
self.tmp = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp"))
self.addCleanup(shutil.rmtree, self.tmp, True)
def test_only_names_no_profile_answers_for(self):
self.assertEqual(
install.unknown_cores(MANIFEST, ["mednafen_psx", "pcsx_rearmed", "mgba",
"parallel_dc"]),
["parallel_dc"],
)
def test_the_info_paths_retroarch_reads(self):
(self.tmp / "parallel_dc_libretro.info").write_text(
'firmware_count = 3\n'
'firmware0_desc = "dc/dc_boot.bin (Dreamcast BIOS)"\n'
'firmware0_path = "dc/dc_boot.bin"\n'
'firmware1_path = dc\\naomi.zip\n'
'firmware2 = "ignored.bin"\n'
)
self.assertEqual(
install.info_firmware([self.tmp / "missing", self.tmp], "parallel_dc"),
["dc/dc_boot.bin", "dc/naomi.zip"],
)
self.assertIsNone(install.info_firmware([self.tmp], "odin"))
def test_the_config_names_the_info_folder(self):
(self.tmp / "retroarch.cfg").write_text('libretro_info_path = "default"\n')
self.assertEqual(
install.info_dirs("retroarch", self.tmp / "system", [self.tmp / "cores"]),
[self.tmp / "info", self.tmp / "cores"],
)
def test_its_declared_files_survive_the_narrowing(self):
files, _ = install.narrow_to_cores(
MANIFEST, ["mednafen_psx"], declared_by_info=["GBA_BIOS.bin", "mgba/extra.bin"])
self.assertEqual(
[f["dest"] for f in files],
["scph5501.bin", "gba_bios.bin", "unlisted.bin", "psx/extra.bin",
"mgba/extra.bin"],
)
class TheBuildersOrder(unittest.TestCase):
"""RetroPie reads megaplay.zip as advancemame (copy A), mame (copy B),
then mame2003 (copy A). Without advancemame the builder ships mame's
@@ -490,6 +567,24 @@ class TheOneLinerReadsInstalledCores(unittest.TestCase):
repo.installed(), ["pcsx/extra.bin", "scph5500.bin", "scph5501.bin"]
)
def test_a_core_the_list_does_not_know_keeps_its_info_files(self):
with _CoreRepository() as repo:
repo.install_core("pcsx_rearmed_neon")
repo.install_core("newgba")
(repo.root / "cores" / "newgba_libretro.info").write_text(
'firmware0_path = "gba_bios.bin"\n')
repo.install_core("noinfo")
proc = repo.run("--installed-cores")
self.assertEqual(proc.returncode, 0, proc.stdout + proc.stderr)
self.assertIn("newgba: a core this list does not know, 1 file its .info "
"declares kept", proc.stdout)
self.assertIn("noinfo: a core this list does not know, with no .info",
proc.stdout)
self.assertEqual(
repo.installed(),
["gba_bios.bin", "pcsx/extra.bin", "scph5500.bin", "scph5501.bin"],
)
def test_no_core_found_is_an_error_not_everything(self):
with _CoreRepository() as repo:
proc = repo.run("--installed-cores")
+9 -1
View File
@@ -984,6 +984,14 @@ class InstallMatchesATargetManifest(unittest.TestCase):
("batocera", "bcm2711"),
("retropie", "rpi4"),
("emudeck", "steamos"),
# A core only Batocera's x86_64 downloader brings, a missing file two
# cores read, a file another emulator installs itself, and a name a
# launcher opens that another core's copy used to fill.
("batocera", "jh7110"),
("knulli", "h700"),
("rocknix", "sdm845"),
("retropie", "x86"),
("retropie", "rpi1"),
)
@classmethod
@@ -1015,7 +1023,7 @@ class InstallMatchesATargetManifest(unittest.TestCase):
))
full = self._manifest(platform)
built = self._manifest(platform, set(cores), target)
files, omitted = install.narrow_to_cores(full, cores)
files, omitted = install.narrow_to_cores(full, cores, target=target)
# A case-insensitive platform reads one file under both
# spellings (BlastEm's 32X_M_BIOS.bin, PicoDrive's .BIN).
from common import load_platform_config
+2 -1
View File
@@ -57,7 +57,8 @@ NAMED_FOR_A_LAUNCHER = {
# Profiles whose entries still rest on a launcher, with the fact that blocks
# reading the emulator itself.
LAUNCHER_SOURCED = {
"lexaloffle": "PICO-8 and Voxatron are sold binaries, and no copy of either is held to read",
"lexaloffle": "PICO-8 is a sold binary, and no copy is held to read",
"voxatron": "Voxatron is a sold binary, and no copy is held to read",
}
_SENTENCE = re.compile(r"(?<=[.!?])\s+(?=[A-Z0-9(\"'])")
+323
View File
@@ -0,0 +1,323 @@
"""Names a platform's launch code reads that the collection does not hold.
The gap analysis compared the collection with the platforms' BIOS lists and
the emulator profiles only. PICO-8's pico8_64 went unseen although four
platforms' launchers run it. The fixtures give a synthetic platform launcher
records of every shape the scrapers write: held names, a name only a profile
alias answers, templates, folders and option values, missing names read by
two emulators, and a name held under another casing.
"""
from __future__ import annotations
import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache
import contextlib
import hashlib
import io
import json
import os
import shutil
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
from unittest import mock
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "scripts"))
import yaml # noqa: E402
import verify # noqa: E402
from common import _emulator_profiles_cache, load_emulator_profiles, load_platform_config # noqa: E402
from cross_reference import ( # noqa: E402
LAUNCHER_READS_KEY,
launcher_file_names,
launcher_reads_not_held,
print_launcher_reads,
)
ROOT = Path(__file__).resolve().parent.parent
CONTENT = {
"held.bin": b"HELD_BY_NAME",
"core.bin": b"CORE_FILE_ALIASED",
"Mixed.ROM": b"HELD_UNDER_ONE_CASING",
}
# Kept as a release asset: in database.json, absent from the checkout.
ASSET = ("asset.bin", b"RELEASE_ASSET_BYTES")
def _record(emulator: str, kind: str, names: list[str], **extra: object) -> dict:
return {
"emulator": emulator, "build": "standalone", "kind": kind, "names": names,
"search_dir": "/userdata/bios", "source_ref": f"gen/{emulator}.py:1", **extra,
}
LAUNCHERS = [
_record("heldemu", "names_searched", ["held.bin", "asset.bin"]),
_record("aliasemu", "fixed_name", ["sub/alias.bin"]),
_record("tplemu", "names_searched", ["tos{L}.img"], expands={"L": ["de", "fr"]}),
_record("tplemu", "scans_dir", ["<first file 4-8 MiB>", "nand*{region}*.bin", "pat*.bin"]),
_record("diremu", "links", ["EUR", "keys"]),
_record("diremu", "core_option", ["default"]),
_record("diremu", "passes_path", []),
{"emulator": "pkg", "build": "standalone", "kind": "package", "names": [],
"source_ref": "pkg.sh:1"},
_record("missemu", "names_searched", ["absent.bin"]),
_record("otheremu", "copies", ["absent.bin"]),
_record("altemu", "names_searched", ["alt.bin", "held.bin", "late.bin"]),
_record("pkgemu", "copies", ["shipped.bin"], search_dir="$md_inst"),
{"emulator": "pkgemu", "build": "standalone", "kind": "copies",
"names": ["written.ini"], "source_ref": "pkg.sh:2"},
_record("setemu", "fixed_name", ["setname.bin"], passes_to="command line -romslot"),
_record("aliasemu", "fixed_name", ["alias.bin.rom"]),
_record("setemu", "copies", ["user.sf2"]),
_record("caseemu", "fixed_name", ["mixed.rom"]),
_record("foldemu", "fixed_name", ["MIXED.rom"], case_insensitive=True),
_record("toolemu", "fixed_name", ["tool.exe"], search_dir="<emulatorLauncher folder>",
passes_to="exec"),
_record("labelemu", "core_option", ["labelled.rom (CDZ)"]),
]
class LauncherGapTest(unittest.TestCase):
def setUp(self) -> None:
_emulator_profiles_cache.clear()
self.root = tempfile.mkdtemp()
self.bios_dir = os.path.join(self.root, "bios")
self.platforms_dir = os.path.join(self.root, "platforms")
self.emulators_dir = os.path.join(self.root, "emulators")
for d in (self.bios_dir, self.platforms_dir, self.emulators_dir):
os.makedirs(d)
files: dict[str, dict] = {}
by_md5: dict[str, str] = {}
by_name: dict[str, list[str]] = {}
def add(name: str, data: bytes, write: bool) -> None:
path = os.path.join(self.bios_dir, name)
if write:
Path(path).write_bytes(data)
sha1 = hashlib.sha1(data).hexdigest()
md5 = hashlib.md5(data).hexdigest()
files[sha1] = {"path": path, "name": name, "md5": md5, "sha1": sha1,
"size": len(data), "crc32": ""}
by_md5[md5] = sha1
by_name.setdefault(name, []).append(sha1)
for name, data in CONTENT.items():
add(name, data, write=True)
add(*ASSET, write=False)
self.db = {
"files": files,
"indexes": {"by_md5": by_md5, "by_name": by_name, "by_crc32": {},
"by_path_suffix": {}},
}
platform = {
"platform": "GapTest",
"verification_mode": "md5",
"base_destination": "bios",
"systems": {
"test-sys": {
"files": [{"name": "held.bin", "destination": "held.bin",
"md5": hashlib.md5(CONTENT["held.bin"]).hexdigest(),
"required": True}],
},
},
"launchers": LAUNCHERS,
}
(Path(self.platforms_dir) / "gaptest.yml").write_text(yaml.dump(platform))
(Path(self.platforms_dir) / "_registry.yml").write_text(
yaml.dump({"platforms": {"gaptest": {"config": "gaptest.yml"}}})
)
profiles = {
"aliasemu": {
"emulator": "AliasEmu", "type": "standalone", "systems": ["test-sys"],
"files": [{"name": "core.bin", "aliases": ["alias.bin"], "required": True}],
},
"setemu": {
"emulator": "SetEmu", "type": "standalone", "systems": ["test-sys"],
"files": [{"name": "core.bin", "config_key": "romslot", "required": True},
{"name": "user.sf2", "required": False,
"unsourceable": "user supplied, no canonical file"}],
},
"missemu": {
"emulator": "MissEmu", "type": "standalone", "systems": ["test-sys"],
"files": [{"name": "absent.bin", "required": True, "md5": "0" * 32}],
},
}
for key, profile in profiles.items():
(Path(self.emulators_dir) / f"{key}.yml").write_text(yaml.dump(profile))
self.config = load_platform_config("gaptest", self.platforms_dir)
self.profiles = load_emulator_profiles(self.emulators_dir)
def tearDown(self) -> None:
shutil.rmtree(self.root)
def _rows(self, configs: dict[str, dict] | None = None, emulator: str = "") -> dict:
rows = launcher_reads_not_held(
configs or {"gaptest": self.config}, self.db, self.profiles, {}, emulator
)
return {(r["platform"], r["name"]): r for r in rows}
def test_a_program_of_the_launcher_itself_is_not_reported(self) -> None:
"""RetroBat runs its own xbox-iso-vfs.exe to mount an Xbox disc
image: part of the platform, no file to collect."""
self.assertNotIn("tool.exe", {name for _, name in self._rows()})
def test_a_held_name_is_not_reported(self) -> None:
names = {name for _, name in self._rows()}
self.assertNotIn("held.bin", names)
def test_a_release_asset_is_held_without_its_bytes(self) -> None:
"""The database answers for a file the checkout does not carry."""
self.assertFalse(os.path.exists(os.path.join(self.bios_dir, "asset.bin")))
self.assertNotIn("asset.bin", {name for _, name in self._rows()})
def test_a_profile_alias_covers_a_launcher_name(self) -> None:
"""alias.bin is the name core.bin's profile entry also answers to."""
self.assertNotIn("sub/alias.bin", {name for _, name in self._rows()})
def test_templates_folders_and_option_values_are_skipped(self) -> None:
for record in LAUNCHERS:
if record["emulator"] in ("tplemu", "diremu", "pkg"):
self.assertEqual(launcher_file_names(record), [], record)
reported = {r["emulators"][0] for r in self._rows().values()}
self.assertFalse(reported & {"tplemu", "diremu", "pkg"})
def test_a_search_with_one_held_name_reads_nothing_missing(self) -> None:
"""The launcher keeps the first name it finds, so the held one fills it."""
names = {name for _, name in self._rows()}
self.assertFalse(names & {"alt.bin", "late.bin"})
def test_a_copy_from_the_platform_package_is_not_owed(self) -> None:
"""RetroPie copies lr-vecx's system.bin from $md_inst and writes mame.ini."""
names = {name for _, name in self._rows()}
self.assertFalse(names & {"shipped.bin", "written.ini"})
def test_a_name_with_an_appended_extension_is_held(self) -> None:
"""ROCKNIX's kick34005.A500.rom is Amiberry's kick34005.A500."""
self.assertNotIn("alias.bin.rom", {name for _, name in self._rows()})
def test_a_name_its_reader_declares_unsourceable_is_counted_apart(self) -> None:
"""RetroBat copies any SoundFont saved as Roland_SC-88.sf2: not a
file to find, yet never dropped silently."""
row = self._rows()[("gaptest", "user.sf2")]
self.assertEqual(row["unsourceable"], "user supplied, no canonical file")
out = io.StringIO()
with contextlib.redirect_stdout(out):
print_launcher_reads(list(self._rows().values()))
text = out.getvalue()
self.assertIn("Launcher reads, not held: 3 names", text)
self.assertIn("Launcher reads, unsourceable: 1 names across 1 platform", text)
self.assertIn("gaptest: user.sf2 [setemu, gen/setemu.py:1]: user supplied, no canonical file",
text)
held_part = text.split("Launcher reads, unsourceable")[0]
self.assertNotIn("user.sf2", held_part)
def test_a_name_handed_to_a_held_entry_setting_is_held(self) -> None:
self.assertNotIn("setname.bin", {name for _, name in self._rows()})
def test_a_label_after_the_name_is_dropped(self) -> None:
self.assertEqual(launcher_file_names(LAUNCHERS[-1]), ["labelled.rom"])
self.assertIn(("gaptest", "labelled.rom"), self._rows())
def test_a_missing_name_is_reported_once_per_platform(self) -> None:
rows = self._rows()
row = rows[("gaptest", "absent.bin")]
self.assertEqual(row["emulators"], ["missemu", "otheremu"])
self.assertEqual(
[(r["kind"], r["source_ref"]) for r in row["readers"]],
[("names_searched", "gen/missemu.py:1"), ("copies", "gen/otheremu.py:1")],
)
self.assertEqual(row["readers"][0]["profiles"], ["missemu"])
self.assertNotIn("held_as", row)
self.assertEqual(sum(1 for _, name in rows if name == "absent.bin"), 1)
def test_each_platform_reports_its_own_row(self) -> None:
rows = self._rows({"gaptest": self.config, "second": self.config})
self.assertIn(("gaptest", "absent.bin"), rows)
self.assertIn(("second", "absent.bin"), rows)
def test_an_emulator_keeps_its_own_records(self) -> None:
rows = self._rows(emulator="missemu")
self.assertEqual(list(rows), [("gaptest", "absent.bin")])
self.assertEqual(rows[("gaptest", "absent.bin")]["emulators"], ["missemu"])
def test_another_casing_satisfies_only_a_folding_launcher(self) -> None:
rows = self._rows()
self.assertEqual(rows[("gaptest", "mixed.rom")]["held_as"], "Mixed.ROM")
self.assertEqual(rows[("gaptest", "mixed.rom")]["emulators"], ["caseemu"])
self.assertNotIn(("gaptest", "MIXED.rom"), rows)
def test_a_folding_filesystem_folds_every_record(self) -> None:
config = {**self.config, "case_insensitive_fs": True}
self.assertNotIn(("gaptest", "mixed.rom"), self._rows({"gaptest": config}))
def test_the_text_report_names_the_category(self) -> None:
out = io.StringIO()
with contextlib.redirect_stdout(out):
print_launcher_reads(list(self._rows().values()))
text = out.getvalue()
self.assertIn("Launcher reads, not held: 3 names across 1 platform", text)
self.assertIn("absent.bin [missemu, otheremu, names_searched, gen/missemu.py:1]", text)
def test_json_carries_the_category_apart(self) -> None:
db_path = Path(self.root) / "database.json"
db_path.write_text(json.dumps(self.db))
result = subprocess.run(
[sys.executable, "scripts/cross_reference.py", "--platform", "gaptest",
"--platforms-dir", self.platforms_dir, "--emulators-dir", self.emulators_dir,
"--db", str(db_path), "--json"],
cwd=ROOT, capture_output=True, text=True, timeout=300,
)
self.assertEqual(result.returncode, 0, result.stderr)
report = json.loads(result.stdout)
names = {r["name"] for r in report[LAUNCHER_READS_KEY]}
self.assertEqual(names, {"absent.bin", "mixed.rom", "labelled.rom", "user.sf2"})
# The emulator rows keep their own shape and counts.
self.assertEqual(set(report) - {LAUNCHER_READS_KEY}, {"aliasemu", "missemu", "setemu"})
def test_verify_counts_and_exit_code_are_unchanged(self) -> None:
"""A launcher name is reported, not judged: nothing else moves."""
with_rows = verify.verify_platform(
self.config, self.db, self.emulators_dir, self.profiles, data_dir_registry={}
)
with mock.patch.object(verify, "launcher_reads_not_held", return_value=[]):
without = verify.verify_platform(
self.config, self.db, self.emulators_dir, self.profiles,
data_dir_registry={},
)
rows = with_rows.pop("launcher_reads_not_held")
without.pop("launcher_reads_not_held")
self.assertEqual({r["name"] for r in rows},
{"absent.bin", "mixed.rom", "labelled.rom", "user.sf2"})
self.assertEqual(with_rows, without)
def exit_code(result: dict) -> int:
try:
with contextlib.redirect_stderr(io.StringIO()):
verify._exit_if_strict(True, [result])
except SystemExit as exc:
return int(exc.code or 0)
return 0
self.assertEqual(exit_code({**with_rows, "launcher_reads_not_held": rows}),
exit_code(without))
def test_verify_prints_a_count_and_lists_on_verbose(self) -> None:
result = verify.verify_platform(
self.config, self.db, self.emulators_dir, self.profiles, data_dir_registry={}
)
for verbose, expected in ((False, "(--verbose lists them)"), (True, "absent.bin")):
out = io.StringIO()
with contextlib.redirect_stdout(out):
verify.print_platform_result(result, ["GapTest"], verbose=verbose)
self.assertIn("Launcher reads, not held: 3", out.getvalue())
self.assertIn(expected, out.getvalue())
if __name__ == "__main__":
unittest.main()
+103 -1
View File
@@ -24,7 +24,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "scripts"))
import yaml # noqa: E402
from common import _emulator_profiles_cache, load_emulator_profiles, load_platform_config # noqa: E402
from launchers import LauncherLayer, launcher_places # noqa: E402
from launchers import LauncherLayer, launcher_places, suffixed_stem # noqa: E402
from verify import find_undeclared_files, verify_platform # noqa: E402
CONTENT = {
@@ -252,6 +252,108 @@ class LauncherLayerTest(unittest.TestCase):
self.assertNotIn("core.bin", {u["name"] for u in self._report()})
self.assertNotIn("core.bin", self._pack_names())
def test_a_file_handed_to_an_entry_setting_takes_the_entry_content(self) -> None:
"""RetroPie runs sdl2trs with `-romfile4p $biosdir/level4p.rom` and
EmuDeck writes a No-Intro name into ares's NeoGeoPocket firmware
setting: neither name is the core's, and the held file of the entry
that setting reads went in under no name at all."""
profile = {
"emulator": "FixEmu", "type": "standalone", "systems": ["test-sys"],
"files": [{"name": "core.bin", "required": True, "config_key": "romslot"},
{"name": "other.bin", "required": True, "config_key": "otherslot"}],
}
with open(os.path.join(self.emulators_dir, "fixemu.yml"), "w") as fh:
yaml.dump(profile, fh)
self.config["launchers"][2]["names"] = ["launcher.rom"]
self.config["launchers"][2]["passes_to"] = "command line -romslot"
_emulator_profiles_cache.clear()
self.profiles = load_emulator_profiles(self.emulators_dir)
added = {u["path"]: u for u in self._report() if u.get("launcher")}
self.assertEqual(added["launcher.rom"]["launcher_of"], "core.bin")
self.assertEqual(added["launcher.rom"]["md5"], _md5(CONTENT["core.bin"]))
self.assertIn("launcher.rom", self._pack_names())
def test_a_fixed_name_with_an_appended_extension_takes_the_entry(self) -> None:
"""ROCKNIX passes kick34005.A500.rom to Amiberry, which names
Kickstart 1.3 kick34005.A500: the pack shipped nothing under it."""
profile = {
"emulator": "FixEmu", "type": "standalone", "systems": ["test-sys"],
"files": [{"name": "core.bin", "aliases": ["kick.A500"], "required": True}],
}
with open(os.path.join(self.emulators_dir, "fixemu.yml"), "w") as fh:
yaml.dump(profile, fh)
self.config["launchers"][2]["names"] = ["kick.A500.rom"]
_emulator_profiles_cache.clear()
self.profiles = load_emulator_profiles(self.emulators_dir)
added = {u["path"]: u for u in self._report() if u.get("launcher")}
self.assertEqual(added["kick.A500.rom"]["md5"], _md5(CONTENT["core.bin"]))
self.assertIsNone(suffixed_stem("scph1001.bin"))
def test_an_entry_the_platform_declares_still_fills_the_launcher_name(self) -> None:
"""AmberELEC declares kick34005.A500, so the report never offers
Amiberry's entry, and its config still passes kick34005.A500.rom."""
profile = {
"emulator": "FixEmu", "type": "standalone", "systems": ["test-sys"],
"files": [{"name": "core.bin", "aliases": ["kick.A500"], "required": True}],
}
with open(os.path.join(self.emulators_dir, "fixemu.yml"), "w") as fh:
yaml.dump(profile, fh)
self.config["launchers"][2]["names"] = ["kick.A500.rom"]
self.config["systems"]["test-sys"]["files"].append(
{"name": "core.bin", "destination": "core.bin", "required": True}
)
_emulator_profiles_cache.clear()
self.profiles = load_emulator_profiles(self.emulators_dir)
added = {u["path"]: u for u in self._report() if u.get("launcher")}
self.assertEqual(added["kick.A500.rom"]["md5"], _md5(CONTENT["core.bin"]))
def test_each_name_of_a_config_takes_its_own_key(self) -> None:
"""AmberELEC's atari800.cfg names eight ROMs under eight keys, and
one record describes them in order: 5200a.rom is ROM_5200_A's file,
not every key's."""
config = {"base_destination": "bios", "launchers": [{
"emulator": "e", "build": "libretro", "kind": "fixed_name",
"names": ["a.rom", "b.rom"], "search_dir": "/storage/roms/bios",
"passes_to": "e.cfg ROM_A, ROM_B", "source_ref": "e.cfg:1",
}]}
places = {p.paths[0]: p.passes_to for p in launcher_places(config)}
self.assertEqual(places, {"a.rom": "e.cfg ROM_A", "b.rom": "e.cfg ROM_B"})
def test_a_core_option_names_the_dump_of_a_model(self) -> None:
"""RetroDECK sets LRPS2's pcsx2_bios to scph10000.bin. LRPS2's entry
is a placeholder for every BIOS its scan finds, and the catalogues
name two revisions of the SCPH-10000: the earlier goes in."""
older, newer = b"S" * 64, b"T" * 64
for data, catalogue in ((newer, "ps2-0101j-20000217.bin"),
(older, "ps2-0100j-20000117.bin")):
sha1 = hashlib.sha1(data).hexdigest()
path = os.path.join(self.bios_dir, catalogue)
with open(path, "wb") as fh:
fh.write(data)
self.db["files"][sha1] = {
"path": path, "name": catalogue, "md5": _md5(data), "sha1": sha1,
"size": len(data), "crc32": "",
"provenance": {"redump": {"name": catalogue,
"description": "SCPH-10000 (Version 5.0)"}},
}
profile = {
"emulator": "OptEmu", "type": "libretro", "systems": ["test-sys"],
"files": [{"name": "<bios>.bin", "path": "ps2/bios/<bios>.bin", "required": True,
"min_size": 32, "max_size": 64, "validation": ["size"],
"config_key": "emu_bios"}],
}
with open(os.path.join(self.emulators_dir, "optemu.yml"), "w") as fh:
yaml.dump(profile, fh)
self.config["launchers"].append({
"emulator": "retroarch", "build": "libretro", "kind": "core_option",
"names": ["scph10000.bin"], "passes_to": "core option emu_bios",
"source_ref": "core-options.cfg:515",
})
_emulator_profiles_cache.clear()
self.profiles = load_emulator_profiles(self.emulators_dir)
added = {u["path"]: u for u in self._report() if u.get("launcher")}
self.assertEqual(added["ps2/bios/scph10000.bin"]["md5"], _md5(older))
def test_the_default_name_a_launcher_replaces_is_not_packed(self) -> None:
"""EmuDeck passes Complex_4627v1.03.bin to xemu, which then never
opens Complex_4627.bin: the pack carried both, one read by nobody."""
+366
View File
@@ -0,0 +1,366 @@
"""Folders a platform's launcher hands an emulator, read from its code.
Batocera patches Citron's path code to read its keys from /userdata/bios/
switch and starts shadPS4 from /userdata/system/configs/shadps4, KNULLI sets
suyu's XDG data folder, and RetroBat creates a portable user folder beside
Citron and shadPS4. Each fixture is a cut-down copy of the lines at the
revisions the platform files pin, and a binding reads the record the
extractor writes.
"""
from __future__ import annotations
import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache
import sys
import textwrap
import unittest
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT / "scripts"))
from launchers import handed_directories, standalone_bindings # noqa: E402
from scraper import retrobat_launchers as rl # noqa: E402
from scraper.batocera_launchers import ( # noqa: E402
GENERATORS,
IMPORTER,
PATHS_MODULE,
Configgen,
LauncherShapeError,
patched_paths,
working_directories,
)
PATCH = "package/batocera/emulators/citron/002-adjust-paths.patch"
PATCH_TEXT = textwrap.dedent("""\
diff --git a/src/common/fs/path_util.cpp b/src/common/fs/path_util.cpp
index f92cbe0f7b..9e3dcd9c18 100644
--- a/src/common/fs/path_util.cpp
+++ b/src/common/fs/path_util.cpp
@@ -121,12 +121,12 @@ public:
GenerateCitronPath(CitronPath::ConfigDir, citron_path_config);
GenerateCitronPath(CitronPath::DumpDir, citron_path / DUMP_DIR);
- GenerateCitronPath(CitronPath::KeysDir, citron_path / KEYS_DIR);
+ GenerateCitronPath(CitronPath::KeysDir, "/userdata/bios/switch");
- GenerateCitronPath(CitronPath::LogDir, citron_path / LOG_DIR);
+ GenerateCitronPath(CitronPath::LogDir, "/userdata/system/logs");
""")
PATHS = """from pathlib import Path
from typing import Final
USERDATA: Final = Path('/userdata')
BIOS: Final = USERDATA / 'bios'
SAVES: Final = USERDATA / 'saves'
CONFIGS: Final = USERDATA / 'system' / 'configs'
"""
IMPORTER_TEXT = """_LEGACY_GENERATOR_MAP = {}
_GENERATOR_MAP = {}
"""
SHADPS4 = f"{GENERATORS}/shadps4/shadps4Generator.py"
SHADPS4_TEXT = textwrap.dedent("""\
import os
from ...batoceraPaths import CONFIGS
class ShadPS4Generator:
def generate(self, system, rom):
configPath = CONFIGS / "shadps4"
userConfigPath = configPath / "user"
os.chdir(configPath)
return None
""")
def records(entries: list) -> list[dict]:
return [entry.entry() if hasattr(entry, "entry") else entry for entry in entries]
class APatchRewritingAFolder(unittest.TestCase):
def test_the_bios_folder_a_patch_gives_is_a_record(self):
(record,) = records(patched_paths({PATCH: PATCH_TEXT}.__getitem__))
self.assertEqual(
(record["emulator"], record["kind"], record["search_dir"], record["source_ref"]),
("citron", "passes_path", "/userdata/bios/switch", f"{PATCH}:8-9"),
)
self.assertIn("CitronPath::KeysDir", record["passes_to"])
self.assertIn("citron_path / KEYS_DIR", record["passes_to"])
def test_a_patch_that_no_longer_rewrites_a_bios_folder_stops_the_scrape(self):
text = PATCH_TEXT.replace('"/userdata/bios/switch"', '"/userdata/saves/switch"')
with self.assertRaises(LauncherShapeError):
patched_paths({PATCH: text}.__getitem__)
def test_the_named_handle_binds_its_folder_alone(self):
config = {"base_destination": "bios", "standalone_cores": ["citron"], "launchers":
records(patched_paths({PATCH: PATCH_TEXT}.__getitem__))}
found = standalone_bindings(
{"citron"}, ["$XDG_DATA_HOME/citron", "CitronPath::KeysDir = keys"],
handed_directories(config),
)
self.assertEqual(found, {"keys": ("", "switch")})
class AFolderTheGeneratorEnters(unittest.TestCase):
def tree(self, text: str = SHADPS4_TEXT) -> Configgen:
files = {PATHS_MODULE: PATHS, IMPORTER: IMPORTER_TEXT, SHADPS4: text}
return Configgen(files.__getitem__)
def test_the_working_directory_is_a_record(self):
(record,) = records(working_directories(self.tree()))
self.assertEqual(
(record["emulator"], record["search_dir"], record["passes_to"], record["source_ref"]),
("shadps4", "/userdata/system/configs/shadps4",
"working directory of shadps4Generator.py", f"{SHADPS4}:6, 8"),
)
def test_a_generator_that_no_longer_enters_a_folder_stops_the_scrape(self):
with self.assertRaises(LauncherShapeError):
working_directories(self.tree(SHADPS4_TEXT.replace("os.chdir(configPath)", "pass")))
def test_the_user_folder_below_it_is_outside_the_bios_tree(self):
config = {"base_destination": "bios", "standalone_cores": ["shadps4"],
"launchers": records(working_directories(self.tree()))}
found = standalone_bindings(
{"shadps4"}, ["getcwd/user", "$XDG_DATA_HOME/shadPS4"], handed_directories(config)
)
self.assertEqual(found, {"": ("outside", "")})
class AVariableADeclaredFolderIsSpelledFrom(unittest.TestCase):
def test_a_data_folder_outside_the_tree_binds_outside(self):
record = {"emulator": "emu", "build": "standalone", "kind": "passes_path",
"names": [], "search_dir": "/userdata/saves/switch",
"passes_to": "environment XDG_DATA_HOME", "source_ref": "x.py:1"}
config = {"base_destination": "bios", "standalone_cores": ["emu"], "launchers": [record]}
found = standalone_bindings(
{"emu"}, ["$XDG_DATA_HOME/emu"], handed_directories(config)
)
self.assertEqual(found, {"": ("outside", "")})
def test_a_data_folder_in_the_tree_binds_below_it(self):
record = {"emulator": "emu", "build": "standalone", "kind": "passes_path",
"names": [], "search_dir": "/userdata/bios/data",
"passes_to": "environment XDG_DATA_HOME", "source_ref": "x.py:1"}
config = {"base_destination": "bios", "standalone_cores": ["emu"], "launchers": [record]}
found = standalone_bindings(
{"emu"}, ["$XDG_DATA_HOME/emu"], handed_directories(config)
)
self.assertEqual(found, {"": ("", "data/emu")})
class APortableUserFolder(unittest.TestCase):
CITRON = """
public override System.Diagnostics.ProcessStartInfo Generate(string system, string emulator, string core, string rom, string playersControllers, ScreenResolution resolution)
{
if (!GetEmulatorPathAndExe(emulator, out string path, out string exe, "citron.exe"))
return null;
// Ensure user folder exists
string userFolder = Path.Combine(path, "user");
if (!Directory.Exists(userFolder)) try { Directory.CreateDirectory(userFolder); }
catch { }
}
"""
SHADPS4 = """
public override System.Diagnostics.ProcessStartInfo Generate(string system, string emulator, string core, string rom, string playersControllers, ScreenResolution resolution)
{
string path = AppConfig.GetFullPath(emulator);
}
private void SetupConfigurationJSON(string path, string rom)
{
string userFolder = Path.Combine(path, "user");
if (!Directory.Exists(userFolder))
try { Directory.CreateDirectory(userFolder); } catch { }
}
"""
RYUJINX = """
public override System.Diagnostics.ProcessStartInfo Generate(string system, string emulator, string core, string rom, string playersControllers, ScreenResolution resolution)
{
string path = AppConfig.GetFullPath("ryujinx");
string portablePath = Path.Combine(AppConfig.GetFullPath("saves"), "switch", "ryujinx", "portable");
string setupPath = Path.Combine(path, "portable");
}
"""
def sources(self) -> dict[str, rl.Source]:
def source(ref: str, text: str) -> rl.Source:
return rl.Source(ref, textwrap.dedent(text).lstrip("\n"))
def yuzu_like(exe: str) -> str:
return self.CITRON.replace("citron.exe", exe)
return {
f"{rl.GENERATORS}/Citron.Generator.cs": source("c", self.CITRON),
f"{rl.GENERATORS}/Eden.Generator.cs": source("e", yuzu_like("eden.exe")),
f"{rl.GENERATORS}/Ryujinx.Generator.cs": source("r", self.RYUJINX),
f"{rl.GENERATORS}/ShadPS4.Generator.cs": source("s", self.SHADPS4),
f"{rl.GENERATORS}/Sudachi.Generator.cs": source("u", yuzu_like("sudachi.exe")),
f"{rl.GENERATORS}/Yuzu.Generator.cs": source("y", yuzu_like("yuzu.exe")),
}
def test_each_generator_gives_its_user_folder(self):
found = rl.portable_users(self.sources())
self.assertEqual(
[(r["emulator"], r["search_dir"], r["source_ref"]) for r in found],
[("citron", '<AppConfig.GetFullPath("citron")>/user', "c:3, 7-8"),
("eden", '<AppConfig.GetFullPath("eden")>/user', "e:3, 7-8"),
("ryujinx", '<AppConfig.GetFullPath("ryujinx")>/portable', "r:3-5"),
("shadps4", '<AppConfig.GetFullPath("shadps4")>/user', "s:3, 8-10"),
("sudachi", '<AppConfig.GetFullPath("sudachi")>/user', "u:3, 7-8"),
("yuzu", '<AppConfig.GetFullPath("yuzu")>/user', "y:3, 7-8")],
)
ryujinx = found[2]
self.assertEqual(ryujinx["passes_to"], "DefaultPortableDir, the portable folder beside Ryujinx.exe")
self.assertEqual(
ryujinx["depends_on_option"], "unless saves/switch/ryujinx/portable exists, passed with -r"
)
def test_the_user_folder_binds_below_the_emulator_folder(self):
config = {
"base_destination": "bios", "standalone_cores": ["citron"],
"emulators_directory": {"launcher_spelling": '<AppConfig.GetFullPath("{key}")>'},
"launchers": rl.portable_users(self.sources())[:1],
}
found = standalone_bindings(
{"citron"}, ["$XDG_DATA_HOME/citron", "PORTABLE_DIR"], handed_directories(config)
)
self.assertEqual(found, {"": ("emulators", "citron/user")})
class OnlyWhatABoardBuildsIsRun(unittest.TestCase):
"""KNULLI's es_systems.yml lists citron and shadps4, which its Config.in
selects only on x86_64 boards (it has none), and its
configgen-defaults.yml picks suyu, which no package builds."""
ES = textwrap.dedent("""\
switch:
emulators:
citron:
citron: { requireAnyOf: [BR2_PACKAGE_CITRON] }
gba:
emulators:
libretro:
mgba: { requireAnyOf: [BR2_PACKAGE_LIBRETRO_MGBA] }
voxatron:
emulators: {}
""")
DEFAULTS = textwrap.dedent("""\
switch:
emulator: suyu
core: suyu
voxatron:
emulator: lexaloffle
core: vox_official
kodi:
emulator: kodi
core: kodi
mpv:
emulator: mpv
core: mpv
""")
LAUNCHERS = [{"emulator": "lexaloffle", "kind": "fixed_name", "passes_to": "exec",
"search_dir": "/userdata/bios"}]
def selection(self, symbols: set[str]):
from scraper.targets.batocera_targets_scraper import BuildSelection
return BuildSelection(
targets={}, emulators=frozenset({"mgba"}),
listed=frozenset({"citron", "mgba"}), symbols=frozenset(symbols),
packages={"kodi": "BR2_PACKAGE_KODI"},
)
def test_only_what_a_board_builds_or_the_user_supplies_is_run(self):
from scraper import batocera_scraper as bs
# A board selects kodi's package and buildroot's mpv. Citron is
# listed by es_systems, so the symbol of a folder of that name does
# not count for it.
built = bs.boards_build(
self.selection({"BR2_PACKAGE_KODI", "BR2_PACKAGE_MPV", "BR2_PACKAGE_CITRON_X"}),
self.LAUNCHERS,
)
cores, standalone, _dual = bs.configgen_cores(self.DEFAULTS, self.ES, set(), built)
self.assertEqual(sorted(cores), ["kodi", "mgba", "mpv", "vox_official"])
self.assertEqual(sorted(standalone), ["kodi", "lexaloffle", "mpv", "vox_official"])
# Each system keeps the list es_systems.yml writes (whose files its
# entries ask for), less a default no package builds.
by_system = bs.es_systems_by_system(self.ES, self.DEFAULTS, set(), built)
self.assertEqual(by_system["switch"], ["citron"])
self.assertEqual(by_system["voxatron"], ["lexaloffle", "vox_official"])
self.assertEqual(by_system["gba"], ["mgba"])
def test_a_listed_name_is_built_only_through_its_packages(self):
from scraper import batocera_scraper as bs
built = bs.boards_build(self.selection({"BR2_PACKAGE_CITRON"}), [])
self.assertFalse(built("citron"))
self.assertTrue(built("mgba"))
self.assertFalse(built("lexaloffle"))
# Without a selection, every name counts, as before.
self.assertIn("suyu", bs.configgen_cores(self.DEFAULTS, self.ES, set())[0])
def test_the_real_lists_name_only_what_a_board_builds(self):
import yaml
for platform, absent in (("knulli", ("suyu", "citron", "shadps4", "pcsx2")),
("batocera", ("citron", "ryujinx", "applewin"))):
config = yaml.safe_load((REPO_ROOT / "platforms" / f"{platform}.yml").read_text())
names = set(config["cores"]) | set(config.get("standalone_cores") or [])
targets = yaml.safe_load(
(REPO_ROOT / "platforms" / "targets" / f"{platform}.yml").read_text())["targets"]
boards = {c for entry in targets.values() for c in entry["cores"]}
with self.subTest(platform=platform):
self.assertFalse(names & set(absent))
# What a board builds and the list once named is still there,
# and what no board builds is a program the user supplies.
self.assertLessEqual(names - boards, {"kodi", "lexaloffle", "mpv", "vox_official"})
class AUserFolderInTheConfigsFolder(unittest.TestCase):
"""Batocera starts shadPS4 from /userdata/system/configs/shadps4, a folder
of the configs root its batoceraPaths builds (../system/configs)."""
def test_the_sys_modules_go_below_the_configs_root(self):
from common import load_emulator_profiles, load_platform_config, platform_layouts
from common import standalone_set
profile = load_emulator_profiles(str(REPO_ROOT / "emulators"))["shadps4"]
# KNULLI's generator does the same, but no KNULLI board builds shadps4.
for platform in ("batocera",):
config = load_platform_config(platform, str(REPO_ROOT / "platforms"))
((view, _standalone),) = platform_layouts("shadps4", profile, standalone_set(config))
with self.subTest(platform=platform):
self.assertEqual(
{(f.get("root"), f["standalone_path"].rsplit("/", 1)[0]) for f in view["files"]},
{("configs", "shadps4/user/sys_modules"), ("configs", "shadps4/user/fonts/font"),
("configs", "shadps4/user/fonts/font2")},
)
def test_the_installer_follows_from_bios_to_the_configs_folder(self):
import install
manifest = {"configs_directory": {"bios_folder": "bios", "from_bios": "../system/configs"}}
install._check_relative_directories(manifest)
files = [{"dest": "shadps4/user/sys_modules/libSceNgs2.sprx", "root": "configs"}]
bios = Path("/userdata/bios")
kept, left = install.place_relative_entries(files, bios, manifest, "x", say=False)
self.assertEqual((len(kept), left), (1, []))
self.assertEqual(
install._entry_place(bios, kept[0])[0], Path("/userdata/system/configs")
)
kept, left = install.place_relative_entries(
files, Path("/elsewhere/firmware"), manifest, "x", say=False)
self.assertEqual((kept, [o["reason"] for o in left]), ([], ["no_configs_directory"]))
for value in ("../C:x", "../../../x", "../system/../x"):
with self.subTest(from_bios=value), self.assertRaises(ValueError):
install._check_relative_directories(
{"configs_directory": {"bios_folder": "bios", "from_bios": value}})
if __name__ == "__main__":
unittest.main()
+557
View File
@@ -0,0 +1,557 @@
"""A platform's launcher moves where an emulator's file lands.
A profile's ``path`` is where the emulator's code reads a file. UAE4All2
reads kickstarts/<name> below its working directory, and RetroPie starts it
in its install directory, whose kickstarts/ it links to BIOS/amiga. The
pack, the manifest and verify all put the file in amiga/ on that platform,
and a platform with no such record keeps the profile's layout.
"""
from __future__ import annotations
import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache
import hashlib
import io
import shutil
import sys
import tempfile
import unittest
import zipfile
from contextlib import redirect_stdout
from pathlib import Path
import yaml
REPO_ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO_ROOT / "scripts"))
from common import ( # noqa: E402
_emulator_profiles_cache,
load_emulator_profiles,
load_platform_config,
platform_layouts,
standalone_set,
)
from generate_pack import generate_manifest, generate_pack # noqa: E402
from verify import verify_platform # noqa: E402
WORKING_DIRECTORY = {
"emulator": "kick", "build": "standalone", "kind": "passes_path", "names": [],
"search_dir": "$md_inst", "passes_to": "working directory of $romdir/amiga/+Start.sh",
"source_ref": "kick.sh:90",
}
LINK = {
"emulator": "kick", "build": "standalone", "kind": "links", "names": [],
"search_dir": "$biosdir/amiga", "passes_to": "$md_inst/kickstarts is a symlink to it",
"source_ref": "kick.sh:79",
}
class ALinkMovesTheDestination(unittest.TestCase):
def setUp(self) -> None:
_emulator_profiles_cache.clear()
(REPO_ROOT / "tmp").mkdir(exist_ok=True)
self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp"))
self.addCleanup(shutil.rmtree, self.root, True)
bios = self.root / "bios" / "Commodore" / "Amiga"
bios.mkdir(parents=True)
files, by_md5, by_name = {}, {}, {}
for name, data in (("kick13.rom", b"KICKSTART 1.3"), ("kick.rom", b"CUSTOM KICKSTART")):
(bios / name).write_bytes(data)
sha1 = hashlib.sha1(data).hexdigest()
md5 = hashlib.md5(data).hexdigest()
files[sha1] = {"path": str(bios / name), "name": name, "sha1": sha1,
"md5": md5, "crc32": "", "size": len(data)}
by_md5[md5] = sha1
by_name[name] = [sha1]
self.db = {
"files": files,
"indexes": {"by_md5": by_md5, "by_name": by_name, "by_crc32": {},
"by_path_suffix": {}},
}
kick13 = by_name["kick13.rom"][0]
self.platforms = self.root / "platforms"
self.emulators = self.root / "emulators"
self.platforms.mkdir()
self.emulators.mkdir()
for name, launchers in (("linkplat", [WORKING_DIRECTORY, LINK]), ("plainplat", [])):
(self.platforms / f"{name}.yml").write_text(yaml.safe_dump({
"platform": name, "version": "1", "verification_mode": "existence",
"base_destination": "BIOS", "cores": ["kick"], "standalone_cores": ["kick"],
"launchers": launchers,
"systems": {"commodore-amiga": {"files": []}},
}))
(self.platforms / "_registry.yml").write_text(yaml.safe_dump({"platforms": {
"linkplat": {"config": "linkplat.yml"}, "plainplat": {"config": "plainplat.yml"},
}}))
(self.emulators / "kick.yml").write_text(yaml.safe_dump({
"emulator": "Kick", "type": "standalone", "cores": ["kick"],
"systems": ["commodore-amiga"],
"standalone_directories": ["getcwd"],
"files": [
{"name": "kick13.rom", "path": "kickstarts/kick13.rom",
"sha1": kick13, "required": False},
# Read in the working directory itself, which the platform
# links nowhere in the BIOS tree.
{"name": "kick.rom", "path": "kick.rom", "required": False},
],
}))
def pack_names(self, platform: str, name: str = "kick13.rom") -> list[str]:
with redirect_stdout(io.StringIO()):
zip_path = generate_pack(
platform, str(self.platforms), self.db, str(self.root / "bios"),
str(self.root / "out" / platform), emulators_dir=str(self.emulators),
offline=True,
)
with zipfile.ZipFile(zip_path) as zf:
return [n for n in zf.namelist() if n.rsplit("/", 1)[-1] == name]
def manifest(self, platform: str) -> dict:
with redirect_stdout(io.StringIO()):
return generate_manifest(
platform, str(self.platforms), self.db, str(self.root / "bios"),
str(self.platforms / "_registry.yml"),
emulators_dir=str(self.emulators), offline=True,
)
def manifest_dests(self, platform: str, name: str = "kick13.rom") -> list[str]:
return [f["dest"] for f in self.manifest(platform)["files"]
if f["dest"].rsplit("/", 1)[-1] == name]
def verify_entries(self, platform: str, name: str = "kick13.rom") -> list[dict]:
config = load_platform_config(platform, str(self.platforms))
result = verify_platform(config, self.db, str(self.emulators))
return [u for u in result["undeclared_files"] if u["name"] == name]
def verify_paths(self, platform: str) -> list[str]:
return [u["path"] for u in self.verify_entries(platform)]
def test_the_link_moves_it_in_pack_manifest_and_verify(self) -> None:
self.assertEqual(self.pack_names("linkplat"), ["amiga/kick13.rom"])
self.assertEqual(self.manifest_dests("linkplat"), ["amiga/kick13.rom"])
self.assertEqual(self.verify_paths("linkplat"), ["amiga/kick13.rom"])
def test_a_platform_without_the_record_is_unchanged(self) -> None:
self.assertEqual(self.pack_names("plainplat"), ["kickstarts/kick13.rom"])
self.assertEqual(self.manifest_dests("plainplat"), ["kickstarts/kick13.rom"])
self.assertEqual(self.verify_paths("plainplat"), ["kickstarts/kick13.rom"])
def test_a_file_outside_every_binding_is_named_never_placed(self) -> None:
self.assertEqual(self.pack_names("linkplat", "kick.rom"), [])
manifest = self.manifest("linkplat")
self.assertEqual(self.manifest_dests("linkplat", "kick.rom"), [])
omitted = [o for o in manifest["omitted_files"] if o["name"] == "kick.rom"]
self.assertEqual(len(omitted), 1)
self.assertEqual(
(omitted[0]["dest"], omitted[0]["root"], omitted[0]["reason"], omitted[0]["cores"]),
("kick.rom", "emulator", "outside_bios_folder", ["kick"]),
)
(entry,) = self.verify_entries("linkplat", "kick.rom")
self.assertFalse(entry["in_pack"])
self.assertIn("outside the BIOS tree", entry["omitted"])
def test_a_root_file_of_another_core_is_not_claimed_by_it(self) -> None:
# Another core reads kick.rom at the BIOS root: kick's own kick.rom,
# in its working directory, is a different place.
for name in ("linkplat", "plainplat"):
path = self.platforms / f"{name}.yml"
data = yaml.safe_load(path.read_text())
data["cores"] = ["kick", "other"]
path.write_text(yaml.safe_dump(data))
(self.emulators / "other.yml").write_text(yaml.safe_dump({
"emulator": "Other", "type": "libretro", "cores": ["other"],
"systems": ["commodore-amiga"],
"files": [{"name": "kick.rom", "path": "kick.rom", "required": False}],
}))
_emulator_profiles_cache.clear()
manifest = self.manifest("linkplat")
(held,) = [f for f in manifest["files"] if f["dest"] == "kick.rom"]
self.assertEqual(held["cores"], ["other"])
omitted = [o for o in manifest["omitted_files"] if o["name"] == "kick.rom"]
self.assertEqual([(o["root"], o["cores"]) for o in omitted], [("emulator", ["kick"])])
def test_two_builds_in_one_folder_are_one_omission(self) -> None:
# RetroPie builds amiberry 5.7.2 and 6.3.3, one per board, both in
# $md_inst of its amiberry package: one place, read by both.
data = yaml.safe_load((self.emulators / "kick.yml").read_text())
for key in ("kick-1", "kick-2"):
(self.emulators / f"{key}.yml").write_text(
yaml.safe_dump({**data, "built_by": ["linkplat"]}))
_emulator_profiles_cache.clear()
omitted = [o for o in self.manifest("linkplat")["omitted_files"]
if o["name"] == "kick.rom"]
self.assertEqual([(o["root"], o["cores"]) for o in omitted],
[("emulator", ["kick-1", "kick-2"])])
def test_the_installer_accepts_the_omission(self) -> None:
import install
manifest = self.manifest("linkplat")
omitted = next(o for o in manifest["omitted_files"] if o["name"] == "kick.rom")
install._check_omission(omitted, omitted["dest"])
# Two emulators reading kick.rom in their own folders read two files.
self.assertNotEqual(
install._entry_key(omitted), install._entry_key({**omitted, "cores": ["other"]})
)
self.assertNotEqual(install._entry_key(omitted), install._entry_key({"dest": "kick.rom"}))
self.assertEqual(install.OMISSION_REASONS[omitted["reason"]], "read outside the BIOS folder")
with self.assertRaises(ValueError):
install._check_root({"root": "emulator"}, "kick.rom")
install._check_root(omitted, "kick.rom", omitted=True)
def test_without_relocation_the_root_file_stays_at_the_root(self) -> None:
self.assertEqual(self.pack_names("plainplat", "kick.rom"), ["kick.rom"])
def test_the_link_alone_binds_nothing(self) -> None:
# Without the working directory the link's $md_inst is not the
# directory the profile's paths are relative to.
config = {"standalone_cores": ["kick"], "launchers": [LINK]}
profile = load_emulator_profiles(str(self.emulators))["kick"]
(view, standalone), = platform_layouts("kick", profile, standalone_set(config))
self.assertTrue(standalone)
self.assertNotIn("standalone_path", view["files"][0])
class UAE4AllOnRetroPie(unittest.TestCase):
"""The real profile against the real launcher records."""
def test_kickstarts_land_in_amiga(self) -> None:
profile = load_emulator_profiles(str(REPO_ROOT / "emulators"))["uae4all"]
config = load_platform_config("retropie", str(REPO_ROOT / "platforms"))
(view, standalone), = platform_layouts("uae4all", profile, standalone_set(config))
self.assertTrue(standalone)
for entry in view["files"]:
if entry["path"].startswith("kickstarts/"):
self.assertEqual(
entry["standalone_path"], "amiga/" + entry["path"].removeprefix("kickstarts/")
)
else:
# kick.rom and rom.key in the working directory, $md_inst
self.assertEqual(entry.get("unplaced"), "outside_bios_folder", entry["path"])
class FsUaeOnRetroPie(unittest.TestCase):
"""RetroPie lists KS 1.3 as kick34005.A500, and its fs-uae launcher
passes $biosdir/kick13.rom (fs-uae.sh:23-26). The listed copy settles
fs-uae's entry by content, and the launcher's name was filled only as
a copy of UAE4All2's amiga/kick13.rom: a board without UAE4All2 lost it."""
def test_the_launcher_name_is_filled_without_another_core(self) -> None:
import json
from common import load_target_config
db_path = REPO_ROOT / "database.json"
if not db_path.exists():
self.skipTest("database.json is not built")
db = json.loads(db_path.read_text(encoding="utf-8"))
cores = load_target_config("retropie", "x86", str(REPO_ROOT / "platforms"))
self.assertNotIn("uae4all", cores)
with redirect_stdout(io.StringIO()):
manifest = generate_manifest(
"retropie", str(REPO_ROOT / "platforms"), db, str(REPO_ROOT / "bios"),
str(REPO_ROOT / "platforms" / "_registry.yml"),
emulators_dir=str(REPO_ROOT / "emulators"), offline=True,
target_cores=set(cores), target_name="x86",
)
held = [(f["dest"], f["cores"]) for f in manifest["files"]
if f["dest"].rsplit("/", 1)[-1] == "kick13.rom"]
self.assertEqual(held, [("kick13.rom", ["fs-uae"])])
class XboxOnRetroBat(unittest.TestCase):
"""RetroBat's launcher writes xemu's eeprom.bin and disk image into
saves/<system> and cxbx-reloaded's EEPROM.bin into its emulator folder,
and each Cxbx build reads its data from the folder it runs from
(Xemu.Generator.cs:82-113, Cxbx.Generator.cs:99-115, 158, 216-223)."""
def test_nothing_lands_at_the_bios_root(self) -> None:
import json
db_path = REPO_ROOT / "database.json"
if not db_path.exists():
self.skipTest("database.json is not built")
db = json.loads(db_path.read_text(encoding="utf-8"))
with redirect_stdout(io.StringIO()):
manifest = generate_manifest(
"retrobat", str(REPO_ROOT / "platforms"), db, str(REPO_ROOT / "bios"),
str(REPO_ROOT / "platforms" / "_registry.yml"),
emulators_dir=str(REPO_ROOT / "emulators"), offline=True,
)
at_root = {f["dest"].lower() for f in manifest["files"] if not f.get("root")}
# The launcher writes the two EEPROMs and the disk image, mounts an
# .iso with its own tool, and each Cxbx build reads keys.bin from
# its own folder. wpcap.dll comes with the Npcap driver.
self.assertFalse(at_root & {
"eeprom.bin", "xbox_hdd.qcow2", "dokan2.dll", "keys.bin", "wpcap.dll",
})
placed = {(f.get("root"), f["dest"]) for f in manifest["files"]}
self.assertIn(("emulators", "cxbx-reloaded/keys.bin"), placed)
self.assertIn(("emulators", "chihiro/EEPROM.bin"), placed)
self.assertNotIn(("emulators", "cxbx-reloaded/EEPROM.bin"), placed)
PROGRAM = b"PROGRAM BINARY"
PROGRAM_DATA = b"PROGRAM DATA"
class AProgramRunFromItsFolder(unittest.TestCase):
"""A program that reads its files beside its executable.
The profile gives the layout of the program's archive (prog/prog,
prog/prog.dat) and declares the executable directory. A platform that
runs prog/prog from its BIOS folder keeps that layout, one that runs it
from roms/prog places the program folder below its roms folder, and one
that runs it from an emulator folder names its files as not placeable.
"""
def setUp(self) -> None:
_emulator_profiles_cache.clear()
(REPO_ROOT / "tmp").mkdir(exist_ok=True)
self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp"))
self.addCleanup(shutil.rmtree, self.root, True)
bios = self.root / "bios" / "Maker" / "Prog"
bios.mkdir(parents=True)
files, by_md5, by_name = {}, {}, {}
for name, data in (("prog", PROGRAM), ("prog.dat", PROGRAM_DATA)):
(bios / name).write_bytes(data)
sha1 = hashlib.sha1(data).hexdigest()
md5 = hashlib.md5(data).hexdigest()
files[sha1] = {"path": str(bios / name), "name": name, "sha1": sha1,
"md5": md5, "crc32": "", "size": len(data)}
by_md5[md5] = sha1
by_name[name] = [sha1]
self.db = {"files": files, "indexes": {
"by_md5": by_md5, "by_name": by_name, "by_crc32": {}, "by_path_suffix": {}}}
self.platforms = self.root / "platforms"
self.emulators = self.root / "emulators"
self.platforms.mkdir()
self.emulators.mkdir()
run = {"emulator": "prog", "build": "standalone", "kind": "fixed_name",
"passes_to": "exec", "source_ref": "start_prog.sh:9"}
launchers = {
"biosplat": [{**run, "names": ["prog/prog"], "search_dir": "/userdata/bios"}],
"romsplat": [{**run, "names": ["prog"], "search_dir": "/storage/roms/prog"}],
"exeplat": [{**run, "names": ["prog"], "search_dir": "<emulator folder>"}],
"emuplat": [{**run, "names": ["prog"], "search_dir": '<GetPath("prog")>'}],
"plainplat": [],
}
for name, records in launchers.items():
(self.platforms / f"{name}.yml").write_text(yaml.safe_dump({
"platform": name, "version": "1", "verification_mode": "existence",
"base_destination": "bios", "cores": ["prog"], "standalone_cores": ["prog"],
"launchers": records,
"systems": {"prog-system": {"files": []}},
}))
(self.platforms / "_registry.yml").write_text(yaml.safe_dump({"platforms": {
**{name: {"config": f"{name}.yml"} for name in launchers},
"emuplat": {"config": "emuplat.yml", "emulators_directory": {
"launcher_spelling": '<GetPath("{key}")>', "bios_folder": "bios",
"searched": ["frontend/{key}", "emulators/{key}"],
"default": "emulators/{key}", "config": "frontend/launcher.cfg"}},
}}))
# The roms root as the OS's own source records it (romfolders).
(self.platforms / "romfolders").mkdir()
(self.platforms / "romfolders" / "romsplat.yml").write_text(yaml.safe_dump({
"setup": "romsplat", "platform": "romsplat",
"roms_root": {"path": "/storage/roms", "from_bios": "..", "source_ref": "os x.mk:1"},
"folders": [],
}))
# A list that installs into the roms root itself, its BIOS folder
# one of the folders there (AmberELEC's /storage/roms).
(self.platforms / "rootplat.yml").write_text(yaml.safe_dump({
"platform": "rootplat", "version": "1", "verification_mode": "existence",
"base_destination": "", "cores": ["prog"], "standalone_cores": ["prog"],
"launchers": [{**run, "names": ["prog"], "search_dir": "/storage/roms/prog"}],
"systems": {"prog-system": {"files": [
{"name": "own.bin", "destination": "bios/own.bin", "required": False},
]}},
}))
registry = yaml.safe_load((self.platforms / "_registry.yml").read_text())
registry["platforms"]["rootplat"] = {"config": "rootplat.yml"}
(self.platforms / "_registry.yml").write_text(yaml.safe_dump(registry))
(self.platforms / "romfolders" / "rootplat.yml").write_text(yaml.safe_dump({
"setup": "rootplat", "platform": "rootplat",
"roms_root": {"path": "/storage/roms", "from_bios": "..", "source_ref": "os x.mk:1"},
"folders": [],
}))
(self.emulators / "prog.yml").write_text(yaml.safe_dump({
"emulator": "Prog", "type": "standalone", "cores": ["prog"],
"systems": ["prog-system"],
"standalone_directories": ["executable directory"],
"files": [
{"name": "prog", "path": "prog/prog", "sha1": by_name["prog"][0],
"required": True},
{"name": "prog.dat", "path": "prog/prog.dat",
"sha1": by_name["prog.dat"][0], "required": True},
],
}))
def pack(self, platform: str) -> list[str]:
with redirect_stdout(io.StringIO()):
zip_path = generate_pack(
platform, str(self.platforms), self.db, str(self.root / "bios"),
str(self.root / "out" / platform), emulators_dir=str(self.emulators),
offline=True,
)
with zipfile.ZipFile(zip_path) as zf:
return sorted(n for n in zf.namelist() if n.split("/")[-1].startswith("prog"))
def manifest(self, platform: str) -> dict:
with redirect_stdout(io.StringIO()):
return generate_manifest(
platform, str(self.platforms), self.db, str(self.root / "bios"),
str(self.platforms / "_registry.yml"),
emulators_dir=str(self.emulators), offline=True,
)
def verify(self, platform: str) -> list[dict]:
config = load_platform_config(platform, str(self.platforms))
result = verify_platform(config, self.db, str(self.emulators))
return [u for u in result["undeclared_files"] if u["name"].startswith("prog")]
def test_run_from_the_bios_folder_keeps_the_layout(self) -> None:
for platform in ("biosplat", "plainplat"):
with self.subTest(platform=platform):
self.assertEqual(self.pack(platform), ["prog/prog", "prog/prog.dat"])
self.assertEqual(
sorted(f["dest"] for f in self.manifest(platform)["files"]),
["prog/prog", "prog/prog.dat"],
)
def test_run_from_the_roms_folder_is_installed_there(self) -> None:
self.assertEqual(self.pack("romsplat"), [])
manifest = self.manifest("romsplat")
self.assertEqual(
sorted((f["dest"], f.get("root")) for f in manifest["files"]),
[("prog/prog", "roms"), ("prog/prog.dat", "roms")],
)
self.assertEqual(manifest["roms_directory"], {"bios_folder": "bios", "from_bios": ".."})
entries = self.verify("romsplat")
self.assertEqual(sorted(u["path"] for u in entries), ["prog/prog", "prog/prog.dat"])
self.assertTrue(all(u["in_pack"] is False for u in entries))
def test_a_roms_root_inside_the_install_tree_is_a_plain_dest(self) -> None:
self.assertEqual(self.pack("rootplat"), ["prog/prog", "prog/prog.dat"])
manifest = self.manifest("rootplat")
self.assertEqual(
sorted((f["dest"], f.get("root")) for f in manifest["files"] if "prog" in f["dest"]),
[("prog/prog", None), ("prog/prog.dat", None)],
)
self.assertNotIn("roms_directory", manifest)
def test_run_from_an_emulator_folder_is_named(self) -> None:
self.assertEqual(self.pack("exeplat"), [])
manifest = self.manifest("exeplat")
self.assertEqual([f["dest"] for f in manifest["files"]], [])
self.assertEqual(
sorted((o["dest"], o["root"], o["reason"]) for o in manifest["omitted_files"]),
[("prog/prog", "emulator", "outside_bios_folder"),
("prog/prog.dat", "emulator", "outside_bios_folder")],
)
def test_the_installer_finds_the_roms_folder_above_the_bios_folder(self) -> None:
import install
manifest = self.manifest("romsplat")
install._check_relative_directories(manifest)
files = list(manifest["files"])
card = self.root / "card" / "roms" / "bios"
kept, left = install.place_relative_entries(files, card, manifest, "romsplat", say=False)
self.assertEqual((len(kept), left), (2, []))
self.assertEqual(
install._entry_path(card, kept[0]),
(card.parent / kept[0]["dest"]).resolve()
if install._entry_path(card, kept[0]).is_absolute() else card.parent / kept[0]["dest"],
)
other = self.root / "elsewhere"
kept, left = install.place_relative_entries(files, other, manifest, "romsplat", say=False)
self.assertEqual(kept, [])
self.assertEqual({o["reason"] for o in left}, {"no_roms_directory"})
with self.assertRaises(ValueError):
install._check_relative_directories({"files": files})
# A roms root beside the BIOS folder (Batocera's ../roms).
beside = {**manifest, "roms_directory": {"bios_folder": "bios", "from_bios": "../roms"}}
install._check_relative_directories(beside)
disk = self.root / "userdata" / "bios"
install.place_relative_entries(files, disk, beside, "romsplat", say=False)
self.assertEqual(install._entry_place(disk, kept_entry := files[0])[0],
self.root / "userdata" / "roms")
self.assertEqual(kept_entry["root"], "roms")
for climbing in ("roms", "../roms/..", "/storage/roms"):
with self.subTest(from_bios=climbing), self.assertRaises(ValueError):
install._check_relative_directories(
{**manifest, "roms_directory": {"bios_folder": "bios", "from_bios": climbing}}
)
def test_run_from_an_emulator_folder_the_registry_describes(self) -> None:
self.assertEqual(self.pack("emuplat"), [])
manifest = self.manifest("emuplat")
self.assertEqual(
sorted((f["dest"], f.get("root")) for f in manifest["files"]),
[("prog/prog", "emulators"), ("prog/prog.dat", "emulators")],
)
self.assertEqual(manifest["emulators_directory"]["default"], "emulators/{key}")
self.assertTrue(all(u["in_pack"] is False for u in self.verify("emuplat")))
def test_the_installer_follows_the_launcher_search(self) -> None:
import install
manifest = self.manifest("emuplat")
install._check_emulators_directory(manifest)
files = list(manifest["files"])
home = self.root / "Frontend"
bios = home / "bios"
bios.mkdir(parents=True)
# Not the platform's folder: no launcher config beside it.
kept, left = install.place_emulator_entries(files, bios, manifest, "emuplat", say=False)
self.assertEqual((kept, {o["reason"] for o in left}), ([], {"no_emulators_directory"}))
(home / "frontend").mkdir()
(home / "frontend" / "launcher.cfg").write_text("other=x\n")
kept, left = install.place_emulator_entries(files, bios, manifest, "emuplat", say=False)
self.assertEqual((len(kept), left), (2, []))
entry = next(f for f in kept if f["dest"] == "prog/prog")
self.assertEqual(install._entry_place(bios, entry), (home / "emulators" / "prog", "prog"))
# The first searched place that exists wins.
(home / "frontend" / "prog").mkdir()
install.place_emulator_entries(files, bios, manifest, "emuplat", say=False)
self.assertEqual(install._entry_place(bios, entry)[0], home / "frontend" / "prog")
# A key the launcher config sets moves the folder: left out.
(home / "frontend" / "launcher.cfg").write_text("prog=D:\\Prog\n")
kept, left = install.place_emulator_entries(files, bios, manifest, "emuplat", say=False)
self.assertEqual((kept, len(left)), ([], 2))
class EachProgramItsOwnProfile(unittest.TestCase):
"""PICO-8 and Voxatron are two programs: a platform running one gets its files only."""
def test_only_the_platforms_that_run_voxatron_get_it(self) -> None:
from common import list_registered_platforms, resolve_platform_cores
profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
runs = {
name: {k for k in ("lexaloffle", "voxatron")
if k in resolve_platform_cores(
load_platform_config(name, str(REPO_ROOT / "platforms")), profiles)}
for name in list_registered_platforms(str(REPO_ROOT / "platforms"))
}
self.assertEqual(
{name for name, found in runs.items() if "voxatron" in found}, {"batocera", "knulli"}
)
self.assertTrue(all("lexaloffle" in runs[name] for name in (
"batocera", "knulli", "rocknix", "retrodeck", "retrobat", "recalbox")))
def test_a_standalone_emulator_is_run(self) -> None:
from common import resolve_platform_cores
profiles = {"emu": {"emulator": "Emu", "type": "standalone", "cores": ["emu"],
"systems": ["sys"], "files": []}}
config = {"cores": ["other"], "standalone_cores": ["emu"], "systems": {}}
self.assertEqual(resolve_platform_cores(config, profiles), {"emu"})
if __name__ == "__main__":
unittest.main()
+233 -2
View File
@@ -29,9 +29,11 @@ from scraper.batocera_launchers import ( # noqa: E402
Configgen,
Launcher,
LauncherShapeError,
config_directories,
duckstation,
extract_launchers,
hatari,
lexaloffle,
)
from scraper.retropie_launchers import Launcher as PackageLauncher # noqa: E402
@@ -57,6 +59,7 @@ _GENERATOR_MAP: Final[dict[str, tuple[str, str]]] = {
DUCKSTATION = f"{GENERATORS}/duckstation/duckstationGenerator.py"
HATARI = f"{GENERATORS}/hatari/hatariGenerator.py"
LEXALOFFLE = f"{GENERATORS}/lexaloffle/lexaloffleGenerator.py"
DUCKSTATION_HEAD = '''from __future__ import annotations
@@ -209,6 +212,102 @@ HATARI_FIND = ''' @staticmethod
raise BatoceraException(f"No bios found for machine {machine}")'''
# lexaloffleGenerator.py, whole file
LEXALOFFLE_GENERATOR = '''from __future__ import annotations
import os
from typing import TYPE_CHECKING, Final
from ... import Command
from ...batoceraPaths import BIOS, HOME, ROMS, SCREENSHOTS, ensure_parents_and_open
from ...controller import generate_sdl_game_controller_config
from ...exceptions import BatoceraException
from ..Generator import Generator
if TYPE_CHECKING:
from pathlib import Path
from ...types import HotkeysContext
PICO8_BIN_PATH: Final = BIOS / "pico-8" / "pico8"
PICO8_ROOT_PATH: Final = ROMS / "pico8"
PICO8_CONTROLLERS: Final = HOME / ".lexaloffle" / "pico-8" / "sdl_controllers.txt"
VOX_BIN_PATH: Final = BIOS / "voxatron" / "vox"
VOX_ROOT_PATH: Final = ROMS / "voxatron"
VOX_CONTROLLERS: Final = HOME / ".lexaloffle" / "Voxatron" / "sdl_controllers.txt"
# Generator for the official pico8 binary from Lexaloffle
class LexaloffleGenerator(Generator):
def getHotkeysContext(self) -> HotkeysContext:
return {
"name": "lexaloffle",
"keys": { "exit": ["KEY_LEFTCTRL", "KEY_Q"], "menu": "KEY_ENTER", "reset": [ "KEY_LEFTCTRL", "KEY_R" ] }
}
def generate(self, system, rom, playersControllers, metadata, guns, wheels, gameResolution):
if (system.name == "pico8"):
LD_LIB=BIOS / "pico-8"
BIN_PATH=PICO8_BIN_PATH
CONTROLLERS=PICO8_CONTROLLERS
ROOT_PATH=PICO8_ROOT_PATH
elif (system.name == "voxatron"):
LD_LIB=BIOS / "voxatron"
BIN_PATH=VOX_BIN_PATH
CONTROLLERS=VOX_CONTROLLERS
ROOT_PATH=VOX_ROOT_PATH
else:
raise BatoceraException(f"The Lexaloffle generator has been called for an unknwon system: {system.name}.")
if not BIN_PATH.exists():
raise BatoceraException(f"Lexaloffle official binary not found at {BIN_PATH}")
if not os.access(BIN_PATH, os.X_OK):
raise BatoceraException(f"{BIN_PATH} is not set as executable")
# the command to run
commandArray: list[str | Path] = [BIN_PATH]
commandArray.extend(["-desktop", SCREENSHOTS]) # screenshots
commandArray.extend(["-windowed", "0"]) # full screen
# Display FPS
if system.config.show_fps:
commandArray.extend(["-show_fps", "1"])
else:
commandArray.extend(["-show_fps", "0"])
rombase = rom.stem
# .m3u support for multi-cart pico-8
if rom.suffix.lower() == ".m3u":
with rom.open() as fpin:
lines = fpin.readlines()
fullpath = rom.absolute().parent / lines[0].strip()
commandArray.extend(["-root_path", fullpath.parent])
rom = fullpath
else:
commandArray.extend(["-root_path", ROOT_PATH]) # store carts from splore
if (rombase.lower() == "splore" or rombase.lower() == "console"):
commandArray.extend(["-splore"])
else:
commandArray.extend(["-run", rom])
controllersconfig = generate_sdl_game_controller_config(playersControllers)
with ensure_parents_and_open(CONTROLLERS, "w") as file:
file.write(controllersconfig)
existing_library_path = os.environ.get("LD_LIBRARY_PATH")
return Command.Command(array=commandArray, env={
"SDL_AUDIODRIVER": "alsa",
"LD_LIBRARY_PATH": f"{LD_LIB}:{existing_library_path}" if existing_library_path else LD_LIB
})
def getInGameRatio(self, config, gameResolution, rom):
return 4/3'''
def placed(blocks: dict[int, str]) -> str:
"""Each block starting at its line, blank lines between."""
lines: list[str] = []
@@ -242,6 +341,10 @@ def hatari_tree(generate: str = HATARI_GENERATE, find: str = HATARI_FIND) -> Con
return configgen({HATARI: placed({1: HATARI_HEAD, 32: generate, 157: find})})
def lexaloffle_tree(text: str = LEXALOFFLE_GENERATOR) -> Configgen:
return configgen({LEXALOFFLE: text + "\n"})
class DuckStationSearch(unittest.TestCase):
def setUp(self) -> None:
self.records = duckstation(duckstation_tree())
@@ -339,6 +442,129 @@ class HatariTosSearch(unittest.TestCase):
hatari(hatari_tree(find=find))
class LexaloffleBinaries(unittest.TestCase):
def setUp(self) -> None:
self.records = [r.entry() for r in lexaloffle(lexaloffle_tree())]
def test_each_system_runs_its_binary_and_loads_its_folder(self):
self.assertEqual(
[(r["slot"], r["kind"], r["names"], r["search_dir"], r["passes_to"])
for r in self.records],
[
("pico8", "fixed_name", ["pico-8/pico8"], "/userdata/bios", "exec"),
("pico8", "passes_path", [], "/userdata/bios/pico-8",
"environment LD_LIBRARY_PATH"),
("voxatron", "fixed_name", ["voxatron/vox"], "/userdata/bios", "exec"),
("voxatron", "passes_path", [], "/userdata/bios/voxatron",
"environment LD_LIBRARY_PATH"),
],
)
for record in self.records:
self.assertEqual((record["emulator"], record["build"]), ("lexaloffle", "standalone"))
def test_a_missing_or_non_executable_binary_stops_the_launch(self):
pico8, library, vox, _ = self.records
self.assertEqual(
pico8["fails_when_missing"],
"Lexaloffle official binary not found at /userdata/bios/pico-8/pico8, "
"/userdata/bios/pico-8/pico8 is not set as executable",
)
self.assertEqual(
vox["fails_when_missing"],
"Lexaloffle official binary not found at /userdata/bios/voxatron/vox, "
"/userdata/bios/voxatron/vox is not set as executable",
)
self.assertFalse(pico8["case_insensitive"])
self.assertFalse(library["fails_when_missing"])
def test_the_lines_cited_are_the_constant_the_branch_the_checks_and_the_command(self):
self.assertEqual(
[r["source_ref"] for r in self.records],
[
f"{LEXALOFFLE}:17, 35, 37, 48-55",
f"{LEXALOFFLE}:35-36, 89",
f"{LEXALOFFLE}:20, 40, 42, 48-55",
f"{LEXALOFFLE}:40-41, 89",
],
)
def test_a_binary_without_the_executable_check_raises(self):
text = LEXALOFFLE_GENERATOR.replace("os.access(BIN_PATH, os.X_OK)", "True")
with self.assertRaises(LauncherShapeError):
lexaloffle(lexaloffle_tree(text))
def test_a_binary_without_the_existence_check_raises(self):
text = LEXALOFFLE_GENERATOR.replace("BIN_PATH.exists()", "BIN_PATH")
with self.assertRaises(LauncherShapeError):
lexaloffle(lexaloffle_tree(text))
def test_a_command_started_another_way_raises(self):
text = LEXALOFFLE_GENERATOR.replace("= [BIN_PATH]", '= ["pico8"]')
with self.assertRaises(LauncherShapeError):
lexaloffle(lexaloffle_tree(text))
def test_a_library_path_set_elsewhere_raises(self):
text = LEXALOFFLE_GENERATOR.replace('"LD_LIBRARY_PATH": ', '"LIBRARY_PATH": ')
with self.assertRaises(LauncherShapeError):
lexaloffle(lexaloffle_tree(text))
def test_a_binary_outside_bios_raises(self):
text = LEXALOFFLE_GENERATOR.replace(
'VOX_BIN_PATH: Final = BIOS / "voxatron" / "vox"',
'VOX_BIN_PATH: Final = Path("/usr/bin/vox")',
)
with self.assertRaises(LauncherShapeError):
lexaloffle(lexaloffle_tree(text))
def test_a_generator_that_no_longer_branches_on_the_system_raises(self):
text = LEXALOFFLE_GENERATOR.replace("system.name ==", "system.emulator ==")
with self.assertRaises(LauncherShapeError):
lexaloffle(lexaloffle_tree(text))
OPENMSX = f"{GENERATORS}/openmsx/openmsxGenerator.py"
OPENMSX_FILEPOOL = ''' def generate(self, system, rom):
with settings_tcl.open("a") as file:
file.write("filepool add -path /userdata/bios/Machines -types system_rom -position 1\\n")
file.write("filepool add -path /userdata/bios/openmsx -types system_rom -position 2\\n")'''
class ConfigDirectories(unittest.TestCase):
"""A BIOS directory written into the emulator's config, at batocera-43.1."""
def test_each_filepool_line_hands_its_directory(self):
cg = configgen({OPENMSX: placed({1: "class OpenmsxGenerator:", 86: OPENMSX_FILEPOOL})})
records = [r.entry() for r in config_directories(cg, ("openmsx.openmsxGenerator",))]
self.assertEqual(
[(r["emulator"], r["kind"], r["search_dir"], r["source_ref"]) for r in records],
[
("openmsx", "passes_path", "/userdata/bios/Machines", f"{OPENMSX}:88"),
("openmsx", "passes_path", "/userdata/bios/openmsx", f"{OPENMSX}:89"),
],
)
self.assertEqual(
records[1]["passes_to"],
"written: filepool add -path /userdata/bios/openmsx -types system_rom -position 2",
)
def test_a_saved_setting_hands_its_directory(self):
amiberry = f"{GENERATORS}/amiberry/amiberryGenerator.py"
text = placed({
1: "from pathlib import Path\n_BIOS_DIR = Path('/userdata/bios/amiga')",
10: "def generate():\n amiberryconf.save('rom_path', _BIOS_DIR)",
})
(record,) = config_directories(configgen({amiberry: text}), ("amiberry.amiberryGenerator",))
self.assertEqual(
(record.search_dir, record.passes_to, record.source_ref),
("/userdata/bios/amiga", "rom_path", f"{amiberry}:11"),
)
def test_a_generator_handing_no_bios_directory_raises(self):
cg = configgen({OPENMSX: "def generate():\n file.write('savestate x')\n"})
with self.assertRaises(LauncherShapeError):
config_directories(cg, ("openmsx.openmsxGenerator",))
class ExtractionNeverEmpty(unittest.TestCase):
def test_a_generator_of_unknown_shape_stops_the_whole_scrape(self):
find = DUCKSTATION_FIND.replace("def find_bios(", "def locate_bios(")
@@ -361,7 +587,7 @@ class PlatformRecords(unittest.TestCase):
cls.schema = json.loads((REPO_ROOT / "schemas" / "platform.schema.json").read_text())
def test_every_emulator_is_one_batocera_names(self):
cores = set(self.config["cores"])
cores = {*self.config["cores"], *self.config.get("standalone_cores", [])}
named = {
name for record in self.config["launchers"]
for name in record["emulator"].split(", ")
@@ -369,8 +595,13 @@ class PlatformRecords(unittest.TestCase):
self.assertEqual(sorted(named - cores), [])
def test_every_reference_is_in_configgen(self):
# Or in a patch Batocera applies to an emulator's own path code.
from scraper.batocera_launchers import PATH_PATCHES
for record in self.config["launchers"]:
self.assertTrue(record["source_ref"].startswith(f"{CONFIGGEN}/"), record)
self.assertTrue(
record["source_ref"].startswith((f"{CONFIGGEN}/", *PATH_PATCHES)), record
)
def test_the_schema_describes_what_the_scraper_writes(self):
fields = {f.name for f in dataclasses.fields(Launcher)}
+345
View File
@@ -0,0 +1,345 @@
"""AmberELEC's launcher layer, read from runemu.py and its emulator scripts.
The fixtures are cut-down copies of what each extractor reads at AmberELEC
a21975bf (prerelease-20261019_1835). Records must name the files in the
order the code writes them, cite the fixture's own lines, and a construct
that is gone must stop the scrape.
"""
from __future__ import annotations
import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache
import sys
import textwrap
import unittest
from pathlib import Path
import yaml
REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT / "scripts"))
from scraper import amberelec_launchers as al # noqa: E402
from scraper.configgen_launchers import LauncherShapeError # noqa: E402
def text(block: str) -> str:
return textwrap.dedent(block).lstrip("\n")
RUNEMU = text(
"""
standalone_emulators = {
'AMIBERRY': StandaloneEmulator('amiberry', ['/usr/bin/amiberry.sh', '<path>']),
'HATARISA': StandaloneEmulator('hatari', ['/usr/bin/hatari.sh', '<path>']),
'pico8': StandaloneEmulator('pico8_64', ['/usr/bin/pico-8.sh', '<path>']),
'piemu': StandaloneEmulator('piemu', ['/usr/bin/bash', '-l', '/usr/bin/piemu.sh', '<path>']),
'yabasanshiroSA': StandaloneEmulator('yabasanshiro', ['/usr/bin/yabasanshiro.sh', '<path>']),
}
class EmuRunner():
def get_retroarch_command(self, shader_arg):
if self.emulator == 'mame':
if rom_path:
cmd = f'{mame_system} -{mame_slot} "{rom_path}" -rp /roms/bios/mame;/roms/bios -cfg_directory /x'
else:
cmd = f'{mame_system} -rp /roms/bios/mame;/roms/bios -cfg_directory /x'
"""
)
YABASANSHIRO = text(
"""
#!/bin/bash
get_setting "use_hlebios"
HLEBIOS='0'
BIOS=""
if [ "${HLEBIOS}" != 1 ]; then
if [ -e "/storage/roms/bios/saturn_bios.bin" ]; then
BIOS="-b /storage/roms/bios/saturn_bios.bin"
else
text_viewer -e -w -t "Notice! Yabasanshiro BIOS Missing!" -m "not found"
fi
fi
{ yabasanshiro -r 2 -i "${1}" ${BIOS}; } > /tmp/logs/exec.log 2>&1
"""
)
PICO8 = text(
"""
#!/bin/bash
mkdir -p "/storage/roms/pico-8"
if [ ! -f "/storage/roms/pico-8/pico8_64" ] || [ ! -f "/storage/roms/pico-8/pico8.dat" ]; then
text_viewer -e -w -t "Missing Pico-8 binaries!" -m "Extract your purchased pico8_64."
else
/storage/roms/pico-8/pico8_64 -home -root_path /storage/roms/pico-8 ${OPTIONS} "${CART}"
fi
"""
)
PIEMU = text(
"""
#!/bin/bash
ROMS_DIR="/storage/roms"
BIOS_DIR="$ROMS_DIR/bios"
if [[ "$EXTENSION" == "pfs" ]]; then
/usr/bin/mkpfi "$BIOS_DIR/all.bin"
fi
"""
)
HATARI_SH = text(
"""
#!/bin/bash
HATARI_CONFIG_DIR=/storage/.config/hatari/conf
cp $HATARI_CONFIG_DIR/Atari-ST-default.cfg "$HATARI_TMP_CONFIG"
nice -n -19 hatari --configfile "$HATARI_TMP_CONFIG" --disk-a "$1" >> $HATARI_LOG 2>&1
"""
)
HATARI_CFG = text(
"""
[ROM]
szTosImageFileName = /storage/roms/bios/tos.img
bPatchTos = TRUE
"""
)
ATARI800_CFG = text(
"""
Atari 800 Emulator, Version 3.1.0
ROM_OS_A_NTSC=
ROM_OS_A_PAL=/storage/roms/bios/ATARIOSA.ROM
ROM_5200=/storage/roms/bios/5200.rom
"""
)
ATARI800_PATCH = text(
"""
+ LDFLAGS += -static-libgcc
+ CFLAGS += -DDEFAULT_CFG_NAME="\\"/storage/.config/distribution/configs/atari800.cfg\\""
"""
)
AMIBERRY_MK = text(
"""
makeinstall_target() {
mkdir -p ${INSTALL}/usr/config/amiberry
ln -s /storage/roms/bios ${INSTALL}/usr/config/amiberry/kickstarts
}
"""
)
AMIBERRY_SH = text(
"""
#!/bin/bash
AMIBERRY_CONFIG_DIR=$AMIBERRY_DIR/conf
AMIBERRY_SET_CONF() {
if [ `echo $1 | egrep 'AGA|CD32' | wc -l` -eq 1 ]; then
cp $AMIBERRY_CONFIG_DIR/AmigaA1200-default.uae "$AMIBERRY_TMP_CONFIG"
else
cp $AMIBERRY_CONFIG_DIR/AmigaA500-default.uae "$AMIBERRY_TMP_CONFIG"
fi
}
"""
)
def uae(rom: str) -> str:
return f"amiberry.rom_path=/storage/.config/amiberry/kickstarts/\nkickstart_rom_file=$(FILE_PATH)/{rom}\n"
SCUMMVM_SH = text(
"""
#!/bin/bash
case $1 in
"libretro")
sed -i '2,2s/^/themepath=\\/roms\\/bios\\/scummvm\\/theme\\n/' ${BIOSPATH}/scummvm.ini
sed -i '2,2s/^/extrapath=\\/roms\\/bios\\/scummvm\\/extra\\n/' ${BIOSPATH}/scummvm.ini
sed -i '2,2s/^/browser_lastpath=\\/roms\\/bios\\/scummvm\\/extra\\n/' ${BIOSPATH}/scummvm.ini
;;
esac
"""
)
FREEJ2ME = text(
"""
#!/bin/bash
if [ ! -f "/storage/roms/bios/{jar}" ]; then
cp /usr/config/distribution/freej2me/{jar} /storage/roms/bios
fi
"""
)
EASYRPG = text(
"""
#!/bin/bash
install_bios() {
BIOS="$1"
curl -Lo "${BIOS}" "${PKG_URL}/${BIOS}"
}
INSTALLPATH="/storage/roms/bios"
PKG_URL="https://dl.degica.com/rpgmakerweb/run-time-packages"
install_bios rpg2000_rtp_installer.exe rtp/2000
"""
)
def tree(**overrides: str) -> dict[str, str]:
files = {
al.RUNEMU: RUNEMU,
al.RETROARCH_CFG: 'savefile_directory = "~/saves"\nsystem_directory = "~/roms/bios"\n',
al.RETRORUN: '/usr/bin/retrorun -c "${RRCONF}" -s /storage/roms/"$3" -d /roms/bios "$EMU" "$2"\n',
al.SCRIPTS["yabasanshiroSA"]: YABASANSHIRO,
al.SCRIPTS["pico8"]: PICO8,
al.SCRIPTS["piemu"]: PIEMU,
al.SCRIPTS["HATARISA"]: HATARI_SH,
al.HATARI_CONFIG: HATARI_CFG,
al.ATARI800_CONFIG: ATARI800_CFG,
al.ATARI800_PATCH: ATARI800_PATCH,
al.AMIBERRY_PACKAGE: AMIBERRY_MK,
al.SCRIPTS["AMIBERRY"]: AMIBERRY_SH,
f"{al.AMIBERRY_CONFIGS}/AmigaA1200-default.uae": uae("kick40068.A1200.rom"),
f"{al.AMIBERRY_CONFIGS}/AmigaA500-default.uae": uae("kick34005.A500.rom"),
al.SCRIPTS["SCUMMVMSA"]: SCUMMVM_SH,
al.EASYRPG: EASYRPG,
**{path: FREEJ2ME.replace("{jar}", f"{core}-lr.jar") for core, path in al.FREEJ2ME},
}
files.update(overrides)
return files
def read(**overrides: str):
return tree(**overrides).__getitem__
class Frontends(unittest.TestCase):
def test_retroarch_system_directory(self):
(record,) = al.retroarch(read())
self.assertEqual(record.search_dir, "~/roms/bios")
self.assertEqual(record.source_ref, f"{al.RETROARCH_CFG}:2")
def test_retrorun_directory(self):
(record,) = al.retrorun(read())
self.assertEqual((record.search_dir, record.passes_to), ("/roms/bios", "command line -d"))
def test_mame_search_path_of_both_commands(self):
(record,) = al.mame(al.Runemu(read()))
self.assertEqual(record.search_dir, "/roms/bios/mame;/roms/bios")
self.assertEqual(record.depends_on_option, "self.emulator == 'mame'")
self.assertEqual(record.source_ref, f"{al.RUNEMU}:11, 13, 15")
def test_a_retroarch_config_without_the_key_raises(self):
with self.assertRaises(LauncherShapeError):
al.retroarch(read(**{al.RETROARCH_CFG: "x = 1\n"}))
class Standalone(unittest.TestCase):
def test_yabasanshiro_flag_after_the_presence_test(self):
(record,) = al.yabasanshiro(read(), al.Runemu(read()))
self.assertEqual(record.names, ["saturn_bios.bin"])
self.assertEqual(record.passes_to, "command line -b")
self.assertIs(record.fails_when_missing, False)
self.assertEqual(record.depends_on_option, "use_hlebios")
self.assertEqual(
record.source_ref,
f"{al.RUNEMU}:6, {al.SCRIPTS['yabasanshiroSA']}:2, 5-7, 12",
)
def test_pico8_binaries_outside_bios(self):
(record,) = al.pico8(read(), al.Runemu(read()))
self.assertEqual(record.names, ["pico8_64", "pico8.dat"])
self.assertEqual(record.search_dir, "/storage/roms/pico-8")
self.assertEqual(record.fails_when_missing, "Missing Pico-8 binaries!")
self.assertEqual(record.source_ref, f"{al.RUNEMU}:4, {al.SCRIPTS['pico8']}:3-6")
def test_piemu_flash_image_source(self):
(record,) = al.piemu(read(), al.Runemu(read()))
self.assertEqual(record.names, ["all.bin"])
self.assertEqual(record.source_ref, f"{al.RUNEMU}:5, {al.SCRIPTS['piemu']}:2-5")
def test_hatari_default_config(self):
(record,) = al.hatari(read(), al.Runemu(read()))
self.assertEqual(record.names, ["tos.img"])
self.assertEqual(record.passes_to, "Atari-ST-default.cfg [ROM] szTosImageFileName")
self.assertEqual(
record.source_ref,
f"{al.RUNEMU}:3, {al.SCRIPTS['HATARISA']}:3-4, {al.HATARI_CONFIG}:2",
)
def test_amiberry_link_and_one_kickstart_per_config(self):
link, a1200, a500 = al.amiberry(read(), al.Runemu(read()))
self.assertEqual(link.kind, "links")
self.assertEqual(link.passes_to, "/usr/config/amiberry/kickstarts is a symlink to it")
self.assertEqual((a1200.slot, a1200.names), ("A1200", ["kick40068.A1200.rom"]))
self.assertEqual((a500.slot, a500.names), ("A500", ["kick34005.A500.rom"]))
self.assertEqual(a500.depends_on_option, f"not ({a1200.depends_on_option})")
def test_a_table_running_another_script_raises(self):
broken = RUNEMU.replace("/usr/bin/yabasanshiro.sh", "/usr/bin/yaba.sh")
with self.assertRaises(LauncherShapeError):
al.yabasanshiro(read(), al.Runemu(read(**{al.RUNEMU: broken})))
def test_a_bios_test_written_another_way_raises(self):
broken = YABASANSHIRO.replace('if [ -e "/storage', 'if test -e "/storage')
with self.assertRaises(LauncherShapeError):
al.yabasanshiro(read(**{al.SCRIPTS["yabasanshiroSA"]: broken}), al.Runemu(read()))
class Cores(unittest.TestCase):
def test_atari800_built_to_read_the_shipped_config(self):
(record,) = al.atari800(read())
self.assertEqual(record.names, ["ATARIOSA.ROM", "5200.rom"])
self.assertEqual(record.source_ref, f"{al.ATARI800_PATCH}:2, {al.ATARI800_CONFIG}:3-4")
def test_atari800_built_for_another_config_raises(self):
broken = ATARI800_PATCH.replace("atari800.cfg", "other.cfg")
with self.assertRaises(LauncherShapeError):
al.atari800(read(**{al.ATARI800_PATCH: broken}))
def test_scummvm_paths_written_under_bios(self):
theme, extra = al.scummvm(read())
self.assertEqual(theme.search_dir, "/roms/bios/scummvm/theme")
self.assertEqual(extra.passes_to, "scummvm.ini extrapath")
def test_freej2me_copies_the_shipped_jar(self):
plain, plus = al.freej2me(read())
self.assertEqual((plain.kind, plain.names), ("copies", ["freej2me-lr.jar"]))
self.assertEqual(plus.names, ["freej2me-plus-lr.jar"])
self.assertEqual(plain.search_dir, "/usr/config/distribution/freej2me")
def test_easyrpg_download_per_runtime(self):
(record,) = al.easyrpg(read())
self.assertEqual(
record.search_dir,
"https://dl.degica.com/rpgmakerweb/run-time-packages/rpg2000_rtp_installer.exe",
)
self.assertEqual(record.passes_to, "/storage/roms/bios/rtp/2000")
def test_every_extractor_runs_on_the_fixture(self):
records = al.extract_launchers(read())
# One easyrpg runtime in the fixture, two at the pinned commit.
self.assertEqual(len(records), 16)
class PlatformFile(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
cls.config = yaml.safe_load((REPO_ROOT / "platforms" / "amberelec.yml").read_text())
def test_the_layer_is_written(self):
self.assertTrue(self.config["launchers"])
def test_every_reference_is_in_the_repository(self):
for record in self.config["launchers"]:
self.assertTrue(record["source_ref"].startswith("packages/"), record)
def test_every_emulator_is_one_amberelec_names(self):
cores = {*self.config["cores"], *self.config.get("standalone_cores", [])}
named = {n for record in self.config["launchers"] for n in record["emulator"].split(", ")}
# RetroArch and retrorun themselves, the two runners of every core.
self.assertEqual(sorted(named - cores), ["retroarch", "retrorun"])
if __name__ == "__main__":
unittest.main()
+655
View File
@@ -0,0 +1,655 @@
"""EmuELEC's launcher layer read from its packages.
Each fixture is a cut-down copy of the lines an extractor reads at EmuELEC
v4.8 (02b45fe53b85c45c75dbad8e44a648092dec2e72). The records must name the
core emuelecRunEmu.sh dispatches, carry the names in the order the code
tries them, point at the fixture's own lines, and a construct that is gone
must stop the scrape.
"""
from __future__ import annotations
import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache
import sys
import textwrap
import unittest
from pathlib import Path
import yaml
REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT / "scripts"))
from scraper import emuelec_launchers as el # noqa: E402
from scraper.emuelec_scraper import launcher_revision # noqa: E402
from scraper.shell_launchers import LauncherPatternMissing, RepoTree # noqa: E402
EMU = el.EMULATORS
def text(block: str) -> str:
return textwrap.dedent(block).lstrip("\n")
RUN_EMU = text(
"""
if [[ "${EMULATOR}" = "libretro" ]]; then
EMU="${CORE}_libretro"
fi
if [[ "${EMULATOR}" = "retrorun" ]]; then
EMU="${CORE}_libretro"
fi
MIDI_OUTPUT=$(get_ee_setting "ra_midi_output" "${PLATFORM}" "${BASEROMNAME}")
if [[ ! -z "${MIDI_OUTPUT}" ]]; then
emuelec-utils set_midi_source "${MIDI_OUTPUT}" "${EMULATOR}"
fi
if [ ${EMU} == "freej2me_libretro" ]; then
freej2me.sh
JAVA_HOME='/storage/roms/bios/jdk'
export JAVA_HOME
fi
case ${PLATFORM} in
"atarist")
if [ "${EMU}" = "HATARISA" ]; then
RUNTHIS='${TBASH} hatari.start "${ROMNAME}"'
fi
;;
"dreamcast"|"naomi")
if [ "${EMU}" = "flycastsa" ]; then
RUNTHIS='${TBASH} flycast.sh "${ROMNAME}"'
elif [ "${EMU}" = "flycast_dojo" ]; then
RUNTHIS='flycastdojo.sh "${ROMNAME}"'
fi
;;
"psx")
if [ "${EMU}" = "duckstation" ]; then
RUNTHIS='${TBASH} duckstation.sh "${ROMNAME}"'
fi
;;
"mame")
if [ "${EMU}" = "AdvanceMame" ]; then
RUNTHIS='${TBASH} advmame.sh "${PLATFORM}" "${ROMNAME}"'
fi
;;
"n64")
if [ "${EMU}" = "rice" ]; then
RUNTHIS='${TBASH} m64p.sh "${ROMNAME}"'
elif [ "${EMU}" = "glide64mk2" ]; then
RUNTHIS='${TBASH} m64p.sh "${ROMNAME}" m64p_gl64mk2'
fi
;;
"scummvm")
if [ "${EMU}" = "SCUMMVMSA" ]; then
RUNTHIS='${TBASH} scummvm.start sa "${ROMNAME}"'
fi
;;
"wii"|"gamecube")
if [ "${EMU}" = "dolphin" ]; then
RUNTHIS='${TBASH} dolphin.sh "${ROMNAME}"'
fi
;;
"pico8")
RUNTHIS='${TBASH} pico8.sh "${ROMNAME}"'
;;
"intellivision")
if [ "${EMU}" = "jzintv" ]; then
RUNTHIS='jzintv.sh "${ROMNAME}"'
fi
;;
"saturn")
if [ "${EMU}" = "yabasanshiroSA" ]; then
RUNTHIS='yabasanshiro.sh "${ROMNAME}"'
elif [ "${EMU}" = "yabasanshiroSA1_5" ]; then
RUNTHIS='yabasanshiro1_5.sh "${ROMNAME}"'
fi
;;
esac
case ${PLATFORM} in
"arcade"|"mame")
if [ "$EMU" = "mame_libretro" ]; then
mame.sh
fi
;;
esac
RUNTHIS='${RABIN} ${VERBOSE} ${RA_ARGS} -L /tmp/cores/${EMU}.so --config ${RACONF} "${ROMNAME}"'
RUNTHIS="retrorun"
RUNTHIS+=' ${CMD_ROTATE} --triggers -g -d /storage/roms/bios /tmp/cores/${EMU}.so "${ROMNAME}"'
"""
)
UTILS = text(
"""
function set_midi_source()
{
case ${midi_source} in
fluidsynth)
fluidsynth -is /storage/roms/bios/sc/SC-55.sf2 &
;;
timidity)
timidity -iA --module 1 &
;;
mt32)
mt32d -o 2 -i 24 -f /roms/bios &
;;
esac
}
"""
)
RETROARCH_MK = text(
"""
sed -i -e "s/# savestate_directory =/savestate_directory =\\/storage\\/roms\\/savestates/" ${INSTALL}/etc/retroarch.cfg
sed -i -e "s/# system_directory =/system_directory =\\/storage\\/roms\\/bios/" ${INSTALL}/etc/retroarch.cfg
"""
)
FREEJ2ME_SH = text(
"""
install_java
if [[ -f "/storage/roms/bios/jdk/eeversion" ]]; then
cp -rf /usr/lib/libretro/freej2me-lr.jar ${HOME}/roms/bios
else
exit 1
fi
"""
)
PICO8_SH = text(
"""
if [[ -e "/storage/roms/bios/pico-8" ]]; then
mkdir -p /emuelec/bin/pico-8
cp -rf /storage/roms/bios/pico-8/* /emuelec/bin/pico-8
rm -rf /storage/roms/bios/pico-8
chmod +x /emuelec/bin/pico-8/pico8_dyn
fi
if [[ "${CART}" == *"/splore"* ]]; then
/emuelec/bin/pico-8/pico8_dyn -splore -home /emuelec/configs/pico-8
else
/emuelec/bin/pico-8/pico8_dyn -run "${CART}" -home /emuelec/configs/pico-8
fi
"""
)
FLYCAST_SH = text(
"""
if [ ! -L "/storage/.local/share/flycast" ]; then
mkdir -p "/storage/roms/bios/dc"
rm -rf "/storage/.local/share/flycast"
ln -sf "/storage/roms/bios/dc" "/storage/.local/share/flycast"
fi
"""
)
FLYCASTDOJO_SH = text(
"""
LOCAL_DATA="/storage/roms/bios/dc_dojo"
LOCAL_HOME="/storage/.local/share/flycast-dojo"
if [ ! -L "${LOCAL_HOME}" ]; then
rm -rf "${LOCAL_HOME}"
ln -sf "${LOCAL_DATA}" "${LOCAL_HOME}"
fi
"""
)
AMIBERRY_MK = text(
"""
cp -a ${PKG_DIR}/config/* ${INSTALL}/usr/config/amiberry/
ln -s /storage/roms/bios ${INSTALL}/usr/config/amiberry/kickstarts
"""
)
TIMIDITY_MK = text(
"""
ln -sf /storage/roms/bios/timidity/freepats ${INSTALL}/usr/config/timidity/freepats
ln -sf /storage/.config/timidity/freepats.cfg ${INSTALL}/etc/timidity/freepats.cfg
"""
)
DUCKSTATION_INI = text(
"""
[BIOS]
SearchDirectory = /storage/roms/bios
PathNTSCU =
PathNTSCJ =
PathPAL =
"""
)
DUCKSTATION_MK = text(
"""
cp -rf ${PKG_DIR}/config/* ${INSTALL}/usr/config/emuelec/configs/duckstation
"""
)
DUCKSTATION_SH = text(
"""
CONFIG_DIR="/emuelec/configs/duckstation"
duckstation-nogui -fullscreen -settings "${CONFIG_DIR}/settings.ini" -- "${1}"
"""
)
def yabasanshiro_sh(program: str) -> str:
return text(
f"""
BIOS=""
HLEBIOS=$(get_ee_setting hlebios saturn "${{ROMNAME}}")
if [ "${{HLEBIOS}}" != 1 ]; then
if [ -e "/storage/roms/bios/saturn_bios.bin" ]; then
BIOS="-b /storage/roms/bios/saturn_bios.bin"
else
BIOS=""
fi
fi
{{ {program} -r 2 -i "${{1}}" ${{BIOS}}; }} > /emuelec/logs/emuelec.log 2>&1
"""
)
JZINTV_SH = text(
"""
exec jzintv -f1 -z "$RES" -p /storage/roms/bios/ "$ROM" $KBD_OPT
"""
)
M64P_SH = text(
"""
BIOSDIR="/storage/roms/bios/Mupen64plus"
IPLROM="${BIOSDIR}/N64DD IPLROM (J).n64"
[ ! -f "${IPLROM}" ] && IPLROM="${BIOSDIR}/IPL.n64"
if [ -f "${GAMEDIR}/${GAMENAME}.ndd" ] && [ -f "${IPLROM}" ]; then
RENMODE="1"
else
IPLROM=""
fi
mupen64plus --fullscreen --dd-ipl-rom "${IPLROM}" --dd-disk "${DDDISK}" "${FILE}" ;;
"""
)
HATARI_START = text(
"""
HATARI_TMP_CONFIG="$HATARI_TMP_DIR"/.hatari-temp.cfg
cp $HATARI_CONFIG_DIR/Atari-ST-default.cfg "$HATARI_TMP_CONFIG"
hatari --configfile "$HATARI_TMP_CONFIG" --disk-a "$1"
"""
)
HATARI_CFG = text(
"""
[HardDisk]
szHardDiskDirectory = /storage/.hatari
[ROM]
szTosImageFileName = /storage/roms/bios/tos.img
szCartridgeImageFileName =
"""
)
HATARI_MK = text(
"""
cp -R ${PKG_DIR}/config/* ${INSTALL}/usr/config/hatari
"""
)
ADVMAME_MK = text(
"""
if [ "${DEVICE}" == "OdroidGoAdvance" ]; then
cp -r ${PKG_DIR}/config/advmame.rc_oga ${INSTALL}/usr/config/emuelec/configs/advmame/advmame.rc
else
cp -r ${PKG_DIR}/config/advmame.rc ${INSTALL}/usr/config/emuelec/configs/advmame/advmame.rc
fi
"""
)
ADVMAME_RC = text(
"""
dir_rom /storage/roms/mame
dir_sample /storage/roms/bios/advmame/samples
"""
)
ADVMAME_SH = text(
"""
SDL_AUDIODRIVER=alsa advmame ${ARG} -quiet
"""
)
MAME_SH = text(
"""
if [ ! -f "/storage/roms/bios/mame/hash/fmtowns_cd.xml" ]; then
mkdir -p /storage/roms/bios/mame/hash
cp -rf "/usr/config/emuelec/configs/mame/hash/"fm* "/storage/roms/bios/mame/hash"
fi
if [ ! -f "/storage/roms/bios/mame/ini/mame.ini" ]; then
mkdir -p /storage/roms/bios/mame/ini
cp -rf "/usr/config/emuelec/configs/mame/ini/"mame* "/storage/roms/bios/mame/ini"
fi
if [ ! -f "/storage/.config/retroarch/config/MAME/MAME.opt" ]; then
cp -rf "/usr/config/emuelec/configs/mame/MAME/"MAME* "/storage/.config/retroarch/config/MAME"
fi
"""
)
MAME_INI = text(
"""
rompath /storage/roms/bios/mame/bios;/storage/roms/mame;/storage/roms/arcade
samplepath /storage/roms/bios/mame/samples
cfg_directory /storage/roms/bios/mame/mame/cfg
"""
)
MAME_OPT = text(
"""
mame_boot_to_bios = "disabled"
mame_read_config = "enabled"
"""
)
SCUMMVM_START = text(
"""
CONFIG_DIR="/storage/.config/scummvm"
if [ -d "/storage/.config/scummvm/extra" ]; then
EXTRA="--extrapath=/storage/.config/scummvm/extra"
fi
case $1 in
"sa")
scummvm --fullscreen --joystick=0 $EXTRA "${GAME}"
;;
"libretro")
retroarch -L /tmp/cores/scummvm_libretro.so --config ${RATMPCONF} "${GAME}"
;;
"add")
scummvm --add --path="/storage/roms/scummvm" --recursive
cp ${CONFIG_DIR}/scummvm.ini /storage/roms/bios/scummvm.ini
;;
esac
"""
)
DOLPHIN_SH = text(
"""
XDG_CONFIG_HOME=/emuelec/configs XDG_DATA_HOME=/storage/roms/dolphin /usr/bin/dolphin-emu-nogui -p fbdev "${1}"
"""
)
FILES = {
el.RUN_EMU: RUN_EMU,
el.UTILS: UTILS,
el.RETROARCH_MK: RETROARCH_MK,
f"{el.LIBRETRO}/freej2me/scripts/freej2me.sh": FREEJ2ME_SH,
f"{el.BIN}/pico8.sh": PICO8_SH,
f"{EMU}/flycastsa/scripts/flycast.sh": FLYCAST_SH,
f"{EMU}/flycast-dojo/scripts/flycastdojo.sh": FLYCASTDOJO_SH,
f"{EMU}/amiberry/package.mk": AMIBERRY_MK,
f"{EMU}/amiberry-lite/package.mk": AMIBERRY_MK.replace("amiberry/", "amiberry-lite/"),
f"{el.SX05RE}/tools/sound/timidity/package.mk": TIMIDITY_MK,
f"{EMU}/duckstation/config/settings.ini": DUCKSTATION_INI,
f"{EMU}/duckstation/package.mk": DUCKSTATION_MK,
f"{EMU}/duckstation/scripts/duckstation.sh": DUCKSTATION_SH,
el.YABASANSHIRO_SCRIPTS[0]: yabasanshiro_sh("yabasanshiro"),
el.YABASANSHIRO_SCRIPTS[1]: yabasanshiro_sh("yabasanshiro1_5"),
f"{EMU}/jzintv/scripts/jzintv.sh": JZINTV_SH,
f"{EMU}/mupen64plussa/mupen64plussa-core/m64p.sh": M64P_SH,
f"{EMU}/hatarisa/scripts/hatari.start": HATARI_START,
f"{EMU}/hatarisa/config/conf/Atari-ST-default.cfg": HATARI_CFG,
f"{EMU}/hatarisa/package.mk": HATARI_MK,
f"{EMU}/advancemame/package.mk": ADVMAME_MK,
f"{EMU}/advancemame/config/advmame.rc": ADVMAME_RC,
f"{EMU}/advancemame/config/advmame.rc_oga": ADVMAME_RC,
f"{EMU}/advancemame/bin/advmame.sh": ADVMAME_SH,
f"{el.LIBRETRO}/mame/scripts/mame.sh": MAME_SH,
f"{el.LIBRETRO}/mame/config/ini/mame.ini": MAME_INI,
f"{el.LIBRETRO}/mame/config/MAME/MAME.opt": MAME_OPT,
f"{EMU}/scummvmsa/bin/scummvm.start": SCUMMVM_START,
f"{EMU}/dolphinSA/scripts/dolphin.sh": DOLPHIN_SH,
}
def tree(**changes: str | None) -> RepoTree:
files = dict(FILES)
for path, content in changes.items():
if content is None:
files.pop(path, None)
else:
files[path] = content
return RepoTree.from_files(files)
def records(extractor, **changes: str | None) -> list[dict]:
built = tree(**changes)
return [r.entry() for r in extractor(built, el.Runs(built))]
def ref(path: str, lines: str) -> str:
return f"{path}:{lines}"
class Dispatch(unittest.TestCase):
def test_each_script_is_named_after_the_core_that_starts_it(self):
runs = el.Runs(tree())
self.assertEqual(runs.emulator("flycast.sh"), "flycastsa")
self.assertEqual(runs.emulator("flycastdojo.sh"), "flycast_dojo")
self.assertEqual(runs.emulator("m64p.sh"), "rice, glide64mk2")
self.assertEqual(runs.emulator("mame.sh"), "mame")
self.assertEqual(runs.emulator("freej2me.sh"), "freej2me")
def test_an_arm_without_a_core_test_names_its_platform(self):
self.assertEqual(el.Runs(tree()).emulator("pico8.sh"), "pico8")
def test_a_script_no_longer_started_raises(self):
runs = el.Runs(tree())
with self.assertRaises(LauncherPatternMissing):
runs.of("gone.sh")
def test_a_dispatch_without_any_script_raises(self):
with self.assertRaises(LauncherPatternMissing):
el.Runs(tree(**{el.RUN_EMU: "echo nothing\n"}))
class LibretroRecords(unittest.TestCase):
def test_retroarch_system_directory_comes_from_the_sed(self):
(record,) = records(el.retroarch)
self.assertEqual(record["search_dir"], "/storage/roms/bios")
self.assertEqual(record["kind"], "passes_path")
self.assertEqual(
record["source_ref"], f"{ref(el.RETROARCH_MK, '2')}, {ref(el.RUN_EMU, '80')}"
)
def test_retrorun_is_handed_the_folder_with_d(self):
(record,) = records(el.retrorun)
self.assertEqual(
(record["emulator"], record["search_dir"], record["passes_to"]),
("retrorun", "/storage/roms/bios", "retrorun -d"),
)
self.assertEqual(record["source_ref"], ref(el.RUN_EMU, "4, 81-82"))
def test_freej2me_gets_java_home_and_its_jar_copied(self):
java, jar = records(el.freej2me)
self.assertEqual(java["passes_to"], "environment JAVA_HOME")
self.assertEqual(java["search_dir"], "/storage/roms/bios/jdk")
self.assertEqual(jar["kind"], "copies")
self.assertEqual(jar["names"], ["freej2me-lr.jar"])
self.assertEqual(jar["passes_to"], "${HOME}/roms/bios")
self.assertEqual(jar["depends_on_option"], "/storage/roms/bios/jdk/eeversion exists")
def test_mame_copies_its_own_files_and_reads_only_path_options(self):
found = records(el.mame)
copies = [r for r in found if r["kind"] == "copies"]
self.assertEqual([r["names"] for r in copies], [["fm*"], ["mame*"]])
folders = [(r["passes_to"], r["search_dir"]) for r in found if r["kind"] == "passes_path"]
self.assertEqual(
folders,
[
("mame.ini rompath", "/storage/roms/bios/mame/bios"),
("mame.ini samplepath", "/storage/roms/bios/mame/samples"),
],
)
self.assertTrue(all(r["depends_on_option"] == "mame_read_config = enabled"
for r in found if r["kind"] == "passes_path"))
def test_mame_without_the_read_config_option_raises(self):
with self.assertRaises(LauncherPatternMissing):
records(el.mame, **{f"{el.LIBRETRO}/mame/config/MAME/MAME.opt": "x = 1\n"})
class StandaloneRecords(unittest.TestCase):
def test_pico8_moves_the_folder_and_runs_the_binary(self):
(record,) = records(el.pico8)
self.assertEqual(record["kind"], "moves")
self.assertEqual(record["names"], ["pico8_dyn"])
self.assertEqual(record["search_dir"], "/storage/roms/bios/pico-8")
self.assertEqual(record["passes_to"], "/emuelec/bin/pico-8")
self.assertEqual(
record["source_ref"],
f"{ref(el.RUN_EMU, '57-58')}, {ref(f'{el.BIN}/pico8.sh', '1-5, 8-10')}",
)
def test_pico8_without_the_removal_is_not_a_move(self):
changed = PICO8_SH.replace(" rm -rf /storage/roms/bios/pico-8\n", "")
with self.assertRaises(LauncherPatternMissing):
records(el.pico8, **{f"{el.BIN}/pico8.sh": changed})
def test_links_from_scripts_and_packages(self):
found = records(el.links)
self.assertEqual(
[(r["emulator"], r["search_dir"]) for r in found],
[
("flycastsa", "/storage/roms/bios/dc"),
("flycast_dojo", "/storage/roms/bios/dc_dojo"),
("amiberry", "/storage/roms/bios"),
("amiberry-lite", "/storage/roms/bios"),
("timidity", "/storage/roms/bios/timidity/freepats"),
],
)
self.assertEqual(
found[1]["source_ref"],
f"{ref(el.RUN_EMU, '26-27')}, "
f"{ref(f'{EMU}/flycast-dojo/scripts/flycastdojo.sh', '1-5')}",
)
self.assertEqual(
found[2]["passes_to"], "symlink /usr/config/amiberry/kickstarts -> /storage/roms/bios"
)
def test_a_script_without_a_bios_link_raises(self):
with self.assertRaises(LauncherPatternMissing):
records(el.links, **{f"{EMU}/flycastsa/scripts/flycast.sh": "flycast \"${1}\"\n"})
def test_duckstation_scans_the_folder_its_config_names(self):
(record,) = records(el.duckstation)
self.assertEqual((record["kind"], record["search_dir"]), ("scans_dir", "/storage/roms/bios"))
def test_duckstation_with_a_fixed_bios_path_raises(self):
changed = DUCKSTATION_INI.replace("PathPAL =", "PathPAL = /storage/roms/bios/scph5502.bin")
with self.assertRaises(LauncherPatternMissing):
records(el.duckstation, **{f"{EMU}/duckstation/config/settings.ini": changed})
def test_yabasanshiro_passes_the_bios_unless_hle_is_chosen(self):
new, old = records(el.yabasanshiro)
self.assertEqual((new["emulator"], old["emulator"]), ("yabasanshiroSA", "yabasanshiroSA1_5"))
self.assertEqual(new["names"], ["saturn_bios.bin"])
self.assertEqual(new["passes_to"], "yabasanshiro -b")
self.assertEqual(old["passes_to"], "yabasanshiro1_5 -b")
self.assertEqual(new["depends_on_option"], "hlebios != 1")
self.assertIs(new["fails_when_missing"], False)
def test_jzintv_is_handed_the_bios_folder(self):
(record,) = records(el.jzintv)
self.assertEqual((record["search_dir"], record["passes_to"]), ("/storage/roms/bios", "jzintv -p"))
def test_mupen64plus_tries_its_ipl_names_in_order(self):
(record,) = records(el.mupen64plus)
self.assertEqual(record["kind"], "names_searched")
self.assertEqual(record["names"], ["N64DD IPLROM (J).n64", "IPL.n64"])
self.assertEqual(record["search_dir"], "/storage/roms/bios/Mupen64plus")
self.assertEqual(record["passes_to"], "mupen64plus --dd-ipl-rom")
self.assertEqual(record["depends_on_option"], '-f "${GAMEDIR}/${GAMENAME}.ndd"')
def test_mupen64plus_without_a_fallback_raises(self):
changed = M64P_SH.replace('[ ! -f "${IPLROM}" ] && IPLROM="${BIOSDIR}/IPL.n64"\n', "")
with self.assertRaises(LauncherPatternMissing):
records(el.mupen64plus, **{f"{EMU}/mupen64plussa/mupen64plussa-core/m64p.sh": changed})
def test_hatari_reads_the_tos_named_by_its_default_config(self):
(record,) = records(el.hatari)
self.assertEqual(record["names"], ["tos.img"])
self.assertEqual(
record["passes_to"], "Atari-ST-default.cfg [ROM] szTosImageFileName (--configfile)"
)
def test_advancemame_one_record_when_every_device_agrees(self):
(record,) = records(el.advancemame)
self.assertEqual(record["search_dir"], "/storage/roms/bios/advmame/samples")
self.assertNotIn("device", record)
def test_advancemame_devices_that_disagree_raise(self):
changed = ADVMAME_RC.replace("bios/advmame", "bios/other")
with self.assertRaises(LauncherPatternMissing):
records(el.advancemame, **{f"{EMU}/advancemame/config/advmame.rc_oga": changed})
def test_scummvm_extrapath_and_the_ini_copied_for_the_core(self):
extra, ini = records(el.scummvm)
self.assertEqual(extra["passes_to"], "scummvm --extrapath")
self.assertEqual(extra["depends_on_option"], "/storage/.config/scummvm/extra exists")
self.assertEqual((ini["emulator"], ini["build"]), ("scummvm", "libretro"))
self.assertEqual(ini["search_dir"], "/storage/.config/scummvm")
self.assertEqual(ini["passes_to"], "/storage/roms/bios/scummvm.ini")
def test_dolphin_data_home(self):
(record,) = records(el.dolphin)
self.assertEqual(record["passes_to"], "environment XDG_DATA_HOME")
self.assertEqual(record["search_dir"], "/storage/roms/dolphin")
def test_midi_sources_that_read_the_bios_folder(self):
found = records(el.midi)
self.assertEqual(
[(r["emulator"], r["kind"], r["names"], r["search_dir"]) for r in found],
[
("fluidsynth", "fixed_name", ["sc/SC-55.sf2"], "/storage/roms/bios"),
("mt32d", "passes_path", [], "/roms/bios"),
],
)
self.assertEqual(found[0]["depends_on_option"], "ra_midi_output = fluidsynth")
self.assertEqual(
found[1]["source_ref"], f"{ref(el.RUN_EMU, '7-9')}, {ref(el.UTILS, '1, 10-11')}"
)
def test_every_extractor_runs_on_the_fixtures(self):
found = el.extract_launchers(tree())
self.assertEqual(len(found), 26)
class Revision(unittest.TestCase):
def test_the_revision_is_the_one_the_bios_list_is_read_at(self):
url = (
"https://raw.githubusercontent.com/EmuELEC/EmuELEC/v4.8/"
"packages/sx05re/emuelec/bin/batocera/batocera-systems"
)
self.assertEqual(launcher_revision(url), "v4.8")
def test_a_url_without_a_revision_raises(self):
with self.assertRaises(ValueError):
launcher_revision("https://example.org/batocera-systems")
class PlatformRecords(unittest.TestCase):
"""The launchers platforms/emuelec.yml carries, as the scraper wrote them."""
@classmethod
def setUpClass(cls) -> None:
cls.config = yaml.safe_load((REPO_ROOT / "platforms" / "emuelec.yml").read_text())
def test_the_platform_carries_launchers(self):
self.assertTrue(self.config.get("launchers"))
def test_every_reference_is_in_the_emuelec_packages(self):
for record in self.config["launchers"]:
for part in record["source_ref"].split(", "):
if ":" in part:
self.assertTrue(part.startswith(f"{el.SX05RE}/"), record)
if __name__ == "__main__":
unittest.main()
+643
View File
@@ -0,0 +1,643 @@
"""KNULLI's launcher layer, read from its configgen and board scripts.
The fixtures are cut-down copies of the blocks each extractor reads at
knulli-linux 20260511. Records must carry the names in the order the code
writes or tries them, cite the fixture's own lines, and a construct that is
gone must stop the scrape instead of returning nothing.
"""
from __future__ import annotations
import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache
import sys
import textwrap
import unittest
from pathlib import Path
import yaml
REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT / "scripts"))
from scraper import knulli_launchers as kl # noqa: E402
from scraper.batocera_launchers import hatari, melonds # noqa: E402
from scraper.configgen_launchers import LauncherShapeError # noqa: E402
G = kl.GENERATORS
def text(block: str) -> str:
return textwrap.dedent(block).lstrip("\n")
PATHS = text(
"""
from pathlib import Path
from typing import Final
KNULLI_SHARE_DIR: Final = Path('/usr/share/knulli')
DATAINIT_DIR: Final = KNULLI_SHARE_DIR / 'datainit'
USERDATA: Final = Path('/userdata')
HOME: Final = USERDATA / 'system'
CONFIGS: Final = HOME / 'configs'
BIOS: Final = USERDATA / 'bios'
ROMS: Final = USERDATA / 'roms'
"""
)
IMPORTER = text(
"""
from typing import Final
_GENERATOR_MAP: Final[dict[str, tuple[str, str]]] = {
'lexaloffle': ('lexaloffle.lexaloffleGenerator', 'LexaloffleGenerator'),
'yabasanshiro': ('yabasanshiro.yabasanshiroGenerator', 'YabasanshiroGenerator'),
'ryujinx': ('ryujinx.ryujinxGenerator', 'RyujinxGenerator'),
'dolphin': ('dolphin.dolphinGenerator', 'DolphinGenerator'),
'scummvm': ('scummvm.scummvmGenerator', 'ScummVMGenerator'),
'openmsx': ('openmsx.openmsxGenerator', 'OpenmsxGenerator'),
'hatari': ('hatari.hatariGenerator', 'HatariGenerator'),
'melonds': ('melonds.melondsGenerator', 'MelonDSGenerator'),
'pcsx2': ('pcsx2.pcsx2Generator', 'Pcsx2Generator'),
'mame': ('mame.mameGenerator', 'MameGenerator'),
}
"""
)
# lexaloffleGenerator.py: the binary constants, the system branches, the two
# checks that log and return, and the command.
LEXALOFFLE = text(
"""
from ...batoceraPaths import BIOS, HOME, ROMS
PICO8_BIN_PATH: Final = BIOS / "pico-8" / "pico8"
VOX_BIN_PATH: Final = BIOS / "voxatron" / "vox"
class LexaloffleGenerator(Generator):
def generate(self, system, rom, playersControllers, metadata, guns, wheels, gameResolution):
if (system.name == "pico8"):
BIN_PATH=PICO8_BIN_PATH
elif (system.name == "voxatron"):
BIN_PATH=VOX_BIN_PATH
else:
return -1
if not BIN_PATH.exists():
eslog.error(f"Lexaloffle official binary not found at {BIN_PATH}")
return -1
if not os.access(BIN_PATH, os.X_OK):
eslog.error(f"File {BIN_PATH} is not set as executable")
return -1
commandArray = [BIN_PATH]
return Command.Command(array=commandArray, env={})
"""
)
# libretroOptions.py: one function of core blocks, the option or a literal.
OPTIONS = text(
"""
def generateCoreSettings(coreSettings, system, rom, guns, wheels):
if (system.config['core'] == 'o2em'):
coreSettings.save('o2em_vkbd_transparency', '"25"')
if system.isOptSet('o2em_bios'):
coreSettings.save('o2em_bios', '"' + system.config['o2em_bios'] + '"')
elif system.name == 'videopacplus':
coreSettings.save('o2em_bios', '"g7400.bin"')
else:
coreSettings.save('o2em_bios', '"o2rom.bin"')
if (system.config['core'] == 'neocd'):
if system.isOptSet('neocd_bios'):
coreSettings.save('neocd_bios', '"' + system.config['neocd_bios'] + '"')
else:
coreSettings.save('neocd_bios', '"neocd_z.rom (CDZ)"')
"""
)
PICO8 = text(
"""
#!/bin/sh
TARGET_DIR="/userdata/bios"
PICO_DIR="$TARGET_DIR/pico-8"
ROMS_DIR="/userdata/roms/pico8"
TEMP_INSTALL_DIR="$ROMS_DIR/pico8-install"
PICO_8_64_FILE="$TEMP_INSTALL_DIR/pico-8/pico8_64"
PICO_8_DAT_FILE="$TEMP_INSTALL_DIR/pico-8/pico8.dat"
PICO_8_ZIPFILE=$(ls -d /userdata/roms/pico8/pico-8*raspi*.zip 2>/dev/null | head -1)
if [ -z $PICO_8_ZIPFILE ] || [ ! -f "$PICO_8_ZIPFILE" ]; then
echo "Please add the Raspberry Pi version of Pico-8 to roms/pico8 and try again."
exit 2
fi
mv $PICO_8_64_FILE "$PICO_DIR/pico8"
mv $PICO_8_DAT_FILE "$PICO_DIR/"
"""
)
YABASANSHIRO = text(
"""
from ...batoceraPaths import BIOS
YABA_BIOS: Final = BIOS / "saturn_bios.bin"
class YabasanshiroGenerator(Generator):
def generate(self, system, rom, playersControllers, metadata, guns, wheels, gameResolution):
commandArray = ["yabasanshiro", "-i", rom]
if not (system.isOptSet('yaba_bios_hle') and system.config['yaba_bios_hle'] == '1'):
if YABA_BIOS.exists():
commandArray[1:1] = ["-b", str(YABA_BIOS)]
return Command.Command(array=commandArray)
"""
)
RYUJINX = text(
"""
from ...batoceraPaths import BIOS, CONFIGS
ryujinxConf: Final = CONFIGS / "Ryujinx"
ryujinxKeys: Final = BIOS / "switch" / "prod.keys"
class RyujinxGenerator(Generator):
def generate(self, system, rom, playersControllers, metadata, guns, wheels, gameResolution):
if ryujinxKeys.exists():
shutil.copyfile(ryujinxKeys, ryujinxConf / "system" / "prod.keys")
"""
)
DOLPHIN_PATHS = text(
"""
from ...batoceraPaths import BIOS
DOLPHIN_BIOS: Final = BIOS / "GC"
"""
)
DOLPHIN = text(
"""
from .dolphinPaths import DOLPHIN_BIOS
class DolphinGenerator(Generator):
def generate(self, system, rom, playersControllers, metadata, guns, wheels, gameResolution):
if system.isOptSet("dolphin_SkipIPL") and system.getOptBoolean("dolphin_SkipIPL"):
ipl_regions = ["USA", "EUR", "JAP"]
if any((DOLPHIN_BIOS / region / "IPL.bin").exists() for region in ipl_regions):
dolphinSettings.set("Core", "SkipIPL", "False")
else:
dolphinSettings.set("Core", "SkipIPL", "True")
"""
)
SCUMMVM = text(
"""
from ...batoceraPaths import BIOS
scummExtra: Final = BIOS / "scummvm" / "extra"
class ScummVMGenerator(Generator):
def generate(self, system, rom, playersControllers, metadata, guns, wheels, gameResolution):
mkdir_if_not_exists(scummExtra)
commandArray = ["/usr/bin/scummvm", "-f"]
commandArray.extend(
[f"--joystick={id}",
f"--extrapath={scummExtra}",
f"{romName}"]
)
"""
)
OPENMSX = text(
"""
class OpenmsxGenerator(Generator):
def generate(self, system, rom, playersControllers, metadata, guns, wheels, gameResolution):
with settings_tcl.open("a") as file:
file.write("filepool add -path /userdata/bios/Machines -types system_rom -position 1\\n")
"""
)
LIBRETRO_CONFIG = text(
"""
def writeLibretroConfigToFile(retroarchConfig, system, rom):
if (system.config['core'] == 'puae') or (system.config['core'] == 'uae4arm'):
retroarchConfig['system_directory'] = '"/userdata/bios/amiga/"'
if system.config['core'] in [ 'mame', 'mess' ]:
libretroMAMEConfig.generateMAMEConfigs(controllers, system, rom, guns)
"""
)
MAME_CONFIG = text(
"""
from ...batoceraPaths import BIOS
def generateMAMEConfigs(playersControllers, system, rom, guns):
if system.name in [ 'mame', 'neogeo' ]:
commandLine += [ '-rompath', f'"{rom.parent};/userdata/bios/mame/;/userdata/bios/"' ]
if not system.isOptSet("sharemameart"):
artPath = f"/usr/bin/mame/artwork/;{BIOS / 'mame' / 'artwork'}"
else:
artPath = f"/usr/bin/mame/artwork/"
commandLine += [ '-artpath', artPath ]
mkdir_if_not_exists(BIOS / "mame" / "samples")
"""
)
# hatariGenerator.py in KNULLI's older form: the language and model read
# with subscripts, the name built bare and joined to BIOS on the command line.
HATARI = text(
"""
from ...batoceraPaths import BIOS
class HatariGenerator(Generator):
def generate(self, system, rom, playersControllers, metadata, guns, wheels, gameResolution):
model_mapping = {"520st_auto": { "machine": "st", "tos": "auto" }}
commandArray = ["hatari", "--fullscreen"]
machine = "st"
tosversion = "auto"
if system.isOptSet("model") and system.config["model"] in model_mapping:
machine = model_mapping[system.config["model"]]["machine"]
tosversion = model_mapping[system.config["model"]]["tos"]
toslang = "us"
if system.isOptSet("language"):
toslang = system.config["language"]
commandArray += ["--machine", machine]
tos = HatariGenerator.findBestTos(BIOS, machine, tosversion, toslang)
commandArray += [ "--tos", BIOS / tos]
@staticmethod
def findBestTos(biosdir, machine, tos_version, language) -> str:
all_languages = ["us", "uk", ""]
all_machines_bios = {
"st": ["etos256", "104"],
}
if machine in all_machines_bios:
for v_tos_version in l_tos:
for v_language in l_lang:
if "etos" in v_tos_version:
biosversion = v_tos_version
else:
biosversion = f"tos{v_tos_version}"
filename = f"{biosversion}{v_language}.img"
if os.path.exists(f"{biosdir}/{filename}"):
return filename
raise Exception(f"no bios found for machine {machine}")
"""
)
MELONDS = text(
"""
from ...batoceraPaths import BIOS
class MelonDSGenerator(Generator):
def generate(self, system, rom, playersControllers, metadata, guns, wheels, gameResolution):
base_config = {
"DS": {
"FirmwarePath": str(BIOS / "firmware.bin"),
"BIOS7Path": str(BIOS / "bios7.bin"),
},
"Emu": {
"ExternalBIOSEnable": True
},
}
if system.isOptSet("melonds_console"):
base_config["Emu"]["ConsoleType"] = int(system.config["melonds_console"])
else:
base_config["Emu"]["ConsoleType"] = 0
"""
)
# pcsx2Generator.py: the default patches copied into BIOS when absent, and
# the BIOS folder written relative to the config folder.
PCSX2 = text(
"""
from ...batoceraPaths import BIOS, CONFIGS, DATAINIT_DIR
_PCSX2_CONFIG: Final = CONFIGS / "PCSX2"
_PCSX2_BIOS: Final = BIOS / "ps2"
class Pcsx2Generator(Generator):
def generate(self, system, rom, playersControllers, metadata, guns, wheels, gameResolution):
pcsx2Patches = _PCSX2_BIOS / "patches.zip"
configureINI(_PCSX2_CONFIG, _PCSX2_BIOS, system)
if not pcsx2Patches.exists():
shutil.copy(DATAINIT_DIR / "bios" / "ps2" / "patches.zip", pcsx2Patches)
def configureINI(config_directory, bios_directory, system):
configFileName = config_directory / 'inis' / "PCSX2.ini"
pcsx2INIConfig.set("Folders", "Bios", "../../../bios/ps2")
pcsx2INIConfig.set("Folders", "Logs", "../../logs")
"""
)
# mameGenerator.py: the Macintosh boot disk named from the bootdisk option.
MAME = text(
"""
class MameGenerator(Generator):
def generate(self, system, rom, playersControllers, metadata, guns, wheels, gameResolution):
if system.name == "macintosh" and system.isOptSet("bootdisk"):
if system.config["bootdisk"] in [ "macos30", "macos608" ]:
bootType = "-flop1"
bootDisk = "/userdata/bios/" + system.config["bootdisk"] + ".img"
else:
bootType = "-hard"
bootDisk = "/userdata/bios/" + system.config["bootdisk"] + ".chd"
commandArray += [ bootType, bootDisk ]
"""
)
FEATURES = text(
"""
mame:
systems:
macintosh:
cfeatures:
bootdisk:
prompt: BOOT DISK
choices:
"System 3.0 (LD Floppy)": macos3
"System 6.0.8 (LD Floppy)": macos608
"System 7.5.5 (Hard Drive)": mac755
"""
)
def tree(**overrides: str) -> dict[str, str]:
files = {
f"{kl.CONFIGGEN}/batoceraPaths.py": PATHS,
f"{G}/importer.py": IMPORTER,
f"{G}/lexaloffle/lexaloffleGenerator.py": LEXALOFFLE,
kl.LIBRETRO_OPTIONS: OPTIONS,
kl.PICO8_INSTALLER: PICO8,
f"{G}/yabasanshiro/yabasanshiroGenerator.py": YABASANSHIRO,
f"{G}/ryujinx/ryujinxGenerator.py": RYUJINX,
f"{G}/dolphin/dolphinPaths.py": DOLPHIN_PATHS,
f"{G}/dolphin/dolphinGenerator.py": DOLPHIN,
f"{G}/scummvm/scummvmGenerator.py": SCUMMVM,
f"{G}/openmsx/openmsxGenerator.py": OPENMSX,
f"{G}/libretro/libretroConfig.py": LIBRETRO_CONFIG,
f"{G}/libretro/libretroMAMEConfig.py": MAME_CONFIG,
f"{G}/hatari/hatariGenerator.py": HATARI,
f"{G}/melonds/melondsGenerator.py": MELONDS,
f"{G}/pcsx2/pcsx2Generator.py": PCSX2,
f"{G}/mame/mameGenerator.py": MAME,
kl.ES_FEATURES: FEATURES,
}
files.update(overrides)
return files
def configgen(**overrides: str) -> kl.Configgen:
files = tree(**overrides)
return kl.configgen(files.__getitem__)
def sites(path: str, kind: str, **fields: object) -> list[dict]:
spec = kl.GenericSites(path, kind, **fields) # type: ignore[arg-type]
return [launcher.entry() for launcher in kl.bios_sites(configgen(), spec)]
class SharedExtractors(unittest.TestCase):
"""Batocera's extractors read KNULLI's older generator forms."""
def test_hatari_with_a_bare_name_joined_to_bios(self):
(st,) = hatari(configgen())
self.assertEqual(st.names, ["etos256{L}.img", "tos104{L}.img"])
self.assertEqual(st.expands, {"L": ["us", "uk", ""]})
self.assertEqual(st.passes_to, "--machine st --tos <file>")
self.assertEqual(st.fails_when_missing, "no bios found for machine st")
self.assertEqual(st.depends_on_option, "model, language")
self.assertTrue(st.source_ref.startswith(f"{G}/hatari/hatariGenerator.py:"))
def test_hatari_reads_the_knulli_package(self):
(st,) = hatari(configgen())
self.assertNotIn("package/batocera", st.source_ref)
def test_hatari_name_built_another_way_raises(self):
broken = HATARI.replace('filename = f"{biosversion}{v_language}.img"', "filename = x")
with self.assertRaises(LauncherShapeError):
hatari(configgen(**{f"{G}/hatari/hatariGenerator.py": broken}))
def test_melonds_console_read_by_subscript(self):
(ds,) = melonds(configgen())
self.assertEqual(ds.names, ["firmware.bin", "bios7.bin"])
self.assertEqual(ds.depends_on_option, "melonds_console")
self.assertEqual(ds.source_ref, f"{G}/melonds/melondsGenerator.py:6-12, 15")
def test_a_configgen_without_the_plain_map_raises(self):
with self.assertRaises(LauncherShapeError):
configgen(**{f"{G}/importer.py": "X = 1\n"})
class Lexaloffle(unittest.TestCase):
def test_each_system_runs_its_binary(self):
pico8, vox = kl.lexaloffle(configgen())
self.assertEqual((pico8.slot, pico8.names), ("pico8", ["pico-8/pico8"]))
self.assertEqual((vox.slot, vox.names), ("voxatron", ["voxatron/vox"]))
self.assertEqual(pico8.search_dir, "/userdata/bios")
self.assertEqual(pico8.passes_to, "exec")
def test_the_two_checks_are_the_failure(self):
pico8, _ = kl.lexaloffle(configgen())
self.assertEqual(
pico8.fails_when_missing,
"Lexaloffle official binary not found at /userdata/bios/pico-8/pico8, "
"File /userdata/bios/pico-8/pico8 is not set as executable",
)
def test_the_lines_cited(self):
pico8, vox = kl.lexaloffle(configgen())
path = f"{G}/lexaloffle/lexaloffleGenerator.py"
self.assertEqual(pico8.source_ref, f"{path}:3, 8-9, 14-20")
self.assertEqual(vox.source_ref, f"{path}:4, 10-11, 14-20")
def test_a_raise_in_place_of_the_log_raises(self):
broken = LEXALOFFLE.replace(
'eslog.error(f"Lexaloffle official binary not found at {BIN_PATH}")\n return -1',
'raise BatoceraException(f"Lexaloffle official binary not found at {BIN_PATH}")',
)
with self.assertRaises(LauncherShapeError):
kl.lexaloffle(configgen(**{f"{G}/lexaloffle/lexaloffleGenerator.py": broken}))
class PicoInstaller(unittest.TestCase):
def test_the_files_moved_into_bios(self):
(record,) = kl.pico8_installer(tree().__getitem__, "/userdata/bios")
self.assertEqual(record.kind, "moves")
self.assertEqual(record.names, ["pico-8/pico8", "pico-8/pico8.dat"])
self.assertEqual(
record.passes_to,
"moved from /userdata/roms/pico8/pico-8*raspi*.zip into /userdata/bios/pico-8",
)
self.assertEqual(
record.fails_when_missing,
"Please add the Raspberry Pi version of Pico-8 to roms/pico8 and try again.",
)
self.assertEqual(record.source_ref, f"{kl.PICO8_INSTALLER}:3-12, 16-17")
def test_an_installer_that_moves_nothing_into_bios_raises(self):
broken = PICO8.replace('"$PICO_DIR/', '"/tmp/')
with self.assertRaises(LauncherShapeError):
kl.pico8_installer(tree(**{kl.PICO8_INSTALLER: broken}).__getitem__, "/userdata/bios")
class CoreFileOptions(unittest.TestCase):
def test_option_then_literal_defaults(self):
o2em, neocd = kl.core_file_options(configgen())
self.assertEqual(o2em.emulator, "o2em")
self.assertEqual(o2em.names, ["g7400.bin", "o2rom.bin"])
self.assertEqual(o2em.depends_on_option, "o2em_bios (default by system.name == 'videopacplus')")
self.assertEqual(o2em.source_ref, f"{kl.LIBRETRO_OPTIONS}:2, 4-9")
self.assertEqual((neocd.names, neocd.depends_on_option), (["neocd_z.rom (CDZ)"], "neocd_bios"))
def test_a_default_that_is_no_literal_raises(self):
broken = OPTIONS.replace("'\"o2rom.bin\"'", "default_bios")
with self.assertRaises(LauncherShapeError):
kl.core_file_options(configgen(**{kl.LIBRETRO_OPTIONS: broken}))
class BiosSites(unittest.TestCase):
def test_a_flag_on_the_command_line_under_a_presence_test(self):
(record,) = sites("yabasanshiro/yabasanshiroGenerator.py", "fixed_name")
self.assertEqual(record["names"], ["saturn_bios.bin"])
self.assertEqual(record["passes_to"], "command line -b")
self.assertEqual(
record["depends_on_option"],
"not (system.isOptSet('yaba_bios_hle') and system.config['yaba_bios_hle'] == '1')",
)
self.assertEqual(record["source_ref"], f"{G}/yabasanshiro/yabasanshiroGenerator.py:9-11")
def test_a_copy_out_of_bios(self):
(record,) = sites("ryujinx/ryujinxGenerator.py", "fixed_name")
self.assertEqual(record["kind"], "copies")
self.assertEqual(record["names"], ["switch/prod.keys"])
self.assertEqual(record["search_dir"], "/userdata/bios")
self.assertEqual(record["passes_to"], "/userdata/system/configs/Ryujinx/system/prod.keys")
self.assertEqual(record["depends_on_option"], "ryujinxKeys.exists()")
def test_a_presence_test_over_a_literal_list(self):
(record,) = sites("dolphin/dolphinGenerator.py", "fixed_name")
self.assertEqual(record["names"], ["GC/{region}/IPL.bin"])
self.assertEqual(record["expands"], {"region": ["USA", "EUR", "JAP"]})
self.assertEqual(record["passes_to"], "presence sets [Core] SkipIPL = False")
self.assertEqual(record["source_ref"], f"{G}/dolphin/dolphinGenerator.py:5, 7-8")
def test_a_flag_written_into_the_argument(self):
(record,) = sites("scummvm/scummvmGenerator.py", "passes_path")
self.assertEqual(record["search_dir"], "/userdata/bios/scummvm/extra")
self.assertEqual(record["passes_to"], "command line --extrapath")
def test_a_line_written_to_a_config(self):
(record,) = sites("openmsx/openmsxGenerator.py", "passes_path")
self.assertEqual(record["search_dir"], "/userdata/bios/Machines")
self.assertTrue(record["passes_to"].startswith("written: filepool add -path"))
def test_a_core_test_names_the_emulator(self):
(record,) = sites("libretro/libretroConfig.py", "passes_path", build="libretro")
self.assertEqual(record["emulator"], "puae, uae4arm")
self.assertEqual(record["passes_to"], "system_directory")
def test_a_helper_takes_the_cores_of_its_caller(self):
records = sites(
"libretro/libretroMAMEConfig.py", "passes_path", build="libretro",
caller=("libretro/libretroConfig.py", "generateMAMEConfigs"),
)
self.assertEqual({r["emulator"] for r in records}, {"mame, mess"})
# The else branch binds an art path outside /userdata/bios: no record.
rompath, art = records
self.assertEqual(rompath["search_dir"], "<rom.parent>;/userdata/bios/mame/;/userdata/bios/")
self.assertEqual(rompath["passes_to"], "command line -rompath")
self.assertEqual(art["search_dir"], "/usr/bin/mame/artwork/;/userdata/bios/mame/artwork")
self.assertEqual(art["depends_on_option"], "not system.isOptSet('sharemameart')")
self.assertEqual(art["source_ref"], f"{G}/libretro/libretroMAMEConfig.py:6-7, 10")
def test_a_generator_without_a_bios_path_raises(self):
files = tree(**{f"{G}/openmsx/openmsxGenerator.py": "def generate():\n return 1\n"})
spec = kl.GenericSites("openmsx/openmsxGenerator.py", "passes_path")
with self.assertRaises(LauncherShapeError):
kl.bios_sites(kl.configgen(files.__getitem__), spec)
class CopiesAndFolders(unittest.TestCase):
def test_a_copy_into_bios_reads_from_the_folder_it_comes_from(self):
(record,) = sites("pcsx2/pcsx2Generator.py", "fixed_name")
self.assertEqual(record["kind"], "copies")
self.assertEqual(record["names"], ["patches.zip"])
self.assertEqual(record["search_dir"], "/usr/share/knulli/datainit/bios/ps2")
self.assertEqual(record["passes_to"], "/userdata/bios/ps2/patches.zip")
self.assertEqual(record["depends_on_option"], "not pcsx2Patches.exists()")
def test_a_relative_folder_resolved_against_the_config_folder(self):
(record,) = kl.relative_folders(configgen(), kl.RELATIVE_FOLDERS[:1])
self.assertEqual(record.kind, "passes_path")
self.assertEqual(record.search_dir, "/userdata/bios/ps2")
self.assertEqual(
record.passes_to,
"inis/PCSX2.ini [Folders] Bios = ../../../bios/ps2, relative to /userdata/system/configs/PCSX2",
)
self.assertEqual(record.source_ref, f"{G}/pcsx2/pcsx2Generator.py:9, 14-15")
def test_a_folder_written_outside_bios_raises(self):
broken = PCSX2.replace("../../../bios/ps2", "../../../saves/ps2")
with self.assertRaises(LauncherShapeError):
kl.relative_folders(
configgen(**{f"{G}/pcsx2/pcsx2Generator.py": broken}), kl.RELATIVE_FOLDERS[:1]
)
class BootDisks(unittest.TestCase):
def records(self, **overrides: str) -> list:
files = tree(**overrides)
return kl.boot_disks(kl.configgen(files.__getitem__), files.__getitem__, kl.BOOT_DISKS[:1])
def test_each_branch_is_a_template_over_the_values_that_reach_it(self):
floppy, hard = self.records()
self.assertEqual((floppy.names, floppy.passes_to), (["{bootdisk}.img"], "command line -flop1"))
self.assertEqual(floppy.expands, {"bootdisk": ["macos30", "macos608"]})
# The values the menu offers that the code's list does not take.
self.assertEqual((hard.names, hard.passes_to), (["{bootdisk}.chd"], "command line -hard"))
self.assertEqual(hard.expands, {"bootdisk": ["macos3", "mac755"]})
self.assertTrue(hard.depends_on_option.startswith("bootdisk (system.name == 'macintosh'"))
self.assertEqual(
hard.source_ref,
f"{G}/mame/mameGenerator.py:3-4, 9-10, {kl.ES_FEATURES}:8-10",
)
def test_a_name_built_another_way_raises(self):
broken = MAME.replace('"/userdata/bios/" + system.config["bootdisk"] + ".chd"', "disk")
with self.assertRaises(LauncherShapeError):
self.records(**{f"{G}/mame/mameGenerator.py": broken})
def test_an_option_the_menu_no_longer_offers_raises(self):
with self.assertRaises(LauncherShapeError):
self.records(**{kl.ES_FEATURES: FEATURES.replace("bootdisk:", "other:")})
class PlatformFile(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
cls.config = yaml.safe_load((REPO_ROOT / "platforms" / "knulli.yml").read_text())
def test_the_layer_is_written(self):
self.assertTrue(self.config["launchers"])
def test_every_reference_is_in_knulli_code(self):
for record in self.config["launchers"]:
# Or in Batocera's patches, read from KNULLI's batocera submodule.
self.assertTrue(
record["source_ref"].startswith((
f"{kl.CONFIGGEN}/", kl.PICO8_INSTALLER,
*(f"{kl.BATOCERA_SUBMODULE}/{patch}" for patch in kl.PATH_PATCHES),
)), record
)
def test_every_emulator_is_one_knulli_names(self):
cores = {*self.config["cores"], *self.config.get("standalone_cores", [])}
named = {n for record in self.config["launchers"] for n in record["emulator"].split(", ")}
# RetroArch itself, and the MAME core names configgen tests that
# KNULLI's es_systems.yml never offers.
self.assertEqual(sorted(named - cores), ["mamevirtual", "mess", "retroarch"])
if __name__ == "__main__":
unittest.main()
+90 -2
View File
@@ -26,6 +26,7 @@ from scraper import recalbox_scraper # noqa: E402
from scraper.recalbox_launchers import ( # noqa: E402
ALL_CORES,
AMIBERRY_CONFIG,
AMIBERRY_GLOBAL,
AMIBERRY_KICKSTARTS,
AMIBERRY_SUBSYSTEMS,
CONFIGGEN,
@@ -41,6 +42,7 @@ from scraper.recalbox_launchers import ( # noqa: E402
RETROARCH,
SOURCE_FILES,
XEMU,
XROAR,
Configgen,
Launcher,
LauncherShapeError,
@@ -57,6 +59,7 @@ from scraper.recalbox_launchers import ( # noqa: E402
pcsx2,
system_directories,
xemu,
xroar,
)
from tests.test_launchers import placed # noqa: E402
@@ -109,6 +112,9 @@ LAUNCHER_BLOCKS = {
80: ''' elif emulator == "pcsx2":
module = __import__("configgen.generators.pcsx2.pcsx2Generator", fromlist=["Pcsx2Generator"])
generatorClass = getattr(module, "Pcsx2Generator")''',
122: ''' elif emulator == "xroar":
module = __import__("configgen.generators.xroar.xroarGenerator", fromlist=["XroarGenerator"])
generatorClass = getattr(module, "XroarGenerator")''',
125: ''' elif emulator == "xemu":
module = __import__("configgen.generators.xemu.xemuGenerator", fromlist=["XemuGenerator"])
generatorClass = getattr(module, "XemuGenerator")''',
@@ -860,6 +866,34 @@ class ConfigGenerator:''',
self.settings.setString("kickstart_ext_rom_file", extended)''',
}
# amiberryGlobalConfig.py:1-10, 30-43
AMIBERRY_GLOBAL_BLOCKS = {
1: '''#!/usr/bin/env python
class AmiberryGlobalConfig:
def __init__(self, userGlobalSettingsFile, finalGlobalSettingsFile):
self.globalSettingsFile = finalGlobalSettingsFile
self.userSettingsFile = userGlobalSettingsFile
def createGlobalSettings(self, verbose: bool, scanline: bool):''',
30: ''' # Forced values
import configgen.recalboxFiles as recalboxFiles
mount = recalboxFiles.amiberryMountPoint
settings.setBool("Quickstart", True)
# Host paths (Amiberry 8.x reads them from amiberry.conf, overriding the
# ones derived from AMIBERRY_HOME_DIR)
settings.setString("config_path", mount + "/conf/")
settings.setString("controllers_path", mount + "/conf/")
settings.setString("retroarch_config", recalboxFiles.retroarchCustom)
settings.setString("whdboot_path", mount + "/whdboot/")
settings.setString("rp9_path", mount + "/conf/")
# Kickstarts: Amiberry scans this folder on startup to build its ROM list
settings.setString("rom_path", recalboxFiles.BIOS + "/amiga/bios/")
settings.setString("logfile_path", mount + "/amiberry.log")''',
}
# pcsx2Generator.py:1-166
PCSX2_BLOCKS = {
1: r'''#!/usr/bin/env python
@@ -1184,6 +1218,22 @@ from configgen.controllers.controller import InputItem, ControllerPerPlayer, Con
mupenSettings.setString(section, "IPL-ROM", "")''',
}
# xroarGenerator.py:1-26 at 10.1.1
XROAR_BLOCKS = {
8: '''class XroarGenerator(Generator):
def generate(self, system: Emulator, playersControllers: ControllerPerPlayer, recalboxOptions: keyValueSettings, args) -> Command:
# Make save dir
import os
import configgen.recalboxFiles as recalboxFiles''',
22: ''' snapFile: str = os.path.basename(args.rom) + ".sna"
commandArray: List[str] = [recalboxFiles.recalboxBins[system.Emulator],
"-vo", "sdl", "-ui", "sdl", "-ao", "pulse",
"-rompath", os.path.join(recalboxFiles.BIOS, args.system),
"-snappath", os.path.join(snapshotFolder, snapFile)]''',
}
BLOCKS = {
FILES_MODULE: FILES_MODULE_BLOCKS,
LAUNCHER: LAUNCHER_BLOCKS,
@@ -1195,10 +1245,12 @@ BLOCKS = {
AMIBERRY_KICKSTARTS: AMIBERRY_KICKSTARTS_BLOCKS,
AMIBERRY_SUBSYSTEMS: AMIBERRY_SUBSYSTEMS_BLOCKS,
AMIBERRY_CONFIG: AMIBERRY_CONFIG_BLOCKS,
AMIBERRY_GLOBAL: AMIBERRY_GLOBAL_BLOCKS,
PCSX2: PCSX2_BLOCKS,
DOLPHIN: DOLPHIN_BLOCKS,
XEMU: XEMU_BLOCKS,
MUPEN_CONFIG: MUPEN_CONFIG_BLOCKS,
XROAR: XROAR_BLOCKS,
}
@@ -1220,6 +1272,21 @@ def ref(path: str, lines: str) -> str:
return f"{path}:{lines}"
class XroarRomPath(unittest.TestCase):
def test_the_rom_path_is_the_bios_folder_of_the_system(self):
(record,) = xroar(configgen())
self.assertEqual(
(record.emulator, record.kind, record.search_dir, record.passes_to, record.source_ref),
("xroar", "passes_path", "/recalbox/share/bios/<system>", "command line -rompath",
ref(XROAR, "25")),
)
def test_a_rom_path_built_another_way_raises(self):
cg = configgen(XROAR, "os.path.join(recalboxFiles.BIOS, args.system)", "args.rompath")
with self.assertRaises(LauncherShapeError):
xroar(cg)
class SystemDirectoryPerCore(unittest.TestCase):
"""libretroRetroarch.py:431-529, the directory RetroArch is given."""
@@ -1405,18 +1472,39 @@ class AmiberryKickstarts(unittest.TestCase):
"No BIOS found, Extended BIOS not found"),
("amiga600, amiga1200", "fixed_name", ["kick02019.AROS", "kick02019.AROS.ext"],
False),
(None, "passes_path", [], False),
],
)
self.assertEqual(records[1].depends_on_option, "rom type DISK")
self.assertEqual(records[0].search_dir, "/recalbox/share/bios/amiga/bios")
self.assertEqual(records[0].passes_to, "kickstart_rom_file")
self.assertEqual(records[-1].passes_to,
self.assertEqual(records[-2].passes_to,
"kickstart_rom_file, kickstart_ext_rom_file "
"(:AROS built in when either is missing)")
self.assertEqual(records[0].source_ref,
f"{ref(AMIBERRY_KICKSTARTS, '9-10, 50-53, 94-142')}, "
f"{ref(AMIBERRY_CONFIG, '337-345')}")
def test_rom_path_is_the_amiga_bios_folder(self):
record = amiberry(configgen())[-1]
self.assertEqual(
(record.emulator, record.build, record.search_dir, record.passes_to,
record.source_ref),
("amiberry", "standalone", "/recalbox/share/bios/amiga/bios",
"written: rom_path in amiberry.conf", ref(AMIBERRY_GLOBAL, "42")),
)
def test_a_rom_path_outside_the_bios_folder_raises(self):
tree = configgen(AMIBERRY_GLOBAL, 'recalboxFiles.BIOS + "/amiga/bios/"',
'mount + "/roms/"')
with self.assertRaises(LauncherShapeError):
amiberry(tree)
def test_a_missing_rom_path_raises(self):
tree = configgen(AMIBERRY_GLOBAL, '"rom_path"', '"rom_dir"')
with self.assertRaises(LauncherShapeError):
amiberry(tree)
def test_several_pairs_for_one_rom_type_raise(self):
tree = configgen(AMIBERRY_KICKSTARTS, '["kick40060.CD32|kick40060.CD32.ext"]',
'["kick40060.CD32|kick40060.CD32.ext", "a|b"]')
@@ -1511,7 +1599,7 @@ class ExtractionNeverEmpty(unittest.TestCase):
records = extract_launchers(reader)
self.assertEqual(sorted(set(read)), sorted(SOURCE_FILES))
self.assertEqual(len(records), 85)
self.assertEqual(len(records), 87)
def test_records_fit_the_schema(self):
schema = json.loads((REPO_ROOT / "schemas" / "platform.schema.json").read_text())
+330 -13
View File
@@ -92,6 +92,38 @@ AMIBERRY = """
var searchDirs = new List<string> { biosPath, Path.Combine(biosPath, "amiga"), Path.Combine(biosPath, "Amiga") };
return null;
}
public override ProcessStartInfo Generate(string system, string emulator, string core, string rom)
{
if (!GetEmulatorPathAndExe(emulator, out string path, out string exe, "Amiberry.exe", "amiberry.exe"))
return null;
}
private void SetupAmiberrySettings(string path, string system)
{
_amiberryRomsPath = Path.Combine(path, "ROMs");
FileTools.TryCreateDirectory(_amiberryRomsPath);
overrides["rom_path"] = _amiberryRomsPath;
overrides["whdboot_path"] = Path.Combine(path, "WHDBoot");
MergeConfLines(confFile, overrides);
}
private void StageRomKey()
{
string source = FindBios(new[] { "rom.key" });
string dest = Path.Combine(_amiberryRomsPath, "rom.key");
if (!File.Exists(dest) || new FileInfo(dest).Length != new FileInfo(source).Length)
File.Copy(source, dest, true);
}
private string StageKickstart(string[] candidates)
{
string source = FindBios(candidates);
string dest = Path.Combine(_amiberryRomsPath, candidates[0]);
if (!dst.Exists || dst.Length != src.Length || dst.LastWriteTimeUtc < src.LastWriteTimeUtc)
File.Copy(source, dest, true);
return dest;
}
"""
MEDNAFEN = """
@@ -145,6 +177,9 @@ OPENMSX = """
{ "Philips_VG_8020", new string[] { "vg8020_basic-bios1.rom" } },
{ "Pioneer_PX-7", new string[] { "px-7_basic-bios1.rom", "px-7_pbasic.rom" } }
};
string sharePath = Path.Combine(AppConfig.GetFullPath("bios"), "openmsx");
ret.EnvironmentVariables["OPENMSX_HOME"] = sharePath;
"""
DUCKSTATION = """
@@ -182,10 +217,28 @@ FEATURES = """
"""
HATARI = """
string tosDir = Path.Combine(AppConfig.GetFullPath("bios"), "hatari", "tos");
string tosfile = Path.Combine(AppConfig.GetFullPath("bios"), "tos.img");
string emutos = Path.Combine(tosDir, "emutos.img");
if (SystemConfig.isOptSet("hatari_tos") && !string.IsNullOrEmpty(SystemConfig["hatari_tos"]))
tosfile = Path.Combine(AppConfig.GetFullPath("bios"), "hatari", "tos", SystemConfig["hatari_tos"]);
if (SystemConfig.isOptSet("hatari_tos") && SystemConfig["hatari_tos"] != "default")
tosfile = Path.Combine(tosDir, SystemConfig["hatari_tos"]);
else if (media.HasHardDiskImage && File.Exists(emutos))
{
tosfile = emutos;
}
else
{
if (!File.Exists(tosfile) && File.Exists(emutos))
tosfile = emutos;
if (old)
{
string newTos = new string[] { "tos104.img", "tos206.img", "emutos.img" }
.Select(t => Path.Combine(tosDir, t))
.FirstOrDefault(t => File.Exists(t));
}
}
if (!File.Exists(tosfile))
throw new ApplicationException("Missing TOS file " + tosName + " in 'bios' folder.");
@@ -332,6 +385,7 @@ class NamesInLauncherOrder(unittest.TestCase):
def test_amiberry_identical_lists_are_one_record(self):
records = rl.amiberry(_sources(**{f"{G}/Amiberry.Generator.cs": AMIBERRY}))
records = [r for r in records if r["kind"] == "names_searched"]
self.assertEqual(
[r["names"] for r in records],
[
@@ -348,6 +402,46 @@ class NamesInLauncherOrder(unittest.TestCase):
"copied to <amiberry roms>/kick40060.CD32.ext, kickstart_ext_rom_file",
)
def test_amiberry_folders_are_below_its_emulator_folder(self):
records = rl.amiberry(_sources(**{f"{G}/Amiberry.Generator.cs": AMIBERRY}))
folders = [r for r in records if r["kind"] == "passes_path"]
self.assertEqual(
[(r["search_dir"], r["passes_to"], r["source_ref"]) for r in folders],
[
('<AppConfig.GetFullPath("amiberry")>/ROMs', "written: rom_path in amiberry.conf",
f"{G}/Amiberry.Generator.cs:31, 37-41"),
('<AppConfig.GetFullPath("amiberry")>/WHDBoot',
"written: whdboot_path in amiberry.conf", f"{G}/Amiberry.Generator.cs:31, 40-41"),
],
)
def test_amiberry_copies_each_kickstart_into_its_roms_folder(self):
records = rl.amiberry(_sources(**{f"{G}/Amiberry.Generator.cs": AMIBERRY}))
copies = [r for r in records if r["kind"] == "copies"]
self.assertEqual(
[(r["names"], r["passes_to"], r["depends_on_option"]) for r in copies],
[
(["kick40060.CD32", "kick40060.CD32.rom"],
'<AppConfig.GetFullPath("amiberry")>/ROMs/kick40060.CD32',
"first name found, the target is absent, smaller or older"),
(["kick40060.CD32.ext", "amiga-os-310-cd32-ext.rom"],
'<AppConfig.GetFullPath("amiberry")>/ROMs/kick40060.CD32.ext',
"first name found, the target is absent, smaller or older"),
(["rom.key"], '<AppConfig.GetFullPath("amiberry")>/ROMs/rom.key',
"the target is absent or its size differs"),
],
)
self.assertEqual(copies[0]["search_dir"], "bios, bios/amiga, bios/Amiga")
self.assertEqual(
copies[0]["source_ref"],
f"{G}/Amiberry.Generator.cs:3-5, 8-10, 15, 23-27, 31, 37-39, 52-59",
)
def test_amiberry_copy_without_its_staleness_test_raises(self):
broken = AMIBERRY.replace(" || dst.LastWriteTimeUtc < src.LastWriteTimeUtc", "")
with self.assertRaises(rl.LauncherPatternMissing):
rl.amiberry(_sources(**{f"{G}/Amiberry.Generator.cs": broken}))
def test_psx_cascade_splits_searched_from_fallback(self):
records = rl.psx_cascades(_psx_sources())
searched, fallback = [r for r in records if r["emulator"] == "mednafen"]
@@ -372,12 +466,21 @@ class NamesInLauncherOrder(unittest.TestCase):
[
("-machine Philips_VG_8020", ["vg8020_basic-bios1.rom"]),
("-machine Pioneer_PX-7", ["px-7_basic-bios1.rom", "px-7_pbasic.rom"]),
("environment OPENMSX_HOME", []),
],
)
self.assertEqual(records[0]["search_dir"], "bios/openmsx/share/systemroms")
self.assertFalse(records[0]["case_insensitive"])
self.assertEqual(records[1]["source_ref"], f"{G}/OpenMSX.Generator.cs:1-4, 10")
def test_openmsx_home_is_handed_as_a_directory(self):
# OPENMSX_HOME is the user directory openMSX reads share/systemroms below.
records = rl.openmsx(_sources(**{f"{G}/OpenMSX.Generator.cs": OPENMSX}))
home = records[-1]
self.assertEqual(home["kind"], "passes_path")
self.assertEqual(home["search_dir"], "bios/openmsx")
self.assertEqual(home["source_ref"], f"{G}/OpenMSX.Generator.cs:13-14")
def test_duckstation_reads_the_standalone_feature_not_the_core(self):
search, option = rl.duckstation(
_sources(**{f"{G}/Duckstation.Generator.cs": DUCKSTATION, rl.FEATURES: FEATURES})
@@ -391,17 +494,21 @@ class NamesInLauncherOrder(unittest.TestCase):
)
def test_hatari_default_and_option(self):
fixed, option = rl.hatari(
fixed, option, emutos, newer = rl.hatari(
_sources(**{f"{G}/Hatari.Generator.cs": HATARI, rl.FEATURES: HATARI_FEATURES})
)
message = "ApplicationException 'Missing TOS file <tosName> in 'bios' folder.'"
self.assertEqual(fixed["names"], ["tos.img"])
self.assertEqual(
fixed["fails_when_missing"],
"ApplicationException 'Missing TOS file <tosName> in 'bios' folder.'",
)
self.assertEqual(fixed["source_ref"], f"{G}/Hatari.Generator.cs:1-9")
self.assertEqual(fixed["search_dir"], "bios")
self.assertEqual(fixed["fails_when_missing"], f"bios/hatari/tos/emutos.img instead, else {message}")
self.assertEqual(fixed["source_ref"], f"{G}/Hatari.Generator.cs:1-3, 13-14, 27")
self.assertEqual(option["names"], ["tos206.img", "tos102.img"])
self.assertEqual(option["search_dir"], "bios/hatari/tos")
self.assertEqual(option["fails_when_missing"], message)
self.assertEqual(emutos["names"], ["emutos.img"])
self.assertEqual(emutos["search_dir"], "bios/hatari/tos")
self.assertEqual(newer["kind"], "names_searched")
self.assertEqual(newer["names"], ["tos104.img", "tos206.img", "emutos.img"])
def _one(text: str, emulator: str, path: str = f"{G}/X.Generator.cs") -> list[dict]:
@@ -996,6 +1103,150 @@ class FilesNeededTogether(unittest.TestCase):
)
XEMU_SAVES = """
public override ProcessStartInfo Generate(string system, string emulator, string core, string rom)
{
_chihiro = (emulator == "xemu-chihiro" || system == "chihiro");
if (!string.IsNullOrEmpty(AppConfig["saves"]) && Directory.Exists(AppConfig.GetFullPath("saves")))
{
string savePath = Path.Combine(AppConfig.GetFullPath("saves"), system);
if (!_chihiro)
{
if (!File.Exists(Path.Combine(savePath, "eeprom.bin")))
{
File.WriteAllBytes(Path.Combine(savePath, "eeprom.bin"), Properties.Resources.eeprom);
}
if (!File.Exists(Path.Combine(savePath, "xbox_hdd.qcow2")))
{
string zipFile = Path.Combine(savePath, "xbox_hdd.qcow2.zip");
File.WriteAllBytes(zipFile, Properties.Resources.xbox_hdd_qcow2);
Zip.Extract(zipFile, savePath);
File.Delete(zipFile);
}
}
}
}
private void SetupTOMLConfiguration(string eepromPath, string hddPath)
{
if (!string.IsNullOrEmpty(eepromPath))
ini.WriteValue("sys.files", "eeprom_path", "'" + eepromPath + "'");
if (!string.IsNullOrEmpty(hddPath))
ini.WriteValue("sys.files", "hdd_path", "'" + hddPath + "'");
}
private void SetupChihiroConfiguration()
{
string savePath = Path.Combine(AppConfig.GetFullPath("saves"), "chihiro");
if (!Directory.Exists(savePath)) try { Directory.CreateDirectory(savePath); } catch { }
if (Directory.Exists(savePath))
ini.WriteValue("chihiro.roms", "snapshot_store_path", "'" + Path.Combine(savePath, "chihiro_snapshots.qcow2") + "'");
}
private void SetupChihiroEeprom(string path)
{
string savePath = Path.Combine(AppConfig.GetFullPath("saves"), "chihiro");
_chihiroEeprom = Path.Combine(path, "chihiro_eeprom.bin");
_chihiroEepromSave = Path.Combine(savePath, "chihiro_eeprom.bin");
}
private void SaveChihiroEeprom()
{
if (File.Exists(_chihiroEeprom))
File.Copy(_chihiroEeprom, _chihiroEepromSave, true);
}
"""
CXBX = """
private string MountIso(string rom)
{
if (Path.GetExtension(rom).ToLowerInvariant() != ".iso")
return rom;
string xboxIsoVfsPath = Path.Combine(Path.GetDirectoryName(typeof(Installer).Assembly.Location), "xbox-iso-vfs.exe");
if (!File.Exists(xboxIsoVfsPath))
throw new ApplicationException("xbox-iso-vfs is required and is not installed");
string dokan = Environment.GetEnvironmentVariable("DokanLibrary2");
dokan = Path.Combine(dokan, "dokan2.dll");
if (!File.Exists(dokan))
{
throw new ApplicationException("Dokan 2 is required and is not installed");
}
}
public override ProcessStartInfo Generate(string system, string emulator, string core, string rom)
{
string path = null;
if ((core != null && core == "chihiro") || (emulator != null && emulator == "chihiro"))
{
path = AppConfig.GetFullPath("chihiro");
}
else if ((core != null && core == "chihiro-gun") || (emulator != null && emulator == "chihiro-gun"))
{
path = AppConfig.GetFullPath("chihiro-ds");
}
if (string.IsNullOrEmpty(path))
path = AppConfig.GetFullPath("cxbx-reloaded");
if (string.IsNullOrEmpty(path))
path = AppConfig.GetFullPath("cxbx-r");
using (var ini = IniFile.FromFile(Path.Combine(path, "settings.ini"), IniOptions.KeepEmptyValues))
{
}
if (system == "xbox")
{
string eeprom = Path.Combine(AppConfig.GetFullPath("cxbx-reloaded"), "EEPROM.bin");
if (!File.Exists(eeprom))
File.WriteAllBytes(eeprom, Properties.Resources.eeprom);
WriteXboxEEPROM(eeprom);
}
}
"""
class XboxFilesTheLauncherWrites(unittest.TestCase):
def test_xemu_keeps_its_eeprom_and_disk_below_saves(self):
records = rl.xemu_saves(_sources(**{f"{G}/Xemu.Generator.cs": XEMU_SAVES}))
self.assertEqual(
[(r["emulator"], r["kind"], r["names"], r["search_dir"], r["source_ref"])
for r in records],
[
("xemu", "fixed_name", ["eeprom.bin", "xbox_hdd.qcow2"], "saves/<system>",
f"{G}/Xemu.Generator.cs:3-19, 27-29"),
("xemu, xemu-chihiro", "copies", ["chihiro_eeprom.bin"], "saves/chihiro",
f"{G}/Xemu.Generator.cs:3, 40-51"),
("xemu, xemu-chihiro", "fixed_name", ["chihiro_snapshots.qcow2"], "saves/chihiro",
f"{G}/Xemu.Generator.cs:3, 34-37"),
],
)
self.assertIn("eeprom_path, hdd_path", records[0]["passes_to"])
self.assertIn('not (emulator == "xemu-chihiro" or system == "chihiro")',
records[0]["depends_on_option"])
def test_cxbx_runs_from_its_folder_and_gets_the_eeprom_there(self):
records = rl.cxbx(_sources(**{f"{G}/Cxbx.Generator.cs": CXBX}))
self.assertEqual(
[(r["emulator"], r["kind"], r["names"], r["search_dir"], r["source_ref"])
for r in records],
[
("chihiro", "passes_path", [], '<AppConfig.GetFullPath("chihiro")>',
f"{G}/Cxbx.Generator.cs:19-21, 31"),
("chihiro-gun", "passes_path", [], '<AppConfig.GetFullPath("chihiro-ds")>',
f"{G}/Cxbx.Generator.cs:23-25, 31"),
("cxbx-reloaded", "passes_path", [], '<AppConfig.GetFullPath("cxbx-reloaded")>',
f"{G}/Cxbx.Generator.cs:27-31"),
("chihiro, chihiro-gun, cxbx-reloaded", "fixed_name", ["xbox-iso-vfs.exe"],
"<emulatorLauncher folder>", f"{G}/Cxbx.Generator.cs:3-7"),
("chihiro, chihiro-gun, cxbx-reloaded", "fixed_name", ["dokan2.dll"],
"%DokanLibrary2%", f"{G}/Cxbx.Generator.cs:3-4, 8-13"),
("cxbx-reloaded", "fixed_name", ["EEPROM.bin"],
'<AppConfig.GetFullPath("cxbx-reloaded")>', f"{G}/Cxbx.Generator.cs:34-41"),
],
)
self.assertTrue(all(r["passes_to"].startswith(rl.CXBX_DATA_FOLDER) for r in records[:3]))
self.assertEqual(records[3]["passes_to"], "exec")
self.assertEqual(records[5]["depends_on_option"], 'system == "xbox"')
class HelpersAndCopies(unittest.TestCase):
def test_blastem_one_record_per_helper_call(self):
records = rl.blastem(_sources(**{f"{G}/Blastem.Generator.cs": BLASTEM}))
@@ -1020,7 +1271,10 @@ class HelpersAndCopies(unittest.TestCase):
)
self.assertEqual(segaboot["kind"], "copies")
self.assertEqual(segaboot["names"], ["triforce/segaboot.gcm", "segaboot.gcm"])
self.assertEqual(segaboot["depends_on_option"], "_triforce, !_crediar")
self.assertEqual(
segaboot["depends_on_option"],
"_triforce, !_crediar, first name found, the target is absent, smaller or older",
)
def test_dosbox_copies_grouped_by_target_folder(self):
sources = _sources(
@@ -1033,16 +1287,17 @@ class HelpersAndCopies(unittest.TestCase):
(
"dosbox-pure",
["MT32_CONTROL.ROM"],
"copied to <emulator>/mt32-roms/<name>, only when the target does not exist",
"<emulator>/mt32-roms/<name>",
),
(
"dosbox-pure",
["Roland_SC-55.sf2"],
"copied to <emulator>/soundfonts/<name>, only when the target does not exist",
"<emulator>/soundfonts/<name>",
),
],
)
self.assertEqual(records[0]["search_dir"], "bios/scummvm/extra")
self.assertEqual(records[0]["depends_on_option"], "the target does not exist")
def test_tsugaru_folder_chain(self):
[record] = rl.tsugaru(_sources(**{f"{G}/Tsugaru.Generator.cs": TSUGARU}))
@@ -1111,14 +1366,76 @@ class FolderArguments(unittest.TestCase):
)
def test_xroar_reassigned_folder_and_config_line(self):
argument, config = rl.xroar(_sources(**{f"{G}/Xroar.Generator.cs": XROAR}))
self.assertEqual(argument["search_dir"], 'bios/dragon, or bios/coco when system == "coco"')
# romPath is bios/dragon, rewritten to bios/coco for the coco system.
default, coco, config = rl.xroar(_sources(**{
f"{G}/Xroar.Generator.cs": XROAR, rl.FEATURES: XROAR_FEATURES,
}))
self.assertEqual(
(default["search_dir"], default["passes_to"], default.get("systems")),
("bios/dragon", "command line -rompath bios/dragon", None),
)
self.assertEqual(
(coco["search_dir"], coco["passes_to"], coco["systems"]),
("bios/coco", "command line -rompath bios/coco", ["coco"]),
)
self.assertEqual(coco["machines"], ["coco", "coco3"])
self.assertNotIn("machines", default)
self.assertEqual(
coco["source_ref"], f"{default['source_ref']}, {rl.FEATURES}:3-6"
)
self.assertEqual(config["search_dir"], "bios/dragon")
self.assertEqual(
config["passes_to"], 'xroar.conf rompath ".\\\\..\\\\..\\\\bios\\\\dragon"'
)
XROAR_FEATURES = """
<emulator name="xroar">
<system name="coco">
<feature submenu="EMULATION" name="MACHINE" value="xroar_machine" order="100">
<choice name="TANDY COCO(PAL)" value="coco"/>
<choice name="TANDY COCO 3(NTSC)" value="coco3"/>
</feature>
</system>
<system name="dragon32,dragon64,dragon">
<feature submenu="EMULATION" name="MACHINE" value="xroar_machine" order="100">
<choice name="DRAGON64" value="dragon64"/>
</feature>
</system>
</emulator>
"""
PICO8 = """
public override System.Diagnostics.ProcessStartInfo Generate(string system, string emulator, string core, string rom, string playersControllers, ScreenResolution resolution)
{
string path = AppConfig.GetFullPath("pico8");
string exe = Path.Combine(path, "pico8.exe");
if (!File.Exists(exe))
return null;
return new ProcessStartInfo()
{
FileName = exe,
WorkingDirectory = path,
Arguments = args,
};
}
"""
class ProgramsRunFromEmulatorFolders(unittest.TestCase):
def test_pico8_runs_its_binary_from_its_emulator_folder(self):
(record,) = rl.pico8(_sources(**{f"{G}/Pico8.Generator.cs": PICO8}))
self.assertEqual(
(record["emulator"], record["kind"], record["names"], record["search_dir"],
record["passes_to"], record["source_ref"]),
("pico8", "fixed_name", ["pico8.exe"], '<AppConfig.GetFullPath("pico8")>', "exec",
f"{G}/Pico8.Generator.cs:3-7, 11-12"),
)
class EveryBiosReferenceIsRead(unittest.TestCase):
def test_unread_reference_stops_the_scrape(self):
extra = EKA2L1 + (
+87
View File
@@ -293,6 +293,81 @@ DRASTIC = module("drastic", """
""", 36)
UAE4ALL = module("uae4all", """
function configure_uae4all() {
mkRomDir "amiga"
moveConfigDir "$md_inst/kickstarts" "$biosdir/amiga"
rm -f "$romdir/amiga/+Start UAE4All.sh"
if [[ "$md_mode" == "install" ]]; then
cat > "$romdir/amiga/+Start UAE4All.sh" << _EOF_
#!/bin/bash
pushd "$md_inst"
./uae4all
popd
_EOF_
fi
addEmulator 1 "$md_id" "amiga" "bash $romdir/amiga/+Start\\ UAE4All.sh"
addSystem "amiga"
}
""", 60)
OPENMSX = module("openmsx", """
function configure_openmsx() {
mkUserDir "$home/.openMSX/share/systemroms"
moveConfigDir "$home/.openMSX" "$configdir/msx/openmsx"
moveConfigDir "$configdir/msx/openmsx/share/systemroms" "$home/RetroPie/BIOS/openmsx"
moveConfigDir "$home/.unrelated" "$configdir/msx/other"
}
""", 74)
XROAR = module("xroar", """
function build_xroar() {
./configure --prefix="$md_inst" "${params[@]}"
}
function configure_xroar() {
mkdir -p "$md_inst/share/xroar"
ln -snf "$biosdir" "$md_inst/share/xroar/roms"
}
""", 36)
class ReachingLinks(unittest.TestCase):
"""The directory outside BIOS that a whole-directory link is read from."""
def test_openmsx_user_directory_holds_the_systemroms_link(self):
found = records({f"{EMULATORS}/openmsx.sh": OPENMSX}, "openmsx")
links = [r for r in found if r["kind"] == "links"]
self.assertEqual(
[(r["search_dir"], r["passes_to"], r["source_ref"]) for r in links],
[
(
"$home/RetroPie/BIOS/openmsx",
"$configdir/msx/openmsx/share/systemroms is a symlink to it",
f"{EMULATORS}/openmsx.sh:77",
),
(
"$configdir/msx/openmsx",
"$home/.openMSX is a symlink to it",
f"{EMULATORS}/openmsx.sh:76",
),
],
)
def test_xroar_install_prefix_holds_the_roms_link(self):
found = records({f"{EMULATORS}/xroar.sh": XROAR}, "xroar")
prefix = [r for r in found if r["kind"] == "passes_path"]
self.assertEqual(
[(r["search_dir"], r["passes_to"], r["source_ref"]) for r in prefix],
[("$md_inst", "${prefix} of configure --prefix", f"{EMULATORS}/xroar.sh:37")],
)
class WorkingDirectory(unittest.TestCase):
def test_drastic_reads_below_the_folder_its_script_enters(self):
found = records({f"{EMULATORS}/drastic.sh": DRASTIC}, "drastic")
@@ -306,6 +381,18 @@ class WorkingDirectory(unittest.TestCase):
)],
)
def test_uae4all_runs_from_its_install_directory(self):
found = records({f"{EMULATORS}/uae4all.sh": UAE4ALL}, "uae4all")
entered = [r for r in found if r["kind"] == "passes_path"]
self.assertEqual(
[(r["search_dir"], r["passes_to"], r["source_ref"]) for r in entered],
[(
"$md_inst",
"working directory of $romdir/amiga/+Start UAE4All.sh",
f"{EMULATORS}/uae4all.sh:69",
)],
)
def test_a_launch_script_that_no_longer_enters_a_folder_raises(self):
files = {f"{EMULATORS}/drastic.sh": DRASTIC.replace('pushd "', 'echo "')}
with self.assertRaises(rl.LauncherPatternMissing):
+71 -2
View File
@@ -143,6 +143,11 @@ AMIBERRY_SH = text(
fi
sed -i "s#@BIOS_PATH@#${BIOS_PATH}#g" ${AMIBERRY_TMP_CONFIG}
}
if [ ! -d "${AMIBERRY_DIR}" ]
then
cp -rf /usr/config/amiberry ${AMIBERRY_DIR}
fi
cd ${AMIBERRY_DIR}
"""
)
@@ -405,7 +410,7 @@ class NamesTheConfigsFix(unittest.TestCase):
f"{pkg}/config/conf/AmigaA500-default.uae": uae.format("kick34005.A500.rom"),
}
)
a1200, a500, link = (r.entry() for r in rl.amiberry(tree))
a1200, a500, link, entered, copied = (r.entry() for r in rl.amiberry(tree))
self.assertEqual((a1200["slot"], a1200["names"]), ("A1200", ["kick40068.A1200.rom"]))
self.assertEqual(a1200["depends_on_option"], "game name matches AGA|CD32")
self.assertEqual((a500["slot"], a500["names"]), ("A500", ["kick34005.A500.rom"]))
@@ -420,6 +425,21 @@ class NamesTheConfigsFix(unittest.TestCase):
link["passes_to"], "symlink /usr/config/amiberry/kickstarts -> /storage/roms/bios"
)
self.assertEqual(link["source_ref"], f"{pkg}/package.mk:4")
# The script runs amiberry in the copy of /usr/config/amiberry, which
# carries the kickstarts link.
self.assertEqual(
(entered["kind"], entered["search_dir"], entered["passes_to"]),
("passes_path", "/storage/.config/amiberry", "working directory of start_amiberry.sh"),
)
self.assertEqual(entered["source_ref"], f"{pkg}/scripts/start_amiberry.sh:1, 16")
self.assertEqual(
copied["passes_to"],
"symlink /storage/.config/amiberry/kickstarts -> /storage/roms/bios,"
" copied with /usr/config/amiberry",
)
self.assertEqual(
copied["source_ref"], f"{pkg}/package.mk:4, {pkg}/scripts/start_amiberry.sh:1, 14-16"
)
def test_mednafen_one_record_per_module(self):
pkg = f"{SA}/mednafen"
@@ -551,6 +571,53 @@ class Links(unittest.TestCase):
rl.links(tree)
START_PICO8 = text(
"""
#!/bin/bash
. /etc/profile
GAME_DIR="/storage/roms/pico-8/"
case ${HW_ARCH} in
aarch64)
STATIC_BIN="pico8_64"
;;
*)
STATIC_BIN="pico8_dyn"
;;
esac
if [ -d "${GAME_DIR}/${HW_ARCH}" ]
then
LAUNCH_DIR="${GAME_DIR}/${HW_ARCH}"
else
LAUNCH_DIR="${GAME_DIR}"
fi
${LAUNCH_DIR}/${STATIC_BIN} -home -root_path ${GAME_DIR} -joystick 0 ${OPTIONS} "${CART}"
"""
)
class ProgramsRunOutsideTheBiosFolder(unittest.TestCase):
PATH = f"{SA}/pico-8/scripts/start_pico8.sh"
def test_pico8_runs_its_binary_from_roms(self):
(record,) = [r.entry() for r in rl.pico8(RepoTree.from_files({self.PATH: START_PICO8}))]
self.assertEqual(
(record["emulator"], record["kind"], record["names"], record["search_dir"],
record["passes_to"]),
("pico-8", "fixed_name", ["pico8_64", "pico8_dyn"], "/storage/roms/pico-8", "exec"),
)
self.assertIn("HW_ARCH aarch64 runs pico8_64", record["depends_on_option"])
self.assertEqual(record["source_ref"], f"{self.PATH}:4-11, 15-22")
def test_a_script_without_its_binary_choice_raises(self):
broken = START_PICO8.replace('STATIC_BIN="pico8_dyn"', "STATIC_BIN=$OTHER")
with self.assertRaises(LauncherPatternMissing):
rl.pico8(RepoTree.from_files({self.PATH: broken}))
class Revision(unittest.TestCase):
def test_the_revision_is_the_one_the_bios_list_is_read_at(self):
url = (
@@ -572,8 +639,10 @@ class PlatformRecords(unittest.TestCase):
cls.config = yaml.safe_load((REPO_ROOT / "platforms" / "rocknix.yml").read_text())
def test_every_emulator_is_one_rocknix_packages(self):
# RetroArch itself runs the libretro cores the list names.
cores = set(self.config["cores"])
self.assertEqual(sorted({r["emulator"] for r in self.config["launchers"]} - cores), [])
self.assertEqual(sorted({r["emulator"] for r in self.config["launchers"]} - cores),
["retroarch"])
def test_every_reference_is_in_the_rocknix_project(self):
for record in self.config["launchers"]:
+3 -2
View File
@@ -54,7 +54,8 @@ class TheEmulatorContextIsChecked(unittest.TestCase):
def test_the_standalone_layout_reaches_a_profile_without_structure(self):
"""BBKEmu has no pack_structure, and its A4980 8.BIN goes to
system/BBKEmu/A4980/ standalone. The hash pack kept the bare name,
system/bbkemu/a4980/ standalone, the lowercase folder its code
matches exactly. The hash pack kept the bare name,
then, once laid out, sent it to the A4988 folder whose entry shares
the name."""
md5 = "ddfc001a6859d63ed46368ea7fe9f20c"
@@ -62,7 +63,7 @@ class TheEmulatorContextIsChecked(unittest.TestCase):
self.skipTest("the A4980 8.BIN is not collected")
proc, names = _pack("--from-md5", md5, "--emulator", "bbkemu", "--standalone")
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertEqual(names, ["system/BBKEmu/A4980/8.BIN"])
self.assertEqual(names, ["system/bbkemu/a4980/8.BIN"])
class SystemAndEmulatorPacksKeepTheirNames(unittest.TestCase):
+22
View File
@@ -86,6 +86,28 @@ class HeldPinsReadTheirBuildFileAgain(unittest.TestCase):
self.assertEqual(found["mame0278 (recalbox)"].status, cf.STALE)
self.assertIn("is gone", found["mame0278 (recalbox)"].detail)
def test_a_file_of_a_submodule_is_read_at_its_gitlink(self):
"""KNULLI builds Batocera's amiberry package through its batocera
submodule: the file is not in knulli-linux's own tree."""
self._platform("10.2")
ref = {**self.REF, "path": "batocera/package/amiberry/amiberry.mk",
"variable": "AMIBERRY_VERSION", "value": "v7.1.0"}
modules = ['[submodule "batocera"]', "\tpath = batocera",
"\turl = https://github.com/batocera-linux/batocera.linux.git"]
def fetch(repo, sha, path, *_args):
if path == ".gitmodules":
return modules
if repo.slug == "batocera-linux/batocera.linux" and sha == "c" * 40:
return ["AMIBERRY_VERSION = v7.1.0"]
return None
profiles = {"amiberry": {"pin_frozen": "x", "pin_build": [ref]}}
with mock.patch.object(cf.upstream, "fetch_file", side_effect=fetch), \
mock.patch.object(cf.upstream, "list_gitlinks", return_value={"batocera": "c" * 40}):
(row,) = cf.check_pin_builds(profiles, self.platforms, "cache", False)
self.assertEqual(row.status, cf.OK, row.detail)
def test_offline_and_uncached_is_skipped(self):
self._platform("10.2")
profiles = {"mame0278": {"pin_frozen": "x", "pin_build": [self.REF]}}
+6 -4
View File
@@ -21,10 +21,10 @@ from common import load_emulator_profiles # noqa: E402
STEM_NAMED = {
# Template and test cores, no emulator page.
"00_example": "template",
"test": "type test",
"testgl": "type test",
"testvulkan": "type test",
"vidtest": "type test",
"test": "role test",
"testgl": "role test",
"testvulkan": "role test",
"vidtest": "role test",
# Aliases, no emulator page.
"ep128emu": "alias",
"mednafen_gba": "alias",
@@ -64,11 +64,13 @@ STEM_NAMED = {
"ioquake3": "the project writes ioquake3",
"izapple2": "README title izapple2",
"jgenesis": "README title jgenesis",
"n64emu": "README title n64emu",
"np2pi": "repository and binary np2pi, no title in the source",
"rpix86": "the author writes rpix86",
"simple64": "window title simple64",
"sixtyforce": "site title sixtyforce",
"veesem": "README title veesem",
"zcdi": "README title zcdi",
}
+29 -12
View File
@@ -1254,6 +1254,17 @@ class TestSelectRepo(unittest.TestCase):
def test_none_when_no_supported_host(self):
self.assertIsNone(select_repo({"source": "https://www.6809.org.uk/"}))
def test_source_keyed_by_mode_without_upstream(self):
repo = select_repo(
{
"source": {
"standalone": "https://github.com/UZDoom/UZDoom",
"libretro": "https://github.com/libretro/uzdoom",
},
}
)
self.assertEqual(repo.name, "UZDoom")
class TestBuildReport(unittest.TestCase):
def setUp(self):
@@ -3065,7 +3076,10 @@ class TestDeliberatelyFrozenPin(TestBuildReport):
# builds mame2014, mess2015 and cdi2015, three system sets. And a
# live build can add a system its frozen revision lacked
# (advancemame's coh1002v, after advmame-1.4), so the frozen one's
# systems are a subset, not an equal set.
# systems are a subset, not an equal set. A live build can also drop
# a system upstream deleted: advancemame removed its Hyper Neo Geo 64
# driver in dff25b6ee7, which advmame-1.4 still carries.
removed_upstream = {("advmame-1.4", "advancemame"): {"hyper-neogeo64"}}
pairs = 0
for names in by_source.values():
frozen = [
@@ -3082,7 +3096,8 @@ class TestDeliberatelyFrozenPin(TestBuildReport):
pairs += 1
with self.subTest(frozen=old, live=new):
self.assertLessEqual(
set(profiles[old].get("systems") or []),
set(profiles[old].get("systems") or [])
- removed_upstream.get((old, new), set()),
set(profiles[new].get("systems") or []),
)
if (old, new) not in builds_differ:
@@ -3289,30 +3304,32 @@ class TestBumpCommit(unittest.TestCase):
self.assertNotIn("uphead", text)
def test_a_profile_one_platform_ships_waits_for_its_build(self):
"""EmuELEC alone ships RigelEngine and builds its package.mk
PKG_VERSION. A bulk advance moved fheroes2 and supertux past that
build, and rigelengine is a commit ahead of it already."""
"""KNULLI alone ships advanced_drastic and builds its
advanced_drastic.mk version. A bulk advance moved fheroes2 and
supertux past the build EmuELEC then pinned, and a pin ahead of the
one build a platform ships describes nothing anyone runs."""
root = Path(__file__).resolve().parents[1]
path = Path(self.tmp.name) / "rigelengine.yml"
path = Path(self.tmp.name) / "advanced_drastic.yml"
path.write_text(
SAMPLE.replace("\nnotes:", "\ntype: standalone\ncores: [rigelengine, RigelEngine]\n\nnotes:", 1),
SAMPLE.replace(
"\nnotes:", "\ntype: standalone\ncores: [advanced_drastic]\n\nnotes:", 1),
encoding="utf-8",
)
report = ProfileReport(
name="rigelengine", repo="o/n", pin="pin", head="newhead", entries=[],
name="advanced_drastic", repo="o/n", pin="pin", head="newhead", entries=[],
counts={}, skipped=profile_sync.NO_SOURCE_REF,
)
platforms = str(root / "platforms")
self.assertEqual(
profile_sync.shipping_platforms("rigelengine", self.tmp.name, platforms),
["emuelec"],
profile_sync.shipping_platforms("advanced_drastic", self.tmp.name, platforms),
["knulli"],
)
with contextlib.redirect_stderr(io.StringIO()) as err:
self.assertFalse(bump_commit(path, report, platforms_dir=platforms))
self.assertIn("only emuelec ships it", err.getvalue())
self.assertIn("only knulli ships it", err.getvalue())
path.write_text(
path.read_text(encoding="utf-8")
+ 'pin_follows: "EmuELEC builds the branch tip"\n',
+ 'pin_follows: "KNULLI builds the branch tip"\n',
encoding="utf-8",
)
self.assertTrue(bump_commit(path, report, platforms_dir=platforms))
+4 -4
View File
@@ -36,9 +36,9 @@ class TheGroupFollowsWhatTheProfileSays(unittest.TestCase):
})
self.assertEqual(groups, ["clk:file:MSX/msx-american.rom"])
def test_a_variant_group_stays_one_slot(self):
def test_a_selection_slot_stays_one_slot(self):
self.assertEqual(
extra_region_groups({"source_emulator": "picodrive", "variant_group": "mcd",
extra_region_groups({"source_emulator": "picodrive", "selection_slot": "mcd",
"source_systems": ["sega-segacd", "sega-mega-cd"]}),
["picodrive:variant:mcd"],
)
@@ -91,10 +91,10 @@ class TheGroupTakesThePlatformSpelling(unittest.TestCase):
["sega-saturn"],
)
def test_file_and_variant_groups_are_untouched(self):
def test_file_and_selection_slots_are_untouched(self):
spellings = system_spellings(["sega-megacd"])
self.assertEqual(
extra_region_groups({"source_emulator": "picodrive", "variant_group": "mcd",
extra_region_groups({"source_emulator": "picodrive", "selection_slot": "mcd",
"source_system": "sega-megacd"}, spellings),
["picodrive:variant:mcd"],
)
+19 -1
View File
@@ -480,7 +480,10 @@ class RocknixRunsItsStandaloneEmulators(unittest.TestCase):
root = Path(__file__).resolve().parents[1]
platform = yaml.safe_load((root / "platforms" / "rocknix.yml").read_text())
self.assertIn(f"/distribution/{platform['version']}/", platform["source"])
self.assertIn("retroarch", platform["cores"])
# RetroArch runs the libretro cores some device image installs, not
# every libretro profile.
self.assertNotIn("retroarch", platform["cores"])
self.assertIn("beetle_psx", platform["cores"])
registry = yaml.safe_load((root / "platforms" / "_registry.yml").read_text())
self.assertNotIn("cores", registry["platforms"]["rocknix"])
@@ -1116,5 +1119,20 @@ class EmptyScrapeWritesNothing(unittest.TestCase):
scraper.module_ids(archive)
class PlatformFileHasNoAnchors(unittest.TestCase):
def test_a_shared_list_is_written_twice(self):
"""RetroBat's amiberry search and copy records share one name list:
the platform file read back the same, but held &id001 and *id001."""
import yaml
from scraper.base_scraper import _PlatformDumper
names = ["kick34005.A500", "amiga-os-130.rom"]
text = yaml.dump([{"names": names}, {"names": names}], Dumper=_PlatformDumper)
self.assertNotIn("&id", text)
self.assertNotIn("*id", text)
self.assertEqual(yaml.safe_load(text), [{"names": names}, {"names": names}])
if __name__ == "__main__":
unittest.main()
+16 -1
View File
@@ -193,7 +193,22 @@ class ProfileContradictionsAreKnown(unittest.TestCase):
self.assertEqual(sorted(unsatisfied), KNOWN_UNSATISFIED)
KNOWN_UNSATISFIED: list[str] = []
KNOWN_UNSATISFIED: list[str] = [
# Amiberry's ROM table identifies the A2000 keyboard MCU by crc32
# c23d280e and sha1 b5c4b8c3 (rommgr.cpp:141-142). The held
# D8039HLC.rom is another dump (crc32 fb92a773), so the ROM to acquire
# is still missing for every amiberry build.
"amiberry-7.1.1-332/D8039HLC.rom",
"amiberry-7.1.1/D8039HLC.rom",
"amiberry-8.0.0/D8039HLC.rom",
"amiberry-8.2.2/D8039HLC.rom",
"amiberry-8.3.0/D8039HLC.rom",
"amiberry/D8039HLC.rom",
# openMSX accepts nms8245_disk.rom with sha1 58ba1887 or 6acd4261
# (share/machines/Philips_NMS_8245.xml:149-153). The held copy, the one
# RetroBat pins by md5, is c3f3ca45: neither dump is held.
"openmsx-libretro/nms8245_disk.rom",
]
class ArchiveNamesDesignateArchives(unittest.TestCase):
+1 -1
View File
@@ -30,7 +30,7 @@ class SiteCoreCounts(unittest.TestCase):
def test_each_platform_count_is_the_resolved_set(self):
platforms = str(REPO_ROOT / "platforms")
profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
unique = {k: v for k, v in profiles.items() if v.get("type") not in ("alias", "test")}
unique = {k: v for k, v in profiles.items() if v.get("type") != "alias" and v.get("role") != "test"}
coverages = {}
for name in list_registered_platforms(platforms):
config = load_platform_config(name, platforms)
+4 -2
View File
@@ -280,12 +280,14 @@ class TheScriptWiresBoth(unittest.TestCase):
# Visible words of each built page: measured before the round and after it,
# the ceiling being the after value with 5 % of room.
# the ceiling being the after value with 5 % of room. A page whose content
# grew is measured again on the same layout: Sega on 2026-11-09, with Model 2
# and new Chihiro and Hikaru files.
WORD_CEILINGS = {
"systems/sony": (2012, 1407),
"systems/sony-playstation": (2709, 2130),
"systems/nintendo": (3598, 2941),
"systems/sega": (4151, 3370),
"systems/sega": (4151, 3545),
"emulators/duckstation": (1188, 1117),
"emulators/yaps2": (3159, 2655),
}
+45 -16
View File
@@ -49,9 +49,18 @@ import validate_site # noqa: E402
EMPTY_DB = {"files": {}, "indexes": {"by_name": {}}}
_LOADED: dict[str, dict] = {}
def _profile(name: str) -> dict:
with open(REPO_ROOT / "emulators" / f"{name}.yml", encoding="utf-8") as handle:
return yaml.safe_load(handle)
"""The profile as the site reads it: load_emulator_profiles derives each
member's required from its groups (DuckStation's ps-bios), which the raw
YAML no longer writes on the files."""
if not _LOADED:
from common import load_emulator_profiles # noqa: PLC0415
_LOADED.update(load_emulator_profiles(str(REPO_ROOT / "emulators"), skip_aliases=False))
return _LOADED[name]
def _page(name: str, profile: dict) -> str:
@@ -64,17 +73,27 @@ def _files(count: int, **fields: object) -> list[dict]:
class TheIntroSaysWhatIsNeeded(unittest.TestCase):
def test_one_bios_per_region(self):
# DuckStation's ps-bios set is required: one image of the game's
# region fills it, and every member is marked required by the loader.
profile = _profile("duckstation")
members = [f for f in profile["files"] if f.get("group") == "ps-bios"]
intro = gs._emulator_intro("DuckStation", profile)
self.assertIn(
"It picks the BIOS for the game's region: scph5500.bin (Japan), "
"scph5501.bin (North America and Latin America) or scph5502.bin "
"(Europe and Oceania).", intro)
others = len(profile["files"]) - 3
self.assertIn(f"The {others} other files are optional.", intro)
self.assertNotIn("3 of them required", intro)
f"It needs one BIOS for the game's region, among the {len(members)} it accepts.",
intro)
self.assertNotIn(f"{len(members)} of them required", intro)
self.assertIn("DuckStation emulates Sony PlayStation.", intro)
def test_three_required_bios_of_three_regions_read_as_one_choice(self):
intro = gs._emulator_intro("X", {"systems": ["sony-playstation"], "files": [
{"name": "j.bin", "required": True, "region": ["japan"]},
{"name": "u.bin", "required": True, "region": ["north-america"]},
{"name": "e.bin", "required": True, "region": ["europe"]},
{"name": "o.bin"}]})
self.assertIn("It picks the BIOS for the game's region: j.bin (Japan)", intro)
self.assertIn("The 1 other file is optional.", intro)
self.assertNotIn("3 of them required", intro)
def test_required_files_without_regions_keep_the_count(self):
intro = gs._emulator_intro("X", {"files": [
{"name": "a.bin", "required": True}, {"name": "b.bin"}]})
@@ -499,7 +518,7 @@ class TheTemplateIsNoEmulator(unittest.TestCase):
self.assertNotIn("00_example", index)
self.assertIn("melonds.md", index)
# A test profile gets no page at all (generate_site's public_profiles).
self.assertEqual(_profile("00_example")["type"], "test")
self.assertEqual(_profile("00_example")["role"], "test")
@unittest.skipUnless((DIST / "emulators" / "aethersx2" / "index.html").is_file(), "site not built")
@@ -511,12 +530,13 @@ class TheBuiltEmulatorPages(unittest.TestCase):
page = self._html("emulators/aethersx2")
self.assertRegex(page, r'Download <a href="[^"]*/systems/sony[^"]*#sha1-[0-9a-f]{12}"')
# The command only where a setup launches AetherSX2 itself (KNULLI,
# ROCKNIX), never through RetroArch's folder, which the app never reads.
self.assertIn("With ROCKNIX or KNULLI:", page)
# ROCKNIX dropped the package in 20261101), never through RetroArch's
# folder, which the app never reads.
self.assertIn("With KNULLI:", page)
self.assertNotIn("RetroArch", page.split("Install this emulator", 1)[1].split("</details>", 1)[0])
def test_the_index_leaves_the_template_out(self):
# 00_example is `type: test`: no page, no index row.
# 00_example has `role: test`: no page, no index row.
self.assertNotIn("00_example", self._html("emulators"))
self.assertIn('data-pagefind-body', self._html("emulators/melonds"))
self.assertFalse((DIST / "emulators" / "00_example").exists())
@@ -629,7 +649,7 @@ class DataFolderPrinted(unittest.TestCase):
if not _generated():
self.skipTest("site pages not generated")
for name, profile in _profiles_with_data_root().items():
if profile.get("type") in ("alias", "test"):
if profile.get("type") == "alias" or profile.get("role") == "test":
continue
page = _built_page(name)
with self.subTest(profile=name):
@@ -751,9 +771,18 @@ class SmallFixes(unittest.TestCase):
self.assertNotRegex(page, r"<details[^>]*open>\s*<summary>Firmware titles")
def test_region_choice_summary(self) -> None:
lines = gs._emulator_file_summary(_profile("duckstation")["files"])
self.assertIn("One of 3 is required, for the games' region.", lines[0])
self.assertNotIn("3 required", lines[0])
profile = _profile("duckstation")
members = sum(1 for f in profile["files"] if f.get("group") == "ps-bios")
lines = gs._emulator_file_summary(profile["files"], profile.get("groups"))
self.assertIn(f"One of {members} is required, for the games' region.", lines[0])
self.assertNotIn(f"{members} required", lines[0])
def test_a_required_set_counts_once(self) -> None:
files = [{"name": "a.rom", "required": True, "group": "boot"},
{"name": "b.rom", "required": True, "group": "boot"},
{"name": "c.rom", "required": True}, {"name": "d.rom"}]
line = gs._emulator_file_summary(files, {"boot": {"required": True}})[0]
self.assertIn("2 required, 1 optional. Any one file of a required set fills it.", line)
def test_no_emulator_part_says_where_it_sits(self) -> None:
if not _generated():
+1 -1
View File
@@ -55,7 +55,7 @@ class EngineIntros(unittest.TestCase):
def test_every_intro_names_what_it_emulates(self):
for path in sorted(glob.glob(str(REPO_ROOT / "emulators" / "*.yml"))):
profile = yaml.safe_load(Path(path).read_text(encoding="utf-8"))
if not isinstance(profile, dict) or profile.get("type") in ("alias", "test"):
if not isinstance(profile, dict) or profile.get("type") == "alias" or profile.get("role") == "test":
continue
name = Path(path).stem
with self.subTest(profile=name):
+8 -1
View File
@@ -262,7 +262,14 @@ class VisibleWordsStayUnderTheirCeiling(unittest.TestCase):
# elements (outside scripts and styles, as validate_site counts them) and
# bytes of HTML, on the built site of 2026-10-27.
BEFORE_WEIGHT = {
"batocera": (12, 18_854, 1_211_117),
# Batocera's x86_64 RetroArch downloads buildbot cores, which its pages
# name since 2026-11-09: each file lists every core that reads it with
# its citations (the Game Boy Advance went from 4 readers to 10), and
# Elektronika BK, FM Towns and Nintendo DS moved to part pages. Built
# site of 27c33b966: 13 pages, 15,662 elements, 1,356,360 bytes, and 40
# bytes more where its Amiberry build is named "Amiberry 8.0.0
# (facaaeb, Batocera)" (twice).
"batocera": (13, 18_854, 1_356_400),
"amberelec": (1, 7_928, 473_388),
"romm": (2, 9_561, 572_487),
"retroarch": (14, 21_503, 1_430_802),
+1
View File
@@ -63,6 +63,7 @@ NAMES: dict[str, str] = {
"a roman numeral in a machine or game name (Model I, Ultima I)",
r"\bI(?= \([A-Z])": "a model letter, I (Palladium)",
r"Java ME": "Java ME, the mobile Java platform",
r"\bME(?=,? (?:and )?MA\b)": "FM Towns ME, a model name beside the MA (geartowns)",
r"laseractive us(?=:)": "the LaserActive region key of geargrafx's BIOS list",
}
+1 -1
View File
@@ -747,7 +747,7 @@ class AnIdLeadsToItsData(unittest.TestCase):
"pcsx2": {"type": "standalone"},
"lrps2": {"type": "libretro", "cores": ["pcsx2"]},
"mednafen_psx_alias": {"type": "alias", "alias_of": "beetle_psx"},
"probe": {"type": "test", "cores": ["probe_core"]},
"probe": {"type": "libretro", "role": "test", "cores": ["probe_core"]},
}
items = generate_site.core_index_items(profiles)
by_name: dict[str, list[tuple[str, bool]]] = {}
+1 -1
View File
@@ -44,13 +44,13 @@ UNLINKED: dict[str, str] = {
"omicron": "Other > omicron",
"rpgmaker": "RPG Maker > easyrpg",
"sdlpal": "the SDLPAL section under its own top, named after the program",
"sega-model1": "Arcade > Arcade and Arcade > MAME: the I/O board device sets",
"sega-system16b": "Arcade > FBNeo, and isgsm.zip is also the ISG Selection Master's",
"smbx": "Game Engines > TheXTech",
"thomson-mo6": "Other > Clock Signal",
"vgmplay": "qsound.zip, ym2413.zip, ym2608.zip: sound chips, no board",
# Files filed with another machine: a link would name the wrong one.
"commodore-c64-supercpu": "VICE's tree under the C128",
"emerson-arcadia-2001": "ar_bios.zip is filed with the Saturn",
"spectravideo": "the SVI ROMs are filed with the MSX",
"taito-type-x": "mame2010 files taitogn.zip, the G-NET BIOS, under this id",
"vvvvvv": "SDL's controller database",
+8 -1
View File
@@ -1268,7 +1268,14 @@ class EachFileDownloadsFromItsCard(unittest.TestCase):
self.skipTest("site not generated")
section = page.read_text(encoding="utf-8").split("## Apple II {", 1)[1]
start = section.split("<section", 1)[0]
self.assertIn("[`apple2e.rom`](#sha1-d756eba578a6)", start)
line = next(row for row in start.splitlines() if row.startswith("- **Apple II**: "))
# The files to start with come before the first sentence ("MAME MESS
# reads ... instead"), which names what other emulators read.
named = line.removeprefix("- **Apple II**: ").split(". ", 1)[0].rstrip(".")
names = [part.strip() for part in named.split(", ")]
self.assertTrue(names)
for name in names:
self.assertRegex(name, r"^\[`[^`]+`\]\(#sha1-[0-9a-f]{12}\)$")
if __name__ == "__main__":
+434 -12
View File
@@ -23,14 +23,21 @@ REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT / "scripts"))
from common import ( # noqa: E402
entry_launch_systems,
load_emulator_profiles,
load_platform_config,
platform_layouts,
standalone_bindings_for,
standalone_destination,
standalone_root_for,
standalone_set,
system_file_index,
)
from launchers import ( # noqa: E402
bound_path,
handed_directories,
normalize_handle,
standalone_bindings,
)
from launchers import handed_directories, normalize_handle, standalone_root # noqa: E402
def link(emulator: str, search_dir: str, passes_to: str, **fields: object) -> dict:
@@ -101,7 +108,11 @@ class HandedDirectories(unittest.TestCase):
class Root(unittest.TestCase):
def root(self, *launchers: dict, base: str = "bios") -> str | None:
return standalone_root(
found = self.bindings(*launchers, base=base).get("")
return found[1] if found else None
def bindings(self, *launchers: dict, base: str = "bios") -> dict[str, tuple[str, str]]:
return standalone_bindings(
{"emu"}, PROFILE["standalone_directories"], handed_directories(config(*launchers, base=base))
)
@@ -130,12 +141,15 @@ class Root(unittest.TestCase):
"dc",
)
def test_link_of_another_directory_gives_nothing(self) -> None:
def test_link_of_a_subfolder_binds_that_subfolder_only(self) -> None:
# A subfolder of the emulator's tree (Dolphin's Triforce) is not the
# directory standalone_path is relative to.
self.assertIsNone(self.root(
# directory standalone_path is relative to, only the files below it move.
found = self.bindings(
link("emu", "$bios_path/Triforce", "$XDG_DATA_HOME/emu/Triforce is a symlink to it"),
))
)
self.assertEqual(found, {"Triforce": ("", "Triforce")})
self.assertEqual(bound_path("Triforce/segaboot.gcm", found), ("", "Triforce/segaboot.gcm"))
self.assertIsNone(bound_path("boot.bin", found))
def test_two_folders_give_nothing(self) -> None:
self.assertIsNone(self.root(
@@ -144,6 +158,179 @@ class Root(unittest.TestCase):
))
def bind(cfg: dict, declared: list[str], pools: dict[str, str] | None = None,
systems: tuple[str, ...] = ()) -> dict[str, tuple[str, str]]:
return standalone_bindings(
{"emu"}, declared, handed_directories(cfg), pools=pools, systems=systems
)
class SearchLists(unittest.TestCase):
"""A setting read as a list of directories, every one searched."""
POOLS = {"filepool": "share/systemroms"}
def filepool(self, folder: str, position: int) -> dict:
return passes(
"emu", f"/userdata/bios/{folder}",
f"written: filepool add -path /userdata/bios/{folder} -types system_rom -position {position}",
)
def test_two_pool_entries_give_the_first_one(self) -> None:
# Batocera adds bios/Machines and bios/openmsx to openMSX's filepool.
cfg = config(self.filepool("Machines", 1), self.filepool("openmsx", 2))
self.assertEqual(
bind(cfg, ["~/.openMSX"], self.POOLS), {"share/systemroms": ("", "Machines")}
)
def test_the_entry_the_platform_list_fills_comes_first(self) -> None:
cfg = config(self.filepool("Machines", 1), self.filepool("openmsx", 2))
cfg["systems"] = {"msx": {"files": [{"name": "a.rom", "destination": "openmsx/a.rom"}]}}
self.assertEqual(
bind(cfg, ["~/.openMSX"], self.POOLS), {"share/systemroms": ("", "openmsx")}
)
def test_without_the_pool_two_folders_give_nothing(self) -> None:
cfg = config(self.filepool("Machines", 1), self.filepool("openmsx", 2))
self.assertEqual(bind(cfg, ["~/.openMSX", "filepool"]), {})
def test_a_colon_list_gives_each_directory_in_order(self) -> None:
# RetroDECK writes XRoar's rompath as four directories.
found = handed_directories(config(passes(
"emu", "$roms_path/coco:$roms_path/dragon32:$bios_path", "xroar.conf rompath",
)))
self.assertEqual(
[h.directory for h in found], ["$roms_path/coco", "$roms_path/dragon32", "$bios_path"]
)
self.assertEqual(
bind(config(passes("emu", "$roms_path/coco:$bios_path/xroar", "xroar.conf rompath")),
[], {"rompath": ""}),
{"": ("", "xroar")},
)
def test_a_drive_letter_is_one_directory(self) -> None:
self.assertEqual(handed_directories(config(passes("emu", "C:/bios", "rompath"))), [])
class AboveTheDeclaredDirectory(unittest.TestCase):
def test_a_prefix_lands_the_declared_directory_where_its_link_is(self) -> None:
# RetroPie builds XRoar with --prefix=$md_inst and links
# $md_inst/share/xroar/roms to $biosdir.
cfg = config(
passes("emu", "$md_inst", "${prefix} of configure --prefix"),
link("emu", "$biosdir", "$md_inst/share/xroar/roms is a symlink to it"),
base="BIOS",
)
self.assertEqual(bind(cfg, ["${prefix}/share/xroar/roms"]), {"": ("", "")})
def test_a_folder_of_the_tree_takes_the_rest_of_the_path(self) -> None:
cfg = config(passes("emu", "$biosdir/emu", "EMU_HOME"), base="BIOS")
self.assertEqual(bind(cfg, ["EMU_HOME/share/roms"]), {"": ("", "emu/share/roms")})
class PerSystem(unittest.TestCase):
"""A record written for some systems replaces, there, the others."""
CFG = {
**config(
passes("emu", "bios/dragon", "command line -rompath"),
{**passes("emu", "bios/coco", "command line -rompath"), "systems": ["coco"]},
),
"systems": {"coco": {"files": [{"name": "x.zip", "native_system": "coco"}]}},
}
POOLS = {"-rompath": ""}
def test_the_system_record_wins_for_its_system(self) -> None:
self.assertEqual(bind(self.CFG, [], self.POOLS, ("coco",)), {"": ("", "coco")})
def test_another_system_keeps_the_generic_record(self) -> None:
self.assertEqual(bind(self.CFG, [], self.POOLS, ("dragon32",)), {"": ("", "dragon")})
self.assertEqual(bind(self.CFG, [], self.POOLS), {"": ("", "dragon")})
def test_native_names_are_read_as_our_ids(self) -> None:
cfg = {
**config({**passes("emu", "bios/trs80coco", "-rompath"), "systems": ["trs80coco"]}),
"systems": {"coco": {"native_id": "trs80coco", "files": []}},
}
self.assertEqual(
[sorted(h.systems) for h in handed_directories(cfg)], [["coco"]]
)
def test_a_system_placeholder_gives_one_directory_per_system(self) -> None:
# Recalbox passes `-rompath os.path.join(BIOS, args.system)`.
cfg = {
**config(passes("emu", "/recalbox/share/bios/<system>", "command line -rompath")),
"systems": {
"coco": {"native_id": "trs80coco", "files": []},
"dragon64": {"native_id": "dragon", "files": []},
},
}
self.assertEqual(
[(h.folder, sorted(h.systems)) for h in handed_directories(cfg)],
[("dragon", ["dragon64"]), ("trs80coco", ["coco"])],
)
self.assertEqual(bind(cfg, [], self.POOLS | {"-rompath": ""}, ("coco",)),
{"": ("", "trs80coco")})
self.assertEqual(bind(cfg, [], {"-rompath": ""}, ("dragon32",)), {})
def test_an_entry_is_launched_for_the_system_that_declares_its_name(self) -> None:
cfg = {
**config({**passes("emu", "bios/coco", "-rompath"), "systems": ["coco"]}),
"systems": {"coco": {"files": [{"name": "coco3.rom", "native_system": "coco"}]}},
}
index = system_file_index(standalone_set(cfg))
self.assertEqual(
entry_launch_systems({"name": "COCO3.ROM", "system": "coco3"}, index),
frozenset({"coco3", "coco"}),
)
class SystemFamily(unittest.TestCase):
def test_an_entry_follows_the_launch_its_system_is_listed_under(self) -> None:
# Recalbox lists mc10.rom under trs80coco: alice.rom, of the same
# profile system, is read there too.
profile = {
"emulator": "Emu", "type": "standalone", "standalone_pools": {"-rompath": ""},
"files": [
{"name": "mc10.rom", "path": "mc10.rom", "system": "mc10"},
{"name": "alice.rom", "path": "alice.rom", "system": "mc10"},
],
}
cfg = {
**config(passes("emu", "/recalbox/share/bios/<system>", "-rompath")),
"systems": {"coco": {"native_id": "trs80coco",
"files": [{"name": "mc10.rom"}]}},
}
((view, _standalone),) = platform_layouts("emu", profile, standalone_set(cfg))
self.assertEqual(
[f.get("standalone_path") for f in view["files"]],
["trs80coco/mc10.rom", "trs80coco/alice.rom"],
)
class OfferedMachine(unittest.TestCase):
def test_an_entry_system_offered_as_a_machine_selects_that_launch(self) -> None:
profile = {
"emulator": "Emu", "type": "standalone", "standalone_pools": {"-rompath": ""},
"files": [
{"name": "coco3.rom", "path": "coco3.rom", "system": "coco3"},
{"name": "mc10.rom", "path": "mc10.rom", "system": "mc10"},
],
}
cfg = {
**config(
passes("emu", "bios/dragon", "-rompath"),
{**passes("emu", "bios/coco", "-rompath"), "systems": ["coco"],
"machines": ["coco", "coco3"]},
),
"systems": {"coco": {"files": [{"name": "x.zip", "native_system": "coco"}]}},
}
((view, _standalone),) = platform_layouts("emu", profile, standalone_set(cfg))
self.assertEqual(
[f.get("standalone_path") for f in view["files"]], ["coco/coco3.rom", "dragon/mc10.rom"]
)
class Layout(unittest.TestCase):
LINKED = link("emu", "$biosdir/dc", "$home/.local/share/emu is a symlink to it")
@@ -186,13 +373,14 @@ class Layout(unittest.TestCase):
union = standalone_set(config(self.LINKED, base="BIOS")) | standalone_set(config(
link("emu", "${biosPath}/emu/bios", "symlink ${biosPath}/emu/bios -> ${HOME}/.local/share/emu"),
))
self.assertIsNone(standalone_root_for("emu", PROFILE, union))
self.assertEqual(standalone_bindings_for("emu", PROFILE, union), {})
def test_destination_function(self) -> None:
entry = PROFILE["files"][0]
self.assertEqual(standalone_destination(entry, "dc"), "dc/boot.bin")
self.assertEqual(standalone_destination(entry, None), "boot.bin")
self.assertEqual(standalone_destination(PROFILE["files"][2], "dc"), "dc/shared.bin")
self.assertEqual(standalone_destination(entry, PROFILE, {"": ("", "dc")}), ("", "dc/boot.bin"))
self.assertIsNone(standalone_destination(entry, PROFILE, {}))
# The entry both builds share keeps path in a dual-build profile.
self.assertIsNone(standalone_destination(PROFILE["files"][2], PROFILE, {"": ("", "dc")}))
class FlycastOnEachPlatform(unittest.TestCase):
@@ -215,7 +403,8 @@ class FlycastOnEachPlatform(unittest.TestCase):
with self.subTest(platform=platform):
cfg = load_platform_config(platform, str(REPO_ROOT / "platforms"))
self.assertEqual(
standalone_root_for("flycast", self.profile, standalone_set(cfg)), folder
standalone_bindings_for("flycast", self.profile, standalone_set(cfg)),
{"": ("", folder)},
)
def test_no_standalone_file_lands_at_the_bios_root(self) -> None:
@@ -351,5 +540,238 @@ class Scrapers(unittest.TestCase):
self.assertIn("Dreamcast.BiosPath", records[0]["passes_to"])
class OpenmsxOnEachPlatform(unittest.TestCase):
"""openMSX finds system ROMs by SHA1 in share/systemroms below its user
directory and in every filepool entry. RetroBat sets OPENMSX_HOME to
bios/openmsx, RetroPie links share/systemroms of its user directory to
BIOS/openmsx, Batocera adds bios/Machines and bios/openmsx to the
filepool and lists its own files in bios/openmsx. KNULLI's generator
does the same, but no KNULLI board builds openmsx."""
EXPECTED = {
"batocera": {"share/systemroms": ("", "openmsx")},
"retrobat": {"": ("", "openmsx")},
"retropie": {"share/systemroms": ("", "openmsx")},
}
@classmethod
def setUpClass(cls) -> None:
cls.profile = load_emulator_profiles(str(REPO_ROOT / "emulators"))["openmsx"]
def test_each_platform_hands_openmsx_its_folder(self) -> None:
for platform, expected in self.EXPECTED.items():
with self.subTest(platform=platform):
cfg = load_platform_config(platform, str(REPO_ROOT / "platforms"))
self.assertEqual(
standalone_bindings_for("openmsx", self.profile, standalone_set(cfg)),
expected,
)
def test_every_system_rom_lands_in_bios_openmsx(self) -> None:
for platform in self.EXPECTED:
with self.subTest(platform=platform):
cfg = load_platform_config(platform, str(REPO_ROOT / "platforms"))
(view, _standalone), = platform_layouts(
"openmsx", self.profile, standalone_set(cfg)
)
for entry in view["files"]:
self.assertNotIn("unplaced", entry)
self.assertTrue(
entry["standalone_path"].startswith("openmsx/"), entry["standalone_path"]
)
class XroarOnEachPlatform(unittest.TestCase):
"""XRoar reads each ROM from a directory of rompath. Batocera writes
rompath bios/xroar, RetroDECK lists $bios_path in it, RetroPie links
the build's ${prefix}/share/xroar/roms to $biosdir, RetroBat passes
-rompath bios/coco for coco and bios/dragon otherwise, Recalbox
-rompath bios/<system>."""
# Platform -> profile system -> folder, "" for the BIOS root.
EXPECTED = {
"batocera": dict.fromkeys(("dragon32", "dragon64", "coco", "coco3", "mc10"), "xroar"),
"retrodeck": dict.fromkeys(("dragon32", "dragon64", "coco", "coco3", "mc10"), ""),
"retropie": dict.fromkeys(("dragon32", "dragon64", "coco", "coco3", "mc10"), ""),
# RetroBat offers XRoar's CoCo 3 machines under coco and no MC-10.
"retrobat": {**dict.fromkeys(("dragon32", "dragon64", "mc10"), "dragon"),
**dict.fromkeys(("coco", "coco3"), "coco")},
"recalbox": {**dict.fromkeys(("dragon32", "dragon64"), "dragon"),
**dict.fromkeys(("coco", "coco3", "mc10"), "trs80coco")},
}
@classmethod
def setUpClass(cls) -> None:
cls.profile = load_emulator_profiles(str(REPO_ROOT / "emulators"))["xroar"]
def test_each_rom_lands_where_its_launch_reads_it(self) -> None:
for platform, folders in self.EXPECTED.items():
cfg = load_platform_config(platform, str(REPO_ROOT / "platforms"))
(view, _standalone), = platform_layouts("xroar", self.profile, standalone_set(cfg))
for entry in view["files"]:
with self.subTest(platform=platform, name=entry["name"]):
self.assertNotIn("unplaced", entry)
folder = folders[entry["system"]]
expected = f"{folder}/{entry['name']}" if folder else entry["name"]
self.assertEqual(entry["standalone_path"], expected)
class AmiberryOnEachPlatform(unittest.TestCase):
"""The standalone Amiberry scans rom_path for its ROMs. Batocera and KNULLI
set it to bios/amiga, Recalbox to bios/amiga/bios."""
BOUND = {
"batocera": ("amiberry-7.1.1-332", "amiga"),
"knulli": ("amiberry-7.1.1", "amiga"),
"recalbox": ("amiberry-8.2.2", "amiga/bios"),
}
@classmethod
def setUpClass(cls) -> None:
cls.profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
def test_rom_path_is_the_platform_folder(self) -> None:
for platform, (name, folder) in self.BOUND.items():
with self.subTest(platform=platform):
cfg = load_platform_config(platform, str(REPO_ROOT / "platforms"))
self.assertEqual(
standalone_bindings_for(name, self.profiles[name], standalone_set(cfg)),
{"": ("", folder)},
)
def test_every_rom_path_entry_lands_in_that_folder(self) -> None:
for platform, (name, folder) in self.BOUND.items():
profile = self.profiles[name]
cfg = load_platform_config(platform, str(REPO_ROOT / "platforms"))
views = platform_layouts(name, profile, standalone_set(cfg))
((view, _standalone),) = [(v, s) for v, s in views if s]
for own, entry in zip(profile["files"], view["files"]):
if own.get("mode") == "libretro":
continue
layout = own.get("standalone_path") or own.get("path") or own["name"]
with self.subTest(platform=platform, name=entry["name"]):
self.assertNotIn("unplaced", entry)
self.assertEqual(entry["standalone_path"], f"{folder}/{layout}")
def test_retrobat_reads_its_folders_below_the_amiberry_emulator_folder(self) -> None:
# RetroBat writes rom_path and whdboot_path below the amiberry
# folder of its install and copies the kickstarts it finds in bios
# into that ROMs folder.
name = "amiberry-8.3.0"
profile = self.profiles[name]
cfg = load_platform_config("retrobat", str(REPO_ROOT / "platforms"))
self.assertEqual(
standalone_bindings_for(name, profile, standalone_set(cfg)),
{"": ("emulators", "amiberry/ROMs"), "WHDBoot": ("emulators", "amiberry/WHDBoot")},
)
((view, _standalone),) = platform_layouts(name, profile, standalone_set(cfg))
for own, entry in zip(profile["files"], view["files"]):
layout = own.get("standalone_path") or own.get("path") or own["name"]
folder = "amiberry" if layout.startswith("WHDBoot/") else "amiberry/ROMs"
with self.subTest(name=entry["name"]):
self.assertNotIn("unplaced", entry)
self.assertEqual(entry.get("root"), "emulators")
self.assertEqual(entry["standalone_path"], f"{folder}/{layout}")
class AmiberryBuildEachPlatformShips(unittest.TestCase):
"""Each platform resolves the name amiberry to the build its own package
compiles. RetroBat keeps the 8.5.0 libretro core beside its standalone,
and Batocera's x86_64 boards fetch it with RetroArch's core downloader
(installable_cores)."""
OWN = {
"rocknix": {"amiberry-5.6.5"},
"amberelec": {"amiberry-7.1.1"},
"emuelec": {"amiberry-8.0.0"},
"batocera": {"amiberry", "amiberry-7.1.1-332"},
"knulli": {"amiberry-7.1.1"},
"recalbox": {"amiberry-8.2.2"},
"retrobat": {"amiberry", "amiberry-8.3.0"},
"retropie": {"amiberry-5.7.2", "amiberry-6.3.3"},
"emudeck": {"amiberry"},
"retrodeck": {"amiberry"},
}
@classmethod
def setUpClass(cls) -> None:
cls.profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
def resolved(self, platform: str) -> set[str]:
from common import resolve_platform_cores
cfg = load_platform_config(platform, str(REPO_ROOT / "platforms"))
return {p for p in resolve_platform_cores(cfg, self.profiles) if p.startswith("amiberry")}
def test_each_platform_resolves_its_own_build(self) -> None:
for platform, own in self.OWN.items():
with self.subTest(platform=platform):
self.assertEqual(self.resolved(platform), own)
def test_no_standalone_amiberry_is_the_buildbot_revision(self) -> None:
from common import list_registered_platforms
for platform in list_registered_platforms(str(REPO_ROOT / "platforms")):
cfg = load_platform_config(platform, str(REPO_ROOT / "platforms"))
if "amiberry" not in self.resolved(platform):
continue
layouts = platform_layouts("amiberry", self.profiles["amiberry"], standalone_set(cfg))
with self.subTest(platform=platform):
self.assertEqual([standalone for _view, standalone in layouts], [False])
def test_the_buildbot_core_runs_where_retroarch_installs_it(self) -> None:
from common import load_target_config, resolve_platform_cores
for platform in ("retroarch", "lakka", "batocera"):
with self.subTest(platform=platform):
self.assertIn("amiberry", self.resolved(platform))
cfg = load_platform_config("batocera", str(REPO_ROOT / "platforms"))
# x86_64 boards download from linux-x86_64, which builds the core.
# linux-armhf does not, and aarch64 boards have no downloader.
for target, runs in (("x86_64", True), ("zen3", True), ("h3", False), ("bcm2711", False)):
cores = load_target_config("batocera", target, str(REPO_ROOT / "platforms"))
with self.subTest(target=target):
resolved = resolve_platform_cores(cfg, self.profiles, cores)
self.assertEqual("amiberry" in resolved, runs)
self.assertIn("amiberry-7.1.1-332", resolved)
def test_retropie_reads_kickstarts_below_its_start_folder(self) -> None:
# amiberry 5.7 and 6.3 read <start path>/kickstarts, which RetroPie
# links to bios/amiga. Its whdboot and roms folders stay below it.
cfg = load_platform_config("retropie", str(REPO_ROOT / "platforms"))
for name in ("amiberry-5.7.2", "amiberry-6.3.3"):
profile = self.profiles[name]
self.assertEqual(
standalone_bindings_for(name, profile, standalone_set(cfg)),
{"kickstarts": ("", "amiga")},
)
((view, _standalone),) = platform_layouts(name, profile, standalone_set(cfg))
for entry in view["files"]:
with self.subTest(name=name, file=entry["name"]):
if entry["path"].startswith("kickstarts/"):
self.assertEqual(entry["standalone_path"],
"amiga/" + entry["path"][len("kickstarts/"):])
else:
self.assertEqual(entry.get("unplaced"), "outside_bios_folder")
def test_rocknix_reads_kickstarts_through_the_copied_link(self) -> None:
# amiberry 5.6.5 reads <cwd>/kickstarts. ROCKNIX runs it in
# /storage/.config/amiberry, the copy of /usr/config/amiberry whose
# kickstarts link points at the BIOS root.
profile = self.profiles["amiberry-5.6.5"]
cfg = load_platform_config("rocknix", str(REPO_ROOT / "platforms"))
self.assertEqual(
standalone_bindings_for("amiberry-5.6.5", profile, standalone_set(cfg)),
{"kickstarts": ("", "")},
)
((view, _standalone),) = platform_layouts("amiberry-5.6.5", profile, standalone_set(cfg))
for entry in view["files"]:
with self.subTest(name=entry["name"]):
if entry["path"].startswith("kickstarts/"):
self.assertEqual(entry["standalone_path"], entry["path"][len("kickstarts/"):])
else:
self.assertEqual(entry.get("unplaced"), "outside_bios_folder")
if __name__ == "__main__":
unittest.main()
+3 -1
View File
@@ -51,7 +51,9 @@ class SystemPackMatchesVerify(unittest.TestCase):
"--output-dir", str(self.out / system),
)
report = json.loads(_run("scripts/verify.py", "--system", system, "--json"))
pack_missing = sorted(re.findall(r"^ MISSING: (\S+)", packed, re.M))
# The rest of the line is the name: openMSX's ROM names hold
# spaces ("Japanese MSX-Write (1986) (Ascii) (J).rom").
pack_missing = sorted(re.findall(r"^ MISSING: (.+)$", packed, re.M))
# One per destination, as the pack reports them. An entry the
# collection cannot hold is counted apart on both sides.
verify_missing = sorted({
+30
View File
@@ -21,6 +21,36 @@ sys.path.insert(0, str(REPO_ROOT / "scripts"))
from common import canonical_target_name # noqa: E402
class EveryBuildbotCoreIsNamed(unittest.TestCase):
"""A core RetroArch installs that its manifest does not name is "a core
this list does not know" to --installed-cores (issue 87). 2048, gong,
radio, video_processor and test were typed by their role, which hid
their libretro build from all_libretro."""
def test_retroarch_names_every_buildbot_core(self):
import yaml # noqa: PLC0415
from common import ( # noqa: PLC0415
load_emulator_profiles,
load_platform_config,
load_target_config,
resolve_platform_cores,
upstream_profile_index,
)
platforms = str(REPO_ROOT / "platforms")
profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
runs = resolve_platform_cores(load_platform_config("retroarch", platforms), profiles)
index = upstream_profile_index(profiles, include_aliases=True)
targets = yaml.safe_load((REPO_ROOT / "platforms" / "targets" / "retroarch.yml").read_text())
names = {
name for target in targets["targets"]
for name in load_target_config("retroarch", target, platforms) or ()
}
unnamed = sorted(name for name in names if not (index.get(name, set()) & runs))
self.assertEqual(unnamed, [])
class AliasesResolveToOneName(unittest.TestCase):
def test_retroarch_switch_aliases(self):
platforms = str(REPO_ROOT / "platforms")
+211 -24
View File
@@ -97,6 +97,13 @@ class FailedRequestsStopTheScrape(unittest.TestCase):
_refuse()
return _Body(b"BR2_PACKAGE_BATOCERA_TARGET_X86_64=y\n"
b"BR2_PACKAGE_BATOCERA_SYSTEM=y\n")
if "/git/trees/" in url:
return _Body(b'{"tree": [], "truncated": false}')
if url.endswith("retroarch.mk"):
return _Body(b"RETROARCH_CONF_OPTS = --enable-networking\n")
if url.startswith("https://raw.githubusercontent.com/") and url.count("/") == 6:
return _Body(b'source "$BR2_EXTERNAL_BATOCERA_PATH/'
b'package/batocera/core/batocera-system/Config.in"\n')
if url.endswith("Config.in"):
return _Body(b"config BR2_PACKAGE_BATOCERA_SYSTEM\n"
b"\tselect BR2_PACKAGE_MGBA\n\n"
@@ -240,6 +247,130 @@ class BatoceraDerivedFlags(unittest.TestCase):
self.assertIn("BR2_PACKAGE_DUCKSTATION_LEGACY", r16)
class CoreDownloaderReach(unittest.TestCase):
"""Batocera and KNULLI build RetroArch with its core downloader, shown in
the menu, and its compiled buildbot URL serves Linux x86_64, i386 and
armv7 hard-float alone (config.def.h:743-749, 1855-1864): a board of
those runs any core of the buildbot list, an aarch64 one none."""
def test_each_architecture_reads_its_buildbot_list(self):
from scraper.targets.batocera_targets_scraper import buildbot_target # noqa: PLC0415
self.assertEqual(buildbot_target({"BR2_x86_64"}), "linux-x86_64")
self.assertEqual(buildbot_target({"BR2_arm", "BR2_ARM_CPU_ARMV7A"}), "linux-armhf")
self.assertIsNone(buildbot_target({"BR2_arm", "BR2_ARM_CPU_ARMV7A", "BR2_ARM_EABI"}))
self.assertIsNone(buildbot_target({"BR2_arm", "BR2_arm1176jzf_s"}))
self.assertIsNone(buildbot_target({"BR2_aarch64"}))
def test_a_build_or_a_blank_url_turns_it_off(self):
from scraper.targets.batocera_targets_scraper import downloader_disabled # noqa: PLC0415
self.assertIsNone(downloader_disabled("--enable-networking", {
"a/retroarch.cfg": 'menu_show_core_updater = "false"\n'}))
self.assertIn("HAVE_LAKKA=1", downloader_disabled("make HAVE_LAKKA=1", {}))
with self.assertRaises(RuntimeError):
downloader_disabled("", {"a/retroarch.cfg": 'core_updater_buildbot_cores_url = ""\n'})
def test_a_board_that_downloads_gets_the_buildbot_list(self):
from common import load_target_config # noqa: PLC0415
root = str(REPO_ROOT / "platforms")
x86 = set(load_target_config("retroarch", "linux-x86_64", root) or ())
armhf = set(load_target_config("retroarch", "linux-armhf", root) or ())
self.assertLessEqual(x86, set(load_target_config("batocera", "x86_64", root) or ()))
self.assertLessEqual(armhf, set(load_target_config("batocera", "rk3288", root) or ()))
self.assertFalse(x86 <= set(load_target_config("batocera", "bcm2711", root) or ()))
self.assertLessEqual(armhf, set(load_target_config("knulli", "r16", root) or ()))
def test_the_platform_names_what_its_boards_install(self):
import yaml # noqa: PLC0415
from common import load_target_config # noqa: PLC0415
root = str(REPO_ROOT / "platforms")
for platform in ("batocera", "knulli"):
config = yaml.safe_load((REPO_ROOT / "platforms" / f"{platform}.yml").read_text())
targets = yaml.safe_load(
(REPO_ROOT / "platforms" / "targets" / f"{platform}.yml").read_text())["targets"]
fetched = set()
for entry in targets.values():
if entry.get("downloads"):
fetched |= load_target_config("retroarch", entry["downloads"], root) or set()
if entry["architecture"] == "aarch64":
self.assertNotIn("downloads", entry)
with self.subTest(platform=platform):
built = ((set(config["cores"]) - set(config.get("standalone_cores") or []))
| set(config.get("dual_mode_cores") or []))
self.assertEqual(set(config["installable_cores"]), fetched - built)
def test_a_standalone_name_keeps_its_buildbot_core(self):
"""Batocera runs amiberry standalone, and its x86_64 boards fetch
amiberry_libretro: removing every name the image builds lost the
libretro core to the name it shares with the standalone package."""
from common import DUAL_MODE_PREFIX, resolve_platform_cores, standalone_set # noqa: PLC0415
from scraper.batocera_scraper import installable_cores # noqa: PLC0415
from scraper.targets.batocera_targets_scraper import BuildSelection # noqa: PLC0415
selection = BuildSelection(
targets={"x86_64": {"architecture": "x86_64", "cores": [],
"downloads": "linux-x86_64"}},
emulators=frozenset(), listed=frozenset(), symbols=frozenset(), packages={},
)
found = installable_cores(selection, ["amiberry", "mgba", "dolphin"],
["amiberry", "dolphin"], ["dolphin"])
self.assertIn("amiberry", found)
self.assertNotIn("mgba", found)
self.assertNotIn("dolphin", found)
profiles = {
"amiberry": {"type": "libretro", "cores": ["amiberry"], "systems": ["amiga"]},
"amiberry-7": {"type": "standalone", "cores": ["amiberry"], "systems": ["amiga"],
"built_by": ["demo"], "source": "https://x/amiberry"},
}
config = {"_key": "demo", "cores": ["amiberry"], "standalone_cores": ["amiberry"],
"installable_cores": ["amiberry"]}
self.assertEqual(resolve_platform_cores(config, profiles), {"amiberry", "amiberry-7"})
self.assertEqual(resolve_platform_cores({**config, "installable_cores": []}, profiles),
{"amiberry-7"})
self.assertIn(DUAL_MODE_PREFIX + "amiberry", standalone_set(config))
class DownloadedCoresReachTheirBoards(unittest.TestCase):
"""A core only the downloader brings runs where the board's downloader
offers one of its names, and the install list says on which boards."""
@classmethod
def setUpClass(cls):
from common import load_emulator_profiles, load_platform_config # noqa: PLC0415
cls.profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
cls.config = load_platform_config("batocera", str(REPO_ROOT / "platforms"))
def test_every_installable_name_counts(self):
"""Batocera lists higan_sfc_balanced and nside_sfc_balanced, and the
buildbot offers the second: reading the first alone dropped the
core from x86_64."""
from common import load_target_config, resolve_platform_cores # noqa: PLC0415
root = str(REPO_ROOT / "platforms")
x86 = load_target_config("batocera", "x86_64", root)
self.assertIn("higan_sfc_balanced", resolve_platform_cores(self.config, self.profiles, x86))
rpi4 = load_target_config("batocera", "bcm2711", root)
resolved = resolve_platform_cores(self.config, self.profiles, rpi4)
self.assertNotIn("amiberry", resolved)
self.assertIn("amiberry-7.1.1-332", resolved)
def test_the_list_names_the_boards_of_each_downloaded_core(self):
import generate_pack # noqa: PLC0415
core_names = {"amiberry": [], "higan_sfc_balanced": ["nside_sfc_balanced"]}
boards = generate_pack._downloaded_cores(
self.config, self.profiles, core_names, str(REPO_ROOT / "platforms"))
self.assertEqual(set(boards), {"amiberry", "higan_sfc_balanced"})
self.assertIn("x86_64", boards["amiberry"])
self.assertNotIn("bcm2711", boards["amiberry"])
class KnulliPerBoard(unittest.TestCase):
"""KNULLI builds per board on Batocera's model from its own tree:
configs/knulli-*.board, package/system/knulli-system/Config.in and
@@ -254,7 +385,7 @@ class KnulliPerBoard(unittest.TestCase):
"BR2_PACKAGE_BATOCERA_TARGET_H700=y\n"
),
"configs/knulli-r16.board": (
"include knulli-board.common\n\nBR2_arm=y\n"
"include knulli-board.common\n\nBR2_arm=y\nBR2_cortex_a7=y\n"
"BR2_PACKAGE_BATOCERA_TARGET_SUNXI_R16=y\n"
),
"configs/knulli-h700_armhf_libs.board": (
@@ -262,6 +393,15 @@ class KnulliPerBoard(unittest.TestCase):
"BR2_arm=y\nBR2_PACKAGE_BATOCERA_TARGET_H700=y\n"
),
"configs/knulli-h700_armhf_libs.packages": "BR2_PACKAGE_SDL2=y\n",
# The root Config.in sources KNULLI's system and Batocera's packages
# from the batocera submodule, where a package selects another.
"Config.in": (
'source "$BR2_EXTERNAL_KNULLI_PATH/package/system/knulli-system/Config.in"\n'
'source "$BR2_EXTERNAL_KNULLI_PATH/batocera/package/batocera/emulators/'
'ppsspp/Config.in"\n'
'#source "$BR2_EXTERNAL_KNULLI_PATH/package/utils/off/Config.in"\n'
'source "$BR2_EXTERNAL_KNULLI_PATH/package/utils/vtree/Config.in"\n'
),
"package/system/knulli-system/Config.in": (
"if BR2_PACKAGE_BATOCERA_TARGET_H700 || \\\n"
" BR2_PACKAGE_BATOCERA_TARGET_A133\n"
@@ -282,6 +422,8 @@ class KnulliPerBoard(unittest.TestCase):
" mgba: {requireAnyOf: [BR2_PACKAGE_LIBRETRO_MGBA]}\n"
"psp:\n emulators:\n ppsspp:\n"
" ppsspp: {requireAnyOf: [BR2_PACKAGE_PPSSPP]}\n"
"pspassets:\n emulators:\n libretro:\n"
" assets: {requireAnyOf: [BR2_PACKAGE_PPSSPP_ASSETS]}\n"
),
}
@@ -314,6 +456,23 @@ class KnulliPerBoard(unittest.TestCase):
return _Body(json.dumps([{"name": n} for n in names]))
if url == f"{api}buildroot?ref={pin}":
return _Body('{"sha": "c2d7985b"}')
if url == f"{api}batocera?ref={pin}":
return _Body('{"sha": "487014d9"}')
if "/git/trees/" in url:
# A board config that hides the downloader leaves its URL.
cfg = "board/r16/retroarch.cfg" if "knulli-linux" in url else "x"
return _Body(json.dumps({"tree": [{"path": cfg}], "truncated": False}))
if url == f"{raw}board/r16/retroarch.cfg":
return _Body('menu_show_core_updater = "false"\n')
if url == f"{raw}package/retroarch/retroarch/retroarch.mk":
return _Body("RETROARCH_CONF_OPTS = --enable-networking\n")
if url == ("https://raw.githubusercontent.com/batocera-linux/batocera.linux/"
"487014d9/package/batocera/emulators/ppsspp/Config.in"):
return _Body("config BR2_PACKAGE_PPSSPP\n\tselect BR2_PACKAGE_PPSSPP_ASSETS\n")
if url == f"{raw}package/utils/vtree/Config.in":
raise urllib.error.HTTPError(url, 404, "Not Found", {}, None)
if url.endswith("/c2d7985b/arch/Config.in.arm"):
return _Body("config BR2_cortex_a7\n\tselect BR2_ARM_CPU_ARMV7A\n")
if url.startswith("https://raw.githubusercontent.com/knulli-cfw/buildroot/c2d7985b/"):
return _Body("config BR2_aarch64\n\tselect BR2_ARCH_IS_64\n")
path = url.removeprefix(raw)
@@ -330,11 +489,14 @@ class KnulliPerBoard(unittest.TestCase):
self.assertEqual(sorted(data["targets"]), ["h700", "r16"])
# The images name what a card's boot/knulli.board holds.
self.assertEqual(data["targets"]["h700"],
{"architecture": "aarch64", "cores": ["mgba", "ppsspp"],
{"architecture": "aarch64", "cores": ["assets", "mgba", "ppsspp"],
"images": ["rg35xx-plus", "rg35xx-sp"]})
# An armv7 hard-float board's RetroArch installs the armhf buildbot list.
self.assertEqual(data["targets"]["r16"],
{"architecture": "arm", "cores": ["mgba"], "images": ["miyoo-a30"]})
self.assertTrue(all(pin in url or "buildroot/c2d7985b" in url for url in seen), seen)
{"architecture": "arm", "cores": ["mgba"], "images": ["miyoo-a30"],
"downloads": "linux-armhf"})
self.assertTrue(all(pin in url or "buildroot/c2d7985b" in url
or "487014d9" in url for url in seen), seen)
class RocknixPerDevice(unittest.TestCase):
@@ -371,35 +533,60 @@ class RocknixPerDevice(unittest.TestCase):
)
def test_each_device_gets_its_own_cores(self):
from scraper.targets.rocknix_targets_scraper import ( # noqa: PLC0415
core_names,
parse_device_cores,
)
from scraper.targets.rocknix_targets_scraper import parse_device_cores # noqa: PLC0415
h700 = core_names(*parse_device_cores(self.PACKAGE_MK, "H700", "aarch64", True))
self.assertTrue({"drastic", "gpsp", "duckstation", "beetle_psx", "hatari",
"81", "neocd"} <= set(h700))
self.assertFalse({"aethersx2", "dolphin"} & set(h700))
no32 = core_names(*parse_device_cores(self.PACKAGE_MK, "H700", "aarch64", False))
self.assertNotIn("gpsp", no32)
amd64 = core_names(*parse_device_cores(self.PACKAGE_MK, "AMD64", "x86_64", False))
self.assertIn("dolphin", amd64)
self.assertNotIn("drastic", amd64)
libretro, standalone = parse_device_cores(self.PACKAGE_MK, "H700", "aarch64", True)
self.assertTrue({"gpsp-lr", "duckstation-lr", "beetle-psx-lr", "81-lr",
"neocd_lr"} <= set(libretro))
self.assertTrue({"drastic-sa", "hatarisa"} <= set(standalone))
self.assertFalse({"aethersx2-sa", "dolphin-sa"} & set(standalone))
libretro, _ = parse_device_cores(self.PACKAGE_MK, "H700", "aarch64", False)
self.assertNotIn("gpsp-lr", libretro)
_, standalone = parse_device_cores(self.PACKAGE_MK, "AMD64", "x86_64", False)
self.assertIn("dolphin-sa", standalone)
self.assertNotIn("drastic-sa", standalone)
def test_a_package_names_the_cores_it_installs(self):
"""vice-lr builds ten EMUTYPEs: read as the package name, vice_x64
and its siblings reached no ROCKNIX device."""
from scraper.targets.rocknix_targets_scraper import installed_cores # noqa: PLC0415
vice = ("makeinstall_target() {\n mkdir -p ${INSTALL}/usr/lib/libretro\n"
" cp -a built/vice_x128_libretro.so ${INSTALL}/usr/lib/libretro\n"
" cp -a built/vice_x64_libretro.so ${INSTALL}/usr/lib/libretro\n}\n")
self.assertEqual(installed_cores(vice, "aarch64", True), ["vice_x128", "vice_x64"])
renamed = ("makeinstall_target() {\n"
" cp -a mednafen_psx_libretro.so ${INSTALL}/usr/lib/libretro/beetle_psx_libretro.so\n"
" cp -a fake08_libretro.{so,info} $INSTALL/usr/lib/libretro\n}\n")
self.assertEqual(installed_cores(renamed, "aarch64", True), ["beetle_psx", "fake08"])
pcsx = ("makeinstall_target() {\n"
" case ${TARGET_ARCH} in\n"
" aarch64|x86_64) cp -a ../pcsx_rearmed_libretro.so ${INSTALL}/usr/lib/libretro ;;\n"
" arm) cp -a ../pcsx_rearmed_libretro.so ${INSTALL}/usr/lib/libretro/pcsx_rearmed32_libretro.so ;;\n"
" esac\n"
' if [ "${TARGET_ARCH}" = "aarch64" ] && [ "${ENABLE_32BIT}" = "true" ]; then\n'
" cp -a x/usr/lib/libretro/pcsx_rearmed32_libretro.so ${INSTALL}/usr/lib/libretro\n"
" fi\n}\n")
self.assertEqual(installed_cores(pcsx, "aarch64", True), ["pcsx_rearmed", "pcsx_rearmed32"])
self.assertEqual(installed_cores(pcsx, "aarch64", False), ["pcsx_rearmed"])
self.assertEqual(installed_cores(pcsx, "x86_64", True), ["pcsx_rearmed"])
with self.assertRaises(RuntimeError):
installed_cores('makeinstall_target() {\n if [ "${DEVICE}" = "H700" ]; then\n'
" cp a_libretro.so ${INSTALL}/usr/lib/libretro\n fi\n}\n",
"aarch64", True)
with self.assertRaises(RuntimeError):
installed_cores("makeinstall_target() {\n :\n}\n", "aarch64", True)
def test_a_standalone_package_keeps_both_spellings(self):
"""vice-standalone answers to vice-sa only, as scummvm-standalone to
scummvm-sa: stripped to vice, every targeted pack left them out
while the untargeted one, read from the platform scraper, kept them."""
from scraper.rocknix_scraper import standalone_emulators # noqa: PLC0415
from scraper.targets.rocknix_targets_scraper import ( # noqa: PLC0415
core_names,
parse_device_cores,
)
from scraper.targets.rocknix_targets_scraper import parse_device_cores # noqa: PLC0415
libretro, standalone = parse_device_cores(self.PACKAGE_MK, "SM8550", "aarch64", False)
names = set(core_names(libretro, standalone))
_, standalone = parse_device_cores(self.PACKAGE_MK, "SM8550", "aarch64", False)
names = set(standalone_emulators(standalone))
self.assertTrue({"aethersx2-sa", "aethersx2", "dolphin-sa", "dolphin"} <= names)
self.assertTrue(set(standalone_emulators(standalone)) <= names)
def test_a_metapackage_names_the_cores_it_installs(self):
from scraper.targets.rocknix_targets_scraper import metapackage_cores # noqa: PLC0415
+20
View File
@@ -79,6 +79,26 @@ class FileShapeChecks(_Fixture):
self.assertFalse(result.passed)
self.assertIn("Blocked file extension", result.to_markdown())
def test_an_executable_a_profile_pins_by_sha1_passes(self):
"""PICO-8's pico8.exe and SDL2.dll come from the official archive and
the lexaloffle profile pins their sha1: known bytes, not a payload."""
import hashlib
data = b"MZ pinned"
rel = self._bios_file("bios/Lexaloffle/PICO-8/pico8.exe", data)
pins = {"sha1": {hashlib.sha1(data).hexdigest(): {"lexaloffle"}}}
result = validate_pr.validate_file(rel, None, EMPTY_HASHES, pins)
self.assertNotIn("Blocked file extension", result.to_markdown())
self.assertIn("pins by sha1: lexaloffle", result.to_markdown())
def test_an_executable_known_only_by_md5_stays_refused(self):
import hashlib
data = b"MZ weak"
rel = self._bios_file("bios/Sony/PS/tool.exe", data)
pins = {"md5": {hashlib.md5(data).hexdigest(): {"someemu"}}}
result = validate_pr.validate_file(rel, None, EMPTY_HASHES, pins)
self.assertFalse(result.passed)
self.assertIn("Blocked file extension", result.to_markdown())
def test_oversized_file_is_refused(self):
rel = self._bios_file("bios/Sony/PS/big.bin")
original = validate_pr.MAX_FILE_SIZE