upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

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