Skip to content
This repository was archived by the owner on Aug 4, 2022. It is now read-only.

Commit ff54f24

Browse files
authored
Only run the selected Xcode on local runs (#19)
* Switch the selected Xcode install on local runs. * Just run the local xcode. * Fix bug. * more fixes. * Cleanup. * Use args.
1 parent f79e776 commit ff54f24

File tree

1 file changed

+50
-22
lines changed

1 file changed

+50
-22
lines changed

bazel.sh

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,8 @@ fi
9191
ACTION="$1"
9292
TARGET="$2"
9393

94-
# Runs our tests on every available Xcode installation.
95-
ls /Applications/ | grep "Xcode" | while read -r xcode_path; do
96-
xcode_version=$(cat /Applications/$xcode_path/Contents/version.plist \
97-
| grep "CFBundleShortVersionString" -A1 \
98-
| grep string \
99-
| cut -d'>' -f2 \
100-
| cut -d'<' -f1)
101-
if [ -n "$MIN_XCODE_VERSION" ]; then
102-
xcode_version_as_number="$(version_as_number $xcode_version)"
103-
104-
if [ "$xcode_version_as_number" -lt "$MIN_XCODE_VERSION" ]; then
105-
continue
106-
fi
107-
fi
108-
94+
invoke_bazel() {
95+
xcode_version="$1"
10996
extra_args=""
11097
if [ "$ACTION" == "build" ]; then
11198
echo "🏗️ $TARGET with Xcode $xcode_version..."
@@ -117,17 +104,58 @@ ls /Applications/ | grep "Xcode" | while read -r xcode_path; do
117104
else
118105
extra_args="--test_output=errors"
119106
fi
107+
fi
120108

121-
if [ -n "$KOKORO_BUILD_NUMBER" ]; then
109+
bazel clean
110+
bazel $ACTION $TARGET --xcode_version $xcode_version $extra_args $verbosity_flags "${POSITIONAL[@]:2}"
111+
}
112+
113+
if [ -n "$KOKORO_BUILD_NUMBER" ]; then
114+
# Runs our tests on every available Xcode installation.
115+
ls /Applications/ | grep "Xcode" | while read -r xcode_path; do
116+
xcode_version=$(cat /Applications/$xcode_path/Contents/version.plist \
117+
| grep "CFBundleShortVersionString" -A1 \
118+
| grep string \
119+
| cut -d'>' -f2 \
120+
| cut -d'<' -f1)
121+
if [ -n "$MIN_XCODE_VERSION" ]; then
122+
xcode_version_as_number="$(version_as_number $xcode_version)"
123+
124+
if [ "$xcode_version_as_number" -lt "$MIN_XCODE_VERSION" ]; then
125+
continue
126+
fi
127+
fi
128+
129+
if [ "$ACTION" == "test" ]; then
122130
sudo xcode-select --switch /Applications/$xcode_path/Contents/Developer
123131
xcodebuild -version
132+
133+
# Resolves the following crash when switching Xcode versions:
134+
# "Failed to locate a valid instance of CoreSimulatorService in the bootstrap"
135+
launchctl remove com.apple.CoreSimulator.CoreSimulatorService || true
124136
fi
125137

126-
# Resolves the following crash when switching Xcode versions:
127-
# "Failed to locate a valid instance of CoreSimulatorService in the bootstrap"
128-
launchctl remove com.apple.CoreSimulator.CoreSimulatorService || true
138+
invoke_bazel $xcode_version
139+
done
140+
else
141+
# Run against whichever Xcode is currently selected.
142+
selected_xcode_developer_path=$(xcode-select -p)
143+
selected_xcode_contents_path=$(dirname "$selected_xcode_developer_path")
144+
145+
xcode_version=$(cat "$selected_xcode_contents_path/version.plist" \
146+
| grep "CFBundleShortVersionString" -A1 \
147+
| grep string \
148+
| cut -d'>' -f2 \
149+
| cut -d'<' -f1)
150+
if [ -n "$MIN_XCODE_VERSION" ]; then
151+
xcode_version_as_number="$(version_as_number $xcode_version)"
152+
153+
if [ "$xcode_version_as_number" -lt "$MIN_XCODE_VERSION" ]; then
154+
echo "The currently selected Xcode version ($xcode_version_as_number) is less than the desired version ($MIN_XCODE_VERSION)."
155+
echo "Stopping execution..."
156+
exit 1
157+
fi
129158
fi
130159

131-
bazel clean
132-
bazel $ACTION $TARGET --xcode_version $xcode_version $extra_args $verbosity_flags "${POSITIONAL[@]:2}"
133-
done
160+
invoke_bazel $xcode_version
161+
fi

0 commit comments

Comments
 (0)