mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-29 12:58:51 -06:00
refactor: build platform packs without printing
build_platform_pack and build_split_packs return what the build came to and print nothing. print_platform_pack holds the report lines, and generate_pack and generate_split_packs compose the two. The variant choice, the plan and the data directory pass return their notices instead of printing them. The callers that silenced stdout to get a record now call the builder.
This commit is contained in:
1 parent
977d3f6874
commit
d8570c6480
15 files changed
+295
-205
No files matched your search
+2
-1
@@ -17,7 +17,8 @@ SCRIPTS = Path(__file__).resolve().parents[1] / "scripts"
|
||||
COMMANDS = {
|
||||
"generate_pack.py": (
|
||||
"packs/archive.py", "packs/naming.py", "packs/scope.py", "packs/datatrees.py",
|
||||
"packs/platformpack.py", "packs/emulatorpack.py", "packs/md5pack.py", "packs/targets.py",
|
||||
"packs/platformpack.py", "packs/platformreport.py", "packs/emulatorpack.py",
|
||||
"packs/md5pack.py", "packs/targets.py",
|
||||
"packs/manifestentry.py", "packs/manifestcores.py", "packs/standalone.py",
|
||||
"packs/manifest.py", "packs/finalize.py", "packs/outputdir.py", "packs/variants.py",
|
||||
"packs/manifestrun.py", "packs/packcheck.py", "packs/runscope.py", "packs/platformrun.py",
|
||||
|
||||
@@ -1558,7 +1558,7 @@ class OneBaselineVerdict(unittest.TestCase):
|
||||
def test_the_builder_and_the_manifest_read_the_same_rules(self):
|
||||
source = script_source("generate_pack.py")
|
||||
tree = ast.parse(source)
|
||||
for name in ("generate_pack", "generate_manifest"):
|
||||
for name in ("build_platform_pack", "generate_manifest"):
|
||||
function = next(
|
||||
node for node in tree.body
|
||||
if isinstance(node, ast.FunctionDef) and node.name == name
|
||||
|
||||
@@ -9,9 +9,7 @@ from __future__ import annotations
|
||||
|
||||
import tests
|
||||
|
||||
import contextlib
|
||||
import hashlib
|
||||
import io
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
@@ -95,11 +93,10 @@ class ThePackReadmeNamesTheSpellingsItLeavesOut(unittest.TestCase):
|
||||
|
||||
platformpack.write_generated_member = capture
|
||||
self.addCleanup(setattr, platformpack, "write_generated_member", real)
|
||||
with contextlib.redirect_stdout(io.StringIO()):
|
||||
platformpack.generate_pack(
|
||||
"p", "platforms", self.db, "bios", "", emulators_dir="emulators",
|
||||
offline=True, record=archive.PackRecord(),
|
||||
)
|
||||
platformpack.build_platform_pack(
|
||||
"p", "platforms", self.db, "bios", "", emulators_dir="emulators",
|
||||
offline=True, record=archive.PackRecord(),
|
||||
)
|
||||
return texts["README.txt"]
|
||||
|
||||
def test_a_platform_also_on_linux_names_them(self):
|
||||
|
||||
@@ -26,7 +26,7 @@ import yaml
|
||||
|
||||
from model.profiles import emulator_profiles_cache
|
||||
from model.platforms import load_platform_config
|
||||
from packs.platformpack import generate_pack
|
||||
from packs.platformpack import build_platform_pack, generate_pack
|
||||
from packs.coverage import verify_platform
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
@@ -83,11 +83,10 @@ class ACoreFileFillsAFreeDeclaration(unittest.TestCase):
|
||||
self.config, self.db, str(self.emulators),
|
||||
)
|
||||
out = self.root / "out"
|
||||
with redirect_stdout(io.StringIO()):
|
||||
zip_path = generate_pack(
|
||||
"fakeplat", str(self.platforms), self.db, str(self.root / "bios"),
|
||||
str(out), emulators_dir=str(self.emulators), offline=True,
|
||||
)
|
||||
zip_path = build_platform_pack(
|
||||
"fakeplat", str(self.platforms), self.db, str(self.root / "bios"),
|
||||
str(out), emulators_dir=str(self.emulators), offline=True,
|
||||
).zip_path
|
||||
with zipfile.ZipFile(zip_path) as zf:
|
||||
self.assertIn("zzz_absent.bin", zf.namelist())
|
||||
self.assertEqual(result["status_counts"], {"ok": 1})
|
||||
@@ -133,11 +132,10 @@ class AFileDeclaredUnderAnotherName(unittest.TestCase):
|
||||
}))
|
||||
config = load_platform_config("fakeplat", str(root / "platforms"))
|
||||
result = verify_platform(config, db, str(root / "emulators"))
|
||||
with redirect_stdout(io.StringIO()):
|
||||
zip_path = generate_pack(
|
||||
"fakeplat", str(root / "platforms"), db, str(root / "bios"),
|
||||
str(root / "out"), emulators_dir=str(root / "emulators"), offline=True,
|
||||
)
|
||||
zip_path = build_platform_pack(
|
||||
"fakeplat", str(root / "platforms"), db, str(root / "bios"),
|
||||
str(root / "out"), emulators_dir=str(root / "emulators"), offline=True,
|
||||
).zip_path
|
||||
with zipfile.ZipFile(zip_path) as zf:
|
||||
self.assertIn("gs/ROM", zf.namelist())
|
||||
reported = [(u["name"], u["in_repo"]) for u in result["undeclared_files"]]
|
||||
|
||||
+5
-6
@@ -2343,7 +2343,7 @@ class TestE2E(unittest.TestCase):
|
||||
"""
|
||||
from orchestrate.consistency import check_consistency
|
||||
from packs.packcounts import PackCounts, write_pack_counts
|
||||
from packs.platformpack import generate_pack
|
||||
from packs.platformpack import build_platform_pack
|
||||
from packs.verifyoutput import write_pack_destinations
|
||||
|
||||
profiles = load_emulator_profiles(self.emulators_dir)
|
||||
@@ -2352,11 +2352,10 @@ class TestE2E(unittest.TestCase):
|
||||
groups, group_results = [], []
|
||||
for platform in ("test_existence", "test_md5"):
|
||||
sink: list[PackCounts] = []
|
||||
with contextlib.redirect_stdout(io.StringIO()):
|
||||
generate_pack(
|
||||
platform, self.platforms_dir, self.db, self.bios_dir, output_dir,
|
||||
emulators_dir=self.emulators_dir, emu_profiles=profiles, counts=sink,
|
||||
)
|
||||
build_platform_pack(
|
||||
platform, self.platforms_dir, self.db, self.bios_dir, output_dir,
|
||||
emulators_dir=self.emulators_dir, emu_profiles=profiles, counts=sink,
|
||||
)
|
||||
self.assertEqual(len(sink), 1)
|
||||
packs.append((platform, [platform], sink[0]))
|
||||
config = load_platform_config(platform, self.platforms_dir)
|
||||
|
||||
@@ -89,9 +89,8 @@ class RealListParity(unittest.TestCase):
|
||||
the list serves from the collection is no choice of either option."""
|
||||
base = self.config(plat).get("base_destination", "")
|
||||
record = archive.PackRecord()
|
||||
with contextlib.redirect_stdout(io.StringIO()), \
|
||||
contextlib.redirect_stderr(io.StringIO()):
|
||||
platformpack.generate_pack(
|
||||
with contextlib.redirect_stderr(io.StringIO()):
|
||||
platformpack.build_platform_pack(
|
||||
plat, str(REPO_ROOT / "platforms"), self.db, str(REPO_ROOT / "bios"),
|
||||
tempfile.gettempdir(), emulators_dir=str(REPO_ROOT / "emulators"),
|
||||
zip_contents=self.zip_contents, emu_profiles=self.profiles,
|
||||
|
||||
@@ -1445,18 +1445,15 @@ class ANativeNameSelectsOneSetEverywhere(unittest.TestCase):
|
||||
cls.profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
|
||||
|
||||
def _packed(self, platform: str, systems: list[str]) -> set[str]:
|
||||
import contextlib
|
||||
import io
|
||||
import zipfile
|
||||
|
||||
with tempfile.TemporaryDirectory() as out, \
|
||||
contextlib.redirect_stdout(io.StringIO()):
|
||||
zip_path = platformpack.generate_pack(
|
||||
with tempfile.TemporaryDirectory() as out:
|
||||
zip_path = platformpack.build_platform_pack(
|
||||
platform, str(REPO_ROOT / "platforms"), self.db,
|
||||
str(REPO_ROOT / "bios"), out,
|
||||
emulators_dir=str(REPO_ROOT / "emulators"),
|
||||
emu_profiles=self.profiles, system_filter=systems, offline=True,
|
||||
)
|
||||
).zip_path
|
||||
with zipfile.ZipFile(zip_path) as zf:
|
||||
infos = [i for i in zf.infolist() if not i.is_dir()]
|
||||
return {i.filename: i.file_size for i in infos}
|
||||
|
||||
@@ -27,7 +27,7 @@ from model.profiles import emulator_profiles_cache, load_emulator_profiles
|
||||
from model.platforms import load_platform_config
|
||||
from resolve.standalone import platform_layouts, standalone_set
|
||||
from packs.manifest import generate_manifest
|
||||
from packs.platformpack import generate_pack
|
||||
from packs.platformpack import build_platform_pack
|
||||
from packs.coverage import verify_platform
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
@@ -94,12 +94,11 @@ class ALinkMovesTheDestination(unittest.TestCase):
|
||||
}))
|
||||
|
||||
def pack_names(self, platform: str, name: str = "kick13.rom") -> list[str]:
|
||||
with redirect_stdout(io.StringIO()):
|
||||
zip_path = generate_pack(
|
||||
platform, str(self.platforms), self.db, str(self.root / "bios"),
|
||||
str(self.root / "out" / platform), emulators_dir=str(self.emulators),
|
||||
offline=True,
|
||||
)
|
||||
zip_path = build_platform_pack(
|
||||
platform, str(self.platforms), self.db, str(self.root / "bios"),
|
||||
str(self.root / "out" / platform), emulators_dir=str(self.emulators),
|
||||
offline=True,
|
||||
).zip_path
|
||||
with zipfile.ZipFile(zip_path) as zf:
|
||||
return [n for n in zf.namelist() if n.rsplit("/", 1)[-1] == name]
|
||||
|
||||
@@ -387,12 +386,11 @@ class AProgramRunFromItsFolder(unittest.TestCase):
|
||||
}))
|
||||
|
||||
def pack(self, platform: str) -> list[str]:
|
||||
with redirect_stdout(io.StringIO()):
|
||||
zip_path = generate_pack(
|
||||
platform, str(self.platforms), self.db, str(self.root / "bios"),
|
||||
str(self.root / "out" / platform), emulators_dir=str(self.emulators),
|
||||
offline=True,
|
||||
)
|
||||
zip_path = build_platform_pack(
|
||||
platform, str(self.platforms), self.db, str(self.root / "bios"),
|
||||
str(self.root / "out" / platform), emulators_dir=str(self.emulators),
|
||||
offline=True,
|
||||
).zip_path
|
||||
with zipfile.ZipFile(zip_path) as zf:
|
||||
return sorted(n for n in zf.namelist() if n.split("/")[-1].startswith("prog"))
|
||||
|
||||
@@ -626,12 +624,11 @@ class ASettingSetsTheBiosFolder(unittest.TestCase):
|
||||
}))
|
||||
|
||||
def pack_names(self, platform: str) -> list[str]:
|
||||
with redirect_stdout(io.StringIO()):
|
||||
zip_path = generate_pack(
|
||||
platform, str(self.platforms), self.db, str(self.root / "bios"),
|
||||
str(self.root / "out" / platform), emulators_dir=str(self.emulators),
|
||||
offline=True,
|
||||
)
|
||||
zip_path = build_platform_pack(
|
||||
platform, str(self.platforms), self.db, str(self.root / "bios"),
|
||||
str(self.root / "out" / platform), emulators_dir=str(self.emulators),
|
||||
offline=True,
|
||||
).zip_path
|
||||
with zipfile.ZipFile(zip_path) as zf:
|
||||
return sorted(n for n in zf.namelist() if n.endswith((".bin", ".zip")))
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ class _Fixture(unittest.TestCase):
|
||||
def _both(self) -> tuple[dict, set[str]]:
|
||||
from model.profiles import load_emulator_profiles
|
||||
from model.platforms import load_platform_config
|
||||
from packs.platformpack import generate_pack
|
||||
from packs.platformpack import build_platform_pack
|
||||
from packs.coverage import verify_platform
|
||||
|
||||
profiles = load_emulator_profiles(str(self.emulators))
|
||||
@@ -72,12 +72,11 @@ class _Fixture(unittest.TestCase):
|
||||
load_platform_config("paths", str(self.platforms)), self.db,
|
||||
str(self.emulators), profiles,
|
||||
)
|
||||
with contextlib.redirect_stdout(io.StringIO()):
|
||||
zip_path = generate_pack(
|
||||
"paths", str(self.platforms), self.db, str(self.bios),
|
||||
str(self.root / "out"), emulators_dir=str(self.emulators),
|
||||
emu_profiles=profiles, offline=True,
|
||||
)
|
||||
zip_path = build_platform_pack(
|
||||
"paths", str(self.platforms), self.db, str(self.bios),
|
||||
str(self.root / "out"), emulators_dir=str(self.emulators),
|
||||
emu_profiles=profiles, offline=True,
|
||||
).zip_path
|
||||
with zipfile.ZipFile(zip_path) as zf:
|
||||
members = {n for n in zf.namelist() if n != "README.txt"}
|
||||
return report, members
|
||||
@@ -131,7 +130,7 @@ class ARequiredOnlyPack(_Fixture):
|
||||
from model.profiles import load_emulator_profiles
|
||||
from model.platforms import load_platform_config
|
||||
from packs.archive import PackRecord
|
||||
from packs.platformpack import generate_pack
|
||||
from packs.platformpack import build_platform_pack
|
||||
from packs.coverage import verify_platform
|
||||
|
||||
(self.emulators / "coreemu.yml").write_text(yaml.safe_dump({
|
||||
@@ -145,17 +144,16 @@ class ARequiredOnlyPack(_Fixture):
|
||||
)
|
||||
profiles = load_emulator_profiles(str(self.emulators))
|
||||
record = PackRecord()
|
||||
with contextlib.redirect_stdout(io.StringIO()):
|
||||
zip_path = generate_pack(
|
||||
"paths", str(self.platforms), self.db, str(self.bios),
|
||||
str(self.root / "out"), emulators_dir=str(self.emulators),
|
||||
emu_profiles=profiles, offline=True, required_only=True,
|
||||
)
|
||||
generate_pack(
|
||||
"paths", str(self.platforms), self.db, str(self.bios), "",
|
||||
emulators_dir=str(self.emulators), emu_profiles=profiles,
|
||||
offline=True, required_only=True, record=record,
|
||||
)
|
||||
zip_path = build_platform_pack(
|
||||
"paths", str(self.platforms), self.db, str(self.bios),
|
||||
str(self.root / "out"), emulators_dir=str(self.emulators),
|
||||
emu_profiles=profiles, offline=True, required_only=True,
|
||||
).zip_path
|
||||
build_platform_pack(
|
||||
"paths", str(self.platforms), self.db, str(self.bios), "",
|
||||
emulators_dir=str(self.emulators), emu_profiles=profiles,
|
||||
offline=True, required_only=True, record=record,
|
||||
)
|
||||
with zipfile.ZipFile(zip_path) as zf:
|
||||
members = set(zf.namelist())
|
||||
# The record names what the archive holds, nothing more or less.
|
||||
|
||||
@@ -149,10 +149,11 @@ class ASplitBuildsOnlyTheTargetsSystems(unittest.TestCase):
|
||||
def record(*_a, **kw):
|
||||
if kw.get("system_filter"):
|
||||
asked.append(kw["system_filter"])
|
||||
return
|
||||
return platformpack.PlatformPackOutcome(zip_path=None)
|
||||
|
||||
with tempfile.TemporaryDirectory() as out, \
|
||||
mock.patch.object(platformpack, "generate_pack", record), \
|
||||
mock.patch.object(platformpack, "build_platform_pack", record), \
|
||||
mock.patch.object(platformpack, "print_split_packs"), \
|
||||
mock.patch.object(platformpack, "collect_emulator_extras", return_value=[]), \
|
||||
mock.patch.object(manifest, "collect_emulator_extras", return_value=[]):
|
||||
packs_platformpack.generate_split_packs(
|
||||
|
||||
@@ -94,7 +94,7 @@ class ValidatedChoice(unittest.TestCase):
|
||||
for call in ast.walk(node)
|
||||
)
|
||||
}
|
||||
self.assertLessEqual({"generate_pack", "generate_manifest"}, callers)
|
||||
self.assertLessEqual({"build_platform_pack", "generate_manifest"}, callers)
|
||||
# The manifest's core extras go through the builder's own lookup,
|
||||
# which reads validated_choice (packextras.ExtraResolver).
|
||||
resolvers = {
|
||||
@@ -106,7 +106,7 @@ class ValidatedChoice(unittest.TestCase):
|
||||
for call in ast.walk(node)
|
||||
)
|
||||
}
|
||||
self.assertLessEqual({"generate_pack", "manifest_core_entries"}, resolvers)
|
||||
self.assertLessEqual({"build_platform_pack", "manifest_core_entries"}, resolvers)
|
||||
extras = ast.parse((REPO_ROOT / "scripts" / "packs" / "extras.py").read_text(encoding="utf-8"))
|
||||
resolve = next(
|
||||
node for node in ast.walk(extras)
|
||||
@@ -119,11 +119,11 @@ class ValidatedChoice(unittest.TestCase):
|
||||
|
||||
def test_core_extras_are_judged_too(self):
|
||||
"""The baseline loop judged a platform's own files while the core-extras loop
|
||||
shipped whatever the name found. Both loops live in generate_pack."""
|
||||
shipped whatever the name found. Both loops live in build_platform_pack."""
|
||||
tree = ast.parse(script_source("generate_pack.py"))
|
||||
builder = next(
|
||||
node for node in ast.walk(tree)
|
||||
if isinstance(node, ast.FunctionDef) and node.name == "generate_pack"
|
||||
if isinstance(node, ast.FunctionDef) and node.name == "build_platform_pack"
|
||||
)
|
||||
calls = [
|
||||
call for call in ast.walk(builder)
|
||||
|
||||
Reference in new issue
Block a user