-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.py
More file actions
213 lines (179 loc) · 6.43 KB
/
Copy pathrun.py
File metadata and controls
213 lines (179 loc) · 6.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import argparse
import atexit
import shutil
import subprocess
import sys
from pathlib import Path
processes: list[subprocess.Popen] = []
PROJECT_ROOT = Path(__file__).parent
AGENT_DIR = str(PROJECT_ROOT / "server-python" / "agent")
HUB_DIR = str(PROJECT_ROOT / "server-python")
GUI_DIR = str(PROJECT_ROOT / "client-godot")
BUILD_DIR = PROJECT_ROOT / "build"
DIST_DIR = PROJECT_ROOT / "dist"
def cleanup():
"""Make sure all the spawned subprocesses are terminated on exit."""
for p in processes:
if p.poll() is None:
print(f"Terminating PID {p.pid}")
p.terminate()
p.wait()
atexit.register(cleanup)
def run_cmd(
cmd: str, cwd: str = ".", wait=True, cleanup=True, shell=False
) -> subprocess.Popen:
"""Helper to run a shell command."""
print(f"[{cwd}]$ {cmd}")
if shell:
p = subprocess.Popen(cmd, shell=True, cwd=cwd)
else:
p = subprocess.Popen(cmd.split(), shell=False, cwd=cwd)
if cleanup:
processes.append(p)
if wait:
p.wait()
return p
def find_godot_executable() -> str | None:
"""Find the path to the Godot executable."""
godot_path = shutil.which("godot")
if godot_path is not None:
return godot_path
if sys.platform == "darwin":
return "/Applications/Godot.app/Contents/MacOS/Godot"
return None
def cmd_dev():
"""Run all components in live-reload development mode."""
print("--- Starting Agent (watch mode) ---")
run_cmd("npm run watch", cwd=AGENT_DIR, wait=False)
print("--- Starting Server (live reload) ---")
run_cmd("uv run watchfiles freat-server", cwd=HUB_DIR, wait=False)
godot_path = find_godot_executable()
if not godot_path:
print("[!] Godot executable not found. Running the headless server...")
try:
while True:
pass
except KeyboardInterrupt:
print("Stopping all services...")
return
else:
try:
print("--- Starting the Godot Editor ---")
run_cmd(f"{godot_path} --path . --editor", cwd=GUI_DIR, wait=True)
print("Godot editor closed. Stopping all services...")
except KeyboardInterrupt:
print("Stopping all services...")
def cmd_test():
"""Run the test suite"""
print("--- Building Agent ---")
run_cmd("npm run build", cwd=AGENT_DIR, wait=True)
print("--- Running tests ---")
run_cmd("uv run pytest", cwd=HUB_DIR, wait=True)
def get_version() -> str:
result = subprocess.run(
["git", "describe", "--tags", "--abbrev=0"],
capture_output=True,
text=True,
)
return result.stdout.strip().lstrip("v") if result.returncode == 0 else "0.0.0"
def cmd_build(platforms: set[str] = {"macos", "linux", "windows"}):
"""Build release package for the specified platforms."""
print("=" * 50)
print("Building Freat Release Package")
print("=" * 50)
print()
print("→ Cleaning build directories...")
if BUILD_DIR.exists():
shutil.rmtree(BUILD_DIR)
if DIST_DIR.exists():
shutil.rmtree(DIST_DIR)
BUILD_DIR.mkdir(parents=True)
DIST_DIR.mkdir(parents=True)
print("✓ Build directories cleaned")
print("\n→ Exporting Godot project...")
godot_path = find_godot_executable()
if not godot_path:
print("❌ ERROR: Godot executable not found")
print(" Please install Godot 4.4+ or set it in PATH")
sys.exit(1)
version = get_version()
outputs: list[Path] = []
# macOS
if "macos" in platforms:
app_path = BUILD_DIR / "Freat.app"
run_cmd(
f'{godot_path} --headless --export-release "macOS" {app_path}',
cwd=GUI_DIR, wait=True, shell=True,
)
if not app_path.exists():
print("❌ ERROR: macOS Godot export failed")
sys.exit(1)
macos_zip = DIST_DIR / f"Freat-v{version}-macOS.zip"
shutil.make_archive(str(macos_zip.with_suffix("")), "zip", BUILD_DIR, "Freat.app")
outputs.append(macos_zip)
print(f"✓ macOS: {macos_zip.name}")
# Linux
if "linux" in platforms:
linux_binary = BUILD_DIR / "Freat.x86_64"
run_cmd(
f'{godot_path} --headless --export-release "Linux" {linux_binary}',
cwd=GUI_DIR, wait=True, shell=True,
)
if not linux_binary.exists():
print("❌ ERROR: Linux Godot export failed")
sys.exit(1)
linux_tar = DIST_DIR / f"Freat-v{version}-Linux.tar.gz"
shutil.make_archive(str(linux_tar.with_suffix("").with_suffix("")), "gztar",
BUILD_DIR, "Freat.x86_64")
outputs.append(linux_tar)
print(f"✓ Linux: {linux_tar.name}")
# Windows
if "windows" in platforms:
win_binary = BUILD_DIR / "Freat.exe"
run_cmd(
f'{godot_path} --headless --export-release "Windows Desktop" {win_binary}',
cwd=GUI_DIR, wait=True, shell=True,
)
if not win_binary.exists():
print("❌ ERROR: Windows Godot export failed")
sys.exit(1)
win_zip = DIST_DIR / f"Freat-v{version}-Windows.zip"
shutil.make_archive(str(win_zip.with_suffix("")), "zip", BUILD_DIR, "Freat.exe")
outputs.append(win_zip)
print(f"✓ Windows: {win_zip.name}")
print()
print("=" * 50)
print("✅ Build Complete!")
print("=" * 50)
print()
for out in outputs:
size_mb = out.stat().st_size / (1024 * 1024)
print(f" {out.name} ({size_mb:.1f} MB)")
print()
def main():
parser = argparse.ArgumentParser(description="freat - an instrumentation toolkit")
subparser = parser.add_subparsers(dest="command", required=True)
subparser.add_parser(
"dev", help="Run all components in live-reload development mode"
)
subparser.add_parser("test", help="Run the test suite")
build_parser = subparser.add_parser("build", help="Build release package for distribution")
build_parser.add_argument(
"--platform",
nargs="+",
choices=["macos", "linux", "windows"],
default=["macos", "linux", "windows"],
help="Platforms to build (default: all)",
)
args = parser.parse_args()
match args.command:
case "dev":
cmd_dev()
case "test":
cmd_test()
case "build":
cmd_build(set(args.platform))
case _:
print("Invalid command")
if __name__ == "__main__":
main()