|
37 | 37 | if [[ -z "${SPM:-}" ]]; then
|
38 | 38 | SPM=false
|
39 | 39 | echo "Defaulting to SPM=$SPM"
|
40 |
| - if [[ -z "${LEGACY:-}" ]]; then |
41 |
| - LEGACY=false |
42 |
| - echo "Defaulting to LEGACY=$LEGACY" |
43 |
| - fi |
| 40 | +fi |
| 41 | +if [[ -z "${LEGACY:-}" ]]; then |
| 42 | + LEGACY=false |
| 43 | + echo "Defaulting to LEGACY=$LEGACY" |
44 | 44 | fi
|
45 | 45 | if [[ -z "${OS:-}" ]]; then
|
46 | 46 | OS=iOS
|
|
56 | 56 | # Set have_secrets to true or false.
|
57 | 57 | source scripts/check_secrets.sh
|
58 | 58 |
|
59 |
| -# Initialize flags |
60 |
| -flags=() |
61 |
| - |
62 |
| -# Set project / workspace |
63 |
| -if [[ "$SPM" == true ]];then |
64 |
| - flags+=( -project "${DIR}/${SAMPLE}Example.xcodeproj" ) |
65 |
| -else |
66 |
| - if [[ "$LEGACY" == true ]]; then |
67 |
| - WORKSPACE="${SAMPLE}/Legacy${SAMPLE}Quickstart/${SAMPLE}Example.xcworkspace" |
| 59 | +# Determine Project Path and OS based on LEGACY flag. |
| 60 | +if [[ "$LEGACY" == true ]]; then |
| 61 | + echo "Configuring for LEGACY build." |
| 62 | + if [[ "$SPM" == true ]]; then |
| 63 | + PROJECT_PATH="${SAMPLE}/Legacy${SAMPLE}Quickstart/${SAMPLE}Example.xcodeproj" |
68 | 64 | else
|
69 |
| - WORKSPACE="${SAMPLE}/${SAMPLE}Example.xcworkspace" |
| 65 | + WORKSPACE_PATH="${SAMPLE}/Legacy${SAMPLE}Quickstart/${SAMPLE}Example.xcworkspace" |
70 | 66 | fi
|
71 |
| - flags+=( -workspace "$WORKSPACE" ) |
72 |
| -fi |
73 |
| - |
74 |
| -# Set scheme |
75 |
| -if [[ -z "${SCHEME:-}" ]]; then |
76 |
| - if [[ "$SPM" == true ]];then |
77 |
| - # Get the list of schemes |
78 |
| - schemes=$(xcodebuild -list -project "${DIR}/${SAMPLE}Example.xcodeproj" | |
79 |
| - grep -E '^\s+' | |
80 |
| - sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') |
81 |
| - |
82 |
| - # Check for the OS-suffixed scheme name |
83 |
| - if echo "$schemes" | grep -q "^${SAMPLE}Example (${OS})$"; then |
84 |
| - SCHEME="${SAMPLE}Example (${OS})" |
85 |
| - # Check for the base scheme name |
86 |
| - elif echo "$schemes" | grep -q "^${SAMPLE}Example$"; then |
87 |
| - SCHEME="${SAMPLE}Example" |
88 |
| - else |
89 |
| - echo "Error: Could not find a suitable scheme for ${SAMPLE}Example in ${OS}." |
90 |
| - echo "Available schemes:" |
91 |
| - echo "$schemes" |
92 |
| - exit 1 |
93 |
| - fi |
| 67 | +else |
| 68 | + echo "Configuring for NON-LEGACY build." |
| 69 | + if [[ "$SPM" == true ]]; then |
| 70 | + # For non-legacy, DIR is passed from the workflow and is the product name. |
| 71 | + # This is the same as SAMPLE. |
| 72 | + PROJECT_PATH="${DIR}/${SAMPLE}Example.xcodeproj" |
94 | 73 | else
|
95 |
| - SCHEME="${SAMPLE}Example${SWIFT_SUFFIX:-}" |
| 74 | + WORKSPACE_PATH="${SAMPLE}/${SAMPLE}Example.xcworkspace" |
96 | 75 | fi
|
97 | 76 | fi
|
98 | 77 |
|
99 |
| -flags+=( -scheme "$SCHEME" ) |
| 78 | +# Initialize flags |
| 79 | +flags=() |
100 | 80 |
|
101 |
| -# Set destination |
| 81 | +# Set destination (now uses the potentially overridden OS variable) |
102 | 82 | if [[ "$OS" == iOS ]]; then
|
103 | 83 | DESTINATION="platform=iOS Simulator,name=${DEVICE}"
|
104 | 84 | flags+=( -destination "$DESTINATION" )
|
|
116 | 96 | fi
|
117 | 97 |
|
118 | 98 | # Add extra flags
|
119 |
| - |
120 | 99 | if [[ "$SAMPLE" == Config ]];then
|
121 | 100 | flags+=( -configuration Debug )
|
122 | 101 | fi
|
@@ -148,11 +127,52 @@ else
|
148 | 127 | fi
|
149 | 128 |
|
150 | 129 | function xcb() {
|
151 |
| - echo xcodebuild "$@" |
| 130 | + echo "xcodebuild $@" |
152 | 131 | xcodebuild "$@" | xcpretty
|
153 | 132 | }
|
154 | 133 |
|
155 | 134 | # Run xcodebuild
|
156 | 135 | sudo xcode-select -s "/Applications/Xcode_${xcode_version}.app/Contents/Developer"
|
157 |
| -xcb "${flags[@]}" |
| 136 | + |
| 137 | +if [[ "$SPM" == true ]]; then |
| 138 | + if [ ! -d "$PROJECT_PATH" ]; then |
| 139 | + echo "Project path does not exist: $PROJECT_PATH" |
| 140 | + exit 1 |
| 141 | + fi |
| 142 | + # Get all schemes from the project, excluding test bundles. |
| 143 | + all_schemes=$(xcodebuild -list -project "$PROJECT_PATH" | |
| 144 | + grep -E '^\s+' | |
| 145 | + sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | |
| 146 | + grep -v "Tests") |
| 147 | + |
| 148 | + # Filter for schemes that are relevant to the current OS. |
| 149 | + # This includes schemes with the OS in their name (e.g., "VisionProExample (visionOS)") |
| 150 | + # and generic schemes that don't specify any OS. |
| 151 | + filtered_schemes=$(echo "$all_schemes" | grep -E "(\(${OS}\)$)|(^((?!iOS|tvOS|macOS|watchOS|catalyst|visionOS).)*$)") |
| 152 | + |
| 153 | + if [ -z "$filtered_schemes" ]; then |
| 154 | + echo "Error: Could not find any suitable schemes for ${SAMPLE}Example in ${OS}." |
| 155 | + echo "Available schemes:" |
| 156 | + echo "$all_schemes" |
| 157 | + exit 1 |
| 158 | + fi |
| 159 | + |
| 160 | + echo "Found schemes to build for OS ${OS}: $filtered_schemes" |
| 161 | + for scheme in $filtered_schemes; do |
| 162 | + echo "Building scheme: $scheme" |
| 163 | + # Create a temporary flags array for this build |
| 164 | + local_flags=("${flags[@]}") |
| 165 | + local_flags+=( -project "$PROJECT_PATH" ) |
| 166 | + local_flags+=( -scheme "$scheme" ) |
| 167 | + xcb "${local_flags[@]}" |
| 168 | + done |
| 169 | +else |
| 170 | + # Legacy workspace logic |
| 171 | + SCHEME="${SAMPLE}Example${SWIFT_SUFFIX:-}" |
| 172 | + local_flags=("${flags[@]}") |
| 173 | + local_flags+=( -workspace "$WORKSPACE_PATH" ) |
| 174 | + local_flags+=( -scheme "$SCHEME" ) |
| 175 | + xcb "${local_flags[@]}" |
| 176 | +fi |
| 177 | + |
158 | 178 | echo "$message"
|
0 commit comments