Skip to content

Commit 5930ad2

Browse files
authored
Factor out a universal build script (#884)
* Add a universal build script * Rewrite test.sh in terms of universal build
1 parent 8ef0f14 commit 5930ad2

File tree

3 files changed

+157
-106
lines changed

3 files changed

+157
-106
lines changed

Firestore/test.sh

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,54 +13,8 @@
1313

1414
set -euo pipefail
1515

16-
FIRESTORE_DIR=$(dirname "${BASH_SOURCE[0]}")
16+
firestore_dir=$(dirname "${BASH_SOURCE[0]}")
17+
scripts_dir="$firestore_dir/../scripts"
1718

18-
test_iOS() {
19-
xcodebuild \
20-
-workspace "$FIRESTORE_DIR/Example/Firestore.xcworkspace" \
21-
-scheme Firestore_Tests \
22-
-sdk iphonesimulator \
23-
-destination 'platform=iOS Simulator,name=iPhone 7' \
24-
build \
25-
test \
26-
ONLY_ACTIVE_ARCH=YES \
27-
CODE_SIGNING_REQUIRED=NO \
28-
| xcpretty
29-
30-
xcodebuild \
31-
-workspace "$FIRESTORE_DIR/Example/Firestore.xcworkspace" \
32-
-scheme SwiftBuildTest \
33-
-sdk iphonesimulator \
34-
-destination 'platform=iOS Simulator,name=iPhone 7' \
35-
build \
36-
ONLY_ACTIVE_ARCH=YES \
37-
CODE_SIGNING_REQUIRED=NO \
38-
| xcpretty
39-
}
40-
41-
test_CMake() {
42-
echo "cpu core: $(sysctl -n hw.ncpu)"
43-
echo "prepare cmake build" && \
44-
mkdir -p build && \
45-
cd build && \
46-
cmake .. || \
47-
exit 1
48-
49-
echo "cmake build and test" && \
50-
make -j $(sysctl -n hw.ncpu) all || \
51-
exit 2
52-
}
53-
54-
test_iOS; RESULT=$?
55-
if [[ $RESULT == 65 ]]; then
56-
echo "xcodebuild exited with 65, retrying"
57-
sleep 5
58-
59-
test_iOS; RESULT=$?
60-
fi
61-
62-
if [ $RESULT != 0 ]; then exit $RESULT; fi
63-
64-
test_CMake; RESULT=$?
65-
66-
if [ $RESULT != 0 ]; then exit $RESULT; fi
19+
$scripts_dir/build.sh Firestore iOS
20+
$scripts_dir/build.sh Firestore macOS cmake

scripts/build.sh

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2018 Google
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# USAGE: build.sh product [platform] [method]
18+
#
19+
# Builds the given product for the given platform using the given build method
20+
21+
set -euo pipefail
22+
23+
if [[ $# -lt 1 ]]; then
24+
cat 1>&2 <<EOF
25+
USAGE: $0 product [platform] [method]
26+
27+
product can be one of:
28+
Firebase
29+
Firestore
30+
31+
platform can be one of:
32+
iOS (default)
33+
macOS
34+
tvOS
35+
36+
method can be one of:
37+
xcodebuild (default)
38+
cmake
39+
EOF
40+
exit 1
41+
fi
42+
43+
product="$1"
44+
45+
platform="iOS"
46+
if [[ $# -gt 1 ]]; then
47+
platform="$2"
48+
fi
49+
50+
method="xcodebuild"
51+
if [[ $# -gt 2 ]]; then
52+
method="$3"
53+
fi
54+
55+
echo "Building $product for $platform using $method"
56+
57+
# Runs xcodebuild with the given flags, piping output to xcpretty
58+
# If xcodebuild fails with known error codes, retries once.
59+
function RunXcodebuild() {
60+
xcodebuild "$@" | xcpretty; result=$?
61+
if [[ $result == 65 ]]; then
62+
echo "xcodebuild exited with 65, retrying" 1>&2
63+
sleep 5
64+
65+
xcodebuild "$@" | xcpretty; result=$?
66+
fi
67+
if [[ $result != 0 ]]; then
68+
exit $result
69+
fi
70+
}
71+
72+
# Compute standard flags for all platforms
73+
case "$platform" in
74+
iOS)
75+
xcb_flags=(
76+
-sdk 'iphonesimulator'
77+
-destination 'platform=iOS Simulator,name=iPhone 7'
78+
)
79+
;;
80+
81+
macOS)
82+
xcb_flags=(
83+
-sdk 'macosx'
84+
-destination 'platform=OS X,arch=x86_64'
85+
)
86+
;;
87+
88+
tvOS)
89+
xcb_flags=(
90+
-sdk "appletvsimulator"
91+
-destination 'platform=tvOS Simulator,name=Apple TV'
92+
)
93+
;;
94+
95+
*)
96+
echo "Unknown platform '$platform'" 1>&2
97+
exit 1
98+
;;
99+
esac
100+
101+
xcb_flags+=(
102+
ONLY_ACTIVE_ARCH=YES
103+
CODE_SIGNING_REQUIRED=NO
104+
)
105+
106+
case "$product-$method-$platform" in
107+
Firebase-xcodebuild-*)
108+
RunXcodebuild \
109+
-workspace 'Example/Firebase.xcworkspace' \
110+
-scheme "AllUnitTests_$platform" \
111+
"${xcb_flags[@]}" \
112+
build \
113+
test
114+
;;
115+
116+
Firestore-xcodebuild-iOS)
117+
RunXcodebuild \
118+
-workspace 'Firestore/Example/Firestore.xcworkspace' \
119+
-scheme 'Firestore_Tests' \
120+
"${xcb_flags[@]}" \
121+
build \
122+
test
123+
124+
RunXcodebuild \
125+
-workspace 'Firestore/Example/Firestore.xcworkspace' \
126+
-scheme 'SwiftBuildTest' \
127+
"${xcb_flags[@]}" \
128+
build
129+
;;
130+
131+
Firestore-cmake-macOS)
132+
test -d build || mkdir build
133+
echo "Preparing cmake build ..."
134+
(cd build; cmake ..)
135+
136+
echo "Building cmake build ..."
137+
cpus=$(sysctl -n hw.ncpu)
138+
(cd build; make -j $cpus all)
139+
;;
140+
141+
*)
142+
echo "Don't know how to build this product-platform-method combination" 1>&2
143+
echo " product=$product" 1>&2
144+
echo " platform=$platform" 1>&2
145+
echo " method=$method" 1>&2
146+
exit 1
147+
;;
148+
esac

