#!/usr/bin/env python3 """ PyInstaller build script for simulation_host.py. Creates a standalone executable that includes PyBullet and pybullet_data. """ import os import platform import sys from pathlib import Path try: import PyInstaller.__main__ import pybullet_data except ImportError as e: print(f"Missing dependency: {e}") print("Install with: pip install pyinstaller pybullet") sys.exit(1) def get_pybullet_data_path() -> str: return pybullet_data.getDataPath() def build_executable(): print("=" * 60) print(" DRONE SIMULATION - BUILD EXECUTABLE") print("=" * 60) script_dir = Path(__file__).parent source_file = script_dir / "simulation_host.py" if not source_file.exists(): print(f"Error: {source_file} not found!") sys.exit(1) system = platform.system().lower() print(f"Platform: {system}") pybullet_path = get_pybullet_data_path() print(f"PyBullet data path: {pybullet_path}") if system == 'windows': separator = ';' else: separator = ':' data_spec = f"{pybullet_path}{separator}pybullet_data" build_args = [ str(source_file), '--onefile', '--clean', '--name=simulation_host', f'--add-data={data_spec}', ] if system == 'windows': build_args.append('--windowed') elif system == 'darwin': build_args.append('--windowed') else: build_args.append('--console') print("\nBuild configuration:") for arg in build_args: print(f" {arg}") print("\nStarting PyInstaller build...") print("-" * 60) try: PyInstaller.__main__.run(build_args) print("-" * 60) print("\nBuild completed successfully!") dist_dir = script_dir / "dist" if system == 'windows': exe_path = dist_dir / "simulation_host.exe" elif system == 'darwin': exe_path = dist_dir / "simulation_host.app" else: exe_path = dist_dir / "simulation_host" print(f"\nExecutable location: {exe_path}") except Exception as e: print(f"\nBuild failed: {e}") sys.exit(1) if __name__ == '__main__': build_executable()