forked from realm/realm-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
610 lines (519 loc) · 20.6 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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
#!/bin/sh
##################################################################################
# Custom build tool for Realm Objective C binding.
#
# (C) Copyright 2011-2014 by realm.io.
##################################################################################
# Warning: pipefail is not a POSIX compatible option, but on OS X it works just fine.
# OS X uses a POSIX complain version of bash as /bin/sh, but apparently it does
# not strip away this feature. Also, this will fail if somebody forces the script
# to be run with zsh.
set -o pipefail
set -e
# You can override the version of the core library
# Otherwise, use the default value
if [ -z "$REALM_CORE_VERSION" ]; then
REALM_CORE_VERSION=0.86.0
fi
PATH=/usr/local/bin:/usr/bin:/bin:/usr/libexec:$PATH
if ! [ -z "${JENKINS_HOME}" ]; then
XCPRETTY_PARAMS="--no-utf --report junit --output build/reports/junit.xml"
CODESIGN_PARAMS="CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO"
fi
usage() {
cat <<EOF
Usage: sh $0 command [argument]
command:
download-core: downloads core library (binary version)
clean [xcmode]: clean up/remove all generated files
build [xcmode]: builds iOS and OS X frameworks with release configuration
build-debug [xcmode]: builds iOS and OS X frameworks with debug configuration
ios [xcmode]: builds iOS framework with release configuration
ios-debug [xcmode]: builds iOS framework with debug configuration
ios-dynamic [xcmode]: builds iOS dynamic framework for iOS 8
osx [xcmode]: builds OS X framework with release configuration
osx-debug [xcmode]: builds OS X framework with debug configuration
test-ios [xcmode]: tests iOS framework with release configuration
test-ios-devices: tests iOS on all attached iOS devices with release configuration
test-ios-devices-debug: tests iOS on all attached iOS devices with debug configuration
test-osx [xcmode]: tests OSX framework with release configuration
test [xcmode]: tests iOS and OS X frameworks with release configuration
test-debug [xcmode]: tests iOS and OS X frameworks with debug configuration
test-all [xcmode]: tests iOS and OS X frameworks with debug and release configurations
examples [xcmode]: builds all examples in examples/ in release configuration
examples-debug [xcmode]: builds all examples in examples/ in debug configuration
browser [xcmode]: builds the RealmBrowser OSX app
verify [xcmode]: cleans, removes docs/output/, then runs docs, test-all and examples
docs: builds docs in docs/output
get-version: get the current version
set-version version: set the version
argument:
xcmode: xcodebuild (default), xcpretty or xctool
version: version in the x.y.z format
EOF
}
######################################
# Xcode Helpers
######################################
xcode() {
mkdir -p build/DerivedData
CMD="xcodebuild -IDECustomDerivedDataLocation=build/DerivedData $@"
echo "Building with command:" $CMD
eval $CMD
}
xc() {
if [[ "$XCMODE" == "xcodebuild" ]]; then
xcode "$@"
elif [[ "$XCMODE" == "xcpretty" ]]; then
mkdir -p build
xcode "$@" | tee build/build.log | xcpretty -c ${XCPRETTY_PARAMS} || {
echo "The raw xcodebuild output is available in build/build.log"
exit 1
}
elif [[ "$XCMODE" == "xctool" ]]; then
xctool "$@"
fi
}
xcrealm() {
PROJECT=Realm.xcodeproj
xc "-project $PROJECT $@"
}
build_fat() {
target="$1"
build_prefix="$2"
out_dir="$3"
xcrealm "-scheme '$target' -configuration Release -sdk iphoneos"
xcrealm "-scheme '$target' -configuration Release -sdk iphonesimulator"
srcdir="build/DerivedData/Realm/Build/Products/Release-dynamic"
mkdir -p build/$out_dir
rm -rf build/$out_dir/Realm.framework
cp -R $build_prefix-iphoneos/Realm.framework build/$out_dir
if [ -d build/$out_dir/Realm.framework/Modules/Realm.swiftmodule ]; then
cp $build_prefix-iphonesimulator/Realm.framework/Modules/Realm.swiftmodule/* build/$out_dir/Realm.framework/Modules/Realm.swiftmodule/
fi
xcrun lipo -create "$build_prefix-iphonesimulator/Realm.framework/Realm" "$build_prefix-iphoneos/Realm.framework/Realm" -output "build/$out_dir/Realm.framework/Realm"
}
######################################
# Device Test Helper
######################################
test_ios_devices() {
XCMODE="$2"
serial_numbers_str=$(system_profiler SPUSBDataType | grep "Serial Number: ")
serial_numbers=()
while read -r line; do
number=${line:15} # Serial number starts at position 15
if [[ ${#number} == 40 ]]; then
serial_numbers+=("$number")
fi
done <<< "$serial_numbers_str"
if [[ ${#serial_numbers[@]} == 0 ]]; then
echo "At least one iOS device must be connected to this computer to run device tests"
if [ -z "${JENKINS_HOME}" ]; then
# Don't fail if running locally and there's no device
exit 0
fi
exit 1
fi
configuration="$1"
for device in "${serial_numbers[@]}"; do
xcrealm "-scheme 'iOS Device Tests' -configuration $configuration -destination 'id=$device' test"
done
exit 0
}
######################################
# Input Validation
######################################
if [ "$#" -eq 0 -o "$#" -gt 2 ]; then
usage
exit 1
fi
######################################
# Variables
######################################
# Xcode sets this variable - set to current directory if running standalone
if [ -z "$SRCROOT" ]; then
SRCROOT="$(pwd)"
fi
download_core() {
echo "Downloading dependency: core ${REALM_CORE_VERSION}"
TMP_DIR="/tmp/core_bin"
mkdir -p "${TMP_DIR}"
CORE_TMP_ZIP="${TMP_DIR}/core-${REALM_CORE_VERSION}.zip.tmp"
CORE_ZIP="${TMP_DIR}/core-${REALM_CORE_VERSION}.zip"
if [ ! -f "${CORE_ZIP}" ]; then
curl -L -s "http://static.realm.io/downloads/core/realm-core-${REALM_CORE_VERSION}.zip" -o "${CORE_TMP_ZIP}"
mv "${CORE_TMP_ZIP}" "${CORE_ZIP}"
fi
(
cd "${TMP_DIR}"
rm -rf core
unzip "${CORE_ZIP}"
mv core core-${REALM_CORE_VERSION}
)
rm -rf core-${REALM_CORE_VERSION} core
mv ${TMP_DIR}/core-${REALM_CORE_VERSION} .
ln -s core-${REALM_CORE_VERSION} core
}
COMMAND="$1"
XCMODE="$2"
: ${XCMODE:=xcodebuild} # must be one of: xcodebuild (default), xcpretty, xctool
case "$COMMAND" in
######################################
# Clean
######################################
"clean")
find . -type d -name build -ls -delete
exit 0
;;
######################################
# Download Core Library
######################################
"download-core")
if [ "$REALM_CORE_VERSION" = "current" ]; then
echo "Using version of core already in core/ directory"
exit 0
fi
if [ -d core -a -d ../tightdb -a ! -L core ]; then
# Allow newer versions than expected for local builds as testing
# with unreleased versions is one of the reasons to use a local build
if ! $(grep -i "${REALM_CORE_VERSION} Release notes" core/release_notes.txt >/dev/null); then
echo "Local build of core is out of date."
exit 1
else
echo "The core library seems to be up to date."
fi
elif ! [ -L core ]; then
echo "core is not a symlink. Deleting..."
rm -rf core
download_core
elif ! $(head -n 1 core/release_notes.txt | grep -i ${REALM_CORE_VERSION} >/dev/null); then
download_core
else
echo "The core library seems to be up to date."
fi
exit 0
;;
######################################
# Building
######################################
"build")
sh build.sh ios "$XCMODE"
sh build.sh osx "$XCMODE"
exit 0
;;
"build-debug")
sh build.sh ios-debug "$XCMODE"
sh build.sh osx-debug "$XCMODE"
exit 0
;;
"ios")
build_fat iOS build/DerivedData/Realm/Build/Products/Release ios
exit 0
;;
"ios-dynamic")
build_fat 'iOS 8' build/DerivedData/Realm/Build/Products/Release-dynamic ios-dynamic
exit 0
;;
"osx")
xcrealm "-scheme OSX -configuration Release"
exit 0
;;
"ios-debug")
xcrealm "-scheme iOS -configuration Debug"
exit 0
;;
"osx-debug")
xcrealm "-scheme OSX -configuration Debug"
exit 0
;;
######################################
# Testing
######################################
"test")
set +e # Run both sets of tests even if the first fails
failed=0
sh build.sh test-ios "$XCMODE" || failed=1
sh build.sh test-ios-devices "$XCMODE" || failed=1
sh build.sh test-osx "$XCMODE" || failed=1
exit $failed
;;
"test-debug")
set +e
failed=0
sh build.sh test-ios-debug "$XCMODE" || failed=1
sh build.sh test-ios-devices-debug "$XCMODE" || failed=1
sh build.sh test-osx-debug "$XCMODE" || failed=1
exit $failed
;;
"test-all")
set +e
failed=0
sh build.sh test "$XCMODE" || failed=1
sh build.sh test-debug "$XCMODE" || failed=1
exit $failed
;;
"test-ios")
xcrealm "-scheme iOS -configuration Release -sdk iphonesimulator -destination 'name=iPhone 6' test"
xcrealm "-scheme iOS -configuration Release -sdk iphonesimulator -destination 'name=iPhone 4S' test"
xcrealm "-scheme 'iOS 8' -configuration Release -sdk iphonesimulator -destination 'name=iPhone 6' test"
exit 0
;;
"test-ios-devices")
test_ios_devices "Release" "$XCMODE"
;;
"test-osx")
xcrealm "-scheme OSX -configuration Release test"
exit 0
;;
"test-ios-debug")
xcrealm "-scheme iOS -configuration Debug -sdk iphonesimulator -destination 'name=iPhone 6' test"
xcrealm "-scheme iOS -configuration Debug -sdk iphonesimulator -destination 'name=iPhone 4S' test"
xcrealm "-scheme 'iOS 8' -configuration Debug -sdk iphonesimulator -destination 'name=iPhone 6' test"
exit 0
;;
"test-ios-devices-debug")
test_ios_devices "Debug" "$XCMODE"
;;
"test-osx-debug")
xcrealm "-scheme OSX -configuration Debug test"
exit 0
;;
"test-cover")
echo "Not yet implemented"
exit 0
;;
"verify")
sh build.sh docs
sh build.sh test-all "$XCMODE"
sh build.sh examples "$XCMODE"
sh build.sh browser "$XCMODE"
(
cd examples/osx/objc/build/DerivedData/RealmExamples/Build/Products/Release
DYLD_FRAMEWORK_PATH=. ./JSONImport
) || exit 1
exit 0
;;
######################################
# Docs
######################################
"docs")
sh scripts/build-docs.sh
exit 0
;;
######################################
# Examples
######################################
"examples")
sh build.sh clean
cd examples
xc "-project ios/objc/RealmExamples.xcodeproj -scheme Simple -configuration Release build ${CODESIGN_PARAMS}"
xc "-project ios/objc/RealmExamples.xcodeproj -scheme TableView -configuration Release build ${CODESIGN_PARAMS}"
xc "-project ios/objc/RealmExamples.xcodeproj -scheme Migration -configuration Release build ${CODESIGN_PARAMS}"
xc "-project ios/objc/RealmExamples.xcodeproj -scheme Backlink -configuration Release build ${CODESIGN_PARAMS}"
xc "-project ios/objc/RealmExamples.xcodeproj -scheme GroupedTableView -configuration Release build ${CODESIGN_PARAMS}"
xc "-project osx/objc/RealmExamples.xcodeproj -scheme JSONImport -configuration Release build ${CODESIGN_PARAMS}"
xc "-project ios/swift/RealmExamples.xcodeproj -scheme Simple -configuration Release build ${CODESIGN_PARAMS}"
xc "-project ios/swift/RealmExamples.xcodeproj -scheme TableView -configuration Release build ${CODESIGN_PARAMS}"
xc "-project ios/swift/RealmExamples.xcodeproj -scheme Migration -configuration Release build ${CODESIGN_PARAMS}"
xc "-project ios/swift/RealmExamples.xcodeproj -scheme Encryption -configuration Release build ${CODESIGN_PARAMS}"
xc "-project ios/swift/RealmExamples.xcodeproj -scheme Backlink -configuration Release build ${CODESIGN_PARAMS}"
xc "-project ios/swift/RealmExamples.xcodeproj -scheme GroupedTableView -configuration Release build ${CODESIGN_PARAMS}"
exit 0
;;
"examples-debug")
sh build.sh clean
cd examples
xc "-project ios/objc/RealmExamples.xcodeproj -scheme Simple -configuration Debug build ${CODESIGN_PARAMS}"
xc "-project ios/objc/RealmExamples.xcodeproj -scheme TableView -configuration Debug build ${CODESIGN_PARAMS}"
xc "-project ios/objc/RealmExamples.xcodeproj -scheme Migration -configuration Debug build ${CODESIGN_PARAMS}"
xc "-project ios/objc/RealmExamples.xcodeproj -scheme Backlink -configuration Debug build ${CODESIGN_PARAMS}"
xc "-project ios/objc/RealmExamples.xcodeproj -scheme GroupedTableView -configuration Debug build ${CODESIGN_PARAMS}"
xc "-project osx/objc/RealmExamples.xcodeproj -scheme JSONImport -configuration Debug build ${CODESIGN_PARAMS}"
xc "-project ios/swift/RealmExamples.xcodeproj -scheme Simple -configuration Debug build ${CODESIGN_PARAMS}"
xc "-project ios/swift/RealmExamples.xcodeproj -scheme TableView -configuration Debug build ${CODESIGN_PARAMS}"
xc "-project ios/swift/RealmExamples.xcodeproj -scheme Migration -configuration Debug build ${CODESIGN_PARAMS}"
xc "-project ios/swift/RealmExamples.xcodeproj -scheme Encryption -configuration Debug build ${CODESIGN_PARAMS}"
xc "-project ios/swift/RealmExamples.xcodeproj -scheme Backlink -configuration Debug build ${CODESIGN_PARAMS}"
xc "-project ios/swift/RealmExamples.xcodeproj -scheme GroupedTableView -configuration Debug build ${CODESIGN_PARAMS}"
exit 0
;;
######################################
# Browser
######################################
"browser")
xc "-project tools/RealmBrowser/RealmBrowser.xcodeproj -scheme RealmBrowser -configuration Release clean build ${CODESIGN_PARAMS}"
exit 0
;;
######################################
# Versioning
######################################
"get-version")
version_file="Realm/Realm-Info.plist"
echo "$(PlistBuddy -c "Print :CFBundleVersion" "$version_file")"
exit 0
;;
"set-version")
realm_version="$2"
version_files="Realm/Realm-Info.plist tools/RealmBrowser/RealmBrowser/RealmBrowser-Info.plist"
if [ -z "$realm_version" ]; then
echo "You must specify a version."
exit 1
fi
for version_file in $version_files; do
PlistBuddy -c "Set :CFBundleVersion $realm_version" "$version_file"
PlistBuddy -c "Set :CFBundleShortVersionString $realm_version" "$version_file"
done
exit 0
;;
######################################
# CocoaPods
######################################
"cocoapods-setup")
sh build.sh download-core
# CocoaPods seems to not like symlinks
mv core tmp
mv $(readlink tmp) core
rm tmp
mkdir include-ios
cp -R core/include/* include-ios
mkdir include-ios/Realm
cp Realm/*.{h,hpp} include-ios/Realm
cp Realm/ios/*.h include-ios/Realm
mkdir include-osx
cp -R core/include/* include-osx
mkdir include-osx/Realm
cp Realm/*.{h,hpp} include-osx/Realm
cp Realm/osx/*.h include-osx/Realm
;;
######################################
# Release packaging
######################################
"package-browser")
cd tightdb_objc
sh build.sh browser "$XCMODE"
cd ${WORKSPACE}/tightdb_objc/tools/RealmBrowser/build/DerivedData/RealmBrowser/Build/Products/Release
zip -r realm-browser.zip Realm\ Browser.app
mv realm-browser.zip ${WORKSPACE}
;;
"package-docs")
cd tightdb_objc
sh build.sh docs
cd docs/output/*
tar --exclude='realm-docset.tgz' \
--exclude='realm.xar' \
-cvzf \
realm-docs.tgz *
;;
"package-examples")
cd tightdb_objc
./scripts/package_examples.rb
zip --symlinks -r realm-obj-examples.zip examples
;;
"package-test-examples")
VERSION=$(file realm-cocoa-*.zip | grep -o '\d*\.\d*\.\d*')
unzip realm-cocoa-*.zip
cp $0 realm-cocoa-${VERSION}
cd realm-cocoa-${VERSION}
sh build.sh examples "$XCMODE"
cd ..
rm -rf realm-cocoa-*
;;
"package-ios")
cd tightdb_objc
sh build.sh test-ios "$XCMODE"
sh build.sh examples "$XCMODE"
cd build/ios
zip --symlinks -r realm-framework-ios.zip Realm.framework
;;
"package-osx")
cd tightdb_objc
sh build.sh test-osx "$XCMODE"
cd build/DerivedData/Realm/Build/Products/Release
zip --symlinks -r realm-framework-osx.zip Realm.framework
;;
"package-release")
TEMPDIR=$(mktemp -d /tmp/realm-release-package.XXXX)
cd tightdb_objc
VERSION=$(sh build.sh get-version)
cd ..
mkdir -p ${TEMPDIR}/realm-cocoa-${VERSION}/osx
mkdir -p ${TEMPDIR}/realm-cocoa-${VERSION}/ios
mkdir -p ${TEMPDIR}/realm-cocoa-${VERSION}/browser
(
cd ${TEMPDIR}/realm-cocoa-${VERSION}/osx
unzip ${WORKSPACE}/realm-framework-osx.zip
)
(
cd ${TEMPDIR}/realm-cocoa-${VERSION}/ios
unzip ${WORKSPACE}/realm-framework-ios.zip
)
(
cd ${TEMPDIR}/realm-cocoa-${VERSION}/browser
unzip ${WORKSPACE}/realm-browser.zip
)
(
cd ${TEMPDIR}/realm-cocoa-${VERSION}
unzip ${WORKSPACE}/realm-obj-examples.zip
)
cp -R ${WORKSPACE}/tightdb_objc/plugin ${TEMPDIR}/realm-cocoa-${VERSION}
cp ${WORKSPACE}/tightdb_objc/LICENSE ${TEMPDIR}/realm-cocoa-${VERSION}/LICENSE.txt
mkdir -p ${TEMPDIR}/realm-cocoa-${VERSION}/Swift
cp ${WORKSPACE}/tightdb_objc/Realm/Swift/RLMSupport.swift ${TEMPDIR}/realm-cocoa-${VERSION}/Swift/
cat > ${TEMPDIR}/realm-cocoa-${VERSION}/docs.webloc <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>URL</key>
<string>http://realm.io/docs/ios/latest</string>
</dict>
</plist>
EOF
(
cd ${TEMPDIR}
zip --symlinks -r realm-cocoa-${VERSION}.zip realm-cocoa-${VERSION}
mv realm-cocoa-${VERSION}.zip ${WORKSPACE}
)
;;
"test-package-release")
# Generate a release package locally for testing purposes
# Real releases should always be done via Jenkins
if [ -z "${WORKSPACE}" ]; then
echo 'WORKSPACE must be set to a directory to assemble the release in'
exit 1
fi
if [ -d "${WORKSPACE}" ]; then
echo 'WORKSPACE directory should not already exist'
exit 1
fi
REALM_SOURCE=$(pwd)
mkdir $WORKSPACE
cd $WORKSPACE
git clone $REALM_SOURCE tightdb_objc
echo 'Packaging iOS'
sh tightdb_objc/build.sh package-ios "$XCMODE"
cp tightdb_objc/build/ios/realm-framework-ios.zip .
echo 'Packaging OS X'
sh tightdb_objc/build.sh package-osx "$XCMODE"
cp tightdb_objc/build/DerivedData/Realm/Build/Products/Release/realm-framework-osx.zip .
echo 'Packaging docs'
sh tightdb_objc/build.sh package-docs
cp tightdb_objc/docs/output/*/realm-docs.tgz .
echo 'Packaging examples'
cd tightdb_objc/examples
git clean -xfd
cd ../..
sh tightdb_objc/build.sh package-examples "$XCMODE"
cp tightdb_objc/realm-obj-examples.zip .
echo 'Packaging browser'
sh tightdb_objc/build.sh package-browser "$XCMODE"
echo 'Building final release package'
sh tightdb_objc/build.sh package-release
echo 'Testing packaged examples'
sh tightdb_objc/build.sh package-test-examples "$XCMODE"
;;
*)
usage
exit 1
;;
esac