mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-25 10:58:52 -06:00
chore: merge the expert installer options
This commit is contained in:
commit
754b1c29d2
69 files changed
+330998
-4147
No files matched your search
+198
-15
@@ -34,6 +34,7 @@ import shutil
|
||||
import tempfile
|
||||
import zipfile
|
||||
from pathlib import Path, PurePosixPath
|
||||
from typing import Any
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
from alternatives import core_file_spares, settle_sets, slot_set_keys
|
||||
@@ -775,14 +776,8 @@ def _select_variants(
|
||||
|
||||
slot_undecidable: list[str] = []
|
||||
if one_per_slot:
|
||||
slot_groups = {
|
||||
sys_id: [(d, n) for d, n in members if d not in region_drops]
|
||||
for sys_id, members in region_groups.items()
|
||||
}
|
||||
slot_drops, slot_undecidable = slot_mod.resolve_slot_drops(
|
||||
slot_groups,
|
||||
slot_mod.platform_slot_index(config, emu_profiles or {}, target_cores),
|
||||
held,
|
||||
slot_drops, slot_undecidable = _slot_drops(
|
||||
config, emu_profiles, target_cores, region_groups, region_drops, held
|
||||
)
|
||||
region_drops = region_drops | slot_drops
|
||||
if slot_undecidable:
|
||||
@@ -794,6 +789,27 @@ def _select_variants(
|
||||
return region_drops, region_fallbacks, slot_undecidable
|
||||
|
||||
|
||||
def _slot_drops(
|
||||
config: dict,
|
||||
emu_profiles: dict | None,
|
||||
target_cores: set[str] | None,
|
||||
region_groups: dict[str, list[tuple[str, str]]],
|
||||
region_drops: set[str],
|
||||
held: set[str],
|
||||
) -> tuple[set[str], list[str]]:
|
||||
"""What --one-per-slot withdraws once the regions have, and the slots no
|
||||
declared order decides. The pack and the manifest both read it."""
|
||||
slot_groups = {
|
||||
sys_id: [(d, n) for d, n in members if d not in region_drops]
|
||||
for sys_id, members in region_groups.items()
|
||||
}
|
||||
return slot_mod.resolve_slot_drops(
|
||||
slot_groups,
|
||||
slot_mod.platform_slot_index(config, emu_profiles or {}, target_cores),
|
||||
held,
|
||||
)
|
||||
|
||||
|
||||
def _platform_pack_name(
|
||||
platform_name: str,
|
||||
platforms_dir: str,
|
||||
@@ -2948,8 +2964,9 @@ 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(
|
||||
manifest = generate_install_list(
|
||||
representative,
|
||||
args.platforms_dir,
|
||||
db,
|
||||
@@ -2967,6 +2984,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()
|
||||
@@ -2989,6 +3007,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:
|
||||
@@ -4649,12 +4670,14 @@ def _manifest_selection(
|
||||
zip_contents: dict | None = None,
|
||||
data_registry: dict | None = None,
|
||||
slot_overrides: dict[str, str] | None = None,
|
||||
one_per_slot: bool = False,
|
||||
) -> tuple[set[str], SelectionIndex, set[str]]:
|
||||
"""Destinations a region list removes, the groups the installer replays,
|
||||
and the destinations the builder holds.
|
||||
"""Destinations a region list and --one-per-slot remove, the groups the
|
||||
installer replays, and the destinations the builder holds.
|
||||
|
||||
Grouped as the pack groups them, so a region the installer applies to
|
||||
the full manifest withdraws what `--region` withdraws from the pack.
|
||||
Grouped as the pack groups them, so a region or a slot the installer
|
||||
decides on the full manifest withdraws what `--region` and
|
||||
`--one-per-slot` withdraw from the pack.
|
||||
"""
|
||||
extras: list[dict] = []
|
||||
held: set[str] = set()
|
||||
@@ -4684,9 +4707,14 @@ def _manifest_selection(
|
||||
if regions
|
||||
else set()
|
||||
)
|
||||
if one_per_slot:
|
||||
drops = drops | _slot_drops(
|
||||
config, emu_profiles, target_cores, region_groups, drops, held
|
||||
)[0]
|
||||
return drops, SelectionIndex.build(
|
||||
region_groups, region_index, pack_systems, extras, required_only,
|
||||
extras_prefix=declared_root(config),
|
||||
slot_claims=slot_mod.platform_slot_claims(config, emu_profiles, target_cores),
|
||||
), held
|
||||
|
||||
|
||||
@@ -4853,6 +4881,9 @@ def generate_manifest(
|
||||
data_registry: dict | None = None,
|
||||
fold_case: bool | None = None,
|
||||
no_game_data: bool = False,
|
||||
one_per_slot: bool = False,
|
||||
known_slot_choices: dict | None = None,
|
||||
build_out: dict | None = None,
|
||||
) -> dict:
|
||||
"""Generate a JSON manifest for a platform (same resolution as generate_pack).
|
||||
|
||||
@@ -4863,6 +4894,9 @@ 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.
|
||||
One build: generate_install_list adds what --source truth and
|
||||
--standalone read. `build_out` receives the slot choices and the
|
||||
profiles this build read, which that second build takes over.
|
||||
"""
|
||||
config = load_platform_config(platform_name, platforms_dir)
|
||||
if fold_case is not None:
|
||||
@@ -4947,8 +4981,10 @@ def generate_manifest(
|
||||
# The full manifest records every core's answer at a contested slot, so a
|
||||
# target narrowed from it gets what that target's own pack serves.
|
||||
whole = target_cores is None and source != "platform" and bool(emu_profiles)
|
||||
# The truth list read inside this run takes the choices already made.
|
||||
slot_choices = (
|
||||
slots.slot_choices(config, emu_profiles, db, zip_contents, data_registry)
|
||||
known_slot_choices if known_slot_choices is not None and whole
|
||||
else slots.slot_choices(config, emu_profiles, db, zip_contents, data_registry)
|
||||
if whole else {}
|
||||
)
|
||||
# Derived from the same choices: computed twice, it was 8% of a run.
|
||||
@@ -5025,7 +5061,7 @@ def generate_manifest(
|
||||
config, pack_systems, emulators_dir, db, base_dest, emu_profiles,
|
||||
target_cores, source, required_only, regions, undeclared=undeclared,
|
||||
zip_contents=zip_contents, data_registry=data_registry,
|
||||
slot_overrides=slot_overrides,
|
||||
slot_overrides=slot_overrides, one_per_slot=one_per_slot,
|
||||
)
|
||||
|
||||
# Phase 1: baseline files
|
||||
@@ -5317,6 +5353,9 @@ def generate_manifest(
|
||||
# Every game data file below says so: the installer's --no-game-data
|
||||
# relies on it, and refuses a list that does not record categories.
|
||||
"categorized": True,
|
||||
# The entries a slot decides carry `slot`, which --one-per-slot
|
||||
# reads: without this mark the installer refuses it.
|
||||
"slot_fields": True,
|
||||
**({"no_game_data": True} if no_game_data else {}),
|
||||
"platform": platform_name,
|
||||
"display_name": platform_display,
|
||||
@@ -5394,9 +5433,153 @@ def generate_manifest(
|
||||
]
|
||||
if variants:
|
||||
result["case_variants"] = variants
|
||||
if build_out is not None:
|
||||
build_out.update(slot_choices=slot_choices, profiles=manifest_profiles)
|
||||
return result
|
||||
|
||||
|
||||
def generate_install_list(
|
||||
platform_name: str,
|
||||
platforms_dir: str,
|
||||
db: dict,
|
||||
bios_dir: str,
|
||||
registry_path: str,
|
||||
standalone_out: dict | None = None,
|
||||
**options: Any,
|
||||
) -> dict:
|
||||
"""The list install.py reads: the full manifest, the files and omissions
|
||||
the --source truth build holds apart from it, and the emulators with a
|
||||
standalone build. `standalone_out` receives, per such emulator, what
|
||||
`--emulator X --standalone` packs, written apart from the list
|
||||
(install/standalone/<platform>.json) and fetched only by a run given
|
||||
--standalone.
|
||||
|
||||
A manifest narrowed by a target, a case fold or --one-per-slot is no
|
||||
list install.py reads by default and gets neither.
|
||||
"""
|
||||
built: dict = {}
|
||||
result = generate_manifest(platform_name, platforms_dir, db, bios_dir, registry_path,
|
||||
build_out=built, **options)
|
||||
if (options.get("source", "full") != "full" or options.get("target_cores") is not None
|
||||
or options.get("fold_case") is not None or options.get("one_per_slot")):
|
||||
return result
|
||||
with contextlib.redirect_stdout(io.StringIO()):
|
||||
truth = generate_manifest(
|
||||
platform_name, platforms_dir, db, bios_dir, registry_path,
|
||||
**{**options, "source": "truth"}, known_slot_choices=built["slot_choices"],
|
||||
)
|
||||
_mark_truth(result, truth)
|
||||
layouts = _standalone_layouts(
|
||||
built["profiles"], options.get("emulators_dir", "emulators"), db, bios_dir,
|
||||
options.get("zip_contents") or {}, options.get("offline"), platforms_dir,
|
||||
os.path.dirname(os.path.dirname(os.path.abspath(__file__))), result,
|
||||
)
|
||||
if 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")
|
||||
cores = tuple(entry.get("cores") or []) if root == "emulator" else ()
|
||||
return (str(entry.get("dest")), root, cores)
|
||||
|
||||
|
||||
def _mark_truth(result: dict, truth: dict) -> None:
|
||||
"""What `--source truth` installs, carried in the full list.
|
||||
|
||||
The truth list holds what the emulator profiles prove is read. A file of
|
||||
the full list it does not hold, by destination and content, is marked
|
||||
`"truth": false`, and what only the truth list holds is `truth_files`.
|
||||
Omissions compare by destination. The installer then rebuilds the
|
||||
truth list from the full one, and a list without `truth_files` is one
|
||||
published before, on which `--source truth` is refused.
|
||||
"""
|
||||
held = {(_truth_key(entry), entry.get("sha1")) for entry in truth["files"]}
|
||||
full = {(_truth_key(entry), entry.get("sha1")) for entry in result["files"]}
|
||||
for entry in result["files"]:
|
||||
if (_truth_key(entry), entry.get("sha1")) not in held:
|
||||
entry["truth"] = False
|
||||
result["truth_files"] = [
|
||||
entry for entry in truth["files"]
|
||||
if (_truth_key(entry), entry.get("sha1")) not in full
|
||||
]
|
||||
absent = {_truth_key(entry) for entry in truth["omitted_files"]}
|
||||
listed = {_truth_key(entry) for entry in result["omitted_files"]}
|
||||
for entry in result["omitted_files"]:
|
||||
if _truth_key(entry) not in absent:
|
||||
entry["truth"] = False
|
||||
result["truth_omitted"] = [
|
||||
entry for entry in truth["omitted_files"] if _truth_key(entry) not in listed
|
||||
]
|
||||
|
||||
|
||||
def _standalone_layouts(
|
||||
profiles: dict[str, dict],
|
||||
emulators_dir: str,
|
||||
db: dict,
|
||||
bios_dir: str,
|
||||
zip_contents: dict,
|
||||
offline: bool | None,
|
||||
platforms_dir: str,
|
||||
repo_root: str,
|
||||
result: dict,
|
||||
) -> dict[str, list]:
|
||||
"""Per emulator with a standalone build, the files `--emulator X
|
||||
--standalone` packs, at the destinations that build reads.
|
||||
|
||||
Built by the emulator pack itself, in memory. A file whose content the
|
||||
list already carries is written as [dest, sha1], its download read from
|
||||
that entry. Another is written whole. A data tree member is left to the
|
||||
list's data directories.
|
||||
"""
|
||||
known = {
|
||||
copy["sha1"]
|
||||
for entry in [*result["files"], *result.get("truth_files", [])]
|
||||
for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])]
|
||||
if copy.get("sha1") and (copy.get("repo_path") or copy.get("release_asset"))
|
||||
}
|
||||
layouts: dict[str, list] = {}
|
||||
for name, profile in sorted(profiles.items()):
|
||||
if "standalone" not in str(profile.get("type", "")):
|
||||
continue
|
||||
record = PackRecord()
|
||||
with contextlib.redirect_stdout(io.StringIO()), \
|
||||
contextlib.redirect_stderr(io.StringIO()):
|
||||
generate_emulator_pack(
|
||||
[name], emulators_dir, db, bios_dir, "", standalone=True,
|
||||
zip_contents=zip_contents, offline=offline,
|
||||
platforms_dir=platforms_dir, record=record,
|
||||
)
|
||||
items: list = []
|
||||
for member in record.files:
|
||||
entry, _size = _manifest_entry(
|
||||
record.sources.get(member), member, [name], db, repo_root, {}
|
||||
)
|
||||
if entry is None:
|
||||
continue
|
||||
items.append([member, entry["sha1"]] if entry["sha1"] in known else entry)
|
||||
layouts[name] = items
|
||||
return layouts
|
||||
|
||||
|
||||
def tree_readers(pack_systems: dict, core_trees: Iterable[dict]) -> dict[str, list[str]]:
|
||||
"""The cores that read each tree, for a tree only cores read. A tree a
|
||||
platform system declares is the system's, whatever core runs it, and
|
||||
|
||||
@@ -18,6 +18,7 @@ from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
|
||||
import region as region_mod
|
||||
import slot as slot_mod
|
||||
from common import _norm_system_id, sanitize_pack_path
|
||||
from packextras import (
|
||||
_kept,
|
||||
@@ -41,6 +42,7 @@ class SelectionIndex:
|
||||
systems_by_dest: dict[str, frozenset[str]]
|
||||
declared_by: dict[str, frozenset[str]]
|
||||
extra_groups: dict[str, frozenset[str]]
|
||||
slots: dict[str, dict]
|
||||
|
||||
@classmethod
|
||||
def build(
|
||||
@@ -51,6 +53,7 @@ class SelectionIndex:
|
||||
extras: list[dict],
|
||||
required_only: bool = False,
|
||||
extras_prefix: str = "",
|
||||
slot_claims: dict[str, dict[str, dict]] | None = None,
|
||||
) -> SelectionIndex:
|
||||
by_norm: dict[str, set[str]] = {}
|
||||
for sys_id in pack_systems:
|
||||
@@ -93,6 +96,7 @@ class SelectionIndex:
|
||||
systems_by_dest,
|
||||
{dest: frozenset(ids) for dest, ids in declared_by.items()},
|
||||
{dest: frozenset(ids) for dest, ids in extra_groups.items()},
|
||||
_slot_fields(region_groups, slot_claims or {}),
|
||||
)
|
||||
|
||||
def fields(self, dest: str, name: str) -> dict:
|
||||
@@ -110,6 +114,8 @@ class SelectionIndex:
|
||||
out["systems"] = sorted(systems)
|
||||
if dest not in self.competing:
|
||||
return out
|
||||
if dest in self.slots:
|
||||
out["slot"] = self.slots[dest]
|
||||
regions = region_mod.lookup_regions(self.region_index, dest, name)
|
||||
if not regions:
|
||||
return out
|
||||
@@ -126,3 +132,65 @@ class SelectionIndex:
|
||||
if priority is not None:
|
||||
out["priority"] = priority
|
||||
return out
|
||||
|
||||
|
||||
def _slot_fields(
|
||||
region_groups: dict[str, list[tuple[str, str]]],
|
||||
claims: dict[str, dict[str, dict]],
|
||||
) -> dict[str, dict]:
|
||||
"""Per destination, the groups it competes in for a slot and the claims
|
||||
at each key slot.lookup_slot would try.
|
||||
|
||||
The builder looks each member up by its own name, so a destination a
|
||||
platform declares under one name and a core under another is looked up
|
||||
twice: the first name's groups and keys head the field, each other
|
||||
name's go in `also`. A name no emulator claims has no keys, which keeps
|
||||
the destination as the builder keeps it. Only a group where some
|
||||
emulator ranks a member can drop a file, so only its members are
|
||||
written, each with all its groups. A key whose claims equal the
|
||||
previous one's answers the same and is left out.
|
||||
"""
|
||||
# Each time a group lists the destination: two cores filing one file in
|
||||
# a group make two candidates of one rank, which no order separates.
|
||||
chains: dict[str, dict[str, list[str]]] = {}
|
||||
for group_id, members in region_groups.items():
|
||||
for dest, name in members:
|
||||
chains.setdefault(dest, {}).setdefault(name, []).append(group_id)
|
||||
|
||||
def keys_of(dest: str, name: str) -> list[str]:
|
||||
return [k for k in slot_mod.slot_lookup_keys(dest, name) if k in claims]
|
||||
|
||||
def ranked(dest: str) -> bool:
|
||||
return any(rank is not None for name in chains.get(dest, {})
|
||||
for key in keys_of(dest, name)
|
||||
for claim in claims[key].values() for rank in claim["ranks"])
|
||||
|
||||
# Every group of such a destination: one where it stays keeps it.
|
||||
written: set[str] = set()
|
||||
for members in region_groups.values():
|
||||
if any(ranked(member) for member, _name in members):
|
||||
written.update(member for member, name in members
|
||||
if any(keys_of(member, other) for other in chains[member]))
|
||||
|
||||
def chain(dest: str, name: str, group_ids: list[str]) -> dict:
|
||||
kept: list[dict] = []
|
||||
for key in keys_of(dest, name):
|
||||
by_emulator = {
|
||||
emulator: {
|
||||
"ranks": claim["ranks"],
|
||||
**({"regions": sorted(claim["regions"])} if claim["regions"] else {}),
|
||||
**({"sets": sorted(g for _owner, g in claim["sets"])}
|
||||
if claim["sets"] else {}),
|
||||
}
|
||||
for emulator, claim in sorted(claims[key].items())
|
||||
}
|
||||
if not kept or kept[-1] != by_emulator:
|
||||
kept.append(by_emulator)
|
||||
return {"groups": sorted(group_ids), "keys": kept}
|
||||
|
||||
fields: dict[str, dict] = {}
|
||||
for dest in sorted(written):
|
||||
first, *others = [chain(dest, name, group_ids)
|
||||
for name, group_ids in chains[dest].items()]
|
||||
fields[dest] = {**first, **({"also": others} if others else {})}
|
||||
return fields
|
||||
@@ -45,6 +45,7 @@ EXIT_CODES = (
|
||||
(1, "a failure: a download, a file list or a folder that cannot be used"),
|
||||
(2, "nothing was done: an option refused, every file failed, or the user quit"),
|
||||
(3, "`--check` found files missing or wrong, nothing having failed"),
|
||||
(4, "`--find` read the hash and the list holds no one file for it"),
|
||||
(130, "stopped with Ctrl+C"),
|
||||
(141, "the output went to a reader that closed early"),
|
||||
)
|
||||
|
||||
@@ -998,7 +998,8 @@ GLANCE_GROUPS: tuple[tuple[str, tuple[str, ...]], ...] = (
|
||||
("Where and for what", ("--platform", "--dest", "--target", "--every-board", "--save-dir",
|
||||
"--romm-firmware", "--standalone-copies", "--add-app")),
|
||||
("Fewer files", ("--for-games", "--required-only", "--all-files", "--system", "--core", "--emulator",
|
||||
"--region", "--no-game-data", "--declared-only", "--installed-cores",
|
||||
"--standalone", "--region", "--one-per-slot", "--no-game-data",
|
||||
"--declared-only", "--source", "--find", "--installed-cores",
|
||||
"--cores-dir")),
|
||||
("Look first", ("--check", "--dry-run", "--list-platforms", "--list-targets",
|
||||
"--list-systems", "--list-cores", "--list-emulators")),
|
||||
@@ -1007,7 +1008,7 @@ GLANCE_GROUPS: tuple[tuple[str, tuple[str, ...]], ...] = (
|
||||
("Remove and put back", ("--remove", "--file", "--misplaced", "--backup", "--backups",
|
||||
"--restore", "--delete-backup")),
|
||||
("How the run talks", ("--tui", "--plain", "--no-input", "--yes", "--quiet", "--verbose",
|
||||
"--events", "--jobs", "--version", "--help")),
|
||||
"--events", "--json", "--jobs", "--version", "--help")),
|
||||
)
|
||||
GLANCE_OTHER = "Other"
|
||||
|
||||
|
||||
+62
-31
@@ -43,15 +43,31 @@ def platform_slot_index(
|
||||
PlayStation BIOS of RomM, whose cores rank none of them, and
|
||||
`--one-per-slot` dropped four images RomM declares.
|
||||
"""
|
||||
return {
|
||||
key: merge_claims(by_emu)
|
||||
for key, by_emu in platform_slot_claims(config, profiles, target_cores).items()
|
||||
}
|
||||
|
||||
|
||||
def platform_slot_claims(
|
||||
config: dict, profiles: dict, target_cores: set[str] | None = None
|
||||
) -> dict[str, dict[str, dict]]:
|
||||
"""What each emulator a platform runs declares at each key, unmerged."""
|
||||
from common import resolve_platform_cores # noqa: PLC0415
|
||||
|
||||
cores = resolve_platform_cores(config, profiles, target_cores=target_cores)
|
||||
return build_slot_index({n: profiles[n] for n in cores if n in profiles})
|
||||
return slot_claims({n: profiles[n] for n in cores if n in profiles})
|
||||
|
||||
|
||||
def build_slot_index(profiles: dict) -> dict[str, dict]:
|
||||
"""Map a file key to its slot metadata, keyed by path then name."""
|
||||
index: dict[str, dict] = {}
|
||||
def slot_claims(profiles: dict) -> dict[str, dict[str, dict]]:
|
||||
"""Per key (path, standalone path, name), what each emulator declares there.
|
||||
|
||||
Each claim holds the ranks the emulator gives the key in declaration
|
||||
order, None for an entry without one, the regions, and the set keys.
|
||||
The install manifest carries these unmerged, so the installer merges
|
||||
them over the cores a board runs as build_slot_index merges them here.
|
||||
"""
|
||||
claims: dict[str, dict[str, dict]] = {}
|
||||
for emu_name, profile in sorted(profiles.items()):
|
||||
if profile.get("type") in ("launcher", "alias"):
|
||||
continue
|
||||
@@ -64,34 +80,49 @@ def build_slot_index(profiles: dict) -> dict[str, dict]:
|
||||
path = f.get("path") or ""
|
||||
# Keyed by the standalone layout too, as build_region_index is.
|
||||
for key in {path, f.get("standalone_path") or "", name} - {""}:
|
||||
entry = index.setdefault(
|
||||
key,
|
||||
{"rank": None, "conflict": False, "regions": set(),
|
||||
"emulators": [], "ranked_by": set(), "unranked_by": set(),
|
||||
"sets": set()},
|
||||
claim = claims.setdefault(key, {}).setdefault(
|
||||
emu_name, {"ranks": [], "regions": set(), "sets": set()}
|
||||
)
|
||||
entry["regions"] |= {str(r) for r in (f.get("region") or [])}
|
||||
entry["sets"] |= set(set_keys(emu_name, f))
|
||||
rank = f.get("priority")
|
||||
entry["unranked_by" if rank is None else "ranked_by"].add(emu_name)
|
||||
if rank is not None:
|
||||
current = entry["rank"]
|
||||
if current is not None and current != rank:
|
||||
entry["conflict"] = True
|
||||
entry["rank"] = (
|
||||
rank if current is None else min(current, rank)
|
||||
)
|
||||
if emu_name not in entry["emulators"]:
|
||||
entry["emulators"].append(emu_name)
|
||||
# A core that declares the file without a rank loads it by a rule of its
|
||||
# own: Genesis Plus GX opens bios_CD_U.bin by name for a US disc, and
|
||||
# PicoDrive's rank 4 for it would let its rank-3 file replace it.
|
||||
for entry in index.values():
|
||||
if entry["ranked_by"] and entry.pop("unranked_by") - entry["ranked_by"]:
|
||||
entry["conflict"] = True
|
||||
entry.pop("unranked_by", None)
|
||||
entry.pop("ranked_by")
|
||||
return index
|
||||
claim["regions"] |= {str(r) for r in (f.get("region") or [])}
|
||||
claim["sets"] |= set(set_keys(emu_name, f))
|
||||
claim["ranks"].append(f.get("priority"))
|
||||
return claims
|
||||
|
||||
|
||||
def merge_claims(by_emulator: dict[str, dict]) -> dict:
|
||||
"""One key's slot metadata, merged over the emulators claiming it.
|
||||
|
||||
Two ranks that differ make the key conflicting. So does an emulator
|
||||
that declares the key without a rank beside one that ranks it: a core
|
||||
that declares the file without a rank loads it by a rule of its own.
|
||||
Genesis Plus GX opens bios_CD_U.bin by name for a US disc, and
|
||||
PicoDrive's rank 4 for it would let its rank-3 file replace it.
|
||||
"""
|
||||
ranks = {r for claim in by_emulator.values() for r in claim["ranks"] if r is not None}
|
||||
ranked_by = {e for e, claim in by_emulator.items()
|
||||
if any(r is not None for r in claim["ranks"])}
|
||||
unranked_by = {e for e, claim in by_emulator.items() if None in claim["ranks"]}
|
||||
return {
|
||||
"rank": min(ranks) if ranks else None,
|
||||
"conflict": len(ranks) > 1 or bool(ranked_by and unranked_by - ranked_by),
|
||||
"regions": {r for claim in by_emulator.values() for r in claim["regions"]},
|
||||
"emulators": sorted(by_emulator),
|
||||
"sets": {k for claim in by_emulator.values() for k in claim["sets"]},
|
||||
}
|
||||
|
||||
|
||||
def build_slot_index(profiles: dict) -> dict[str, dict]:
|
||||
"""Map a file key to its slot metadata, keyed by path then name."""
|
||||
return {key: merge_claims(by_emu) for key, by_emu in slot_claims(profiles).items()}
|
||||
|
||||
|
||||
def slot_lookup_keys(destination: str, name: str) -> list[str]:
|
||||
"""The keys lookup_slot tries, in its order."""
|
||||
keys: list[str] = []
|
||||
if destination:
|
||||
parts = destination.split("/")
|
||||
keys += ["/".join(parts[i:]) for i in range(len(parts))]
|
||||
return [*keys, name]
|
||||
|
||||
|
||||
def lookup_slot(index: dict[str, dict], destination: str, name: str) -> dict | None:
|
||||
|
||||
@@ -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,38 @@ def _semantic_install_checks(path: Path, manifest: dict) -> list[str]:
|
||||
return out
|
||||
|
||||
|
||||
def _semantic_standalone_checks(path: Path, layouts: object) -> 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)
|
||||
if not isinstance(layouts, dict):
|
||||
return [f"{where}: not an object"]
|
||||
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") or [])]
|
||||
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 +1031,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")
|
||||
|
||||
Reference in new issue
Block a user