Skip to content

Commit e937932

Browse files
committed
script updates
1 parent e441825 commit e937932

File tree

1 file changed

+63
-43
lines changed

1 file changed

+63
-43
lines changed

scripts/test.sh

Lines changed: 63 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ fi
3737
if [[ -z "${SPM:-}" ]]; then
3838
SPM=false
3939
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"
4444
fi
4545
if [[ -z "${OS:-}" ]]; then
4646
OS=iOS
@@ -56,49 +56,29 @@ fi
5656
# Set have_secrets to true or false.
5757
source scripts/check_secrets.sh
5858

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"
6864
else
69-
WORKSPACE="${SAMPLE}/${SAMPLE}Example.xcworkspace"
65+
WORKSPACE_PATH="${SAMPLE}/Legacy${SAMPLE}Quickstart/${SAMPLE}Example.xcworkspace"
7066
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"
9473
else
95-
SCHEME="${SAMPLE}Example${SWIFT_SUFFIX:-}"
74+
WORKSPACE_PATH="${SAMPLE}/${SAMPLE}Example.xcworkspace"
9675
fi
9776
fi
9877

99-
flags+=( -scheme "$SCHEME" )
78+
# Initialize flags
79+
flags=()
10080

101-
# Set destination
81+
# Set destination (now uses the potentially overridden OS variable)
10282
if [[ "$OS" == iOS ]]; then
10383
DESTINATION="platform=iOS Simulator,name=${DEVICE}"
10484
flags+=( -destination "$DESTINATION" )
@@ -116,7 +96,6 @@ else
11696
fi
11797

11898
# Add extra flags
119-
12099
if [[ "$SAMPLE" == Config ]];then
121100
flags+=( -configuration Debug )
122101
fi
@@ -148,11 +127,52 @@ else
148127
fi
149128

150129
function xcb() {
151-
echo xcodebuild "$@"
130+
echo "xcodebuild $@"
152131
xcodebuild "$@" | xcpretty
153132
}
154133

155134
# Run xcodebuild
156135
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+
158178
echo "$message"

0 commit comments

Comments
 (0)