mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-24 10:37:54 -06:00
refactor: convert mame tags and versions once
This commit is contained in:
1 parent
f8003e90c8
commit
30cd881ef3
4 files changed
+34
-22
No files matched your search
@@ -59,7 +59,7 @@ from core.upstream import parse_repo
|
||||
from .base_scraper import BlobMismatchError, download, fetch_verified_blob
|
||||
from .clex import DriverSourceError, blank_comments, call_args, call_span
|
||||
from .listxml import Opener, attrs, iter_elements, open_listxml, rom_members
|
||||
from .romset_dat_importer import MAME_LISTXML_URL, _api_json, fetch_pack
|
||||
from .romset_dat_importer import MAME_LISTXML_URL, _api_json, fetch_pack, mame_tag
|
||||
|
||||
SCHEMA_VERSION = 1
|
||||
DEFAULT_OUTPUT = Path("games") / "arcade"
|
||||
@@ -950,7 +950,7 @@ def import_profile(
|
||||
source: dict[str, object]
|
||||
openers: list[Opener]
|
||||
if kind == "listxml":
|
||||
tag = "mame" + str(data["core_version"]).replace(".", "").zfill(4)
|
||||
tag = mame_tag(str(data["core_version"]))
|
||||
if offline:
|
||||
pack = cache_dir / f"{tag}lx.zip"
|
||||
if not pack.is_file():
|
||||
|
||||
@@ -28,7 +28,7 @@ from model.safeparse import yaml_load
|
||||
|
||||
from core import upstream
|
||||
|
||||
from .base_scraper import download, fetch_github_latest_version
|
||||
from .base_scraper import fetch_github_latest_version
|
||||
from ._hash_merge import (
|
||||
_build_contents,
|
||||
_build_source_ref,
|
||||
@@ -53,6 +53,7 @@ from .mame_devices import (
|
||||
source_path,
|
||||
)
|
||||
from .listxml import open_listxml
|
||||
from .romset_dat_importer import fetch_pack, mame_tag, mame_version
|
||||
from .sparse_clone import fresh_cache, remove_clone, sparse_clone
|
||||
from .mame_parser import parse_mame_source_tree
|
||||
from core.paths import EMULATORS_DIR, PLATFORMS_DIR, REPO_ROOT
|
||||
@@ -105,15 +106,7 @@ def _get_version() -> str:
|
||||
version.cpp is generated at build time, not in the repo. A failed lookup
|
||||
raises: "unknown" was cached for a day and written as core_version.
|
||||
"""
|
||||
return _parse_version_tag(fetch_github_latest_version(MAME_REPO))
|
||||
|
||||
|
||||
def _parse_version_tag(tag: str) -> str:
|
||||
prefix = "mame"
|
||||
raw = tag.removeprefix(prefix) if tag.startswith(prefix) else tag
|
||||
if raw.isdigit() and len(raw) >= 4:
|
||||
return f"{raw[0]}.{raw[1:]}"
|
||||
return raw
|
||||
return mame_version(fetch_github_latest_version(MAME_REPO))
|
||||
|
||||
|
||||
# Profile discovery
|
||||
@@ -219,7 +212,7 @@ def _fetch_hashes(force: bool) -> dict[str, Any]:
|
||||
tag = fetch_github_latest_version(MAME_REPO)
|
||||
commit = _sparse_clone(tag)
|
||||
bios_sets = parse_mame_source_tree(str(_CLONE_DIR))
|
||||
version = _parse_version_tag(tag)
|
||||
version = mame_version(tag)
|
||||
if not bios_sets:
|
||||
# An empty read was cached for a day and every profile entry
|
||||
# came out "out of scope", so nothing was refreshed and the
|
||||
@@ -308,12 +301,7 @@ def fetch_release_listxml(version: str) -> Path:
|
||||
|
||||
0.289 is the tag mame0289 and the asset mame0289lx.zip.
|
||||
"""
|
||||
from .romset_dat_importer import MAME_LISTXML_URL
|
||||
|
||||
tag = "mame" + version.replace(".", "")
|
||||
listxml = REPO_ROOT / ".cache" / "dats" / f"{tag}lx.zip"
|
||||
download(MAME_LISTXML_URL.format(tag=tag), listxml, skip_existing=True)
|
||||
return listxml
|
||||
return fetch_pack("mame", mame_tag(version), REPO_ROOT / ".cache" / "dats")[0]
|
||||
|
||||
|
||||
def release_profile(
|
||||
@@ -334,8 +322,7 @@ def release_profile(
|
||||
are the release's own, and so is a set the release runs without: recel is
|
||||
undumped at 0.258 and dumped later.
|
||||
"""
|
||||
version = release.removeprefix("mame")
|
||||
version = f"{version[0]}.{version[1:]}" if version.isdigit() else version
|
||||
version = mame_version(release)
|
||||
known = {
|
||||
str(f.get("name")): f for f in reference.get("files") or []
|
||||
if f.get("category") == "bios_zip"
|
||||
@@ -449,7 +436,7 @@ def _merge_devices(args: argparse.Namespace) -> None:
|
||||
profile = yaml_load(text) or {}
|
||||
with open_listxml(args.listxml) as stream:
|
||||
tag, devices, machines = scan_release(stream)
|
||||
version = _parse_version_tag(tag)
|
||||
version = mame_version(tag)
|
||||
if str(profile.get("core_version")) != version:
|
||||
raise RuntimeError(
|
||||
f"{args.listxml} is MAME {version}, mame.yml is pinned on "
|
||||
|
||||
@@ -398,6 +398,22 @@ MAME_LISTXML_URL = (
|
||||
"https://github.com/mamedev/mame/releases/download/{tag}/{tag}lx.zip"
|
||||
)
|
||||
MAME_REPO = "mamedev/mame"
|
||||
|
||||
|
||||
def mame_tag(version: str) -> str:
|
||||
"""The mamedev/mame release tag of a version: 0.289 is mame0289."""
|
||||
return "mame" + version.replace(".", "").zfill(4)
|
||||
|
||||
|
||||
def mame_version(tag: str) -> str:
|
||||
"""The version a mamedev/mame release tag names: mame0289 is 0.289.
|
||||
|
||||
Anything else (a branch, a commit) is returned as it is.
|
||||
"""
|
||||
raw = tag.removeprefix("mame")
|
||||
if raw.isdigit() and len(raw) >= 4:
|
||||
return f"{raw[0]}.{raw[1:]}"
|
||||
return raw
|
||||
FBNEO_API = "https://api.github.com/repos/libretro/FBNeo"
|
||||
|
||||
|
||||
|
||||
@@ -584,6 +584,15 @@ class ListXmlRecipes(unittest.TestCase):
|
||||
with open(output, encoding="utf-8") as handle:
|
||||
self.assertEqual(json.load(handle)["upstream"], {"blobs": {"X.dat": "bbb"}})
|
||||
|
||||
def test_mame_tags_and_versions(self):
|
||||
from scripts.scraper.romset_dat_importer import mame_tag, mame_version
|
||||
|
||||
self.assertEqual(mame_tag("0.289"), "mame0289")
|
||||
self.assertEqual(mame_tag("0.78"), "mame0078")
|
||||
self.assertEqual(mame_version("mame0289"), "0.289")
|
||||
self.assertEqual(mame_version("mame78"), "78")
|
||||
self.assertEqual(mame_version("master"), "master")
|
||||
|
||||
def test_git_blob_sha_matches_git(self):
|
||||
# The values git hash-object gives for the empty blob and for "hi".
|
||||
self.assertEqual(git_blob_sha(b""), "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391")
|
||||
|
||||
Reference in new issue
Block a user