mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
refactor: read the declarations once per database
collect_all_aliases opened platforms/ and emulators/ from paths fixed to the working directory while declarations took them as parameters, so a build walked every YAML twice. read_declarations now reads both once, reports unreadable sources, and hands the alias pass and the proven-name index their entries. generate_db gains --platforms-dir and --emulators-dir and refuses a missing one.
This commit is contained in:
1 parent
a30984912c
commit
49dbb2828d
5 files changed
+174
-228
No files matched your search
@@ -3,13 +3,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
|
||||
from collection.declared import hash_values
|
||||
from core.cli import SourceUnreadable
|
||||
from model.profiles import source_yaml_paths
|
||||
from model.registry import list_registered_platforms
|
||||
from model.sources import source_yaml_file
|
||||
from collection.declared import Declarations, hash_values
|
||||
from resolve.localfile import variant_base_name
|
||||
|
||||
|
||||
@@ -26,14 +21,6 @@ def _own_aliases(file_entry: dict, primary_names: set[str]) -> list[str]:
|
||||
]
|
||||
|
||||
|
||||
class UnreadableSource(Exception):
|
||||
"""Platform or profile files that do not parse, named one per line."""
|
||||
|
||||
def __init__(self, sources: list[str]) -> None:
|
||||
super().__init__("\n".join(sources))
|
||||
self.sources = sources
|
||||
|
||||
|
||||
@dataclass
|
||||
class _AliasBook:
|
||||
"""The alternate names collected so far, and what designates a content."""
|
||||
@@ -103,47 +90,29 @@ def _alias_book(files: dict, copies: dict | None) -> _AliasBook:
|
||||
return _AliasBook(files, md5_to_sha1, name_to_sha1, holders, families, named_primaries)
|
||||
|
||||
|
||||
def _platform_aliases(book: _AliasBook, unreadable: list[str]) -> None:
|
||||
def _platform_aliases(book: _AliasBook, entries: list[dict]) -> None:
|
||||
"""Register the names platform YAMLs give a held content."""
|
||||
platforms_dir = Path("platforms")
|
||||
if not platforms_dir.is_dir():
|
||||
return
|
||||
for platform_name in list_registered_platforms(
|
||||
str(platforms_dir)
|
||||
):
|
||||
config_file = platforms_dir / f"{platform_name}.yml"
|
||||
try:
|
||||
config = source_yaml_file(config_file) or {}
|
||||
except SourceUnreadable as e:
|
||||
unreadable.append(str(e))
|
||||
continue
|
||||
except OSError as e:
|
||||
unreadable.append(f"{config_file}: {e}")
|
||||
for file_entry in entries:
|
||||
name = file_entry.get("name", "")
|
||||
sha1 = file_entry.get("sha1", "")
|
||||
md5 = file_entry.get("md5", "")
|
||||
|
||||
# A zipped_file entry verifies a ROM INSIDE the archive, so its
|
||||
# hash describes the member and not the file the name designates.
|
||||
# Registering the name against that hash made d2fdc.zip an alias of
|
||||
# a loose 256-byte state-machine-16.rom, which three platforms were
|
||||
# then served in place of the archive.
|
||||
if file_entry.get("zipped_file"):
|
||||
continue
|
||||
|
||||
for system in config.get("systems", {}).values():
|
||||
for file_entry in system.get("files", []):
|
||||
name = file_entry.get("name", "")
|
||||
sha1 = file_entry.get("sha1", "")
|
||||
md5 = file_entry.get("md5", "")
|
||||
matched = None
|
||||
if sha1 and sha1 in book.files:
|
||||
matched = sha1
|
||||
elif md5 and md5 in book.md5_to_sha1:
|
||||
matched = book.md5_to_sha1[md5]
|
||||
|
||||
# A zipped_file entry verifies a ROM INSIDE the
|
||||
# archive, so its hash describes the member and not
|
||||
# the file the name designates. Registering the name
|
||||
# against that hash made d2fdc.zip an alias of a
|
||||
# loose 256-byte state-machine-16.rom, which three
|
||||
# platforms were then served in place of the archive.
|
||||
if file_entry.get("zipped_file"):
|
||||
continue
|
||||
|
||||
matched = None
|
||||
if sha1 and sha1 in book.files:
|
||||
matched = sha1
|
||||
elif md5 and md5 in book.md5_to_sha1:
|
||||
matched = book.md5_to_sha1[md5]
|
||||
|
||||
if matched:
|
||||
book.add(name, matched)
|
||||
if matched:
|
||||
book.add(name, matched)
|
||||
|
||||
|
||||
def _profile_entry_aliases(
|
||||
@@ -196,29 +165,18 @@ def _profile_entry_aliases(
|
||||
|
||||
def _profile_aliases(
|
||||
book: _AliasBook,
|
||||
profiles: list[list[dict]],
|
||||
shadowed: list[tuple[str, set[str], list[str]]] | None,
|
||||
unreadable: list[str],
|
||||
) -> None:
|
||||
"""Register the aliases emulator YAMLs give (aliases field on file entries)."""
|
||||
emulators_dir = Path("emulators")
|
||||
if not emulators_dir.is_dir():
|
||||
return
|
||||
for emu_file in source_yaml_paths(emulators_dir):
|
||||
try:
|
||||
emu_config = source_yaml_file(emu_file) or {}
|
||||
except SourceUnreadable as e:
|
||||
unreadable.append(str(e))
|
||||
continue
|
||||
except OSError as e:
|
||||
unreadable.append(f"{emu_file}: {e}")
|
||||
continue
|
||||
for entries in profiles:
|
||||
# A profile whose entries name each other (dosbox-x opens
|
||||
# MT32_CONTROL.ROM and CM32L_CONTROL.ROM alike, so each entry
|
||||
# aliases the other) states that ITS slot takes either name.
|
||||
# Indexed globally that became evidence for every emulator:
|
||||
# ScummVM's MT-32 slot received the CM-32L ROMs.
|
||||
primary_names = _primary_names(emu_config.get("files", []))
|
||||
for file_entry in emu_config.get("files", []):
|
||||
primary_names = _primary_names(entries)
|
||||
for file_entry in entries:
|
||||
_profile_entry_aliases(book, file_entry, primary_names, shadowed)
|
||||
|
||||
|
||||
@@ -269,30 +227,27 @@ KNOWN_ALIAS_GROUPS = [
|
||||
|
||||
def collect_all_aliases(
|
||||
files: dict,
|
||||
declared: Declarations,
|
||||
copies: dict | None = None,
|
||||
shadowed: list[tuple[str, set[str], list[str]]] | None = None,
|
||||
) -> dict:
|
||||
"""Collect alternate filenames from platform YAMLs, core-info, and known aliases.
|
||||
"""Collect alternate filenames from platform YAMLs, profiles, and known aliases.
|
||||
|
||||
Registers alternate names so generate_pack can resolve files stored under different names.
|
||||
``declared`` holds the platform and profile file entries.
|
||||
``copies`` maps a sha1 to the other files the scan found with that content.
|
||||
``shadowed`` receives, per profile entry, its name, the contents its hashes
|
||||
designate and the aliases a primary's name already carries.
|
||||
"""
|
||||
book = _alias_book(files, copies)
|
||||
|
||||
# A source that does not parse is reported and the run refused: written
|
||||
# without it, the database lost every alias the file proves and the
|
||||
# command exited 0 (dosbox-x's wqy fonts answered not_found).
|
||||
unreadable: list[str] = []
|
||||
_platform_aliases(book, unreadable)
|
||||
_platform_aliases(book, declared.platform_entries)
|
||||
|
||||
# core-info is not read here: it was the only network call of a build
|
||||
# that must give the same database offline, and the one name it added
|
||||
# (gearcoleco's writer.rom) is a profile entry proven by its sha1, which
|
||||
# the profile pass below now registers.
|
||||
|
||||
_profile_aliases(book, shadowed, unreadable)
|
||||
_profile_aliases(book, declared.profile_entries, shadowed)
|
||||
|
||||
for group in KNOWN_ALIAS_GROUPS:
|
||||
matched_sha1 = None
|
||||
@@ -305,8 +260,6 @@ def collect_all_aliases(
|
||||
for name in group:
|
||||
book.add(name, matched_sha1)
|
||||
|
||||
if unreadable:
|
||||
raise UnreadableSource(unreadable)
|
||||
return book.aliases
|
||||
|
||||
|
||||
@@ -314,10 +267,11 @@ def add_declared_aliases(
|
||||
files: dict,
|
||||
aliases: dict[str, list[dict]],
|
||||
shadowed: list[tuple[str, set[str], list[str]]],
|
||||
declared: Declarations,
|
||||
) -> None:
|
||||
"""Append to the scan's copies every alternate name the declarations give a held content."""
|
||||
declared = collect_all_aliases(files, aliases, shadowed)
|
||||
for sha1, name_list in declared.items():
|
||||
found = collect_all_aliases(files, declared, aliases, shadowed)
|
||||
for sha1, name_list in found.items():
|
||||
for alias_entry in name_list:
|
||||
if sha1 not in aliases:
|
||||
aliases[sha1] = []
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
|
||||
from core.cli import SourceUnreadable
|
||||
from model.profiles import source_yaml_paths
|
||||
from model.registry import list_registered_platforms
|
||||
from model.sources import source_yaml_file
|
||||
@@ -17,18 +19,59 @@ def hash_values(value: object) -> list[str]:
|
||||
return [str(v).strip().lower() for v in values if str(v).strip()]
|
||||
|
||||
|
||||
def declarations(platforms_dir: Path, emulators_dir: Path) -> list[dict]:
|
||||
"""Every file entry the registered platforms and the profiles declare."""
|
||||
sources = [
|
||||
platforms_dir / f"{name}.yml"
|
||||
for name in list_registered_platforms(str(platforms_dir))
|
||||
] if platforms_dir.is_dir() else []
|
||||
entries: list[dict] = []
|
||||
for source in sources:
|
||||
config = source_yaml_file(source) or {}
|
||||
for system in (config.get("systems") or {}).values():
|
||||
entries.extend(system.get("files") or [])
|
||||
class UnreadableSource(Exception):
|
||||
"""Platform or profile files that do not parse, named one per line."""
|
||||
|
||||
def __init__(self, sources: list[str]) -> None:
|
||||
super().__init__("\n".join(sources))
|
||||
self.sources = sources
|
||||
|
||||
|
||||
@dataclass
|
||||
class Declarations:
|
||||
"""The file entries of every registered platform, and of each profile apart."""
|
||||
|
||||
platform_entries: list[dict] = field(default_factory=list)
|
||||
# One list per profile: an entry's aliases are judged against its own profile.
|
||||
profile_entries: list[list[dict]] = field(default_factory=list)
|
||||
|
||||
def entries(self) -> list[dict]:
|
||||
"""Every declared file entry, platforms first."""
|
||||
return self.platform_entries + [
|
||||
entry for entries in self.profile_entries for entry in entries
|
||||
]
|
||||
|
||||
|
||||
def _read_source(path: Path, unreadable: list[str]) -> dict | None:
|
||||
"""One platform or profile file, None and its name recorded when it does not read."""
|
||||
try:
|
||||
return source_yaml_file(path) or {}
|
||||
except SourceUnreadable as e:
|
||||
unreadable.append(str(e))
|
||||
except OSError as e:
|
||||
unreadable.append(f"{path}: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def read_declarations(platforms_dir: Path, emulators_dir: Path) -> Declarations:
|
||||
"""Every file entry the registered platforms and the profiles declare.
|
||||
|
||||
A source that does not parse is reported and the run refused: written
|
||||
without it, the database lost every alias the file proves and the
|
||||
command exited 0 (dosbox-x's wqy fonts answered not_found).
|
||||
"""
|
||||
declared = Declarations()
|
||||
unreadable: list[str] = []
|
||||
if platforms_dir.is_dir():
|
||||
for name in list_registered_platforms(str(platforms_dir)):
|
||||
config = _read_source(platforms_dir / f"{name}.yml", unreadable)
|
||||
for system in ((config or {}).get("systems") or {}).values():
|
||||
declared.platform_entries.extend(system.get("files") or [])
|
||||
if emulators_dir.is_dir():
|
||||
for source in source_yaml_paths(emulators_dir):
|
||||
entries.extend((source_yaml_file(source) or {}).get("files") or [])
|
||||
return entries
|
||||
profile = _read_source(source, unreadable)
|
||||
if profile is not None:
|
||||
declared.profile_entries.append(profile.get("files") or [])
|
||||
if unreadable:
|
||||
raise UnreadableSource(unreadable)
|
||||
return declared
|
||||
@@ -6,8 +6,8 @@ import argparse
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from collection.aliases import UnreadableSource, add_declared_aliases
|
||||
from collection.declared import declarations
|
||||
from collection.aliases import add_declared_aliases
|
||||
from collection.declared import UnreadableSource, read_declarations
|
||||
from collection.hashcache import CACHE_FILE, load_cache, save_cache
|
||||
from collection.indexes import database_indexes
|
||||
from collection.record import database_record, record_retired, write_database
|
||||
@@ -66,19 +66,18 @@ def generate(args: argparse.Namespace) -> int:
|
||||
|
||||
shadowed: list[tuple[str, set[str], list[str]]] = []
|
||||
try:
|
||||
add_declared_aliases(files, aliases, shadowed)
|
||||
declared = read_declarations(Path(args.platforms_dir), Path(args.emulators_dir))
|
||||
except UnreadableSource as exc:
|
||||
for source in exc.sources:
|
||||
print(f"Error: cannot read {source}", file=sys.stderr)
|
||||
print(f"Error: {args.output} not written", file=sys.stderr)
|
||||
return 1
|
||||
add_declared_aliases(files, aliases, shadowed, declared)
|
||||
|
||||
snapshots = load_provenance_snapshots(args.provenance_dir)
|
||||
provenance_counts = annotate_provenance(files, snapshots)
|
||||
|
||||
indexes = database_indexes(
|
||||
files, aliases, shadowed, declarations(Path("platforms"), Path("emulators"))
|
||||
)
|
||||
indexes = database_indexes(files, aliases, shadowed, declared.entries())
|
||||
database = database_record(files, indexes, args.bios_dir)
|
||||
total_size = database["total_size"]
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ DEFAULT_OUTPUT = "database.json"
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(allow_abbrev=False, description="Generate multi-indexed BIOS database")
|
||||
parser.add_argument("--force", action="store_true", help="Force rehash all files")
|
||||
add_repo_inputs(parser, "bios")
|
||||
add_repo_inputs(parser, "bios", "platforms", "emulators")
|
||||
parser.add_argument(
|
||||
"--output", "-o", default=DEFAULT_OUTPUT, help="Output JSON file"
|
||||
)
|
||||
@@ -47,6 +47,8 @@ def main() -> int:
|
||||
)
|
||||
args = parser.parse_args()
|
||||
require_directory(args.bios_dir)
|
||||
require_directory(args.platforms_dir, "--platforms-dir")
|
||||
require_directory(args.emulators_dir, "--emulators-dir")
|
||||
with repository_output_lock(args.output):
|
||||
return generate(args)
|
||||
|
||||
|
||||
+78
-130
@@ -10,12 +10,12 @@ from __future__ import annotations
|
||||
|
||||
import tests
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from collection.aliases import UnreadableSource, collect_all_aliases
|
||||
from collection.aliases import collect_all_aliases
|
||||
from collection.declared import Declarations, UnreadableSource, read_declarations
|
||||
from collection.scan import scan_bios_dir
|
||||
from tests.sources import script_source
|
||||
|
||||
@@ -24,17 +24,8 @@ REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
class AliasesNeedAnUnambiguousName(unittest.TestCase):
|
||||
def _aliases(self, files: dict) -> dict:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
previous = os.getcwd()
|
||||
os.chdir(tmp)
|
||||
try:
|
||||
Path("emulators").mkdir()
|
||||
Path("emulators/x.yml").write_text(
|
||||
'files:\n - name: "disk.rom"\n aliases: ["n88sub.rom"]\n'
|
||||
)
|
||||
return collect_all_aliases(files)
|
||||
finally:
|
||||
os.chdir(previous)
|
||||
profile = [{"name": "disk.rom", "aliases": ["n88sub.rom"]}]
|
||||
return collect_all_aliases(files, Declarations(profile_entries=[profile]))
|
||||
|
||||
@staticmethod
|
||||
def _file(name: str, path: str, md5: str) -> dict:
|
||||
@@ -82,61 +73,34 @@ class NoNetworkInTheBuild(unittest.TestCase):
|
||||
self.assertNotIn("urllib.request", source)
|
||||
|
||||
def test_hash_proven_entry_registers_its_own_name(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
previous = os.getcwd()
|
||||
os.chdir(tmp)
|
||||
try:
|
||||
Path("emulators").mkdir()
|
||||
Path("emulators/g.yml").write_text(
|
||||
'files:\n - name: "writer.rom"\n sha1: "s1"\n'
|
||||
)
|
||||
aliases = collect_all_aliases(
|
||||
{"s1": {"name": "WRITER.ROM", "path": "bios/WRITER.ROM", "md5": "m"}}
|
||||
)
|
||||
finally:
|
||||
os.chdir(previous)
|
||||
aliases = collect_all_aliases(
|
||||
{"s1": {"name": "WRITER.ROM", "path": "bios/WRITER.ROM", "md5": "m"}},
|
||||
Declarations(profile_entries=[[{"name": "writer.rom", "sha1": "s1"}]]),
|
||||
)
|
||||
self.assertEqual([a["name"] for a in aliases.get("s1", [])], ["writer.rom"])
|
||||
|
||||
class AcceptedRevisionLists(unittest.TestCase):
|
||||
def test_a_list_of_sha1_names_every_held_revision(self):
|
||||
"""A profile accepting several revisions writes sha1 as a list."""
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
previous = os.getcwd()
|
||||
os.chdir(tmp)
|
||||
try:
|
||||
Path("emulators").mkdir()
|
||||
Path("emulators/m.yml").write_text(
|
||||
'files:\n - name: "MT32_CONTROL.ROM"\n'
|
||||
' sha1: ["s1", "s2", "absent"]\n'
|
||||
)
|
||||
aliases = collect_all_aliases({
|
||||
"s1": {"name": "ctrl_1_04.rom", "path": "a", "md5": "m1"},
|
||||
"s2": {"name": "ctrl_1_05.rom", "path": "b", "md5": "m2"},
|
||||
})
|
||||
finally:
|
||||
os.chdir(previous)
|
||||
profile = [{"name": "MT32_CONTROL.ROM", "sha1": ["s1", "s2", "absent"]}]
|
||||
aliases = collect_all_aliases({
|
||||
"s1": {"name": "ctrl_1_04.rom", "path": "a", "md5": "m1"},
|
||||
"s2": {"name": "ctrl_1_05.rom", "path": "b", "md5": "m2"},
|
||||
}, Declarations(profile_entries=[profile]))
|
||||
for sha in ("s1", "s2"):
|
||||
self.assertEqual([a["name"] for a in aliases.get(sha, [])], ["MT32_CONTROL.ROM"])
|
||||
|
||||
class CrossNamingStaysInItsProfile(unittest.TestCase):
|
||||
def test_an_alias_naming_a_sibling_entry_is_not_indexed(self):
|
||||
"""dosbox-x aliases MT32_CONTROL.ROM and CM32L_CONTROL.ROM to each other."""
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
previous = os.getcwd()
|
||||
os.chdir(tmp)
|
||||
try:
|
||||
Path("emulators").mkdir()
|
||||
Path("emulators/d.yml").write_text(
|
||||
'files:\n'
|
||||
' - name: "MT32_CONTROL.ROM"\n sha1: "mt"\n aliases: ["CM32L_CONTROL.ROM"]\n'
|
||||
' - name: "CM32L_CONTROL.ROM"\n sha1: "cm"\n aliases: ["MT32_CONTROL.ROM"]\n'
|
||||
)
|
||||
aliases = collect_all_aliases({
|
||||
"mt": {"name": "mt32_control.rom", "path": "a", "md5": "m1"},
|
||||
"cm": {"name": "cm32l_control.rom", "path": "b", "md5": "m2"},
|
||||
})
|
||||
finally:
|
||||
os.chdir(previous)
|
||||
profile = [
|
||||
{"name": "MT32_CONTROL.ROM", "sha1": "mt", "aliases": ["CM32L_CONTROL.ROM"]},
|
||||
{"name": "CM32L_CONTROL.ROM", "sha1": "cm", "aliases": ["MT32_CONTROL.ROM"]},
|
||||
]
|
||||
aliases = collect_all_aliases({
|
||||
"mt": {"name": "mt32_control.rom", "path": "a", "md5": "m1"},
|
||||
"cm": {"name": "cm32l_control.rom", "path": "b", "md5": "m2"},
|
||||
}, Declarations(profile_entries=[profile]))
|
||||
self.assertEqual([a["name"] for a in aliases["mt"]], ["MT32_CONTROL.ROM"])
|
||||
self.assertEqual([a["name"] for a in aliases["cm"]], ["CM32L_CONTROL.ROM"])
|
||||
|
||||
@@ -145,21 +109,45 @@ class AnUnreadableSourceStopsTheRun(unittest.TestCase):
|
||||
written without its aliases and the command exited 0."""
|
||||
|
||||
def test_the_file_is_named_and_nothing_collected(self):
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
|
||||
root = Path(tempfile.mkdtemp())
|
||||
self.addCleanup(shutil.rmtree, root, True)
|
||||
previous = os.getcwd()
|
||||
os.chdir(root)
|
||||
self.addCleanup(os.chdir, previous)
|
||||
Path("emulators").mkdir()
|
||||
Path("emulators/broken.yml").write_text("files: [\n - name: a\n")
|
||||
with self.assertRaises(UnreadableSource) as caught:
|
||||
collect_all_aliases({})
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
emulators = Path(tmp) / "emulators"
|
||||
emulators.mkdir()
|
||||
(emulators / "broken.yml").write_text("files: [\n - name: a\n")
|
||||
(emulators / "good.yml").write_text('files:\n - name: "b"\n')
|
||||
with self.assertRaises(UnreadableSource) as caught:
|
||||
read_declarations(Path(tmp) / "platforms", emulators)
|
||||
self.assertIn("broken.yml", str(caught.exception))
|
||||
self.assertNotIn("good.yml", str(caught.exception))
|
||||
|
||||
|
||||
class TheBuildReadsTheDeclarationsOnce(unittest.TestCase):
|
||||
"""The alias pass and the proven-name index each walked platforms/ and
|
||||
emulators/, the first from paths fixed to the working directory."""
|
||||
|
||||
def test_entries_keep_each_profile_apart(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
(root / "platforms").mkdir()
|
||||
(root / "platforms/_registry.yml").write_text("platforms:\n p:\n config: p.yml\n")
|
||||
(root / "platforms/p.yml").write_text(
|
||||
'systems:\n s:\n files:\n - name: "a.bin"\n'
|
||||
)
|
||||
(root / "emulators").mkdir()
|
||||
(root / "emulators/x.yml").write_text('files:\n - name: "b.bin"\n')
|
||||
(root / "emulators/y.yml").write_text('files:\n - name: "c.bin"\n')
|
||||
declared = read_declarations(root / "platforms", root / "emulators")
|
||||
self.assertEqual([e["name"] for e in declared.platform_entries], ["a.bin"])
|
||||
self.assertEqual(
|
||||
[[e["name"] for e in entries] for entries in declared.profile_entries],
|
||||
[["b.bin"], ["c.bin"]],
|
||||
)
|
||||
self.assertEqual([e["name"] for e in declared.entries()], ["a.bin", "b.bin", "c.bin"])
|
||||
|
||||
def test_the_build_takes_the_directories_from_its_options(self):
|
||||
source = script_source("generate_db.py")
|
||||
self.assertIn("read_declarations(Path(args.platforms_dir), Path(args.emulators_dir))", source)
|
||||
self.assertNotIn('Path("platforms")', source)
|
||||
self.assertNotIn('Path("emulators")', source)
|
||||
|
||||
|
||||
class DrasticNamesTheDSDumps(unittest.TestCase):
|
||||
@@ -169,14 +157,7 @@ class DrasticNamesTheDSDumps(unittest.TestCase):
|
||||
its own three names."""
|
||||
|
||||
def _aliases(self, files: dict) -> dict:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
previous = os.getcwd()
|
||||
os.chdir(tmp)
|
||||
try:
|
||||
Path("emulators").mkdir()
|
||||
return collect_all_aliases(files)
|
||||
finally:
|
||||
os.chdir(previous)
|
||||
return collect_all_aliases(files, Declarations())
|
||||
|
||||
def test_the_collection_answers_drastic_names(self):
|
||||
files = {
|
||||
@@ -206,23 +187,12 @@ class AliasesFollowContentNotPrimaryCopy(unittest.TestCase):
|
||||
a copy. project64 names the second and declares no hash, so its aliases
|
||||
attached only while that copy happened to be primary."""
|
||||
|
||||
PROFILE = (
|
||||
'files:\n - name: "64DD_IPL_v12_JPN.bin"\n'
|
||||
' aliases: ["64DD_IPL_JP.n64", "64dd_ipl_J.bin"]\n'
|
||||
)
|
||||
PROFILE = [{"name": "64DD_IPL_v12_JPN.bin", "aliases": ["64DD_IPL_JP.n64", "64dd_ipl_J.bin"]}]
|
||||
|
||||
def _aliases(self, primary: str, copy: str) -> dict:
|
||||
files = {"s": {"name": primary, "path": f"bios/N64DD/{primary}", "md5": "m"}}
|
||||
copies = {"s": [{"name": copy, "path": f"bios/N64DD/{copy}"}]}
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
previous = os.getcwd()
|
||||
os.chdir(tmp)
|
||||
try:
|
||||
Path("emulators").mkdir()
|
||||
Path("emulators/p.yml").write_text(self.PROFILE)
|
||||
return collect_all_aliases(files, copies)
|
||||
finally:
|
||||
os.chdir(previous)
|
||||
return collect_all_aliases(files, Declarations(profile_entries=[self.PROFILE]), copies)
|
||||
|
||||
def test_either_copy_primary_gives_the_same_names(self):
|
||||
names = []
|
||||
@@ -241,22 +211,13 @@ class AliasesFollowContentNotPrimaryCopy(unittest.TestCase):
|
||||
"b": {"name": "Satellaview_BS-X.sfc", "path": "bios/SNES/x.sfc", "md5": "m2"},
|
||||
}
|
||||
copies = {"b": [{"name": "BS-X.bin", "path": "bios/Satellaview/BS-X.bin"}]}
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
previous = os.getcwd()
|
||||
os.chdir(tmp)
|
||||
try:
|
||||
Path("emulators").mkdir()
|
||||
Path("emulators/s.yml").write_text(
|
||||
'files:\n - name: "BS-X.bin"\n aliases: ["BS-X.bios"]\n'
|
||||
)
|
||||
aliases = collect_all_aliases(files, copies)
|
||||
finally:
|
||||
os.chdir(previous)
|
||||
profile = [{"name": "BS-X.bin", "aliases": ["BS-X.bios"]}]
|
||||
aliases = collect_all_aliases(files, Declarations(profile_entries=[profile]), copies)
|
||||
self.assertEqual(aliases, {})
|
||||
|
||||
def test_the_build_passes_the_scan_copies(self):
|
||||
source = script_source("generate_db.py")
|
||||
self.assertIn("collect_all_aliases(files, aliases, shadowed)", source)
|
||||
self.assertIn("collect_all_aliases(files, declared, aliases, shadowed)", source)
|
||||
|
||||
|
||||
class TheSmsBiosKeepsItsNames(unittest.TestCase):
|
||||
@@ -265,25 +226,24 @@ class TheSmsBiosKeepsItsNames(unittest.TestCase):
|
||||
and the two names were refused because .variants/ copies carried them.
|
||||
Genesis Plus GX then got the Store Display Unit BIOS as bios_U.sms."""
|
||||
|
||||
@staticmethod
|
||||
def _platform() -> Declarations:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
platforms = Path(tmp)
|
||||
(platforms / "_registry.yml").write_text("platforms:\n p:\n config: p.yml\n")
|
||||
(platforms / "p.yml").write_text(
|
||||
"systems:\n sms:\n files:\n"
|
||||
' - name: "bios_U.sms"\n sha1: "v13"\n'
|
||||
)
|
||||
return read_declarations(platforms, platforms / "emulators")
|
||||
|
||||
def test_a_name_only_variants_carry_is_registered_for_the_pinned_content(self):
|
||||
files = {
|
||||
"v13": {"name": "SMS_us_1.3.sms", "path": "bios/Sega/MS/SMS_us_1.3.sms", "md5": "m13"},
|
||||
"kiosk": {"name": "bios_U.sms", "path": "bios/Sega/MS/.variants/bios_U.sms.ee2c29ba",
|
||||
"md5": "mk"},
|
||||
}
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
previous = os.getcwd()
|
||||
os.chdir(tmp)
|
||||
try:
|
||||
Path("platforms").mkdir()
|
||||
Path("platforms/_registry.yml").write_text("platforms:\n p:\n config: p.yml\n")
|
||||
Path("platforms/p.yml").write_text(
|
||||
"systems:\n sms:\n files:\n"
|
||||
' - name: "bios_U.sms"\n sha1: "v13"\n'
|
||||
)
|
||||
aliases = collect_all_aliases(files)
|
||||
finally:
|
||||
os.chdir(previous)
|
||||
aliases = collect_all_aliases(files, self._platform())
|
||||
self.assertIn("bios_U.sms", {a["name"] for a in aliases.get("v13", [])})
|
||||
|
||||
def test_a_primary_name_still_refuses_another_content(self):
|
||||
@@ -291,19 +251,7 @@ class TheSmsBiosKeepsItsNames(unittest.TestCase):
|
||||
"v13": {"name": "SMS_us_1.3.sms", "path": "bios/Sega/MS/SMS_us_1.3.sms", "md5": "m13"},
|
||||
"other": {"name": "bios_U.sms", "path": "bios/Sega/MS/bios_U.sms", "md5": "mo"},
|
||||
}
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
previous = os.getcwd()
|
||||
os.chdir(tmp)
|
||||
try:
|
||||
Path("platforms").mkdir()
|
||||
Path("platforms/_registry.yml").write_text("platforms:\n p:\n config: p.yml\n")
|
||||
Path("platforms/p.yml").write_text(
|
||||
"systems:\n sms:\n files:\n"
|
||||
' - name: "bios_U.sms"\n sha1: "v13"\n'
|
||||
)
|
||||
aliases = collect_all_aliases(files)
|
||||
finally:
|
||||
os.chdir(previous)
|
||||
aliases = collect_all_aliases(files, self._platform())
|
||||
self.assertEqual(aliases, {})
|
||||
|
||||
def test_a_copy_under_its_machine_is_the_path_over_an_emulator_tree(self):
|
||||
|
||||
Reference in new issue
Block a user