Skip to content

Commit e995363

Browse files
committed
Revert "script updates"
This reverts commit e937932.
1 parent e937932 commit e995363

File tree

1 file changed

+43
-63
lines changed

1 file changed

+43
-63
lines changed

scripts/test.sh

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

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"
6468
else
65-
WORKSPACE_PATH="${SAMPLE}/Legacy${SAMPLE}Quickstart/${SAMPLE}Example.xcworkspace"
69+
WORKSPACE="${SAMPLE}/${SAMPLE}Example.xcworkspace"
6670
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
7394
else
74-
WORKSPACE_PATH="${SAMPLE}/${SAMPLE}Example.xcworkspace"
95+
SCHEME="${SAMPLE}Example${SWIFT_SUFFIX:-}"
7596
fi
7697
fi
7798

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

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

98118
# Add extra flags
119+
99120
if [[ "$SAMPLE" == Config ]];then
100121
flags+=( -configuration Debug )
101122
fi
@@ -127,52 +148,11 @@ else
127148
fi
128149

129150
function xcb() {
130-
echo "xcodebuild $@"
151+
echo xcodebuild "$@"
131152
xcodebuild "$@" | xcpretty
132153
}
133154

134155
# Run xcodebuild
135156
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[@]}"
178158
echo "$message"

0 commit comments

Comments
 (0)