test.sh

Lines changed: 5 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,60 +13,9 @@
1313

1414
set -eo pipefail
1515

16-
test_iOS() {
17-
xcodebuild \
18-
-workspace Example/Firebase.xcworkspace \
19-
-scheme AllUnitTests_iOS \
20-
-sdk iphonesimulator \
21-
-destination 'platform=iOS Simulator,name=iPhone 7' \
22-
build \
23-
test \
24-
ONLY_ACTIVE_ARCH=YES \
25-
CODE_SIGNING_REQUIRED=NO \
26-
| xcpretty
27-
}
16+
top_dir=$(dirname "${BASH_SOURCE[0]}")
17+
scripts_dir="$top_dir/scripts"
2818

29-
test_macOS() {
30-
xcodebuild \
31-
-workspace Example/Firebase.xcworkspace \
32-
-scheme AllUnitTests_macOS \
33-
-sdk macosx \
34-
-destination 'platform=OS X,arch=x86_64' \
35-
build \
36-
test \
37-
ONLY_ACTIVE_ARCH=YES \
38-
CODE_SIGNING_REQUIRED=NO \
39-
| xcpretty
40-
}
41-
42-
test_tvOS() {
43-
xcodebuild \
44-
-workspace Example/Firebase.xcworkspace \
45-
-scheme AllUnitTests_tvOS \
46-
-sdk appletvsimulator \
47-
-destination 'platform=tvOS Simulator,name=Apple TV' \
48-
build \
49-
test \
50-
ONLY_ACTIVE_ARCH=YES \
51-
CODE_SIGNING_REQUIRED=NO \
52-
| xcpretty
53-
}
54-
55-
test_iOS; RESULT=$?
56-
57-
if [ $RESULT != 0 ]; then exit $RESULT; fi
58-
59-
test_macOS; RESULT=$?
60-
61-
if [ $RESULT == 65 ]; then
62-
echo "xcodebuild exited with 65, retrying"
63-
sleep 5
64-
65-
test_macOS; RESULT=$?
66-
fi
67-
68-
if [ $RESULT != 0 ]; then exit $RESULT; fi
69-
70-
test_tvOS; RESULT=$?
71-
72-
if [ $RESULT != 0 ]; then exit $RESULT; fi
19+
$scripts_dir/build.sh Firebase iOS
20+
$scripts_dir/build.sh Firebase macOS
21+
$scripts_dir/build.sh Firebase tvOS

0 commit comments

Comments
 (0)