diff options
| author | Issai <279266118+Arkex-ai@users.noreply.github.com> | 2026-11-23 13:04:30 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-23 10:04:30 -0600 |
| commit | cc67780893d315ce845c1fa6d13716774f1cb982 (patch) | |
| tree | 592f7867213c66b7845e8bc2babc03a45be9fbb2 /scripts/dev.py | |
| parent | 4155c236734c1989824da60eecc89e7e0e655796 (diff) | |
BUILD-2248: run a synthetic guest scene with persistent output from the development CLI (#6691)
Squash-merged after diff review of PR #6691 - BUILD-2248: run a synthetic guest scene with persistent output from the development CLI
Diffstat (limited to 'scripts/dev.py')
| -rw-r--r-- | scripts/dev.py | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/scripts/dev.py b/scripts/dev.py new file mode 100644 index 000000000..f0761d0c3 --- /dev/null +++ b/scripts/dev.py | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | #!/usr/bin/env python3 | ||
| 2 | """Use development tools from this Leonida checkout.""" | ||
| 3 | |||
| 4 | import argparse | ||
| 5 | import json | ||
| 6 | import subprocess | ||
| 7 | import sys | ||
| 8 | from pathlib import Path | ||
| 9 | |||
| 10 | |||
| 11 | ROOT = Path(__file__).resolve().parents[1] | ||
| 12 | BOOT_TRACE = "tools/boot_trace.py" | ||
| 13 | GUEST_SCENE = "scripts/run_guest_scene.py" | ||
| 14 | TOOLS = ( | ||
| 15 | ( | ||
| 16 | "boot-trace", | ||
| 17 | BOOT_TRACE, | ||
| 18 | ("Python 3", "Startup JSONL from gta6rt --trace or stderr from gta6rt --trace-d3d12"), | ||
| 19 | ), | ||
| 20 | ( | ||
| 21 | "guest-scene", | ||
| 22 | GUEST_SCENE, | ||
| 23 | ( | ||
| 24 | "Python 3", | ||
| 25 | "gta6rt and tiny_guest_draw built with LEONIDA_GUEST_SCENE (static SDL3)", | ||
| 26 | "Vulkan and the synthetic M1.5 shader fixture with a spirv/ directory", | ||
| 27 | "Wine when running the Windows loader outside Windows", | ||
| 28 | ), | ||
| 29 | ), | ||
| 30 | ) | ||
| 31 | |||
| 32 | |||
| 33 | def discover() -> dict: | ||
| 34 | tools = [] | ||
| 35 | for name, path, requirements in TOOLS: | ||
| 36 | present = (ROOT / path).is_file() | ||
| 37 | tools.append({ | ||
| 38 | "id": name, | ||
| 39 | "path": path, | ||
| 40 | "present": present, | ||
| 41 | "help_argv": ["python", "-I", path, "--help"] if present else None, | ||
| 42 | "requirements": requirements, | ||
| 43 | }) | ||
| 44 | return { | ||
| 45 | "schema_version": 1, | ||
| 46 | "tools": tools, | ||
| 47 | "live_controls": { | ||
| 48 | "available": False, | ||
| 49 | "reason": "This entry point does not expose live attach, pause, step, input or screenshots.", | ||
| 50 | }, | ||
| 51 | } | ||
| 52 | |||
| 53 | |||
| 54 | def run_producer(relative_path: str, args: list[str]) -> int: | ||
| 55 | producer = ROOT / relative_path | ||
| 56 | if not producer.is_file(): | ||
| 57 | print(f"error: {relative_path} is missing; use a complete Leonida checkout", file=sys.stderr) | ||
| 58 | return 2 | ||
| 59 | try: | ||
| 60 | return subprocess.run( | ||
| 61 | [sys.executable, "-I", str(producer), *args], | ||
| 62 | cwd=Path.cwd(), | ||
| 63 | ).returncode | ||
| 64 | except OSError as exc: | ||
| 65 | print(f"error: could not run {relative_path}: {exc}", file=sys.stderr) | ||
| 66 | return 2 | ||
| 67 | |||
| 68 | |||
| 69 | def guest_scene(args: list[str]) -> int: | ||
| 70 | # Only enforce the persistent output option here. The runner parses the original argv. | ||
| 71 | parser = argparse.ArgumentParser(prog="dev.py guest-scene", add_help=False, allow_abbrev=False) | ||
| 72 | parser.add_argument("-h", "--help", action="store_true") | ||
| 73 | parser.add_argument("--out", metavar="PATH") | ||
| 74 | options, _ = parser.parse_known_args(args) | ||
| 75 | if not options.help and not options.out: | ||
| 76 | parser.error("--out PATH is required to keep the scene results") | ||
| 77 | |||
| 78 | return run_producer(GUEST_SCENE, args) | ||
| 79 | |||
| 80 | |||
| 81 | def main() -> int: | ||
| 82 | # The producer owns its arguments and help. Forward before argparse handles them. | ||
| 83 | argv = sys.argv[1:] | ||
| 84 | if argv[:1] == ["boot-trace"]: | ||
| 85 | return run_producer(BOOT_TRACE, argv[1:]) | ||
| 86 | if argv[:1] == ["guest-scene"]: | ||
| 87 | return guest_scene(argv[1:]) | ||
| 88 | |||
| 89 | parser = argparse.ArgumentParser(description=__doc__) | ||
| 90 | commands = parser.add_subparsers(dest="command", required=True) | ||
| 91 | inventory = commands.add_parser("discover", help="list producer scripts and their requirements") | ||
| 92 | inventory.add_argument("--json", action="store_true", help="write a JSON inventory to stdout") | ||
| 93 | commands.add_parser("boot-trace", help="summarize startup and D3D12 boot traces") | ||
| 94 | commands.add_parser("guest-scene", help="run the synthetic guest scene with a required --out") | ||
| 95 | args = parser.parse_args(argv) | ||
| 96 | |||
| 97 | result = discover() | ||
| 98 | if args.json: | ||
| 99 | print(json.dumps(result, indent=2)) | ||
| 100 | else: | ||
| 101 | print("Paths and help commands are relative to the Leonida checkout root.") | ||
| 102 | for tool in result["tools"]: | ||
| 103 | status = "present" if tool["present"] else "missing" | ||
| 104 | print(f"{tool['id']}: {tool['path']} ({status})") | ||
| 105 | if tool["help_argv"]: | ||
| 106 | print(f" Help: {' '.join(tool['help_argv'])}") | ||
| 107 | print(" Requirements (not checked):") | ||
| 108 | for requirement in tool["requirements"]: | ||
| 109 | print(f" - {requirement}") | ||
| 110 | print(f"Live controls: unavailable. {result['live_controls']['reason']}") | ||
| 111 | return 0 | ||
| 112 | |||
| 113 | |||
| 114 | if __name__ == "__main__": | ||
| 115 | raise SystemExit(main()) | ||