|
| 1 | +#!/bin/bash |
| 2 | +# test-cmake-ios.sh - Test CMake iOS builds for iPlug2 examples |
| 3 | +# |
| 4 | +# Tests that all iPlug2 examples with CMakeLists.txt files build |
| 5 | +# successfully for iOS (simulator). |
| 6 | +# |
| 7 | +# Usage: ./test-cmake-ios.sh [--clean] [--device] |
| 8 | +# --clean: Remove build directories before tests |
| 9 | +# --device: Build for physical device instead of simulator |
| 10 | + |
| 11 | +set -o pipefail |
| 12 | + |
| 13 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 14 | +IPLUG2_DIR="$SCRIPT_DIR/iPlug2" |
| 15 | +EXAMPLES_DIR="$IPLUG2_DIR/Examples" |
| 16 | + |
| 17 | +# Test counters |
| 18 | +PASSED=0 |
| 19 | +FAILED=0 |
| 20 | +FAILED_TESTS=() |
| 21 | + |
| 22 | +# Options |
| 23 | +CLEAN_BUILDS=false |
| 24 | +BUILD_FOR_DEVICE=false |
| 25 | + |
| 26 | +for arg in "$@"; do |
| 27 | + case $arg in |
| 28 | + --clean) |
| 29 | + CLEAN_BUILDS=true |
| 30 | + ;; |
| 31 | + --device) |
| 32 | + BUILD_FOR_DEVICE=true |
| 33 | + ;; |
| 34 | + esac |
| 35 | +done |
| 36 | + |
| 37 | +# ============================================================================= |
| 38 | +# Output helpers |
| 39 | +# ============================================================================= |
| 40 | +RED='\033[0;31m' |
| 41 | +GREEN='\033[0;32m' |
| 42 | +YELLOW='\033[1;33m' |
| 43 | +CYAN='\033[0;36m' |
| 44 | +NC='\033[0m' # No Color |
| 45 | + |
| 46 | +pass() { |
| 47 | + echo -e " ${GREEN}✓${NC} $1" |
| 48 | + ((PASSED++)) |
| 49 | +} |
| 50 | + |
| 51 | +fail() { |
| 52 | + echo -e " ${RED}✗${NC} $1" |
| 53 | + ((FAILED++)) |
| 54 | + FAILED_TESTS+=("$1") |
| 55 | +} |
| 56 | + |
| 57 | +section() { |
| 58 | + echo "" |
| 59 | + echo -e "${CYAN}[$1]${NC}" |
| 60 | +} |
| 61 | + |
| 62 | +info() { |
| 63 | + echo -e " ${YELLOW}→${NC} $1" |
| 64 | +} |
| 65 | + |
| 66 | +# ============================================================================= |
| 67 | +# Test functions |
| 68 | +# ============================================================================= |
| 69 | + |
| 70 | +# Generate Xcode project for iOS using CMake |
| 71 | +# Args: project_dir build_dir |
| 72 | +test_cmake_generate_ios() { |
| 73 | + local project_dir="$1" |
| 74 | + local build_dir="$2" |
| 75 | + local test_name="CMake iOS generation" |
| 76 | + |
| 77 | + if [ "$CLEAN_BUILDS" = true ] && [ -d "$build_dir" ]; then |
| 78 | + rm -rf "$build_dir" |
| 79 | + fi |
| 80 | + |
| 81 | + mkdir -p "$build_dir" |
| 82 | + |
| 83 | + local cmake_args="-G Xcode -S $project_dir -B $build_dir -DCMAKE_SYSTEM_NAME=iOS" |
| 84 | + |
| 85 | + if [ "$BUILD_FOR_DEVICE" = false ]; then |
| 86 | + cmake_args="$cmake_args -DCMAKE_OSX_SYSROOT=iphonesimulator" |
| 87 | + test_name="CMake iOS Simulator generation" |
| 88 | + else |
| 89 | + cmake_args="$cmake_args -DCMAKE_OSX_SYSROOT=iphoneos" |
| 90 | + test_name="CMake iOS Device generation" |
| 91 | + fi |
| 92 | + |
| 93 | + if cmake $cmake_args > "$build_dir/cmake_output.log" 2>&1; then |
| 94 | + pass "$test_name" |
| 95 | + return 0 |
| 96 | + else |
| 97 | + fail "$test_name" |
| 98 | + echo " CMake output:" |
| 99 | + tail -20 "$build_dir/cmake_output.log" | sed 's/^/ /' |
| 100 | + return 1 |
| 101 | + fi |
| 102 | +} |
| 103 | + |
| 104 | +# Verify Xcode project was created |
| 105 | +# Args: build_dir project_name |
| 106 | +test_xcodeproj_exists() { |
| 107 | + local build_dir="$1" |
| 108 | + local project_name="$2" |
| 109 | + local xcodeproj="$build_dir/$project_name.xcodeproj" |
| 110 | + |
| 111 | + if [ -d "$xcodeproj" ]; then |
| 112 | + pass "$project_name.xcodeproj exists" |
| 113 | + return 0 |
| 114 | + else |
| 115 | + fail "$project_name.xcodeproj exists" |
| 116 | + return 1 |
| 117 | + fi |
| 118 | +} |
| 119 | + |
| 120 | +# Build iOS targets using xcodebuild |
| 121 | +# Args: build_dir project_name |
| 122 | +test_xcode_build_ios() { |
| 123 | + local build_dir="$1" |
| 124 | + local project_name="$2" |
| 125 | + local xcodeproj="$build_dir/$project_name.xcodeproj" |
| 126 | + |
| 127 | + info "Building $project_name for iOS (this may take a while)..." |
| 128 | + |
| 129 | + local sdk="iphonesimulator" |
| 130 | + local destination="generic/platform=iOS Simulator" |
| 131 | + if [ "$BUILD_FOR_DEVICE" = true ]; then |
| 132 | + sdk="iphoneos" |
| 133 | + destination="generic/platform=iOS" |
| 134 | + fi |
| 135 | + |
| 136 | + # Build ALL_BUILD scheme which builds all targets |
| 137 | + if xcodebuild -project "$xcodeproj" \ |
| 138 | + -scheme ALL_BUILD \ |
| 139 | + -configuration Release \ |
| 140 | + -sdk "$sdk" \ |
| 141 | + -destination "$destination" \ |
| 142 | + -quiet \ |
| 143 | + CODE_SIGNING_ALLOWED=NO \ |
| 144 | + > "$build_dir/build_output.log" 2>&1; then |
| 145 | + pass "xcodebuild iOS ALL_BUILD" |
| 146 | + return 0 |
| 147 | + else |
| 148 | + fail "xcodebuild iOS ALL_BUILD" |
| 149 | + echo " Build output (last 40 lines):" |
| 150 | + tail -40 "$build_dir/build_output.log" | sed 's/^/ /' |
| 151 | + return 1 |
| 152 | + fi |
| 153 | +} |
| 154 | + |
| 155 | +# Check iOS bundle exists (flat structure) |
| 156 | +# Args: bundle_path bundle_type |
| 157 | +test_ios_bundle_exists() { |
| 158 | + local bundle_path="$1" |
| 159 | + local bundle_type="$2" |
| 160 | + |
| 161 | + if [ -d "$bundle_path" ]; then |
| 162 | + pass "$bundle_type iOS bundle exists" |
| 163 | + return 0 |
| 164 | + else |
| 165 | + fail "$bundle_type iOS bundle exists ($bundle_path)" |
| 166 | + return 1 |
| 167 | + fi |
| 168 | +} |
| 169 | + |
| 170 | +# Check Info.plist exists in iOS bundle (flat structure) |
| 171 | +# Args: bundle_path bundle_type |
| 172 | +test_ios_info_plist() { |
| 173 | + local bundle_path="$1" |
| 174 | + local bundle_type="$2" |
| 175 | + local plist_path="$bundle_path/Info.plist" |
| 176 | + |
| 177 | + if [ -f "$plist_path" ]; then |
| 178 | + pass "$bundle_type iOS Info.plist exists" |
| 179 | + return 0 |
| 180 | + else |
| 181 | + fail "$bundle_type iOS Info.plist exists ($plist_path)" |
| 182 | + return 1 |
| 183 | + fi |
| 184 | +} |
| 185 | + |
| 186 | +# ============================================================================= |
| 187 | +# Test a complete iOS project |
| 188 | +# ============================================================================= |
| 189 | +# Args: display_name project_dir xcodeproj_name |
| 190 | +test_ios_project() { |
| 191 | + local display_name="$1" |
| 192 | + local project_dir="$2" |
| 193 | + local xcodeproj_name="$3" |
| 194 | + local build_dir="${project_dir}/build-ios-xcode" |
| 195 | + |
| 196 | + local platform_name="Simulator" |
| 197 | + if [ "$BUILD_FOR_DEVICE" = true ]; then |
| 198 | + platform_name="Device" |
| 199 | + fi |
| 200 | + |
| 201 | + section "$display_name - iOS $platform_name" |
| 202 | + |
| 203 | + # Phase 1: Generate Xcode project for iOS |
| 204 | + test_cmake_generate_ios "$project_dir" "$build_dir" || return 1 |
| 205 | + |
| 206 | + # Phase 2: Verify project structure |
| 207 | + test_xcodeproj_exists "$build_dir" "$xcodeproj_name" || return 1 |
| 208 | + |
| 209 | + # Phase 3: Build all iOS targets |
| 210 | + test_xcode_build_ios "$build_dir" "$xcodeproj_name" || return 1 |
| 211 | + |
| 212 | + # Phase 4: Verify iOS bundle outputs |
| 213 | + # CMake Xcode generator puts output in out/Release/ (not out/Release-iphonesimulator/) |
| 214 | + local release_dir="$build_dir/out/Release" |
| 215 | + |
| 216 | + # iOS App bundle |
| 217 | + local app_path="$release_dir/$display_name.app" |
| 218 | + if test_ios_bundle_exists "$app_path" "iOS App"; then |
| 219 | + test_ios_info_plist "$app_path" "iOS App" |
| 220 | + fi |
| 221 | + |
| 222 | + # iOS AUv3 Framework |
| 223 | + local framework_path="$release_dir/${display_name}AU.framework" |
| 224 | + if test_ios_bundle_exists "$framework_path" "iOS AUv3Framework"; then |
| 225 | + test_ios_info_plist "$framework_path" "iOS AUv3Framework" |
| 226 | + fi |
| 227 | + |
| 228 | + # iOS AUv3 Appex |
| 229 | + local appex_path="$release_dir/${display_name}AUv3.appex" |
| 230 | + if test_ios_bundle_exists "$appex_path" "iOS AUv3Appex"; then |
| 231 | + test_ios_info_plist "$appex_path" "iOS AUv3Appex" |
| 232 | + fi |
| 233 | + |
| 234 | + return 0 |
| 235 | +} |
| 236 | + |
| 237 | +# ============================================================================= |
| 238 | +# Main test execution |
| 239 | +# ============================================================================= |
| 240 | +echo "" |
| 241 | +echo "=== CMake iOS Build Test Suite ===" |
| 242 | +echo "" |
| 243 | +echo "Script directory: $SCRIPT_DIR" |
| 244 | +echo "iPlug2 directory: $IPLUG2_DIR" |
| 245 | +if [ "$BUILD_FOR_DEVICE" = true ]; then |
| 246 | + echo "Target: iOS Device (iphoneos)" |
| 247 | +else |
| 248 | + echo "Target: iOS Simulator (iphonesimulator)" |
| 249 | +fi |
| 250 | +echo "" |
| 251 | + |
| 252 | +# List of examples with CMakeLists.txt that have iOS support |
| 253 | +# Exclusions: |
| 254 | +# - WebView examples (IPlugWebUI, IPlugP5js, IPlugSvelteUI): WebView has macOS-specific code |
| 255 | +# - Swift examples (IPlugSwiftUI, IPlugCocoaUI): Uses APIs that require iOS 15+, but iPlug2 targets iOS 14 |
| 256 | +# - REAPER examples: macOS/Windows only |
| 257 | +# - IPlugOSCEditor: OSC/networking may have iOS-specific issues |
| 258 | +EXAMPLES=( |
| 259 | + "IPlugEffect" |
| 260 | + "IPlugInstrument" |
| 261 | + "IPlugControls" |
| 262 | + "IPlugConvoEngine" |
| 263 | + "IPlugChunks" |
| 264 | + "IPlugDrumSynth" |
| 265 | + "IPlugMidiEffect" |
| 266 | + "IPlugResponsiveUI" |
| 267 | + "IPlugSideChain" |
| 268 | + "IPlugSurroundEffect" |
| 269 | + "IPlugVisualizer" |
| 270 | +) |
| 271 | + |
| 272 | +# Test projects with iOS support |
| 273 | +TEST_PROJECTS=( |
| 274 | + "IGraphicsTest" |
| 275 | + "IGraphicsStressTest" |
| 276 | + "MetaParamTest" |
| 277 | +) |
| 278 | + |
| 279 | +# Test each example |
| 280 | +for example in "${EXAMPLES[@]}"; do |
| 281 | + example_dir="$EXAMPLES_DIR/$example" |
| 282 | + |
| 283 | + if [ -f "$example_dir/CMakeLists.txt" ]; then |
| 284 | + test_ios_project "$example" "$example_dir" "$example" |
| 285 | + else |
| 286 | + section "$example" |
| 287 | + info "Skipping - no CMakeLists.txt found" |
| 288 | + fi |
| 289 | +done |
| 290 | + |
| 291 | +# Test each test project |
| 292 | +for test_proj in "${TEST_PROJECTS[@]}"; do |
| 293 | + test_dir="$IPLUG2_DIR/Tests/$test_proj" |
| 294 | + |
| 295 | + if [ -f "$test_dir/CMakeLists.txt" ]; then |
| 296 | + test_ios_project "$test_proj" "$test_dir" "$test_proj" |
| 297 | + else |
| 298 | + section "$test_proj" |
| 299 | + info "Skipping - no CMakeLists.txt found" |
| 300 | + fi |
| 301 | +done |
| 302 | + |
| 303 | +# Also test TemplateProject from iPlug2OOS |
| 304 | +test_ios_project "TemplateProject" "$SCRIPT_DIR/TemplateProject" "TemplateProject" |
| 305 | + |
| 306 | +# ============================================================================= |
| 307 | +# Summary |
| 308 | +# ============================================================================= |
| 309 | +echo "" |
| 310 | +echo "=== Summary ===" |
| 311 | +TOTAL=$((PASSED + FAILED)) |
| 312 | +echo "Total: $TOTAL tests" |
| 313 | +echo -e "Passed: ${GREEN}$PASSED${NC}" |
| 314 | +echo -e "Failed: ${RED}$FAILED${NC}" |
| 315 | + |
| 316 | +if [ ${#FAILED_TESTS[@]} -gt 0 ]; then |
| 317 | + echo "" |
| 318 | + echo "Failed tests:" |
| 319 | + for test in "${FAILED_TESTS[@]}"; do |
| 320 | + echo -e " ${RED}✗${NC} $test" |
| 321 | + done |
| 322 | +fi |
| 323 | + |
| 324 | +# Clean up if requested |
| 325 | +if [ "$CLEAN_BUILDS" = true ]; then |
| 326 | + echo "" |
| 327 | + echo "Cleaning up build directories..." |
| 328 | + rm -rf "$SCRIPT_DIR/TemplateProject/build-ios-xcode" |
| 329 | + for example in "${EXAMPLES[@]}"; do |
| 330 | + rm -rf "$EXAMPLES_DIR/$example/build-ios-xcode" |
| 331 | + done |
| 332 | + for test_proj in "${TEST_PROJECTS[@]}"; do |
| 333 | + rm -rf "$IPLUG2_DIR/Tests/$test_proj/build-ios-xcode" |
| 334 | + done |
| 335 | +fi |
| 336 | + |
| 337 | +echo "" |
| 338 | +if [ $FAILED -gt 0 ]; then |
| 339 | + echo -e "${RED}Some tests failed!${NC}" |
| 340 | + exit 1 |
| 341 | +else |
| 342 | + echo -e "${GREEN}All tests passed!${NC}" |
| 343 | + exit 0 |
| 344 | +fi |
0 commit comments