forked from realm/realm-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·1140 lines (966 loc) · 37.8 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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
##################################################################################
# Custom build tool for Realm Objective-C binding.
#
# (C) Copyright 2011-2015 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
: ${REALM_CORE_VERSION:=0.95.0} # set to "current" to always use the current build
# You can override the xcmode used
: ${XCMODE:=xcodebuild} # must be one of: xcodebuild (default), xcpretty, xctool
PATH=/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
export REALM_SKIP_DEBUGGER_CHECKS=YES
usage() {
cat <<EOF
Usage: sh $0 command [argument]
command:
clean: clean up/remove all generated files
download-core: downloads core library (binary version)
set-core-bitcode-symlink: set core symlink to bitcode version for Xcode 7+ or non-bitcode version otherwise
build: builds all iOS and OS X frameworks
ios-static: builds fat iOS static framework
ios-dynamic: builds iOS dynamic frameworks
ios-swift: builds RealmSwift frameworks for iOS
watchos: builds watchOS framwork
watchos-swift: builds RealmSwift framework for watchOS
osx: builds OS X framework
osx-swift: builds RealmSwift framework for OS X
test: tests all iOS and OS X frameworks
test-all: tests all iOS and OS X frameworks in both Debug and Release configurations
test-ios-static: tests static iOS framework on 32-bit and 64-bit simulators
test-ios-dynamic: tests dynamic iOS framework on 32-bit and 64-bit simulators
test-ios-swift: tests RealmSwift iOS framework on 32-bit and 64-bit simulators
test-ios-devices: tests ObjC & Swift iOS frameworks on all attached iOS devices
test-ios-devices-objc: tests ObjC iOS framework on all attached iOS devices
test-ios-devices-swift: tests Swift iOS framework on all attached iOS devices
test-osx: tests OS X framework
test-osx-swift: tests RealmSwift OS X framework
verify: verifies docs, osx, osx-swift, ios-static, ios-dynamic, ios-swift, ios-device in both Debug and Release configurations, swiftlint
docs: builds docs in docs/output
examples: builds all examples
examples-ios: builds all static iOS examples
examples-ios-swift: builds all Swift iOS examples
examples-osx: builds all OS X examples
get-version: get the current version
set-version version: set the version
cocoapods-setup: download realm-core and create a stub RLMPlatform.h file to enable building via CocoaPods
argument:
version: version in the x.y.z format
environment variables:
XCMODE: xcodebuild (default), xcpretty or xctool
CONFIGURATION: Debug or Release (default)
REALM_CORE_VERSION: version in x.y.z format or "current" to use local build
REALM_EXTRA_BUILD_ARGUMENTS: additional arguments to pass to the build tool
EOF
}
######################################
# Xcode Helpers
######################################
xcode() {
mkdir -p build/DerivedData
CMD="xcodebuild -IDECustomDerivedDataLocation=build/DerivedData $@ $REALM_EXTRA_BUILD_ARGUMENTS"
echo "Building with command:" $CMD
eval "$CMD"
}
xc() {
# Logs xcodebuild output in realtime
: ${NSUnbufferedIO:=YES}
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
}
copy_bcsymbolmap() {
find "$1" -name '*.bcsymbolmap' -type f -exec cp {} "$2" \;
}
build_ios_combined() {
local scheme="$1"
local module_name="$2"
local scope_suffix="$3"
local version_suffix="$4"
local config="$CONFIGURATION"
# Derive build paths
local build_products_path="build/DerivedData/Realm/Build/Products"
local product_name="$module_name.framework"
local binary_path="$module_name"
local iphoneos_path="$build_products_path/$config-iphoneos$scope_suffix/$product_name"
local iphonesimulator_path="$build_products_path/$config-iphonesimulator$scope_suffix/$product_name"
local out_path="build/ios$scope_suffix$version_suffix"
# Build for each platform
xc "-scheme '$scheme' -configuration $config -sdk iphoneos"
xc "-scheme '$scheme' -configuration $config -sdk iphonesimulator -destination 'name=iPhone 6' ONLY_ACTIVE_ARCH=NO"
# Combine .swiftmodule
if [ -d $iphonesimulator_path/Modules/$module_name.swiftmodule ]; then
cp $iphonesimulator_path/Modules/$module_name.swiftmodule/* $iphoneos_path/Modules/$module_name.swiftmodule/
fi
# Copy *.bcsymbolmap to .framework for submitting app with bitcode
copy_bcsymbolmap "$build_products_path/$config-iphoneos$scope_suffix" "$iphoneos_path"
# Retrieve build products
clean_retrieve $iphoneos_path $out_path $product_name
# Combine ar archives
xcrun lipo -create "$iphonesimulator_path/$binary_path" "$iphoneos_path/$binary_path" -output "$out_path/$product_name/$module_name"
}
build_watchos_combined() {
local scheme="$1"
local module_name="$2"
local scope_suffix="$3"
local config="$CONFIGURATION"
# Derive build paths
local build_products_path="build/DerivedData/Realm/Build/Products"
local product_name="$module_name.framework"
local binary_path="$module_name"
local watchos_path="$build_products_path/$config-watchos$scope_suffix/$product_name"
local watchsimulator_path="$build_products_path/$config-watchsimulator$scope_suffix/$product_name"
local out_path="build/watchos$scope_suffix"
# Build for each platform
xc "-scheme '$scheme' -configuration $config -sdk watchos"
xc "-scheme '$scheme' -configuration $config -sdk watchsimulator -destination 'name=Apple Watch - 42mm' ONLY_ACTIVE_ARCH=NO"
# Combine .swiftmodule
if [ -d $watchsimulator_path/Modules/$module_name.swiftmodule ]; then
cp $watchsimulator_path/Modules/$module_name.swiftmodule/* $watchos_path/Modules/$module_name.swiftmodule/
fi
# Copy *.bcsymbolmap
copy_bcsymbolmap "$build_products_path/$config-watchos$scope_suffix" "$watchos_path"
# Retrieve build products
clean_retrieve $watchos_path $out_path $product_name
# Combine ar archives
xcrun lipo -create "$watchsimulator_path/$binary_path" "$watchos_path/$binary_path" -output "$out_path/$product_name/$module_name"
}
xc_work_around_rdar_23055637() {
# xcodebuild times out waiting for the iOS simulator to launch if it takes > 120 seconds for the tests to
# build (<http://openradar.appspot.com/23055637>). Work around this by having the test phases intentionally
# exit after they finish building the first time, then run the tests for real.
( REALM_EXIT_AFTER_BUILDING_TESTS=YES xc "$1" ) || true
xc "$1"
}
clean_retrieve() {
mkdir -p "$2"
rm -rf "$2/$3"
cp -R "$1" "$2"
}
move_to_clean_dir() {
rm -rf "$2"
mkdir -p "$2"
mv "$1" "$2"
}
shutdown_simulators() {
# Shut down simulators until there's no booted ones left
# Only do one at a time because devices sometimes show up multiple times
while xcrun simctl list | grep -q Booted; do
xcrun simctl list | grep Booted | sed 's/.* (\(.*\)) (Booted)/\1/' | head -n 1 | xargs xcrun simctl shutdown
done
}
######################################
# Device Test Helper
######################################
test_ios_devices() {
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
scheme="$1"
configuration="$2"
failed=0
for device in "${serial_numbers[@]}"; do
xc "-scheme '$scheme' -configuration $configuration -destination 'id=$device' test" || failed=1
done
return $failed
}
######################################
# Docs
######################################
build_docs() {
local language="$1"
local version=$(sh build.sh get-version)
local xcodebuild_arguments="--objc,Realm/Realm.h,-x,objective-c,-isysroot,$(xcrun --show-sdk-path),-I,$(pwd)"
local module="Realm"
local objc="--objc"
if [[ "$language" == "swift" ]]; then
: ${REALM_SWIFT_VERSION:=2.1}
sh build.sh set-swift-version
xcodebuild_arguments="-scheme,RealmSwift"
module="RealmSwift"
objc=""
fi
touch Realm/RLMPlatform.h # jazzy will fail if it can't find all public header files
jazzy \
${objc} \
--clean \
--author Realm \
--author_url https://realm.io \
--github_url https://github.com/realm/realm-cocoa \
--github-file-prefix https://github.com/realm/realm-cocoa/tree/v${version} \
--module-version ${version} \
--xcodebuild-arguments ${xcodebuild_arguments} \
--module ${module} \
--root-url https://realm.io/docs/${language}/${version}/api/ \
--output $(pwd)/docs/${language}_output \
--template-directory $(pwd)/docs/templates
rm Realm/RLMPlatform.h
}
######################################
# Input Validation
######################################
if [ "$#" -eq 0 -o "$#" -gt 3 ]; then
usage
exit 1
fi
######################################
# Variables
######################################
download_core() {
echo "Downloading dependency: core ${REALM_CORE_VERSION}"
TMP_DIR="$TMPDIR/core_bin"
mkdir -p "${TMP_DIR}"
CORE_TMP_TAR="${TMP_DIR}/core-${REALM_CORE_VERSION}.tar.bz2.tmp"
CORE_TAR="${TMP_DIR}/core-${REALM_CORE_VERSION}.tar.bz2"
if [ ! -f "${CORE_TAR}" ]; then
curl -f -L -s "https://static.realm.io/downloads/core/realm-core-${REALM_CORE_VERSION}.tar.bz2" -o "${CORE_TMP_TAR}" ||
(echo "Downloading core failed. Please try again once you have an Internet connection." && exit 1)
mv "${CORE_TMP_TAR}" "${CORE_TAR}"
fi
(
cd "${TMP_DIR}"
rm -rf core
tar xjf "${CORE_TAR}"
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"
# Use Debug config if command ends with -debug, otherwise default to Release
case "$COMMAND" in
*-debug)
COMMAND="${COMMAND%-debug}"
CONFIGURATION="Debug"
;;
*) CONFIGURATION=${CONFIGURATION:-Release}
esac
export CONFIGURATION
source "$(dirname "$0")/scripts/swift-version.sh"
case "$COMMAND" in
######################################
# Clean
######################################
"clean")
find . -type d -name build -exec rm -r "{}" +\;
exit 0
;;
######################################
# Core
######################################
"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 ../realm-core -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
# With a prebuilt version we only want to check the first non-empty
# line so that checking out an older commit will download the
# appropriate version of core if the already-present version is too new
elif ! $(grep -m 1 . core/release_notes.txt | grep -i "${REALM_CORE_VERSION} RELEASE NOTES" >/dev/null); then
download_core
else
echo "The core library seems to be up to date."
fi
exit 0
;;
"set-core-bitcode-symlink")
cd core
rm -f librealm-ios.a librealm-ios-dbg.a
if [ $REALM_SWIFT_VERSION = '1.2' ]; then
echo "Using core without bitcode"
ln -s librealm-ios-no-bitcode.a librealm-ios.a
ln -s librealm-ios-no-bitcode-dbg.a librealm-ios-dbg.a
else
echo "Using core with bitcode"
ln -s librealm-ios-bitcode.a librealm-ios.a
ln -s librealm-ios-bitcode-dbg.a librealm-ios-dbg.a
fi
;;
######################################
# Object Store
######################################
"push-object-store-changes")
commit="$2"
path="$3"
if [ -z "$commit" -o -z "$path" ]; then
echo "usage: sh build.sh push-object-store-changes [base commit] [path to objectore repo]"
exit 1
fi
# List all commits since $commit which touched the objecstore, generate
# patches for each of them, and then apply those patches to the
# objectstore repo
git rev-list --reverse $commit..HEAD -- Realm/ObjectStore \
| xargs -I@ git format-patch --stdout @^! Realm/ObjectStore \
| git -C $path am -p 3
;;
"pull-object-store-changes")
commit="$2"
path="$3"
if [ -z "$commit" -o -z "$path" ]; then
echo "usage: sh build.sh pull-object-store-changes [base commit] [path to objectore repo]"
exit 1
fi
git -C $path format-patch --stdout $commit..HEAD | git am --directory Realm/ObjectStore
;;
######################################
# Swift versioning
######################################
"set-swift-version")
version="$2"
if [[ -z "$version" ]]; then
version="$REALM_SWIFT_VERSION"
fi
# Update the symlinks to point to the correct verion of the source, and
# then tell git to ignore the fact that we just changed a tracked file so
# that the new symlink doesn't accidentally get committed
rm -rf RealmSwift
ln -s "RealmSwift-swift$version" RealmSwift
git update-index --assume-unchanged RealmSwift || true
cd Realm/Tests
rm -rf Swift
ln -s "Swift$version" Swift
git update-index --assume-unchanged Swift || true
exit 0
;;
"prelaunch-simulator")
sh $(dirname $0)/scripts/reset-simulators.sh
;;
######################################
# Building
######################################
"build")
sh build.sh ios-static
sh build.sh ios-dynamic
sh build.sh ios-swift
sh build.sh watchos
sh build.sh watchos-swift
sh build.sh osx
sh build.sh osx-swift
exit 0
;;
"ios-static")
build_ios_combined 'Realm iOS static' Realm "-static"
exit 0
;;
"ios-dynamic")
build_ios_combined "Realm" Realm
exit 0
;;
"ios-swift")
sh build.sh ios-dynamic
build_ios_combined RealmSwift RealmSwift '' "/swift-$REALM_SWIFT_VERSION"
cp -R build/ios/Realm.framework build/ios/swift-$REALM_SWIFT_VERSION
exit 0
;;
"watchos")
build_watchos_combined Realm Realm
exit 0
;;
"watchos-swift")
sh build.sh watchos
build_watchos_combined RealmSwift RealmSwift
exit 0
;;
"osx")
xc "-scheme Realm -configuration $CONFIGURATION"
rm -rf build/osx
mkdir build/osx
cp -R build/DerivedData/Realm/Build/Products/$CONFIGURATION/Realm.framework build/osx
exit 0
;;
"osx-swift")
sh build.sh osx
xc "-scheme 'RealmSwift' -configuration $CONFIGURATION build"
destination="build/osx/swift-$REALM_SWIFT_VERSION"
clean_retrieve "build/DerivedData/Realm/Build/Products/$CONFIGURATION/RealmSwift.framework" "$destination" "RealmSwift.framework"
cp -R build/osx/Realm.framework "$destination"
exit 0
;;
######################################
# Testing
######################################
"test")
set +e # Run both sets of tests even if the first fails
failed=0
sh build.sh test-ios-static || failed=1
sh build.sh test-ios-dynamic || failed=1
sh build.sh test-ios-swift || failed=1
sh build.sh test-ios-devices || failed=1
sh build.sh test-osx || failed=1
sh build.sh test-osx-swift || failed=1
exit $failed
;;
"test-all")
set +e
failed=0
sh build.sh test || failed=1
sh build.sh test-debug || failed=1
exit $failed
;;
"test-ios-static")
xc_work_around_rdar_23055637 "-scheme 'Realm iOS static' -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 6' test"
shutdown_simulators
xc_work_around_rdar_23055637 "-scheme 'Realm iOS static' -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 4s' test"
exit 0
;;
"test-ios7-static")
xc_work_around_rdar_23055637 "-scheme 'Realm iOS static' -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 5S,OS=7.1' test"
shutdown_simulators
xc_work_around_rdar_23055637 "-scheme 'Realm iOS static' -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 4s,OS=7.1' test"
exit 0
;;
"test-ios-dynamic")
xc_work_around_rdar_23055637 "-scheme Realm -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 6' test"
shutdown_simulators
xc_work_around_rdar_23055637 "-scheme Realm -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 4s' test"
exit 0
;;
"test-ios-swift")
xc "-scheme RealmSwift -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 6' build test"
shutdown_simulators
xc "-scheme RealmSwift -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 4s' build test"
exit 0
;;
"test-ios-devices")
failed=0
trap "failed=1" ERR
sh build.sh test-ios-devices-objc
sh build.sh test-ios-devices-swift
exit $failed
;;
"test-ios-devices-objc")
test_ios_devices "Realm iOS static" "$CONFIGURATION"
exit $?
;;
"test-ios-devices-swift")
test_ios_devices "RealmSwift" "$CONFIGURATION"
exit $?
;;
"test-osx")
COVERAGE_PARAMS=""
if [[ "$CONFIGURATION" == "Debug" ]]; then
COVERAGE_PARAMS="GCC_GENERATE_TEST_COVERAGE_FILES=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES"
fi
xc "-scheme Realm -configuration $CONFIGURATION test $COVERAGE_PARAMS"
exit 0
;;
"test-osx-swift")
xc "-scheme RealmSwift -configuration $CONFIGURATION test"
exit 0
;;
######################################
# Full verification
######################################
"verify")
sh build.sh verify-cocoapods
sh build.sh verify-docs
sh build.sh verify-osx
sh build.sh verify-osx-debug
sh build.sh verify-osx-swift
sh build.sh verify-osx-swift-debug
sh build.sh verify-ios-static
sh build.sh verify-ios-static-debug
sh build.sh verify-ios7-static
sh build.sh verify-ios7-static-debug
sh build.sh verify-ios-dynamic
sh build.sh verify-ios-dynamic-debug
sh build.sh verify-ios-swift
sh build.sh verify-ios-swift-debug
sh build.sh verify-ios-device-objc
sh build.sh verify-ios-device-swift
sh build.sh verify-watchos
sh build.sh verify-swiftlint
;;
"verify-cocoapods")
cd examples/installation
# FIXME: tests are duplicated to work around https://github.com/realm/realm-cocoa/issues/2701
sh build.sh test-ios-objc-cocoapods || sh build.sh test-ios-objc-cocoapods || exit 1
sh build.sh test-ios-swift-cocoapods || sh build.sh test-ios-swift-cocoapods || exit 1
;;
"verify-osx")
sh build.sh test-osx
sh build.sh examples-osx
(
cd examples/osx/objc/build/DerivedData/RealmExamples/Build/Products/$CONFIGURATION
DYLD_FRAMEWORK_PATH=. ./JSONImport >/dev/null
) || exit 1
exit 0
;;
"verify-osx-swift")
sh build.sh test-osx-swift
exit 0
;;
"verify-ios-static")
sh build.sh test-ios-static
sh build.sh examples-ios
;;
"verify-ios7-static")
sh build.sh test-ios7-static
;;
"verify-ios-dynamic")
sh build.sh test-ios-dynamic
;;
"verify-ios-swift")
sh build.sh test-ios-swift
sh build.sh examples-ios-swift
;;
"verify-ios-device-objc")
sh build.sh test-ios-devices-objc
exit 0
;;
"verify-ios-device-swift")
sh build.sh test-ios-devices-swift
exit 0
;;
"verify-docs")
sh build.sh docs
for lang in swift objc; do
undocumented="docs/${lang}_output/undocumented.txt"
if [ -s "$undocumented" ]; then
echo "Undocumented Realm $lang declarations:"
cat "$undocumented"
exit 1
fi
done
exit 0
;;
"verify-watchos")
if [ $REALM_SWIFT_VERSION != '1.2' ]; then
sh build.sh watchos-swift
fi
exit 0
;;
"verify-swiftlint")
swiftlint lint --strict
exit 0
;;
######################################
# Docs
######################################
"docs")
build_docs objc
build_docs swift
exit 0
;;
######################################
# Examples
######################################
"examples")
sh build.sh clean
sh build.sh examples-ios
sh build.sh examples-ios-swift
sh build.sh examples-osx
exit 0
;;
"examples-ios")
if [[ -d "examples/ios/objc" ]]; then
project="examples/ios/objc/RealmExamples.xcodeproj"
elif [[ "$REALM_SWIFT_VERSION" = 1.2 ]]; then
project="examples/ios/xcode-6/objc/RealmExamples.xcodeproj"
else
project="examples/ios/xcode-7/objc/RealmExamples.xcodeproj"
fi
xc "-project $project -scheme Simple -configuration $CONFIGURATION build ${CODESIGN_PARAMS}"
xc "-project $project -scheme TableView -configuration $CONFIGURATION build ${CODESIGN_PARAMS}"
xc "-project $project -scheme Migration -configuration $CONFIGURATION build ${CODESIGN_PARAMS}"
xc "-project $project -scheme Backlink -configuration $CONFIGURATION build ${CODESIGN_PARAMS}"
xc "-project $project -scheme GroupedTableView -configuration $CONFIGURATION build ${CODESIGN_PARAMS}"
xc "-project $project -scheme Encryption -configuration $CONFIGURATION build ${CODESIGN_PARAMS}"
if [ ! -z "${JENKINS_HOME}" ]; then
xc "-project $project -scheme Extension -configuration $CONFIGURATION build ${CODESIGN_PARAMS}"
fi
exit 0
;;
"examples-ios-swift")
project="examples/ios/swift-$REALM_SWIFT_VERSION/RealmExamples.xcodeproj"
xc "-project $project -scheme Simple -configuration $CONFIGURATION build ${CODESIGN_PARAMS}"
xc "-project $project -scheme TableView -configuration $CONFIGURATION build ${CODESIGN_PARAMS}"
xc "-project $project -scheme Migration -configuration $CONFIGURATION build ${CODESIGN_PARAMS}"
xc "-project $project -scheme Encryption -configuration $CONFIGURATION build ${CODESIGN_PARAMS}"
xc "-project $project -scheme Backlink -configuration $CONFIGURATION build ${CODESIGN_PARAMS}"
xc "-project $project -scheme GroupedTableView -configuration $CONFIGURATION build ${CODESIGN_PARAMS}"
exit 0
;;
"examples-osx")
xc "-project examples/osx/objc/RealmExamples.xcodeproj -scheme JSONImport -configuration ${CONFIGURATION} build ${CODESIGN_PARAMS}"
;;
######################################
# 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"
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")
if [[ "$2" != "without-core" ]]; then
sh build.sh download-core
mv core/librealm.a core/librealm-osx.a
if [[ "$REALM_SWIFT_VERSION" = "1.2" ]]; then
echo 'Installing for Xcode 6.'
mv core/librealm-ios-no-bitcode.a core/librealm-ios.a
else
echo 'Installing for Xcode 7+.'
mv core/librealm-ios-bitcode.a core/librealm-ios.a
fi
fi
# CocoaPods won't automatically preserve files referenced via symlinks
for symlink in $(find . -not -path "./.git/*" -type l); do
if [[ -L "$symlink" ]]; then
link="$(dirname "$symlink")/$(readlink "$symlink")"
rm "$symlink"
cp -RH "$link" "$symlink"
fi
done
if [[ "$2" != "without-core" ]]; then
# CocoaPods doesn't support multiple header_mappings_dir, so combine
# both sets of headers into a single directory
rm -rf include
# Create uppercase `Realm` header directory for a case-sensitive filesystem.
# Both `Realm` and `realm` directories are required.
if [ ! -e core/include/Realm ]; then
cp -R core/include/realm core/include/Realm
fi
cp -R core/include include
mkdir -p include/Realm
cp Realm/*.{h,hpp} include/Realm
cp Realm/ObjectStore/*.hpp include/Realm
cp Realm/ObjectStore/impl/*.hpp include/Realm
cp Realm/ObjectStore/impl/apple/*.hpp include/Realm
touch include/Realm/RLMPlatform.h
fi
;;
######################################
# Continuous Integration
######################################
"ci-pr")
mkdir -p build/reports
if [ "$target" = "docs" ]; then
sh build.sh set-swift-version
sh build.sh verify-docs
elif [ "$target" = "swiftlint" ]; then
sh build.sh verify-swiftlint
else
export sha=$ghprbSourceBranch
export REALM_SWIFT_VERSION=$swift_version
export CONFIGURATION=$configuration
export REALM_EXTRA_BUILD_ARGUMENTS='GCC_GENERATE_DEBUGGING_SYMBOLS=NO REALM_PREFIX_HEADER=Realm/RLMPrefix.h'
sh build.sh prelaunch-simulator
# Verify that no Realm files still exist
! find ~/Library/Developer/CoreSimulator/Devices/ -name '*.realm' | grep -q .
sh build.sh verify-$target | tee build/build.log | xcpretty -r junit -o build/reports/junit.xml || \
(echo "\n\n***\nbuild/build.log\n***\n\n" && cat build/build.log && exit 1)
fi
if [ "$target" = "osx" ] && [ "$configuration" = "Debug" ]; then
gcovr -r . -f ".*Realm.*" -e ".*Tests.*" -e ".*core.*" --xml > build/reports/coverage-report.xml
WS=$(pwd | sed "s/\//\\\\\//g")
sed -i ".bak" "s/<source>\./<source>${WS}/" build/reports/coverage-report.xml
fi
;;
######################################
# Release packaging
######################################
"package-examples")
cd tightdb_objc
./scripts/package_examples.rb
zip --symlinks -r realm-examples.zip examples -x "examples/installation/*"
;;
"package-test-examples")
if ! VERSION=$(echo realm-objc-*.zip | grep -o '\d*\.\d*\.\d*-[a-z]*'); then
VERSION=$(echo realm-objc-*.zip | grep -o '\d*\.\d*\.\d*')
fi
OBJC="realm-objc-${VERSION}"
SWIFT="realm-swift-${VERSION}"
unzip ${OBJC}.zip
cp $0 ${OBJC}
cp -r $(dirname $0)/scripts ${OBJC}
cd ${OBJC}
REALM_SWIFT_VERSION=1.2 sh build.sh examples-ios
REALM_SWIFT_VERSION=2.1 sh build.sh examples-ios
sh build.sh examples-osx
cd ..
rm -rf ${OBJC}
unzip ${SWIFT}.zip
cp $0 ${SWIFT}
cp -r $(dirname $0)/scripts ${SWIFT}
cd ${SWIFT}
REALM_SWIFT_VERSION=1.2 sh build.sh examples-ios-swift
REALM_SWIFT_VERSION=2.1 sh build.sh examples-ios-swift
cd ..
rm -rf ${SWIFT}
;;
"package-ios-static")
cd tightdb_objc
REALM_SWIFT_VERSION=1.2 sh build.sh prelaunch-simulator
REALM_SWIFT_VERSION=1.2 sh build.sh test-ios-static
REALM_SWIFT_VERSION=1.2 sh build.sh ios-static
move_to_clean_dir build/ios-static/Realm.framework xcode-6
rm -rf build
REALM_SWIFT_VERSION=2.1 sh build.sh prelaunch-simulator
REALM_SWIFT_VERSION=2.1 sh build.sh test-ios-static
REALM_SWIFT_VERSION=2.1 sh build.sh ios-static
move_to_clean_dir build/ios-static/Realm.framework xcode-7
zip --symlinks -r build/ios-static/realm-framework-ios.zip xcode-6 xcode-7
;;
"package-ios-dynamic")
cd tightdb_objc
REALM_SWIFT_VERSION=1.2 sh build.sh prelaunch-simulator
REALM_SWIFT_VERSION=1.2 sh build.sh ios-dynamic
move_to_clean_dir build/ios/Realm.framework xcode-6
rm -rf build
REALM_SWIFT_VERSION=2.1 sh build.sh prelaunch-simulator
REALM_SWIFT_VERSION=2.1 sh build.sh ios-dynamic
move_to_clean_dir build/ios/Realm.framework xcode-7
zip --symlinks -r build/ios/realm-dynamic-framework-ios.zip xcode-6 xcode-7
;;
"package-osx")
cd tightdb_objc
REALM_SWIFT_VERSION=2.1 sh build.sh test-osx
cd build/DerivedData/Realm/Build/Products/Release
zip --symlinks -r realm-framework-osx.zip Realm.framework
;;
"package-ios-swift")
cd tightdb_objc
for version in 1.2 2.1; do
rm -rf build/ios/Realm.framework
REALM_SWIFT_VERSION=$version sh build.sh prelaunch-simulator
REALM_SWIFT_VERSION=$version sh build.sh ios-swift
done
cd build/ios
zip --symlinks -r realm-swift-framework-ios.zip swift-1.2 swift-2.1
;;
"package-osx-swift")
cd tightdb_objc
REALM_SWIFT_VERSION=1.2 sh build.sh osx-swift
REALM_SWIFT_VERSION=2.1 sh build.sh osx-swift
cd build/osx
zip --symlinks -r realm-swift-framework-osx.zip swift-1.2 swift-2.1
;;
"package-watchos")
cd tightdb_objc
REALM_SWIFT_VERSION=2.1 sh build.sh watchos
cd build/watchos
zip --symlinks -r realm-framework-watchos.zip Realm.framework
;;
"package-watchos-swift")
cd tightdb_objc
REALM_SWIFT_VERSION=2.1 sh build.sh watchos-swift
cd build/watchos
zip --symlinks -r realm-swift-framework-watchos.zip RealmSwift.framework Realm.framework
;;
"package-release")
LANG="$2"
TEMPDIR=$(mktemp -d $TMPDIR/realm-release-package-${LANG}.XXXX)
cd tightdb_objc
VERSION=$(sh build.sh get-version)
cd ..
FOLDER=${TEMPDIR}/realm-${LANG}-${VERSION}
mkdir -p ${FOLDER}/osx ${FOLDER}/ios ${FOLDER}/watchos
if [[ "${LANG}" == "objc" ]]; then
mkdir -p ${FOLDER}/ios/static
mkdir -p ${FOLDER}/ios/dynamic
mkdir -p ${FOLDER}/Swift
(
cd ${FOLDER}/osx
unzip ${WORKSPACE}/realm-framework-osx.zip
)
(
cd ${FOLDER}/ios/static
unzip ${WORKSPACE}/realm-framework-ios.zip
)
(
cd ${FOLDER}/ios/dynamic
unzip ${WORKSPACE}/realm-dynamic-framework-ios.zip
)
(
cd ${FOLDER}/watchos
unzip ${WORKSPACE}/realm-framework-watchos.zip
)
else
(
cd ${FOLDER}/osx
unzip ${WORKSPACE}/realm-swift-framework-osx.zip
)
(
cd ${FOLDER}/ios
unzip ${WORKSPACE}/realm-swift-framework-ios.zip
)
(
cd ${FOLDER}/watchos
unzip ${WORKSPACE}/realm-swift-framework-watchos.zip