162 lines
5.0 KiB
Bash
Executable File
162 lines
5.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# Build and run Gaze application
|
|
# Usage: ./run [build|test|run]
|
|
# Default action is build and run
|
|
ACTION=${1:-run}
|
|
VERBOSE=false
|
|
OUTPUT_FILE=""
|
|
# Function to kill any existing Gaze processes
|
|
kill_existing_gaze_processes() {
|
|
echo "🔍 Checking for existing Gaze processes..."
|
|
|
|
# Find and kill any running Gaze processes
|
|
pids=$(pgrep -f "Gaze.app")
|
|
if [ -n "$pids" ]; then
|
|
echo "🛑 Killing existing Gaze processes (PID(s): $pids)..."
|
|
kill $pids 2>/dev/null
|
|
# Wait a moment for processes to terminate
|
|
sleep 1
|
|
else
|
|
echo "✅ No existing Gaze processes found"
|
|
fi
|
|
}
|
|
# Function to update LSP configuration
|
|
update_lsp_config() {
|
|
echo "🔧 Updating LSP configuration..."
|
|
|
|
# Check if xcode-build-server is installed
|
|
if command -v xcode-build-server &> /dev/null; then
|
|
# Generate buildServer.json for LSP
|
|
xcode-build-server config -project Gaze.xcodeproj -scheme Gaze > /dev/null 2>&1
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "✅ LSP configuration updated (buildServer.json created)"
|
|
else
|
|
echo "⚠️ Could not update LSP configuration"
|
|
fi
|
|
else
|
|
echo "⚠️ xcode-build-server not found. Install with: brew install xcode-build-server"
|
|
echo " This helps Neovim's LSP recognize your Swift modules"
|
|
fi
|
|
}
|
|
# Parse command line arguments
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
-v|--verbose)
|
|
VERBOSE=true
|
|
shift
|
|
;;
|
|
-o|--output)
|
|
OUTPUT_FILE="$2"
|
|
VERBOSE=true
|
|
shift 2
|
|
;;
|
|
--no-lsp)
|
|
SKIP_LSP=true
|
|
shift
|
|
;;
|
|
*)
|
|
ACTION="$1"
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
# Function to run command with output control
|
|
run_with_output() {
|
|
local cmd="$1"
|
|
if [ "$VERBOSE" = true ] && [ -n "$OUTPUT_FILE" ]; then
|
|
# Both verbose and output file specified
|
|
eval "$cmd" | tee "$OUTPUT_FILE"
|
|
elif [ "$VERBOSE" = true ]; then
|
|
# Verbose only
|
|
eval "$cmd"
|
|
elif [ -n "$OUTPUT_FILE" ]; then
|
|
# Output file only (treat as verbose)
|
|
eval "$cmd" > "$OUTPUT_FILE" 2>&1
|
|
else
|
|
# Neither verbose nor output file, send to /dev/null
|
|
eval "$cmd" > /dev/null 2>&1
|
|
fi
|
|
}
|
|
echo "=== Gaze Application Script ==="
|
|
if [ "$ACTION" = "build" ]; then
|
|
echo "Building Gaze project..."
|
|
run_with_output "xcodebuild -project Gaze.xcodeproj -scheme Gaze -configuration Debug build"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "✅ Build succeeded!"
|
|
echo "💡 The app is located at: build/Debug/Gaze.app"
|
|
|
|
# Update LSP config after successful build
|
|
if [ "$SKIP_LSP" != true ]; then
|
|
update_lsp_config
|
|
fi
|
|
else
|
|
echo "❌ Build failed!"
|
|
exit 1
|
|
fi
|
|
|
|
elif [ "$ACTION" = "test" ]; then
|
|
echo "Running unit tests..."
|
|
run_with_output "xcodebuild -project Gaze.xcodeproj -scheme Gaze -configuration Debug test"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "✅ Tests passed!"
|
|
else
|
|
echo "❌ Tests failed!"
|
|
exit 1
|
|
fi
|
|
elif [ "$ACTION" = "run" ]; then
|
|
echo "Building and running Gaze application..."
|
|
|
|
# Kill any existing Gaze processes first
|
|
kill_existing_gaze_processes
|
|
|
|
# Always build first, then run
|
|
run_with_output "xcodebuild -project Gaze.xcodeproj -scheme Gaze -configuration Debug build"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "✅ Build succeeded!"
|
|
|
|
# Update LSP config after successful build
|
|
if [ "$SKIP_LSP" != true ]; then
|
|
update_lsp_config
|
|
fi
|
|
|
|
# Get the actual build output directory from xcodebuild
|
|
BUILD_DIR="$(xcodebuild -project Gaze.xcodeproj -scheme Gaze -configuration Debug -showBuildSettings 2>/dev/null | grep -m 1 "BUILT_PRODUCTS_DIR" | sed 's/.*= //')"
|
|
APP_PATH="${BUILD_DIR}/Gaze.app"
|
|
|
|
if [ -d "$APP_PATH" ]; then
|
|
echo "🚀 Launching: $APP_PATH"
|
|
open "$APP_PATH"
|
|
else
|
|
echo "⚠️ App not found at expected location, trying fallback..."
|
|
# Fallback to derived data location
|
|
open "$HOME/Library/Developer/Xcode/DerivedData/Gaze-*/Build/Products/Debug/Gaze.app"
|
|
fi
|
|
else
|
|
echo "❌ Build failed!"
|
|
exit 1
|
|
fi
|
|
elif [ "$ACTION" = "lsp" ]; then
|
|
# New command to just update LSP config
|
|
echo "Updating LSP configuration only..."
|
|
update_lsp_config
|
|
|
|
else
|
|
echo "Usage: $0 [build|test|run|lsp] [-v|--verbose] [-o|--output <file_name>] [--no-lsp]"
|
|
echo ""
|
|
echo "Commands:"
|
|
echo " build - Build the application"
|
|
echo " test - Run unit tests"
|
|
echo " run - Build and run the application (default)"
|
|
echo " lsp - Update LSP configuration only (buildServer.json)"
|
|
echo ""
|
|
echo "Options:"
|
|
echo " -v, --verbose - Show output in stdout"
|
|
echo " -o, --output - Write output to log file"
|
|
echo " --no-lsp - Skip LSP configuration update"
|
|
exit 1
|
|
fi
|