1+ #! /usr/bin/env bash
2+
3+ # This script builds all necessary Python executables for the application.
4+
5+ set -e # Exit immediately if a command fails.
6+
7+ # Get the directory where this script is located to resolve paths correctly.
8+ SCRIPT_DIR=$( cd -- " $( dirname -- " ${BASH_SOURCE[0]} " ) " & > /dev/null && pwd )
9+ EXTERNALS_DIR=" $SCRIPT_DIR /externals/python"
10+
11+ # --- Reusable Build Function ---
12+ # This function handles the logic for building a single Python executable.
13+ # Arguments:
14+ # $1: The directory of the Python project to build (e.g., "window_inspector").
15+ build_python_executable () {
16+ local component_name=$1
17+ local component_dir=" $EXTERNALS_DIR /$component_name "
18+
19+ echo " "
20+ echo " --- Building: $component_name ---"
21+
22+ if [ ! -d " $component_dir " ]; then
23+ echo " ❌ Error: Directory not found at $component_dir "
24+ return 1
25+ fi
26+
27+ echo " 📂 Navigating to $component_dir "
28+ cd " $component_dir "
29+
30+ # --- Pre-build Check ---
31+ # Check if the executable already exists to skip unnecessary work.
32+ local executable_path_dir=" dist/$component_name /$component_name "
33+ local executable_path_file=" dist/$component_name "
34+
35+ if [ -f " $executable_path_dir " ] || [ -f " $executable_path_file " ]; then
36+ echo " ✅ Executable for $component_name already exists. Skipping build."
37+ return 0 # Successfully skipped
38+ fi
39+
40+ echo " 🔎 Executable not found for $component_name . Proceeding with build..."
41+
42+ echo " 🐍 Creating Python virtual environment..."
43+ python3 -m venv venv
44+
45+ echo " 🐍 Activating virtual environment..."
46+ source venv/bin/activate
47+
48+ if [ -f " requirements.txt" ]; then
49+ echo " 📦 Installing dependencies from requirements.txt..."
50+ pip3 install -r requirements.txt
51+ else
52+ echo " ⚠️ Warning: requirements.txt not found in $component_dir ."
53+ fi
54+
55+ echo " 📦 Installing PyInstaller..."
56+ pip3 install pyinstaller
57+
58+ if [ -f " $component_name .spec" ]; then
59+ echo " 🛠️ Building executable with PyInstaller ($component_name .spec)..."
60+ pyinstaller " $component_name .spec"
61+ else
62+ echo " ❌ Error: $component_name .spec not found. Cannot build."
63+ deactivate
64+ return 1
65+ fi
66+
67+ # --- Post-build Verification ---
68+ echo " 🔎 Verifying build output..."
69+ if [ -f " $executable_path_dir " ]; then
70+ echo " ✅ Executable created at $executable_path_dir "
71+ elif [ -f " $executable_path_file " ]; then
72+ echo " ✅ Executable created at $executable_path_file "
73+ else
74+ echo " ❌ Error: Build verification failed. Executable not found in 'dist/' directory after build."
75+ deactivate
76+ return 1
77+ fi
78+
79+ echo " ✅ Successfully built $component_name ."
80+ deactivate
81+ }
82+
83+ # --- Build All Components ---
84+ echo " 🚀 Starting Python build process..."
85+
86+ build_python_executable " window_inspector"
87+ build_python_executable " window_capture"
88+
89+ echo " "
90+ echo " 🎉 All Python executables have been built successfully!"
0 commit comments