forked from RetroPortingToolKit/psxrecomp
-
Notifications
You must be signed in to change notification settings - Fork 0
Review: check BIOS assets selected by the setup recipe #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Alexbeav
wants to merge
2
commits into
review-base/mstan-8d56cf659fd8
from
review/setup-bios-assets-20260907
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Setup SDK BIOS assets | ||
|
|
||
| The staged game.toml selects the required BIOS profile. Retail-only recipes do not require the unused OpenBIOS image and license. | ||
| Default OpenBIOS recipes still require their profile, image and license. The selected profile must be a file inside the staged kit. | ||
| The gate does not bundle retail BIOS dumps and does not change the CLI's BIOS selection or generated-code readiness checks. | ||
|
|
||
| Every required asset is resolved before the containment check, including default profiles and OpenBIOS assets. A file or parent-directory symlink cannot make an external asset count as part of the kit. Symlinks whose targets remain inside the kit are allowed. | ||
|
|
||
| Run `python runtime/tests/test_setup_bios_assets.py` for ten synthetic fixture tests. Symlink controls run when the host permits symlink creation; other controls always run. | ||
| The existing `stage_setup_sdk.sh` gate calls the same production checker. Python 3.11 uses tomllib; older Python needs tomli, as other setup tools do. | ||
|
|
||
| This gate is independently useful for retail SCPH1001 setup. Full selected-profile/SCPH5552 support also needs matching CLI, profile and generation support. | ||
| The current upstream CLI still hardcodes SCPH1001 in its retail generate path. Passing this gate alone does not establish SCPH5552 setup support. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| #!/usr/bin/env python3 | ||
| """Exercise the production SDK BIOS gate with synthetic files only.""" | ||
| import importlib.util | ||
| import tempfile | ||
| import unittest | ||
| from pathlib import Path | ||
| ROOT = Path(__file__).resolve().parents[2] | ||
| spec = importlib.util.spec_from_file_location("gate", ROOT / "tools/check_setup_bios_assets.py") | ||
| gate = importlib.util.module_from_spec(spec) | ||
| spec.loader.exec_module(gate) | ||
|
|
||
|
|
||
| class GateTests(unittest.TestCase): | ||
| def setUp(self): | ||
| self.tmp = tempfile.TemporaryDirectory() | ||
| self.addCleanup(self.tmp.cleanup) | ||
| self.root = Path(self.tmp.name) | ||
| (self.root / "psxrecomp/bios").mkdir(parents=True) | ||
|
|
||
| def recipe(self, text): | ||
| (self.root / "game.toml").write_text(text) | ||
|
|
||
| def asset(self, name): | ||
| (self.root / "psxrecomp/bios" / name).write_text("synthetic fixture") | ||
|
|
||
| def test_retail_profile_without_openbios(self): | ||
| self.recipe('[runtime]\nopenbios=false\n[recompiler]\nbios_config="psxrecomp/bios/SCPH5552.toml"\n') | ||
| self.asset("SCPH5552.toml") | ||
| self.assertEqual(gate.check(self.root), [str(Path("psxrecomp/bios/SCPH5552.toml"))]) | ||
|
|
||
| def test_retail_missing_profile_fails(self): | ||
| self.recipe('[runtime]\nopenbios=false\n[recompiler]\nbios_config="psxrecomp/bios/SCPH5552.toml"\n') | ||
| with self.assertRaisesRegex(ValueError, "SCPH5552"): | ||
| gate.check(self.root) | ||
|
|
||
| def test_default_openbios_requires_all_assets(self): | ||
| self.recipe('[runtime]\n') | ||
| for name in ("OpenBIOS.toml", "openbios.bin", "OpenBIOS.LICENSE"): | ||
| with self.assertRaises(ValueError): | ||
| gate.check(self.root) | ||
| self.asset(name) | ||
| self.assertEqual(len(gate.check(self.root)), 3) | ||
|
|
||
| def test_external_profile_fails(self): | ||
| self.recipe('[runtime]\nopenbios=false\n[recompiler]\nbios_config="../external.toml"\n') | ||
| with self.assertRaisesRegex(ValueError, "inside"): | ||
| gate.check(self.root) | ||
|
|
||
| def test_absent_recipe_fails(self): | ||
| with self.assertRaisesRegex(ValueError, "game.toml"): | ||
| gate.check(self.root) | ||
|
|
||
| def symlink(self, link, target, directory=False): | ||
| try: | ||
| link.symlink_to(target, target_is_directory=directory) | ||
| except (OSError, NotImplementedError) as error: | ||
| self.skipTest("symlink creation unavailable: " + str(error)) | ||
|
|
||
| def outside(self): | ||
| tmp = tempfile.TemporaryDirectory() | ||
| self.addCleanup(tmp.cleanup) | ||
| return Path(tmp.name) | ||
|
|
||
| def test_default_retail_rejects_external_profile_symlink(self): | ||
| self.recipe('[runtime]\nopenbios=false\n') | ||
| target = self.outside() / "SCPH1001.toml" | ||
| target.write_text("synthetic fixture") | ||
| self.symlink(self.root / "psxrecomp/bios/SCPH1001.toml", target) | ||
| with self.assertRaisesRegex(ValueError, "inside"): | ||
| gate.check(self.root) | ||
|
|
||
| def test_openbios_rejects_external_asset_symlinks(self): | ||
| self.recipe('[runtime]\n') | ||
| names = ("OpenBIOS.toml", "openbios.bin", "OpenBIOS.LICENSE") | ||
| for name in names: | ||
| self.asset(name) | ||
| target = self.outside() / "asset" | ||
| target.write_text("synthetic fixture") | ||
| for name in names: | ||
| with self.subTest(asset=name): | ||
| link = self.root / "psxrecomp/bios" / name | ||
| link.unlink() | ||
| self.symlink(link, target) | ||
| with self.assertRaisesRegex(ValueError, "inside"): | ||
| gate.check(self.root) | ||
| link.unlink() | ||
| self.asset(name) | ||
|
|
||
| def test_default_retail_rejects_external_bios_directory(self): | ||
| self.recipe('[runtime]\nopenbios=false\n') | ||
| target = self.outside() | ||
| (target / "SCPH1001.toml").write_text("synthetic fixture") | ||
| link = self.root / "psxrecomp/bios" | ||
| link.rmdir() | ||
| self.symlink(link, target, directory=True) | ||
| with self.assertRaisesRegex(ValueError, "inside"): | ||
| gate.check(self.root) | ||
|
|
||
| def test_openbios_rejects_external_framework_directory(self): | ||
| self.recipe('[runtime]\n') | ||
| target = self.outside() | ||
| (target / "bios").mkdir() | ||
| for name in ("OpenBIOS.toml", "openbios.bin", "OpenBIOS.LICENSE"): | ||
| (target / "bios" / name).write_text("synthetic fixture") | ||
| (self.root / "psxrecomp/bios").rmdir() | ||
| link = self.root / "psxrecomp" | ||
| link.rmdir() | ||
| self.symlink(link, target, directory=True) | ||
| with self.assertRaisesRegex(ValueError, "inside"): | ||
| gate.check(self.root) | ||
|
|
||
| def test_internal_asset_symlinks_are_accepted(self): | ||
| self.recipe('[runtime]\n') | ||
| target = self.root / "shared-asset" | ||
| target.write_text("synthetic fixture") | ||
| for name in ("OpenBIOS.toml", "openbios.bin", "OpenBIOS.LICENSE"): | ||
| self.symlink(self.root / "psxrecomp/bios" / name, target) | ||
| self.assertEqual(len(gate.check(self.root)), 3) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/usr/bin/env python3 | ||
| """Require BIOS assets selected by the staged title recipe.""" | ||
| import sys | ||
| from pathlib import Path | ||
| try: | ||
| import tomllib | ||
| except ModuleNotFoundError: | ||
| import tomli as tomllib | ||
|
|
||
|
|
||
| def check(stage): | ||
| stage = Path(stage).resolve() | ||
| recipe = stage / "game.toml" | ||
| if not recipe.is_file(): | ||
| raise ValueError("missing staged game.toml for BIOS policy") | ||
| with recipe.open("rb") as handle: | ||
| config = tomllib.load(handle) | ||
| openbios = config.get("runtime", {}).get("openbios", True) | ||
| if not isinstance(openbios, bool): | ||
| raise ValueError("runtime.openbios must be a boolean") | ||
| profile = config.get("recompiler", {}).get("bios_config") | ||
| required = [] | ||
| if profile: | ||
| required.append(stage / profile) | ||
| elif not openbios: | ||
| # Existing title recipes without a profile use the CLI default. | ||
| required.append(stage / "psxrecomp/bios/SCPH1001.toml") | ||
| if openbios: | ||
| required.extend(stage / "psxrecomp/bios" / name for name in | ||
| ("OpenBIOS.toml", "openbios.bin", "OpenBIOS.LICENSE")) | ||
| for path in required: | ||
| path = path.resolve() | ||
| try: | ||
| path.relative_to(stage) | ||
| except ValueError: | ||
| raise ValueError("BIOS asset must remain inside the staged kit") | ||
| if not path.is_file(): | ||
| raise ValueError("missing staged BIOS asset: " + str(path.relative_to(stage))) | ||
|
Alexbeav marked this conversation as resolved.
|
||
| return [str(path.relative_to(stage)) for path in required] | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| try: | ||
| print("staged BIOS policy: " + ", ".join(check(sys.argv[1]))) | ||
| except (ValueError, OSError) as error: | ||
| sys.exit("error: " + str(error)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.