mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-26 11:28:51 -06:00
refactor: move verify, slots, crossref into packs
The three commands keep their parser, main and printing. Scans, scopes, report text, the JSON forms, the strict gate and the destinations file live in new packs modules, one subject each.
This commit is contained in:
1 parent
1e95a73a4d
commit
6ba52a9682
21 files changed
+897
-774
No files matched your search
+8
-186
@@ -20,129 +20,15 @@ feeds the report this module prints.
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
from core.paths import PLATFORMS_DIR
|
||||
from core.cli import add_repo_inputs
|
||||
from model.cliargs import platform_arg, require_platform
|
||||
from model.database import load_database
|
||||
from model.platforms import load_platform_config
|
||||
from core.ziptools import build_zip_contents_index
|
||||
from model.profiles import load_emulator_profiles
|
||||
from model.registry import list_registered_platforms, load_data_dir_registry
|
||||
from model.targets import target_scope
|
||||
from resolve.localfile import resolution_is_hash_exact
|
||||
from resolve.nativemode import platform_mode
|
||||
from resolve.standalone import standalone_set as platform_standalone_set
|
||||
|
||||
from packs.slots import ADDRESSEE, Claim, Conflict, Decision, arbitrate, find_conflicts
|
||||
from resolve.collisions import Collision, find_collisions
|
||||
|
||||
|
||||
def _pinned_elsewhere(claims: list[Claim], winner: str | None) -> set[str]:
|
||||
"""Emulators that pin content the served file does not carry."""
|
||||
return {
|
||||
c.emulator for c in claims
|
||||
if c.emulator and c.local_path != winner and resolution_is_hash_exact(c.status)
|
||||
}
|
||||
|
||||
|
||||
def format_decision(decision: Decision) -> str:
|
||||
"""One line naming the contested slot, the winner and the ground for it."""
|
||||
conflict = decision.conflict
|
||||
if decision.serves_both:
|
||||
winner = decision.winner.local_path
|
||||
# A claim that only matched a path is answered by whatever file sits
|
||||
# there. Only one that pins content can be left wanting.
|
||||
pinned_elsewhere = _pinned_elsewhere(conflict.profile_claims, winner)
|
||||
served = sorted({
|
||||
c.emulator for c in conflict.profile_claims if c.emulator
|
||||
} - pinned_elsewhere)
|
||||
others = sorted(pinned_elsewhere)
|
||||
line = (
|
||||
f"{conflict.destination}: serve {winner} "
|
||||
f"({', '.join(served) or 'profile'}): the frontend only "
|
||||
"checks the path, so both are satisfied"
|
||||
)
|
||||
if others:
|
||||
# One path holds one file: an emulator pinning another is not served.
|
||||
line += f"; {', '.join(others)} expected another file"
|
||||
return line
|
||||
if decision.reason == ADDRESSEE:
|
||||
return (
|
||||
f"{conflict.destination}: serve {decision.winner.local_path}, "
|
||||
"the pack answers to the emulator"
|
||||
)
|
||||
rejected = ", ".join(
|
||||
f"{path}, the file {', '.join(emulators) or 'the profile'} reads"
|
||||
for path, emulators, _status in conflict.files_read()
|
||||
)
|
||||
return (
|
||||
f"{conflict.destination}: keep {decision.winner.local_path}, the frontend "
|
||||
f"verifies content and would reject {rejected}"
|
||||
)
|
||||
|
||||
|
||||
def _collision_json(collision: Collision) -> dict:
|
||||
return {
|
||||
"destination": collision.destination,
|
||||
"resolved": list(collision.resolved),
|
||||
"shipped": collision.shipped,
|
||||
"declarations": [
|
||||
{"system": system, "name": entry.get("name", ""), "file": local}
|
||||
for system, (entry, local) in zip(collision.systems, collision.declarations)
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def format_collision(collision: Collision) -> str:
|
||||
"""One line naming the destination, which system declares which file,
|
||||
and the one the pack ships there."""
|
||||
owners: dict[str, list[str]] = {}
|
||||
for system, (_entry, local) in zip(collision.systems, collision.declarations):
|
||||
if local and system not in owners.setdefault(local, []):
|
||||
owners[local].append(system)
|
||||
parts = [
|
||||
f"{path} ({', '.join(owners[path])}) "
|
||||
+ ("packed" if path == collision.shipped else "left out")
|
||||
for path in collision.resolved
|
||||
]
|
||||
return f"{collision.destination}: " + ", ".join(parts)
|
||||
|
||||
|
||||
def format_conflict(conflict: Conflict) -> str:
|
||||
"""One line per conflict, naming both answers and who gave them."""
|
||||
emus = ", ".join(conflict.emulators) or "profile"
|
||||
return (
|
||||
f"{conflict.destination}: pack ships {conflict.platform_claim.local_path} "
|
||||
f"({conflict.platform_claim.status}), {emus} says "
|
||||
f"{conflict.profile_claims[0].local_path} "
|
||||
f"({conflict.profile_claims[0].status})"
|
||||
)
|
||||
|
||||
|
||||
def scan_platform(
|
||||
platform: str, profiles: dict, db: dict, platforms_dir: str = PLATFORMS_DIR,
|
||||
target_cores: set[str] | None = None, zip_index: dict | None = None,
|
||||
data_registry: dict | None = None,
|
||||
) -> list[Conflict]:
|
||||
"""Conflicts on one platform, using the cores that platform actually runs."""
|
||||
from model.platforms import load_platform_config
|
||||
from resolve.cores import resolve_platform_cores
|
||||
|
||||
config = load_platform_config(platform, platforms_dir)
|
||||
keys = resolve_platform_cores(config, profiles, target_cores=target_cores)
|
||||
relevant = {k: profiles[k] for k in keys if k in profiles}
|
||||
# The same evidence the builder and the verifier resolve with: without
|
||||
# the ZIP index and the data-directory registry the arbitration judged
|
||||
# with less than the tools that read its verdict.
|
||||
return find_conflicts(
|
||||
config,
|
||||
relevant,
|
||||
db,
|
||||
config.get("base_destination", ""),
|
||||
platform_standalone_set(config),
|
||||
build_zip_contents_index(db) if zip_index is None else zip_index,
|
||||
load_data_dir_registry(platforms_dir) if data_registry is None else data_registry,
|
||||
)
|
||||
from packs.slotreport import report_json, report_lines
|
||||
from packs.slotscan import scan_platforms
|
||||
|
||||
|
||||
def main() -> int:
|
||||
@@ -197,79 +83,15 @@ def main() -> int:
|
||||
names, args.target, args.platforms_dir, is_all=not args.platform
|
||||
)
|
||||
|
||||
zip_index = build_zip_contents_index(db)
|
||||
found: dict[str, list[Conflict]] = {}
|
||||
collided: dict[str, list[Collision]] = {}
|
||||
for name in names:
|
||||
conflicts = scan_platform(
|
||||
name, profiles, db, args.platforms_dir, target_cores.get(name),
|
||||
zip_index, data_registry,
|
||||
)
|
||||
if conflicts:
|
||||
found[name] = conflicts
|
||||
collisions = find_collisions(
|
||||
load_platform_config(name, args.platforms_dir),
|
||||
db,
|
||||
zip_index,
|
||||
data_registry,
|
||||
)
|
||||
if collisions:
|
||||
collided[name] = collisions
|
||||
found, collided = scan_platforms(
|
||||
names, profiles, db, args.platforms_dir, target_cores, data_registry,
|
||||
)
|
||||
|
||||
if args.json:
|
||||
# --strict gates on collisions too, so a document that carries only
|
||||
# conflicts hands a consumer an empty answer and a non-zero exit.
|
||||
payload = {
|
||||
"conflicts": {
|
||||
platform: [
|
||||
{
|
||||
"destination": c.destination,
|
||||
"ships": c.platform_claim.local_path,
|
||||
"ships_evidence": c.platform_claim.status,
|
||||
"emulators": c.emulators,
|
||||
"expected": [
|
||||
{"file": path, "evidence": status, "emulators": emulators}
|
||||
for path, emulators, status in c.files_read()
|
||||
],
|
||||
}
|
||||
for c in conflicts
|
||||
]
|
||||
for platform, conflicts in found.items()
|
||||
},
|
||||
"collisions": {
|
||||
platform: [_collision_json(c) for c in platform_collisions]
|
||||
for platform, platform_collisions in collided.items()
|
||||
},
|
||||
}
|
||||
print(json.dumps(payload, indent=2))
|
||||
print(json.dumps(report_json(found, collided), indent=2))
|
||||
else:
|
||||
fixable = 0
|
||||
for platform, conflicts in found.items():
|
||||
config = load_platform_config(platform, args.platforms_dir)
|
||||
mode = platform_mode(config)
|
||||
print(f"{platform}: {len(conflicts)} contradicted [{mode}]")
|
||||
for conflict in conflicts:
|
||||
decision = arbitrate(conflict, mode, rule=config.get("hash_rule", ""))
|
||||
fixable += decision.serves_both
|
||||
print(f" {format_decision(decision)}")
|
||||
total = sum(len(c) for c in found.values())
|
||||
for platform, collisions in collided.items():
|
||||
print(f"{platform}: {len(collisions)} destinations declared twice")
|
||||
for collision in collisions:
|
||||
print(f" {format_collision(collision)}")
|
||||
# The totals close the run, collisions counted: printed before that
|
||||
# section, they were not the last word and left it out.
|
||||
doubled = sum(len(c) for c in collided.values())
|
||||
print(
|
||||
f"\n{total} contested destinations. {fixable} the pack settles on "
|
||||
f"its own, {total - fixable} follow the platform's list. "
|
||||
f"{doubled} destinations declared twice."
|
||||
)
|
||||
if not args.strict and (total or doubled):
|
||||
print(
|
||||
"Reported, not failed: the remainder changes when the platform's "
|
||||
"list does, which no build can do. Use --strict to gate on them."
|
||||
)
|
||||
for line in report_lines(found, collided, args.platforms_dir, args.strict):
|
||||
print(line)
|
||||
|
||||
return 1 if ((found or collided) and args.strict) else 0
|
||||
|
||||
|
||||
Reference in new issue
Block a user