forked from facebook/idb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·314 lines (270 loc) · 7.75 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/bin/bash
set -e
set -o pipefail
if hash xcpretty 2>/dev/null; then
HAS_XCPRETTY=true
fi
BUILD_DIRECTORY=build
CLI_E2E_PATH=fbsimctl/cli-tests/executable-under-test
function invoke_xcodebuild() {
local arguments=$@
if [[ -n $HAS_XCPRETTY ]]; then
NSUnbufferedIO=YES xcodebuild $arguments | xcpretty -c
else
xcodebuild $arguments
fi
}
function assert_has_carthage() {
if ! command -v carthage; then
echo "build needs 'carthage' to bootstrap dependencies"
echo "You can install it using brew. E.g. $ brew install carthage"
exit 1;
fi
}
function build_fbsimctl_deps() {
if [ -z "$CUSTOM_FBSIMCTL_DEPS_SCRIPT" ]; then
assert_has_carthage
pushd fbsimctl
carthage bootstrap --platform Mac
popd
else
"$CUSTOM_FBSIMCTL_DEPS_SCRIPT"
fi
}
function build_test_deps() {
if [ -z "$CUSTOM_TEST_DEPS_SCRIPT" ]; then
assert_has_carthage
carthage bootstrap --platform Mac
else
"$CUSTOM_TEST_DEPS_SCRIPT"
fi
}
function framework_build() {
local name=$1
local output_directory=$2
invoke_xcodebuild \
-project FBSimulatorControl.xcodeproj \
-scheme $name \
-sdk macosx \
-derivedDataPath $BUILD_DIRECTORY \
build
if [[ -n $output_directory ]]; then
framework_install $name $output_directory
fi
}
function framework_install() {
local name=$1
local output_directory=$2
local artifact="$BUILD_DIRECTORY/Build/Products/Debug/$name.framework"
local output_directory_framework="$output_directory/Frameworks"
echo "Copying Build output of $artifact to $output_directory_framework"
mkdir -p "$output_directory_framework"
cp -R $artifact "$output_directory_framework/"
}
function framework_test() {
local name=$1
invoke_xcodebuild \
-project FBSimulatorControl.xcodeproj \
-scheme $name \
-sdk macosx \
-derivedDataPath $BUILD_DIRECTORY \
test
}
function core_framework_build() {
framework_build FBControlCore $1
}
function core_framework_test() {
framework_test FBControlCore
}
function xctest_framework_build() {
framework_build XCTestBootstrap $1
}
function xctest_framework_test() {
framework_test XCTestBootstrap
}
function simulator_framework_build() {
framework_build FBSimulatorControl $1
}
function simulator_framework_test() {
framework_test FBSimulatorControl
}
function device_framework_build() {
framework_build FBDeviceControl $1
}
function device_framework_test() {
framework_test FBDeviceControl
}
function all_frameworks_build() {
local output_directory=$1
core_framework_build $output_directory
xctest_framework_build $output_directory
simulator_framework_build $output_directory
device_framework_build $output_directory
}
function all_frameworks_test() {
core_framework_test
xctest_framework_test
simulator_framework_test
device_framework_test
}
function strip_framework() {
local FRAMEWORK_PATH="$BUILD_DIRECTORY/Build/Products/Debug/$1"
if [ -d "$FRAMEWORK_PATH" ]; then
echo "Stripping Framework $FRAMEWORK_PATH"
rm -r "$FRAMEWORK_PATH"
fi
}
function cli_build() {
local name=$1
local output_directory=$2
local script_directory=$1/Scripts
invoke_xcodebuild \
-workspace $name/$name.xcworkspace \
-scheme $name \
-sdk macosx \
-derivedDataPath $BUILD_DIRECTORY \
build
strip_framework "FBSimulatorControlKit.framework/Versions/Current/Frameworks/FBSimulatorControl.framework"
strip_framework "FBSimulatorControlKit.framework/Versions/Current/Frameworks/FBDeviceControl.framework"
strip_framework "FBSimulatorControl.framework/Versions/Current/Frameworks/XCTestBootstrap.framework"
strip_framework "FBSimulatorControl.framework/Versions/Current/Frameworks/FBControlCore.framework"
strip_framework "FBDeviceControl.framework/Versions/Current/Frameworks/XCTestBootstrap.framework"
strip_framework "FBDeviceControl.framework/Versions/Current/Frameworks/FBControlCore.framework"
strip_framework "XCTestBootstrap.framework/Versions/Current/Frameworks/FBControlCore.framework"
if [[ -n $output_directory ]]; then
cli_install $output_directory $script_directory
fi
}
function cli_install() {
local output_directory=$1
local script_directory=$2
local cli_artifact="$BUILD_DIRECTORY/Build/Products/Debug/!(*.framework)"
local framework_artifact="$BUILD_DIRECTORY/Build/Products/Debug/*.framework"
local output_directory_cli="$output_directory/bin"
local output_directory_framework="$output_directory/Frameworks"
mkdir -p "$output_directory_cli"
mkdir -p "$output_directory_framework"
shopt -s extglob
echo "Copying Build output from $cli_artifact to $output_directory_cli"
cp -R $cli_artifact "$output_directory_cli"
echo "Copying Build output from $framework_artifact to $output_directory_framework"
cp -R $framework_artifact "$output_directory_framework"
if [[ -d $script_directory ]]; then
echo "Copying Scripts from $script_directory to $output_directory_cli"
cp -R "$2"/* "$output_directory_cli"
fi
shopt -u extglob
}
function cli_framework_test() {
NAME=$1
invoke_xcodebuild \
-workspace $NAME/$NAME.xcworkspace \
-scheme $NAME \
-sdk macosx \
-derivedDataPath $BUILD_DIRECTORY \
test
}
function cli_e2e_test() {
NAME=$1
pushd $NAME/cli-tests
py=$(which python3.6 || which python3 || which python)
$py ./tests.py
popd
}
function print_usage() {
cat <<EOF
./build.sh usage:
/build.sh <target> <command> [<arg>]*
Supported Commands:
help
Print usage.
framework build <output-directory>
Build the FBSimulatorControl.framework. Optionally copies the Framework to <output-directory>
framework test
Build then Test the FBSimulatorControl.framework.
fbsimctl build <output-directory>
Build the fbsimctl exectutable. Optionally copies the executable and it's dependencies to <output-directory>
fbsimctl test
Build the FBSimulatorControlKit.framework and runs the tests.
fbsimctl e2e-test
Build the fbsimctl executable and run fbsimctl's e2e tests against it. Requires python3.
fbxctest build <output-directory>
Build the xctest exectutable. Optionally copies the executable and it's dependencies to <output-directory>
fbxctest test
Builds the FBXCTestKit.framework and runs the tests.
EOF
}
if [[ -n $TARGET ]]; then
echo "using target $TARGET"
elif [[ -n $1 ]]; then
TARGET=$1
echo "using target $TARGET"
else
echo "No target argument or $TARGET provided"
print_usage
exit 1
fi
if [[ -n $COMMAND ]]; then
echo "using command $COMMAND"
elif [[ -n $2 ]]; then
COMMAND=$2
echo "using command $COMMAND"
else
echo "No command argument or $COMMAND provided"
print_usage
exit 1
fi
if [[ -n $OUTPUT_DIRECTORY ]]; then
echo "using output directory $OUTPUT_DIRECTORY"
elif [[ -n $3 ]]; then
echo "using output directory $3"
OUTPUT_DIRECTORY=$3
else
echo "No output directory specified"
fi
case $TARGET in
help)
print_usage;;
framework)
case $COMMAND in
build)
all_frameworks_build $OUTPUT_DIRECTORY;;
test)
build_test_deps
all_frameworks_test;;
*)
echo "Unknown Command $2"
exit 1;;
esac;;
fbsimctl)
build_fbsimctl_deps
case $COMMAND in
build)
cli_build fbsimctl $OUTPUT_DIRECTORY;;
test)
build_test_deps
cli_framework_test fbsimctl;;
e2e-test)
rm -r "$CLI_E2E_PATH" || true
cli_build fbsimctl "$CLI_E2E_PATH"
cli_e2e_test fbsimctl;;
*)
echo "Unknown Command $COMMAND"
exit 1;;
esac;;
fbxctest)
case $COMMAND in
build)
cli_build fbxctest $OUTPUT_DIRECTORY;;
test)
build_test_deps
cli_framework_test fbxctest;;
*)
echo "Unknown Command $COMMAND"
exit 1;;
esac;;
*)
echo "Unknown Command $TARGET"
exit 1;;
esac
# vim: set tabstop=2 shiftwidth=2 filetype=sh: