mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
refactor: keep standalone layouts in a file apart
The layouts every list carried grew the download of each run by up to 30% for an option few use. They now live in install/standalone/<platform>.json, written by the same --manifest run and fetched only by a run given --standalone, beside --manifest first. The list names the builds (standalone_builds). A missing, unreachable or invalid file stops --standalone on one line, code 1.
This commit is contained in:
1 parent
03f80eb570
commit
9cb9fec49e
13 files changed
+924
-77
No files matched your search
+1
-1
@@ -16,7 +16,7 @@
|
||||
# and Invoke-WebRequest throws on a cut transfer before the hash is read:
|
||||
# the site's build rewrites this line there (scripts/sitebootstrap.py).
|
||||
$mismatchAdvice = "The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
|
||||
$defaultInstallSha256 = "b92824f7fd4b3a4e40a02c48838a9d8597cb2228a3cd1e01ce051a3015d4ad29"
|
||||
$defaultInstallSha256 = "b2b012c9e63239c0d68aa2e87aab59e5a5f1fa0f17c33db63e6da221e5d7f42b"
|
||||
# The pin above refuses any changed byte: this cap only stops a body that
|
||||
# cannot be the installer (a sign-in portal's page) before it is hashed.
|
||||
$maximumInstallerBytes = 8MB
|
||||
|
||||
+60
-20
@@ -104,6 +104,9 @@ def _checked_base_url(value: str) -> str:
|
||||
BASE_URL = _checked_base_url(os.environ.get("RETROBIOS_BASE_URL", DEFAULT_BASE_URL))
|
||||
MANIFEST_URL = f"{BASE_URL}/install/{{platform}}.json"
|
||||
TARGETS_URL = f"{BASE_URL}/install/targets/{{platform}}.json"
|
||||
# What --standalone reads, apart from the list every run downloads.
|
||||
STANDALONE_DIR = "standalone"
|
||||
STANDALONE_URL = f"{BASE_URL}/install/standalone/{{platform}}.json"
|
||||
# The platforms that publish a core list per board, install/targets/ in the
|
||||
# repository: a test holds the two equal. Offline, a platform outside it
|
||||
# has no hardware targets, where the run sent the user after a list that
|
||||
@@ -124,6 +127,7 @@ MAX_RETRIES = 3
|
||||
CONNECT_TIMEOUT = 4.0
|
||||
MAX_MANIFEST_BYTES = 16 * 1024 * 1024
|
||||
MAX_TARGETS_BYTES = 4 * 1024 * 1024
|
||||
MAX_STANDALONE_BYTES = 16 * 1024 * 1024
|
||||
MAX_MANIFEST_FILES = 100_000
|
||||
MAX_DOWNLOAD_SIZE = 1024 * 1024 * 1024
|
||||
# A data directory's source archive: PCSX2's source tarball is the largest.
|
||||
@@ -4206,27 +4210,30 @@ def _check_truth_lists(data: dict, seen_destinations: set[str]) -> int:
|
||||
return largest
|
||||
|
||||
|
||||
def _check_standalone_layouts(data: dict) -> int:
|
||||
"""standalone_layouts: per emulator, entries or [dest, sha1] pairs whose
|
||||
content the list carries. Returns the largest size they may fetch."""
|
||||
def _check_standalone_layouts(data: object, manifest: dict, plat: str) -> dict:
|
||||
"""install/standalone/<platform>.json, checked as the list is: per
|
||||
emulator the list names, entries or [dest, sha1] pairs whose content
|
||||
the list carries. Returns the layouts."""
|
||||
if not isinstance(data, dict) or data.get("schema") != 1 or data.get("platform") != plat:
|
||||
raise ValueError(f"it is no standalone layout of {plat}")
|
||||
layouts = data.get("standalone_layouts")
|
||||
if layouts is None:
|
||||
return 0
|
||||
if not isinstance(layouts, dict) or len(layouts) > MAX_SELECTION_TAGS:
|
||||
raise ValueError("invalid standalone_layouts")
|
||||
if sorted(layouts) != sorted(manifest.get("standalone_builds") or []):
|
||||
raise ValueError("its builds are not the ones the file list names")
|
||||
sizes = {
|
||||
copy["sha1"]: copy.get("size", 0)
|
||||
for entry in [*data.get("files", []), *(data.get("truth_files") or [])]
|
||||
for entry in [*manifest.get("files", []), *(manifest.get("truth_files") or [])]
|
||||
for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])]
|
||||
if isinstance(copy, dict) and copy.get("sha1")
|
||||
and (copy.get("repo_path") or copy.get("release_asset"))
|
||||
}
|
||||
largest = 0
|
||||
for name, items in layouts.items():
|
||||
if (not isinstance(name, str) or not 0 < len(name) <= 256
|
||||
or not isinstance(items, list) or len(items) > MAX_MANIFEST_FILES):
|
||||
raise ValueError("invalid standalone_layouts entry")
|
||||
seen: set[str] = set()
|
||||
largest = 0
|
||||
for index, item in enumerate(items):
|
||||
where = f"standalone_layouts[{name!r}][{index}]"
|
||||
if isinstance(item, list):
|
||||
@@ -4240,7 +4247,9 @@ def _check_standalone_layouts(data: dict) -> int:
|
||||
largest += int(sizes[item[1]] or 0)
|
||||
else:
|
||||
largest += _check_entry(item, where, seen)[1]
|
||||
return largest
|
||||
if largest > MAX_TOTAL_DOWNLOAD_SIZE:
|
||||
raise ValueError("standalone build size exceeds safety limit")
|
||||
return layouts
|
||||
|
||||
|
||||
def _check_data_directory(entry: object, where: str) -> None:
|
||||
@@ -4393,7 +4402,8 @@ def _validate_manifest(data: object, plat: str) -> dict:
|
||||
if data.get("slot_fields", True) is not True:
|
||||
raise ValueError("invalid slot_fields")
|
||||
largest_total += _check_truth_lists(data, seen_destinations)
|
||||
largest_total += _check_standalone_layouts(data)
|
||||
if "standalone_builds" in data:
|
||||
_check_tags(data, "standalone_builds", "the file list")
|
||||
if largest_total > MAX_TOTAL_DOWNLOAD_SIZE:
|
||||
raise ValueError("manifest total size exceeds safety limit")
|
||||
declared_total_omitted = data.get("total_omitted")
|
||||
@@ -4887,6 +4897,35 @@ def local_targets(plat: str) -> "dict | None":
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def fetch_standalone(plat: str, manifest: dict) -> dict:
|
||||
"""What each standalone build reads, for --standalone only: the file
|
||||
beside --manifest (standalone/<platform>.json, where the repository
|
||||
keeps it), else downloaded as the list is. Missing, unreachable or
|
||||
invalid, the run stops on one line, code 1."""
|
||||
beside = (LOCAL.manifest.parent / STANDALONE_DIR / f"{plat}.json"
|
||||
if LOCAL.manifest is not None else None)
|
||||
url = STANDALONE_URL.format(platform=plat)
|
||||
where = str(beside) if beside is not None and _is_file(beside) else url
|
||||
try:
|
||||
if where != url:
|
||||
raw = _read_capped(Path(where), MAX_STANDALONE_BYTES)
|
||||
data = json.loads((raw or b"").decode("utf-8"))
|
||||
else:
|
||||
data = _fetch_json(url, MAX_STANDALONE_BYTES, "standalone layout")
|
||||
return _check_standalone_layouts(data, manifest, plat)
|
||||
except urllib.error.HTTPError as exc:
|
||||
problem = f"HTTP {exc.code}"
|
||||
except (urllib.error.URLError, OSError) as exc:
|
||||
problem = str(exc) if isinstance(exc, _Offline) else network_words(exc)[1]
|
||||
except (UnicodeDecodeError, ValueError) as exc:
|
||||
problem = f"not valid: {exc}"
|
||||
EVENTS.emit("error", stage="manifest", reason="unavailable", platform=plat,
|
||||
message=f"--standalone needs {where}: {problem}")
|
||||
print(f"Error: --standalone needs {where}, which could not be read ({problem}).",
|
||||
file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def fetch_targets(plat: str, attempts: int = MAX_RETRIES,
|
||||
timeout: float | None = None) -> "dict | None":
|
||||
"""The target core list: the one this run has at hand, else downloaded.
|
||||
@@ -5412,11 +5451,10 @@ def truth_lists(manifest: dict, files: list[dict],
|
||||
+ list(manifest.get("truth_omitted") or []))
|
||||
|
||||
|
||||
def standalone_entries(manifest: dict, profile: str) -> list[dict] | None:
|
||||
def standalone_entries(manifest: dict, layouts: dict, profile: str) -> list[dict] | None:
|
||||
"""The files a profile's standalone build reads, as entries of the list:
|
||||
None for a profile without one. An item [dest, sha1] takes its download
|
||||
from the copy of the list with that content."""
|
||||
layouts = manifest.get("standalone_layouts") or {}
|
||||
if profile not in layouts:
|
||||
return None
|
||||
copies = {
|
||||
@@ -5438,15 +5476,16 @@ def standalone_entries(manifest: dict, profile: str) -> list[dict] | None:
|
||||
return result
|
||||
|
||||
|
||||
def standalone_layout(manifest: dict, profiles: list[str], files: list[dict],
|
||||
omitted: list[dict]) -> tuple[list[dict], list[dict]]:
|
||||
def standalone_layout(manifest: dict, layouts: dict, profiles: list[str],
|
||||
files: list[dict], omitted: list[dict]
|
||||
) -> tuple[list[dict], list[dict]]:
|
||||
"""--emulator with --standalone: the platform's own files of the systems
|
||||
the emulators run, and beside them each emulator's standalone build, in
|
||||
profile order, first at a destination wins, as `generate_pack.py
|
||||
--emulator --standalone` packs them."""
|
||||
built: dict[str, dict] = {}
|
||||
for profile in sorted(profiles):
|
||||
for entry in standalone_entries(manifest, profile) or []:
|
||||
for entry in standalone_entries(manifest, layouts, profile) or []:
|
||||
built.setdefault(_entry_key(entry), entry)
|
||||
own = [entry for entry in files
|
||||
if entry.get("cores") is None and _entry_key(entry) not in built]
|
||||
@@ -11933,19 +11972,20 @@ def _standalone_builds(
|
||||
"""--emulator with --standalone: each emulator's standalone build in
|
||||
place of the files its core reads. An emulator with no standalone
|
||||
build is refused, as `generate_pack.py --standalone` refuses it."""
|
||||
if "standalone_layouts" not in manifest:
|
||||
print(f"Error: the {plat} file list does not say what each standalone build "
|
||||
"reads, which --standalone needs.", file=sys.stderr)
|
||||
if "standalone_builds" not in manifest:
|
||||
print(f"Error: the {plat} file list does not say which emulators have a "
|
||||
"standalone build, which --standalone needs.", file=sys.stderr)
|
||||
print(_older_list_advice(plat), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
profiles = sorted({names[name] for name in resolve_choices(values, sorted(names),
|
||||
"emulator")})
|
||||
lacking = [p for p in profiles if p not in manifest["standalone_layouts"]]
|
||||
lacking = [p for p in profiles if p not in manifest["standalone_builds"]]
|
||||
if lacking:
|
||||
refuse_name(plat, f"Error: {', '.join(lacking)} has no standalone build: run "
|
||||
"again without --standalone.")
|
||||
before = len(files)
|
||||
files, omitted = standalone_layout(manifest, profiles, files, omitted)
|
||||
files, omitted = standalone_layout(manifest, fetch_standalone(plat, manifest), profiles,
|
||||
files, omitted)
|
||||
detail(f" The standalone {'builds' if len(profiles) > 1 else 'build'}: "
|
||||
f"{before} to {len(files)} files")
|
||||
return files, omitted
|
||||
@@ -22535,7 +22575,7 @@ def _tui_standalone_offered(state: TuiState) -> bool:
|
||||
"""Whether Change offers --standalone: emulators are chosen, and the
|
||||
list records a standalone build for each of them."""
|
||||
manifest = state.manifest or {}
|
||||
layouts = manifest.get("standalone_layouts") or {}
|
||||
layouts = manifest.get("standalone_builds") or []
|
||||
if not state.emulators or not layouts:
|
||||
return False
|
||||
names = emulator_names(manifest, *tui_run_files(state))
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/ins
|
||||
# curl or wget stop on a cut transfer before the hash is read: the site's
|
||||
# build rewrites this line there (scripts/sitebootstrap.py).
|
||||
MISMATCH_ADVICE="The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
|
||||
DEFAULT_INSTALL_SHA256="b92824f7fd4b3a4e40a02c48838a9d8597cb2228a3cd1e01ce051a3015d4ad29"
|
||||
DEFAULT_INSTALL_SHA256="b2b012c9e63239c0d68aa2e87aab59e5a5f1fa0f17c33db63e6da221e5d7f42b"
|
||||
# The pin above refuses any changed byte: this cap only stops a body that
|
||||
# cannot be the installer (a sign-in portal's page) before it is hashed.
|
||||
MAX_INSTALLER_BYTES=8388608
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
{
|
||||
"dest": "roms/ports/retrobios/install.py",
|
||||
"repo_path": "install.py",
|
||||
"size": 1365027,
|
||||
"sha256": "b92824f7fd4b3a4e40a02c48838a9d8597cb2228a3cd1e01ce051a3015d4ad29",
|
||||
"size": 1367313,
|
||||
"sha256": "b2b012c9e63239c0d68aa2e87aab59e5a5f1fa0f17c33db63e6da221e5d7f42b",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
@@ -71,8 +71,8 @@
|
||||
"muos": {
|
||||
"archive": {
|
||||
"dest": "ARCHIVE/RetroBIOS.muxapp",
|
||||
"size": 1418652,
|
||||
"sha256": "fbc544c18ceadfceb06f98f9b35341ab311a0b29f560f0a4530444bd99e5960c"
|
||||
"size": 1420938,
|
||||
"sha256": "7d23a5c6d1028b39ef54467d03860493d188d3dec79d70723f149e6f1411475d"
|
||||
},
|
||||
"members": [
|
||||
{
|
||||
@@ -92,8 +92,8 @@
|
||||
{
|
||||
"name": "RetroBIOS/install.py",
|
||||
"repo_path": "install.py",
|
||||
"size": 1365027,
|
||||
"sha256": "b92824f7fd4b3a4e40a02c48838a9d8597cb2228a3cd1e01ce051a3015d4ad29",
|
||||
"size": 1367313,
|
||||
"sha256": "b2b012c9e63239c0d68aa2e87aab59e5a5f1fa0f17c33db63e6da221e5d7f42b",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
@@ -166,8 +166,8 @@
|
||||
{
|
||||
"dest": ".config/modules/retrobios/install.py",
|
||||
"repo_path": "install.py",
|
||||
"size": 1365027,
|
||||
"sha256": "b92824f7fd4b3a4e40a02c48838a9d8597cb2228a3cd1e01ce051a3015d4ad29",
|
||||
"size": 1367313,
|
||||
"sha256": "b2b012c9e63239c0d68aa2e87aab59e5a5f1fa0f17c33db63e6da221e5d7f42b",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
|
||||
@@ -468,34 +468,14 @@
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"standalone_layouts": {
|
||||
"description": "Per emulator with a standalone build, the files generate_pack.py --emulator --standalone packs, at the destinations that build reads: an entry, or [dest, sha1] when the list carries that content.",
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "array",
|
||||
"prefixItems": [
|
||||
{
|
||||
"type": "string",
|
||||
"pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$)).+$"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"pattern": "^[a-f0-9]{40}$"
|
||||
}
|
||||
],
|
||||
"minItems": 2,
|
||||
"maxItems": 2
|
||||
},
|
||||
{
|
||||
"$ref": "#/$defs/file"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
"standalone_builds": {
|
||||
"description": "The emulators whose standalone build install/standalone/<platform>.json describes, which --emulator NAME --standalone reads. Absent when none has one.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
},
|
||||
"uniqueItems": true
|
||||
},
|
||||
"data_directories": {
|
||||
"description": "Data trees the pack carries, rebuilt by the installer from their source archive. Each file is kept only when its sha1 matches.",
|
||||
|
||||
@@ -0,0 +1,654 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://abdess.github.io/retrobios/api/v1/schemas/install-standalone.schema.json",
|
||||
"title": "RetroBIOS standalone build layouts",
|
||||
"description": "install/standalone/<platform>.json: per emulator with a standalone build, the files generate_pack.py --emulator NAME --standalone packs, at the destinations that build reads. install.py reads it only with --standalone.",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"schema",
|
||||
"platform",
|
||||
"standalone_layouts"
|
||||
],
|
||||
"properties": {
|
||||
"schema": {
|
||||
"const": 1
|
||||
},
|
||||
"platform": {
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
},
|
||||
"standalone_layouts": {
|
||||
"description": "Per emulator with a standalone build, the files generate_pack.py --emulator --standalone packs, at the destinations that build reads: an entry, or [dest, sha1] when the list carries that content.",
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "array",
|
||||
"prefixItems": [
|
||||
{
|
||||
"type": "string",
|
||||
"pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$)).+$"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"pattern": "^[a-f0-9]{40}$"
|
||||
}
|
||||
],
|
||||
"minItems": 2,
|
||||
"maxItems": 2
|
||||
},
|
||||
{
|
||||
"$ref": "#/$defs/file"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"$defs": {
|
||||
"file": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"dest",
|
||||
"sha1",
|
||||
"sha256",
|
||||
"size",
|
||||
"repo_path",
|
||||
"cores"
|
||||
],
|
||||
"properties": {
|
||||
"dest": {
|
||||
"type": "string",
|
||||
"pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$)).+$",
|
||||
"description": "Path below base_destination, below the save directory when root is save, below the roms folder when root is roms, below the configs folder when root is configs, or in an emulator folder when root is emulators (its key first)."
|
||||
},
|
||||
"sha1": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-f0-9]{40}$",
|
||||
"description": "SHA1 of the copy the repository serves. The installer checks it after download."
|
||||
},
|
||||
"sha256": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-f0-9]{64}$",
|
||||
"description": "SHA256 of the same copy."
|
||||
},
|
||||
"size": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"description": "Bytes of the same copy."
|
||||
},
|
||||
"repo_path": {
|
||||
"type": "string",
|
||||
"description": "Path in the repository. Fetched from `https://raw.githubusercontent.com/Abdess/retrobios/<ref>/<repo_path>`, ref being main unless RETROBIOS_REF names a tag."
|
||||
},
|
||||
"cores": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "null"
|
||||
},
|
||||
{
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"uniqueItems": true
|
||||
}
|
||||
],
|
||||
"description": "Profiles whose core brings the file into the pack. Null for a file the platform's own list declares."
|
||||
},
|
||||
"storage": {
|
||||
"const": "release",
|
||||
"description": "release when the file is a large-files release asset."
|
||||
},
|
||||
"release_asset": {
|
||||
"type": "string",
|
||||
"pattern": "^[^/\\\\]+$",
|
||||
"description": "Asset of the large-files release, fetched from `https://github.com/Abdess/retrobios/releases/download/large-files/<asset>` instead of repo_path."
|
||||
},
|
||||
"systems": {
|
||||
"description": "Every platform system that declares the file, for the installer's --system.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 256
|
||||
},
|
||||
"minItems": 1,
|
||||
"maxItems": 1000,
|
||||
"uniqueItems": true
|
||||
},
|
||||
"regions": {
|
||||
"description": "The regions the emulator code selects the file for. Absent when it never competes.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"argentina",
|
||||
"asia",
|
||||
"asia-ntsc",
|
||||
"asia-pal",
|
||||
"australia",
|
||||
"brazil",
|
||||
"canada",
|
||||
"china",
|
||||
"denmark",
|
||||
"europe",
|
||||
"finland",
|
||||
"france",
|
||||
"germany",
|
||||
"greece",
|
||||
"hong-kong",
|
||||
"india",
|
||||
"italy",
|
||||
"japan",
|
||||
"latin-america",
|
||||
"mexico",
|
||||
"netherlands",
|
||||
"new-zealand",
|
||||
"north-america",
|
||||
"norway",
|
||||
"oceania",
|
||||
"poland",
|
||||
"portugal",
|
||||
"russia",
|
||||
"singapore",
|
||||
"south-korea",
|
||||
"spain",
|
||||
"sweden",
|
||||
"taiwan",
|
||||
"uk",
|
||||
"world"
|
||||
]
|
||||
},
|
||||
"minItems": 1,
|
||||
"maxItems": 1000,
|
||||
"uniqueItems": true
|
||||
},
|
||||
"region_groups": {
|
||||
"description": "Groups the file competes in as a core extra, whatever systems are chosen.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 256
|
||||
},
|
||||
"minItems": 1,
|
||||
"maxItems": 1000,
|
||||
"uniqueItems": true
|
||||
},
|
||||
"region_system_groups": {
|
||||
"description": "Groups the file competes in as the platform's own declaration: present only when that system is kept.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 256
|
||||
},
|
||||
"minItems": 1,
|
||||
"maxItems": 1000,
|
||||
"uniqueItems": true
|
||||
},
|
||||
"priority": {
|
||||
"description": "The rank the code searches the file at, lower first: a world file withdraws an unmatched regional one only when it ranks no worse.",
|
||||
"type": "integer"
|
||||
},
|
||||
"truth": {
|
||||
"description": "false when the list --source truth installs lacks this file at this destination with these bytes.",
|
||||
"const": false
|
||||
},
|
||||
"slot": {
|
||||
"$ref": "#/$defs/slot"
|
||||
},
|
||||
"alternatives": {
|
||||
"description": "Copies other cores read at this destination when they disagree on its content, in the order the pack builder tries them. A narrowing that drops the entry's cores takes the first whose cores remain.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"sha1",
|
||||
"sha256",
|
||||
"size",
|
||||
"repo_path",
|
||||
"cores"
|
||||
],
|
||||
"properties": {
|
||||
"sha1": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-f0-9]{40}$",
|
||||
"description": "SHA1 of this copy."
|
||||
},
|
||||
"sha256": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-f0-9]{64}$",
|
||||
"description": "SHA256 of this copy."
|
||||
},
|
||||
"size": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"description": "Bytes of this copy."
|
||||
},
|
||||
"repo_path": {
|
||||
"type": "string",
|
||||
"description": "Path of this copy in the repository, fetched as the entry's repo_path is."
|
||||
},
|
||||
"storage": {
|
||||
"const": "release",
|
||||
"description": "release when this copy is a large-files release asset."
|
||||
},
|
||||
"release_asset": {
|
||||
"type": "string",
|
||||
"pattern": "^[^/\\\\]+$",
|
||||
"description": "Asset of the large-files release holding this copy, fetched instead of repo_path."
|
||||
},
|
||||
"cores": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"minItems": 1,
|
||||
"uniqueItems": true,
|
||||
"description": "Profiles whose core reads this copy."
|
||||
},
|
||||
"executable": {
|
||||
"type": "boolean",
|
||||
"description": "The repository keeps this copy executable."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"slot_choices": {
|
||||
"description": "On a platform file a core's own source contradicts while the frontend only checks the path: the copy each core's presence puts there, in the order the pack builder settles the slot. A narrowing serves the first whose cores remain. One naming only cores, or none remaining, leaves `declared_choices`.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"cores"
|
||||
],
|
||||
"properties": {
|
||||
"sha1": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-f0-9]{40}$",
|
||||
"description": "SHA1 of this copy."
|
||||
},
|
||||
"sha256": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-f0-9]{64}$",
|
||||
"description": "SHA256 of this copy."
|
||||
},
|
||||
"size": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"description": "Bytes of this copy."
|
||||
},
|
||||
"repo_path": {
|
||||
"type": "string",
|
||||
"description": "Path of this copy in the repository, fetched as the entry's repo_path is."
|
||||
},
|
||||
"storage": {
|
||||
"const": "release",
|
||||
"description": "release when this copy is a large-files release asset."
|
||||
},
|
||||
"release_asset": {
|
||||
"type": "string",
|
||||
"pattern": "^[^/\\\\]+$",
|
||||
"description": "Asset of the large-files release holding this copy, fetched instead of repo_path."
|
||||
},
|
||||
"cores": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"minItems": 1,
|
||||
"uniqueItems": true,
|
||||
"description": "Profiles whose presence puts this copy in the slot."
|
||||
},
|
||||
"executable": {
|
||||
"type": "boolean",
|
||||
"description": "The repository keeps this copy executable."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"declared_choices": {
|
||||
"description": "The platform's own answer at the destination by the declaring systems that remain, in the order the pack builder takes the declarations. A narrowing serves the first whose systems remain.",
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"sha1",
|
||||
"sha256",
|
||||
"size",
|
||||
"repo_path",
|
||||
"systems"
|
||||
],
|
||||
"properties": {
|
||||
"sha1": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-f0-9]{40}$",
|
||||
"description": "SHA1 of this copy."
|
||||
},
|
||||
"sha256": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-f0-9]{64}$",
|
||||
"description": "SHA256 of this copy."
|
||||
},
|
||||
"size": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"description": "Bytes of this copy."
|
||||
},
|
||||
"repo_path": {
|
||||
"type": "string",
|
||||
"description": "Path of this copy in the repository, fetched as the entry's repo_path is."
|
||||
},
|
||||
"storage": {
|
||||
"const": "release",
|
||||
"description": "release when this copy is a large-files release asset."
|
||||
},
|
||||
"release_asset": {
|
||||
"type": "string",
|
||||
"pattern": "^[^/\\\\]+$",
|
||||
"description": "Asset of the large-files release holding this copy, fetched instead of repo_path."
|
||||
},
|
||||
"executable": {
|
||||
"type": "boolean",
|
||||
"description": "The repository keeps this copy executable."
|
||||
},
|
||||
"systems": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
},
|
||||
"minItems": 1,
|
||||
"uniqueItems": true,
|
||||
"description": "Platform systems whose declaration this copy answers."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"category": {
|
||||
"description": "game_data: a game's own data, not firmware. Absent on firmware. The installer's --no-game-data leaves these out, as a pack built with --no-game-data does.",
|
||||
"const": "game_data"
|
||||
},
|
||||
"executable": {
|
||||
"description": "The repository keeps the file executable, and the installer gives it the execute bits the umask allows.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"declared_in": {
|
||||
"description": "The platform systems declaring the file, when fewer than `systems`, which also names the systems whose cores read it there.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
},
|
||||
"uniqueItems": true
|
||||
},
|
||||
"absent_claims": {
|
||||
"description": "Cores that want this destination and have nothing held, after the cores served here: a narrowing that keeps none of those takes the first named one as a file left out, as a pack built for it lists it.",
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"name",
|
||||
"system",
|
||||
"required",
|
||||
"reason",
|
||||
"cores"
|
||||
],
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"description": "File name the declaration gives."
|
||||
},
|
||||
"system": {
|
||||
"type": "string",
|
||||
"description": "System id of the declaration. Empty when the core's file names none."
|
||||
},
|
||||
"required": {
|
||||
"type": "boolean",
|
||||
"description": "The platform or the core needs the file to run, as the declaration says."
|
||||
},
|
||||
"reason": {
|
||||
"enum": [
|
||||
"hash_mismatch",
|
||||
"not_found",
|
||||
"external",
|
||||
"user_provided",
|
||||
"no_platform_slug",
|
||||
"below_platform_folder"
|
||||
],
|
||||
"description": "Why the file is left out, as a code. enumDescriptions gives the meaning of each code, in the order of enum.",
|
||||
"enumDescriptions": [
|
||||
"The platform checks the hash and the only copy held contradicts the one it declares, so the frontend would refuse it.",
|
||||
"The collection holds no copy the declaration accepts.",
|
||||
"The declaration keeps the file outside the repository (storage: external). The pack builder downloads it from its own address, the installer does not.",
|
||||
"The user supplies the file (storage: user_provided). The pack writes its instructions in its place.",
|
||||
"The platform keeps one folder per system and has none for the system the core's file belongs to.",
|
||||
"The platform lists each system folder flat (firmware_folder_flat) and the file would sit in a subfolder it does not read."
|
||||
]
|
||||
},
|
||||
"cores": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "null"
|
||||
},
|
||||
{
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"uniqueItems": true
|
||||
}
|
||||
],
|
||||
"description": "Profiles whose core wants the file. Null for a file the platform's own list declares."
|
||||
},
|
||||
"regions": {
|
||||
"description": "The regions the emulator code selects the file for. Absent when it never competes.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"argentina",
|
||||
"asia",
|
||||
"asia-ntsc",
|
||||
"asia-pal",
|
||||
"australia",
|
||||
"brazil",
|
||||
"canada",
|
||||
"china",
|
||||
"denmark",
|
||||
"europe",
|
||||
"finland",
|
||||
"france",
|
||||
"germany",
|
||||
"greece",
|
||||
"hong-kong",
|
||||
"india",
|
||||
"italy",
|
||||
"japan",
|
||||
"latin-america",
|
||||
"mexico",
|
||||
"netherlands",
|
||||
"new-zealand",
|
||||
"north-america",
|
||||
"norway",
|
||||
"oceania",
|
||||
"poland",
|
||||
"portugal",
|
||||
"russia",
|
||||
"singapore",
|
||||
"south-korea",
|
||||
"spain",
|
||||
"sweden",
|
||||
"taiwan",
|
||||
"uk",
|
||||
"world"
|
||||
]
|
||||
},
|
||||
"minItems": 1,
|
||||
"maxItems": 1000,
|
||||
"uniqueItems": true
|
||||
},
|
||||
"region_groups": {
|
||||
"description": "Groups the file competes in as a core extra, whatever systems are chosen.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 256
|
||||
},
|
||||
"minItems": 1,
|
||||
"maxItems": 1000,
|
||||
"uniqueItems": true
|
||||
},
|
||||
"region_system_groups": {
|
||||
"description": "Groups the file competes in as the platform's own declaration: present only when that system is kept.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 256
|
||||
},
|
||||
"minItems": 1,
|
||||
"maxItems": 1000,
|
||||
"uniqueItems": true
|
||||
},
|
||||
"systems": {
|
||||
"description": "Every platform system that declares the file, for the installer's --system.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 256
|
||||
},
|
||||
"minItems": 1,
|
||||
"maxItems": 1000,
|
||||
"uniqueItems": true
|
||||
},
|
||||
"priority": {
|
||||
"description": "The rank the code searches the file at, lower first: a world file withdraws an unmatched regional one only when it ranks no worse.",
|
||||
"type": "integer"
|
||||
},
|
||||
"declared_in": {
|
||||
"description": "The platform systems declaring the file, when fewer than `systems`, which also names the systems whose cores read it there.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
},
|
||||
"uniqueItems": true
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"description": "save: dest is relative to the save directory the frontend hands the core (RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY), not to the BIOS directory. roms: dest is relative to the platform's roms folder, which roms_directory locates (a file its launcher runs from there, ROCKNIX's roms/pico-8). emulators: dest is the key of an emulator folder of the platform, then the path in it, located by emulators_directory (RetroBat's emulators/pico8). configs: dest is relative to the frontend's configs folder, which configs_directory locates (Batocera starts shadPS4 from configs/shadps4). Absent for a file of the BIOS tree.",
|
||||
"enum": [
|
||||
"save",
|
||||
"roms",
|
||||
"emulators",
|
||||
"configs"
|
||||
]
|
||||
},
|
||||
"core_folder": {
|
||||
"description": "The core's library_name, the folder a frontend sorting saves by core (RetroArch's sort_savefiles_enable) inserts between its save directory and dest. Only with root: save. Absent on a save entry when the core reads the same place sorted or not.",
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"pattern": "^[^/\\\\]+$"
|
||||
}
|
||||
},
|
||||
"oneOf": [
|
||||
{
|
||||
"required": [
|
||||
"release_asset"
|
||||
]
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"repo_path": {
|
||||
"type": "string",
|
||||
"pattern": "^bios/",
|
||||
"description": "Without release_asset, the copy is served from the repository's bios/ tree."
|
||||
}
|
||||
},
|
||||
"not": {
|
||||
"required": [
|
||||
"release_asset"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"slot": {
|
||||
"description": "What --one-per-slot reads: the groups the file competes in, once per time a group lists it, then the keys the slot lookup tries, each with what every emulator declares there.",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"groups",
|
||||
"keys"
|
||||
],
|
||||
"properties": {
|
||||
"groups": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
},
|
||||
"minItems": 1
|
||||
},
|
||||
"keys": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"minProperties": 1,
|
||||
"additionalProperties": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"ranks"
|
||||
],
|
||||
"properties": {
|
||||
"ranks": {
|
||||
"description": "The priority: of each entry of the emulator at this key, null for one without, lower first.",
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": {
|
||||
"type": [
|
||||
"integer",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"regions": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"sets": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2963,6 +2963,7 @@ def _run_manifest_mode(
|
||||
tc = target_cores_cache.get(representative) if args.target else None
|
||||
if _skip_empty_truth(args, source, representative, emu_profiles, tc, failed):
|
||||
continue
|
||||
layouts: dict = {}
|
||||
try:
|
||||
manifest = generate_manifest(
|
||||
representative,
|
||||
@@ -2982,6 +2983,7 @@ def _run_manifest_mode(
|
||||
offline=args.offline,
|
||||
required_only=required_only,
|
||||
no_game_data=getattr(args, "no_game_data", False),
|
||||
standalone_out=layouts,
|
||||
)
|
||||
narrow_suffix = "".join(
|
||||
tag.lower()
|
||||
@@ -3004,6 +3006,9 @@ def _run_manifest_mode(
|
||||
f"{manifest['total_size']} bytes, "
|
||||
f"{manifest['total_omitted']} safely omitted"
|
||||
)
|
||||
for plat in group_platforms if layouts else ():
|
||||
print(f" {_write_standalone_layouts(args.output_dir, plat, layouts)}: "
|
||||
f"{len(layouts)} standalone builds")
|
||||
# Create aliases for grouped platforms (e.g., lakka -> retroarch)
|
||||
for alias_plat in group_platforms:
|
||||
if alias_plat != representative:
|
||||
@@ -4877,6 +4882,7 @@ def generate_manifest(
|
||||
no_game_data: bool = False,
|
||||
one_per_slot: bool = False,
|
||||
known_slot_choices: dict | None = None,
|
||||
standalone_out: dict | None = None,
|
||||
) -> dict:
|
||||
"""Generate a JSON manifest for a platform (same resolution as generate_pack).
|
||||
|
||||
@@ -4887,6 +4893,10 @@ def generate_manifest(
|
||||
A file that is a game's data, not firmware, carries ``"category":
|
||||
"game_data"``, so the installer can leave it out as the builder does
|
||||
under ``no_game_data``. Firmware carries no category.
|
||||
`standalone_out` receives, per emulator with a standalone build, what
|
||||
`--emulator X --standalone` packs (standalone_layouts), which the list
|
||||
itself only names (standalone_builds): written apart, it is fetched
|
||||
only by a run given --standalone.
|
||||
"""
|
||||
config = load_platform_config(platform_name, platforms_dir)
|
||||
if fold_case is not None:
|
||||
@@ -5438,10 +5448,26 @@ def generate_manifest(
|
||||
platforms_dir, repo_root, result,
|
||||
)
|
||||
if layouts:
|
||||
result["standalone_layouts"] = layouts
|
||||
result["standalone_builds"] = sorted(layouts)
|
||||
if standalone_out is not None:
|
||||
standalone_out.update(layouts)
|
||||
return result
|
||||
|
||||
|
||||
STANDALONE_DIR = "standalone"
|
||||
|
||||
|
||||
def _write_standalone_layouts(output_dir: str, platform: str, layouts: dict) -> str:
|
||||
"""install/standalone/<platform>.json, what --standalone reads beside the
|
||||
list. Its [dest, sha1] items take their download from that list."""
|
||||
path = os.path.join(output_dir, STANDALONE_DIR, f"{platform}.json")
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
_write_manifest_if_changed(path, {
|
||||
"schema": 1, "platform": platform, "standalone_layouts": layouts,
|
||||
})
|
||||
return path
|
||||
|
||||
|
||||
def _truth_key(entry: dict) -> tuple:
|
||||
"""What tells one entry from another, as the installer's _entry_key."""
|
||||
root = entry.get("root")
|
||||
|
||||
@@ -1883,6 +1883,15 @@ def _publish_manifests(api: Path) -> list[tuple]:
|
||||
_record(targets / source.name)
|
||||
assets.append((targets / source.name, f"Target list: {source.stem}",
|
||||
"application/json", "schemas/target-manifest.schema.json"))
|
||||
# What install.py --standalone reads beside the list, apart so that no
|
||||
# other run downloads it.
|
||||
standalone = api / "standalone"
|
||||
standalone.mkdir(parents=True, exist_ok=True)
|
||||
for source in sorted((_REPO_ROOT / "install" / "standalone").glob("*.json")):
|
||||
shutil.copy2(source, standalone / source.name)
|
||||
_record(standalone / source.name)
|
||||
assets.append((standalone / source.name, f"Standalone layouts: {source.stem}",
|
||||
"application/json", "schemas/install-standalone.schema.json"))
|
||||
# Every change each updated platform file carries, for a maintainer who
|
||||
# reviews them by script: the Exports page linked only the files.
|
||||
exports = api / "exports"
|
||||
|
||||
@@ -738,6 +738,11 @@ def _semantic_install_checks(path: Path, manifest: dict) -> list[str]:
|
||||
f"{path.relative_to(ROOT)}: entries read below the save directory "
|
||||
"and no save_directory"
|
||||
)
|
||||
builds = ROOT / "install" / "standalone" / path.name
|
||||
if manifest.get("standalone_builds") and path.parent == ROOT / "install" \
|
||||
and not builds.is_file():
|
||||
out.append(f"{path.relative_to(ROOT)}: standalone_builds and no "
|
||||
f"install/standalone/{path.name}")
|
||||
stray = sorted(
|
||||
entry["dest"] for entry in [*files, *omitted]
|
||||
if entry.get("core_folder") and entry.get("root") != "save"
|
||||
@@ -749,6 +754,36 @@ def _semantic_install_checks(path: Path, manifest: dict) -> list[str]:
|
||||
return out
|
||||
|
||||
|
||||
def _semantic_standalone_checks(path: Path, layouts: dict) -> list[str]:
|
||||
"""A standalone layout file goes with its platform's list: the list
|
||||
names the same builds, and each [dest, sha1] item takes its download
|
||||
from a copy of that list."""
|
||||
where = path.relative_to(ROOT)
|
||||
plat = layouts.get("platform")
|
||||
if path.stem != plat:
|
||||
return [f"{where}: platform {plat} in a file named {path.stem}"]
|
||||
listed = ROOT / "install" / f"{plat}.json"
|
||||
if not listed.is_file():
|
||||
return [f"{where}: no install/{plat}.json beside it"]
|
||||
manifest = json.loads(listed.read_text(encoding="utf-8"))
|
||||
out: list[str] = []
|
||||
if sorted(layouts.get("standalone_layouts", {})) != manifest.get("standalone_builds"):
|
||||
out.append(f"{where}: its builds differ from standalone_builds in {listed.name}")
|
||||
held = {
|
||||
copy.get("sha1")
|
||||
for entry in [*manifest.get("files", []), *manifest.get("truth_files", [])]
|
||||
for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])]
|
||||
}
|
||||
missing = sorted({
|
||||
item[1] for items in layouts.get("standalone_layouts", {}).values()
|
||||
for item in items if isinstance(item, list) and item[1] not in held
|
||||
})
|
||||
if missing:
|
||||
out.append(f"{where}: {len(missing)} sha1 no copy of {listed.name} carries "
|
||||
f"({missing[0]})")
|
||||
return out
|
||||
|
||||
|
||||
def _event_schema_errors() -> list[str]:
|
||||
"""install-events.schema.json is EVENT_KEYS written out, and a valid schema."""
|
||||
import generate_event_schema # noqa: PLC0415
|
||||
@@ -994,6 +1029,14 @@ def main() -> int:
|
||||
)
|
||||
)
|
||||
|
||||
standalone_paths = sorted((ROOT / "install" / "standalone").glob("*.json"))
|
||||
errors.extend(
|
||||
_validate_json_files(
|
||||
standalone_paths, "install-standalone.schema.json",
|
||||
_semantic_standalone_checks,
|
||||
)
|
||||
)
|
||||
|
||||
target_paths = sorted((ROOT / "install" / "targets").glob("*.json"))
|
||||
errors.extend(
|
||||
_validate_json_files(target_paths, "target-manifest.schema.json")
|
||||
|
||||
@@ -2480,6 +2480,25 @@ class EveryManifestEntryIsFetchable(unittest.TestCase):
|
||||
data = json.loads(path.read_text())
|
||||
install._validate_manifest(data, data["platform"])
|
||||
|
||||
def test_every_standalone_layout_goes_with_its_list(self):
|
||||
"""install/standalone/<platform>.json, which only --standalone
|
||||
reads: the installer accepts it against its own list, each item
|
||||
written whole has a source, and a list naming builds has its file."""
|
||||
listed = {path.stem: json.loads(path.read_text())
|
||||
for path in sorted((ROOT / "install").glob("*.json"))}
|
||||
layouts = sorted((ROOT / "install" / "standalone").glob("*.json"))
|
||||
self.assertEqual({path.stem for path in layouts},
|
||||
{plat for plat, data in listed.items()
|
||||
if data.get("standalone_builds")})
|
||||
for path in layouts:
|
||||
with self.subTest(layout=path.name):
|
||||
data = json.loads(path.read_text())
|
||||
kept = install._check_standalone_layouts(data, listed[path.stem], path.stem)
|
||||
orphans = [item["dest"] for items in kept.values() for item in items
|
||||
if isinstance(item, dict)
|
||||
and not item.get("repo_path") and not item.get("release_asset")]
|
||||
self.assertEqual(orphans, [])
|
||||
|
||||
def test_schema_and_installer_name_the_same_reasons(self):
|
||||
schema = json.loads(
|
||||
(ROOT / "schemas" / "install-manifest.schema.json").read_text()
|
||||
|
||||
@@ -60,17 +60,21 @@ class RealListParity(unittest.TestCase):
|
||||
cls.by_path = {entry["path"]: sha1 for sha1, entry in cls.db["files"].items()}
|
||||
cls.platforms = list_registered_platforms(str(REPO_ROOT / "platforms"))
|
||||
cls.manifests: dict[str, dict] = {}
|
||||
cls.layouts: dict[str, dict] = {}
|
||||
cls.baselines: dict[str, set[str]] = {}
|
||||
|
||||
def manifest(self, plat: str) -> dict:
|
||||
"""The list, its standalone layouts kept aside as the run writes them
|
||||
(install/standalone/<platform>.json)."""
|
||||
if plat not in self.manifests:
|
||||
self.layouts[plat] = {}
|
||||
with contextlib.redirect_stdout(io.StringIO()):
|
||||
self.manifests[plat] = self.gp.generate_manifest(
|
||||
plat, str(REPO_ROOT / "platforms"), self.db, str(REPO_ROOT / "bios"),
|
||||
str(REPO_ROOT / "platforms" / "_registry.yml"),
|
||||
emulators_dir=str(REPO_ROOT / "emulators"),
|
||||
zip_contents=self.zip_contents, emu_profiles=self.profiles,
|
||||
offline=True)
|
||||
offline=True, standalone_out=self.layouts[plat])
|
||||
return self.manifests[plat]
|
||||
|
||||
def packed(self, plat: str, **options) -> dict[str, str | None]:
|
||||
@@ -156,7 +160,11 @@ class RealListParity(unittest.TestCase):
|
||||
checked = 0
|
||||
for plat in self.platforms:
|
||||
full = self.manifest(plat)
|
||||
for profile in sorted(full.get("standalone_layouts") or {}):
|
||||
layouts = install._check_standalone_layouts(
|
||||
{"schema": 1, "platform": plat, "standalone_layouts": self.layouts[plat]},
|
||||
full, plat)
|
||||
self.assertEqual(sorted(layouts), full.get("standalone_builds", []))
|
||||
for profile in sorted(layouts):
|
||||
with self.subTest(platform=plat, emulator=profile):
|
||||
record = self.gp.PackRecord()
|
||||
with contextlib.redirect_stdout(io.StringIO()), \
|
||||
@@ -168,8 +176,8 @@ class RealListParity(unittest.TestCase):
|
||||
offline=True, record=record)
|
||||
files, omitted = install._narrow_to_emulators(
|
||||
[profile], full, plat, full["files"], full["omitted_files"])
|
||||
files, _omitted = install.standalone_layout(full, [profile], files,
|
||||
omitted)
|
||||
files, _omitted = install.standalone_layout(full, layouts, [profile],
|
||||
files, omitted)
|
||||
packed = {member: self.by_path[record.sources[member]]
|
||||
for member in record.files
|
||||
if record.sources.get(member) in self.by_path}
|
||||
@@ -279,16 +287,26 @@ class Lists(unittest.TestCase):
|
||||
self.root = Path(scratch.name)
|
||||
self.dest = self.root / "bios"
|
||||
|
||||
def write(self, manifest: dict) -> Path:
|
||||
def write(self, manifest: dict, layouts: dict | None = None) -> Path:
|
||||
"""The list, and its standalone layouts beside it where the
|
||||
repository keeps them, unless layouts is {}."""
|
||||
path = self.root / "retroarch.json"
|
||||
path.write_text(json.dumps(manifest), encoding="utf-8")
|
||||
beside = self.root / "standalone" / "retroarch.json"
|
||||
if layouts == {}:
|
||||
if beside.exists():
|
||||
beside.unlink()
|
||||
else:
|
||||
beside.parent.mkdir(exist_ok=True)
|
||||
beside.write_text(json.dumps(layouts or LAYOUTS), encoding="utf-8")
|
||||
return path
|
||||
|
||||
def run_install(self, manifest: dict, *argv: str) -> subprocess.CompletedProcess:
|
||||
env = dict(os.environ, RETROBIOS_OS="linux", RETROBIOS_OFFLINE="1")
|
||||
def run_install(self, manifest: dict, *argv: str, layouts: dict | None = None,
|
||||
env: dict | None = None) -> subprocess.CompletedProcess:
|
||||
env = dict(os.environ, RETROBIOS_OS="linux", RETROBIOS_OFFLINE="1", **(env or {}))
|
||||
return subprocess.run(
|
||||
[sys.executable, str(REPO_ROOT / "install.py"), "--platform", "retroarch",
|
||||
"--dest", str(self.dest), "--manifest", str(self.write(manifest)),
|
||||
"--dest", str(self.dest), "--manifest", str(self.write(manifest, layouts)),
|
||||
"--no-input", *argv],
|
||||
capture_output=True, text=True, timeout=120, env=env, check=False)
|
||||
|
||||
@@ -313,9 +331,10 @@ LIST = {
|
||||
"omitted_files": [],
|
||||
"truth_files": [_copy("ds/only.bin", b"truth", ["duckstation"])],
|
||||
"truth_omitted": [],
|
||||
"standalone_layouts": {"duckstation": [["ds/scph5501.bin",
|
||||
hashlib.sha1(b"two").hexdigest()]]},
|
||||
"standalone_builds": ["duckstation"],
|
||||
}
|
||||
LAYOUTS = {"schema": 1, "platform": "retroarch", "standalone_layouts": {
|
||||
"duckstation": [["ds/scph5501.bin", hashlib.sha1(b"two").hexdigest()]]}}
|
||||
|
||||
|
||||
class FindByHash(Lists):
|
||||
@@ -390,7 +409,7 @@ class ExpertRuns(Lists):
|
||||
|
||||
def test_a_list_without_the_fields_is_refused(self):
|
||||
older = copy.deepcopy(LIST)
|
||||
for field in ("slot_fields", "truth_files", "truth_omitted", "standalone_layouts"):
|
||||
for field in ("slot_fields", "truth_files", "truth_omitted", "standalone_builds"):
|
||||
older.pop(field)
|
||||
for argv, words in (
|
||||
(["--one-per-slot"], "which --one-per-slot needs"),
|
||||
@@ -416,11 +435,64 @@ class ExpertRuns(Lists):
|
||||
bad["files"][0][field] = value
|
||||
with self.assertRaises(ValueError):
|
||||
install._validate_manifest(bad, "retroarch")
|
||||
bad = copy.deepcopy(LIST)
|
||||
bad["standalone_layouts"]["duckstation"] = [["../x.bin", "0" * 40]]
|
||||
with self.assertRaises(ValueError):
|
||||
install._validate_manifest(bad, "retroarch")
|
||||
install._validate_manifest(copy.deepcopy(LIST), "retroarch")
|
||||
for broken in ([["../x.bin", LAYOUTS["standalone_layouts"]["duckstation"][0][1]]],
|
||||
[["ds/x.bin", "0" * 40]]):
|
||||
with self.subTest(layout=broken):
|
||||
with self.assertRaises(ValueError):
|
||||
install._check_standalone_layouts(
|
||||
{**LAYOUTS, "standalone_layouts": {"duckstation": broken}},
|
||||
LIST, "retroarch")
|
||||
with self.assertRaises(ValueError):
|
||||
install._check_standalone_layouts({**LAYOUTS, "standalone_layouts": {}},
|
||||
LIST, "retroarch")
|
||||
|
||||
def test_a_layout_file_missing_or_unreachable_refuses_on_one_line(self):
|
||||
"""Only --standalone reads the file: a list without it beside still
|
||||
installs everything else, and --standalone stops on one line."""
|
||||
cases = (
|
||||
({}, {"RETROBIOS_INSTALL_OFFLINE": "1"}, "makes no network request"),
|
||||
({"schema": 1, "platform": "recalbox", "standalone_layouts": {}}, {},
|
||||
"not valid"),
|
||||
)
|
||||
for layouts, env, words in cases:
|
||||
with self.subTest(words=words):
|
||||
proc = self.run_install(LIST, "--dry-run", "--emulator", "duckstation",
|
||||
"--standalone", layouts=layouts, env=env)
|
||||
self.assertEqual(proc.returncode, 1, proc.stdout + proc.stderr)
|
||||
said = [line for line in proc.stderr.splitlines() if line.strip()]
|
||||
self.assertEqual(len(said), 1, said)
|
||||
self.assertIn("--standalone needs", said[0])
|
||||
self.assertIn(words, said[0])
|
||||
proc = self.run_install(LIST, "--dry-run", "--emulator", "duckstation",
|
||||
layouts={}, env={"RETROBIOS_INSTALL_OFFLINE": "1"})
|
||||
self.assertEqual(proc.returncode, 0, proc.stdout + proc.stderr)
|
||||
|
||||
def test_a_layout_file_missing_from_the_server(self):
|
||||
import http.server
|
||||
import threading
|
||||
|
||||
served = self.root / "served"
|
||||
(served / "install").mkdir(parents=True)
|
||||
|
||||
class Quiet(http.server.SimpleHTTPRequestHandler):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, directory=str(served), **kwargs)
|
||||
|
||||
def log_message(self, *_args):
|
||||
return
|
||||
|
||||
server = http.server.ThreadingHTTPServer(("127.0.0.1", 0), Quiet)
|
||||
threading.Thread(target=server.serve_forever, daemon=True).start()
|
||||
self.addCleanup(server.server_close)
|
||||
self.addCleanup(server.shutdown)
|
||||
base = f"http://127.0.0.1:{server.server_address[1]}"
|
||||
proc = self.run_install(LIST, "--dry-run", "--emulator", "duckstation", "--standalone",
|
||||
layouts={}, env={"RETROBIOS_BASE_URL": base})
|
||||
self.assertEqual(proc.returncode, 1, proc.stdout + proc.stderr)
|
||||
said = [line for line in proc.stderr.splitlines() if line.strip()]
|
||||
self.assertEqual(said, [f"Error: --standalone needs {base}/install/standalone/"
|
||||
"retroarch.json, which could not be read (HTTP 404)."])
|
||||
|
||||
|
||||
class ChangeRows(unittest.TestCase):
|
||||
@@ -460,7 +532,7 @@ class ChangeRows(unittest.TestCase):
|
||||
|
||||
def test_no_row_on_a_list_without_the_fields(self):
|
||||
older = {key: value for key, value in LIST.items()
|
||||
if key not in ("slot_fields", "standalone_layouts")}
|
||||
if key not in ("slot_fields", "standalone_builds")}
|
||||
state = self.state(older)
|
||||
state.emulators = ["duckstation"]
|
||||
self.assertFalse({"slot", "standalone"} & set(self.actions(state)))
|
||||
|
||||
@@ -1006,7 +1006,7 @@ def golden_states() -> dict:
|
||||
option_focus(slots, "slot")
|
||||
states["change-slot"] = slots
|
||||
standalone = checked_state()
|
||||
standalone.manifest = {**MANIFEST, "standalone_layouts": {"pcsx_rearmed": []}}
|
||||
standalone.manifest = {**MANIFEST, "standalone_builds": ["pcsx_rearmed"]}
|
||||
standalone.stack.append("options")
|
||||
standalone.emulators = ["pcsx_rearmed"]
|
||||
option_focus(standalone, "standalone")
|
||||
|
||||
+5
-1
@@ -1258,6 +1258,10 @@ sha1), on the real list of every registered platform.
|
||||
- [`--standalone`](#option-standalone), with `--emulator`, installs the
|
||||
emulator's standalone build in place of its core's layout. Change shows
|
||||
**Standalone version of it** once an emulator with such a build is ticked.
|
||||
The layouts live apart, in `install/standalone/<platform>.json`, read only
|
||||
by a run given `--standalone`: beside `--manifest FILE` when a
|
||||
`standalone/` folder holds it, else downloaded as the list is. Missing,
|
||||
unreachable or invalid, the run stops on one line with code 1.
|
||||
- [`--source truth`](#option-source) keeps only what the emulator profiles
|
||||
prove a core reads, the platform's own declarations aside.
|
||||
- [`--find HASH`](#option-find) installs the one BIOS with that content.
|
||||
@@ -1306,7 +1310,7 @@ option takes the recorded choice whole.
|
||||
| <span id="option-no-game-data"></span>`--no-game-data` | Leave out game data (a game's own files, not firmware) and install the firmware only. What it leaves out is named. See [Firmware without game data](#firmware-without-game-data) |
|
||||
| <span id="option-declared-only"></span>`--declared-only` | Keep only the files the platform's own list names (`cores: null` in the manifest), not the extra files cores load. With `--check`, the answer is about the list the platform itself checks. Refused with `--core`, the listings it does not change, `--standalone-copies` and `--tui` |
|
||||
| <span id="option-one-per-slot"></span>`--one-per-slot` | Keep one BIOS per console and region, the one the emulators' own search order (`priority:`, lower first) ranks first, as `generate_pack.py --one-per-slot` does. A slot with an unranked candidate, or a candidate two cores rank apart, keeps all of them. Decided over the whole list, by the board's cores on a board: refused with `--system`, `--emulator`, `--for-games`, `--declared-only` and the listings. See [One level further](#one-level-further) |
|
||||
| <span id="option-standalone"></span>`--standalone` | With `--emulator`: that emulator's standalone build, at the paths it reads, beside the platform's own BIOS of its systems, as `generate_pack.py --emulator NAME --standalone` packs it. An emulator without a standalone build is refused, and so are `--region`, `--one-per-slot`, `--core` and `--system` beside it |
|
||||
| <span id="option-standalone"></span>`--standalone` | With `--emulator`: that emulator's standalone build, at the paths it reads, beside the platform's own BIOS of its systems, as `generate_pack.py --emulator NAME --standalone` packs it. The layouts come from `install/standalone/<platform>.json`, fetched only for this option. An emulator without a standalone build is refused, and so are `--region`, `--one-per-slot`, `--core` and `--system` beside it |
|
||||
| <span id="option-source"></span>`--source SOURCE` | `truth`: only what the emulator profiles prove a core reads, as `generate_pack.py --source truth` packs it. `full`, the default, is the platform's list and what its cores read. `truth` takes no other choice, opens no full screen, and is refused on a list published before it |
|
||||
| <span id="option-find"></span>`--find HASH` | Install the one BIOS of the list with this content: a sha1 or sha256 always, an md5 or crc32 where the list records it. A content at several destinations is installed at each. A hash two contents share is named and refused, as is one the list lacks. Takes no other choice |
|
||||
| <span id="option-json"></span>`--json` | With `--find`: print the matches as one JSON object per platform and install nothing. The shape is in [One level further](#one-level-further). Exit code 0 when found, 2 otherwise |
|
||||
|
||||
Reference in new issue
Block a user