"""Build GaCy Go for Android and package its runtime data. Usage: python tools/package_go_runtime.py PATH_TO_GAC_GO The source checkout is read only; its current source/resources are packaged. Mutable saves are seeded from the checkout's committed defaults, never from the operator's live working files. """ import os from pathlib import Path import subprocess import sys import zipfile root = Path(__file__).resolve().parents[1] source = Path(sys.argv[1]).resolve() if not (source / "go.mod").is_file(): raise SystemExit("Expected a GaC-hkrpg-go checkout") native = root / "app/src/main/jniLibs/arm64-v8a" native.mkdir(parents=True, exist_ok=True) env = os.environ.copy() env.update(GOOS="android", GOARCH="arm64", CGO_ENABLED="0") for name in ("sdkserver", "gameserver"): subprocess.run(["go", "build", "-o", str(native / f"libgacy_{name}.so"), f"./cmd/{name}"], cwd=source, env=env, check=True) # Optional emulator-only binaries use Linux syscalls on the x86_64 emulator. # They are excluded from ordinary ARM64 builds. if "--emulator" in sys.argv[2:]: emulator = root / "app/src/debug/jniLibs/x86_64" emulator.mkdir(parents=True, exist_ok=True) env.update(GOOS="linux", GOARCH="amd64", CGO_ENABLED="0") for name in ("sdkserver", "gameserver"): subprocess.run(["go", "build", "-o", str(emulator / f"libgacy_{name}.so"), f"./cmd/{name}"], cwd=source, env=env, check=True) archive = root / "app/src/goAssets/gacy-go-data.zip" archive.parent.mkdir(parents=True, exist_ok=True) resources = ("server.json", "hotfix.json", "versions.json", "res.json", "teleports.json", "challenge_data.json", "mission_unlocks.json") scripts = ("damage_analyst_live.lua", "fps_settings_120.lua", "freecam.lua", "hide_ui.lua", "navigation_profiles.lua", "ping_rainbow.lua") with zipfile.ZipFile(archive, "w", zipfile.ZIP_DEFLATED, compresslevel=6) as z: for name in resources: z.write(source / name, name) for path in (source / "resources").rglob("*"): if path.is_file(): z.write(path, path.relative_to(source).as_posix()) for name in scripts: z.write(source / "scripts" / name, "scripts/" + name) for name in ("persistent", "freesr-data.json"): data = subprocess.check_output(["git", "show", f"HEAD:{name}"], cwd=source) z.writestr(name, data) print(f"Packaged Go runtime: {archive}")