""" Deploy/build helpers for the Prole installer (root-level package). Encapsulates Xcode tools check and building the native Prole app. """ from __future__ import annotations from pathlib import Path import platform import subprocess from tkinter import messagebox def check_xcode_tools() -> bool: if platform.system() != "Darwin": return False try: result = subprocess.run(["xcrun", "--find", "swiftc"], capture_output=True, text=True, timeout=10) return result.returncode == 0 except Exception: return False def build_prole_app(project_root: Path) -> None: if platform.system() != "Darwin": raise Exception("Building the macOS app requires macOS.") if not check_xcode_tools(): raise Exception("Xcode Command Line Tools not found. Please run: xcode-select --install") # Use the top-level prole-app project directory prole_app_dir = Path(project_root) / "prole-app" build_script = prole_app_dir / "build.sh" if not build_script.exists(): raise Exception( f"Build script not found at {build_script}" ) result = subprocess.run(["bash", str(build_script), "build"], cwd=prole_app_dir, capture_output=True, text=True) if result.returncode != 0: raise Exception(f"Prole build failed: {result.stderr or result.stdout}") app_path = prole_app_dir / "dist" / "Prole.app" if not app_path.exists(): raise Exception("Build completed but Prole.app was not found in dist/") try: msg = ( "Prole.app has been built successfully.\n\n" f"Location: {app_path}\n\n" "Would you like to copy it to /Applications?" ) if messagebox.askyesno("Prole Built", msg): dest = Path("/Applications") / "Prole.app" subprocess.run(["cp", "-R", str(app_path), str(dest)], check=True) messagebox.showinfo("Copied", f"Copied to {dest}") except Exception as copy_err: print(f"Copy to /Applications failed: {copy_err}")