Skip to content

Commit 7452958

Browse files
authored
[Infra] Avoid subshells in test script (#11094)
1 parent 8badb28 commit 7452958

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

scripts/check_firestore_symbols.sh

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#
3535
# USAGE: ./check_firestore_symbols.sh <PATH_TO_FIREBASE_REPO> <PATH_TO_FIRESTORE_XCFRAMEWORK>
3636

37+
set -euo pipefail
38+
3739
if [[ $# -ne 2 ]]; then
3840
echo "Usage: ./check_firestore_symbols.sh <PATH_TO_FIREBASE_REPO> <PATH_TO_FIRESTORE_XCFRAMEWORK>"
3941
exit 1
@@ -123,35 +125,38 @@ cd "$TEST_PKG_ROOT"
123125
# Build the test package *without* the `-ObjC` linker flag, and dump the
124126
# resulting executable file's Objective-C symbols into a text file.
125127
echo "Building test package without -ObjC linker flag..."
126-
# Invoke a subshell to avoid pipefail affecting the rest of the script.
127-
(
128-
set -eo pipefail && FIREBASECI_USE_LOCAL_FIRESTORE_ZIP=1 \
129-
xcodebuild -scheme 'TestPkg' -destination 'generic/platform=macOS' \
130-
-derivedDataPath "$HOME/Library/Developer/Xcode/DerivedData/TestPkg" \
131-
| xcpretty
132-
)
133-
128+
FIREBASECI_USE_LOCAL_FIRESTORE_ZIP=1 xcodebuild -scheme 'TestPkg' \
129+
-destination 'generic/platform=macOS' \
130+
-derivedDataPath "$HOME/Library/Developer/Xcode/DerivedData/TestPkg" \
131+
| xcpretty
134132

135133
nm ~/Library/Developer/Xcode/DerivedData/TestPkg/Build/Products/Debug/TestPkg \
136134
| grep -o "[-+]\[.*\]" > objc_symbols_without_linker_flag.txt
137135

138136
# Build the test package *with* the -ObjC linker flag, and dump the
139137
# resulting executable file's Objective-C symbols into a text file.
140138
echo "Building test package with -ObjC linker flag..."
141-
# Invoke a subshell to avoid pipefail affecting the rest of the script.
142-
(
143-
set -eo pipefail && FIREBASECI_USE_LOCAL_FIRESTORE_ZIP=1 \
144-
xcodebuild -scheme 'TestPkg' -destination 'generic/platform=macOS' \
145-
-derivedDataPath "$HOME/Library/Developer/Xcode/DerivedData/TestPkg-ObjC" \
146-
OTHER_LDFLAGS='-ObjC' \
147-
| xcpretty
148-
)
139+
FIREBASECI_USE_LOCAL_FIRESTORE_ZIP=1 xcodebuild -scheme 'TestPkg' \
140+
-destination 'generic/platform=macOS' \
141+
-derivedDataPath "$HOME/Library/Developer/Xcode/DerivedData/TestPkg-ObjC" \
142+
OTHER_LDFLAGS='-ObjC' \
143+
| xcpretty
149144

150145
nm ~/Library/Developer/Xcode/DerivedData/TestPkg-ObjC/Build/Products/Debug/TestPkg \
151146
| grep -o "[-+]\[.*\]" > objc_symbols_with_linker_flag.txt
152147

153-
# Compare the two text files to see if the -ObjC linker flag has any effect.
154-
DIFF=$(diff objc_symbols_without_linker_flag.txt objc_symbols_with_linker_flag.txt)
148+
# Compare the two text files to see if the -ObjC linker flag caused additional
149+
# symbols to link.
150+
#
151+
# Note: In the case where the diff is non-empty, the diff command will
152+
# return exit code 1, which will cause the set pipefail to terminate execution.
153+
# To avoid this, `|| true` ensures the exit code always indicates success.
154+
DIFF=$(
155+
git diff --no-index \
156+
objc_symbols_without_linker_flag.txt \
157+
objc_symbols_with_linker_flag.txt \
158+
|| true
159+
)
155160
if [[ -n "$DIFF" ]]; then
156161
echo "Failure: Unlinked Objective-C symbols have been detected:"
157162
echo "$DIFF"

0 commit comments

Comments
 (0)