|
37 | 37 | if [[ -z "${SPM:-}" ]]; then
|
38 | 38 | SPM=false
|
39 | 39 | echo "Defaulting to SPM=$SPM"
|
40 |
| -fi |
41 |
| -if [[ -z "${LEGACY:-}" ]]; then |
42 |
| - LEGACY=false |
43 |
| - echo "Defaulting to LEGACY=$LEGACY" |
| 40 | + if [[ -z "${LEGACY:-}" ]]; then |
| 41 | + LEGACY=false |
| 42 | + echo "Defaulting to LEGACY=$LEGACY" |
| 43 | + fi |
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 |
| -# 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" |
| 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" |
64 | 68 | else
|
65 |
| - WORKSPACE_PATH="${SAMPLE}/Legacy${SAMPLE}Quickstart/${SAMPLE}Example.xcworkspace" |
| 69 | + WORKSPACE="${SAMPLE}/${SAMPLE}Example.xcworkspace" |
66 | 70 | 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" |
| 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 |
73 | 94 | else
|
74 |
| - WORKSPACE_PATH="${SAMPLE}/${SAMPLE}Example.xcworkspace" |
| 95 | + SCHEME="${SAMPLE}Example${SWIFT_SUFFIX:-}" |
75 | 96 | fi
|
76 | 97 | fi
|
77 | 98 |
|
78 |
| -# Initialize flags |
79 |
| -flags=() |
| 99 | +flags+=( -scheme "$SCHEME" ) |
80 | 100 |
|
81 |
| -# Set destination (now uses the potentially overridden OS variable) |
| 101 | +# Set destination |
82 | 102 | if [[ "$OS" == iOS ]]; then
|
83 | 103 | DESTINATION="platform=iOS Simulator,name=${DEVICE}"
|
84 | 104 | flags+=( -destination "$DESTINATION" )
|
|
96 | 116 | fi
|
97 | 117 |
|
98 | 118 | # Add extra flags
|
| 119 | + |
99 | 120 | if [[ "$SAMPLE" == Config ]];then
|
100 | 121 | flags+=( -configuration Debug )
|
101 | 122 | fi
|
@@ -127,52 +148,11 @@ else
|
127 | 148 | fi
|
128 | 149 |
|
129 | 150 | function xcb() {
|
130 |
| - echo "xcodebuild $@" |
| 151 | + echo xcodebuild "$@" |
131 | 152 | xcodebuild "$@" | xcpretty
|
132 | 153 | }
|
133 | 154 |
|
134 | 155 | # Run xcodebuild
|
135 | 156 | sudo xcode-select -s "/Applications/Xcode_${xcode_version}.app/Contents/Developer"
|
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 |
| - |
| 157 | +xcb "${flags[@]}" |
178 | 158 | echo "$message"
|
0 commit comments