forked from realm/realm-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·931 lines (785 loc) · 30.2 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
#!/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.92.2} # 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/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
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)
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 dynamic and Swift iOS frameworks 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
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() {
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 $@"
}
xcrealmswift() {
PROJECT=RealmSwift.xcodeproj
xc "-project $PROJECT $@"
}
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/$module_name/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
cmd=$(echo "xc$module_name" | tr '[:upper:]' '[:lower:]') # lowercase the module name to generate command (xcrealm or xcrealmswift)
$cmd "-scheme '$scheme' -configuration $config -sdk iphoneos"
$cmd "-scheme '$scheme' -configuration $config -sdk iphonesimulator 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
# 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/$module_name/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
cmd=$(echo "xc$module_name" | tr '[:upper:]' '[:lower:]') # lowercase the module name to generate command (xcrealm or xcrealmswift)
$cmd "-scheme '$scheme' -configuration $config -sdk watchos"
$cmd "-scheme '$scheme' -configuration $config -sdk watchsimulator 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
# 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"
}
clean_retrieve() {
mkdir -p "$2"
rm -rf "$2/$3"
cp -R "$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
cmd="$1"
scheme="$2"
configuration="$3"
failed=0
for device in "${serial_numbers[@]}"; do
$cmd "-scheme '$2' -configuration $configuration -destination 'id=$device' test" || failed=1
done
return $failed
}
######################################
# Input Validation
######################################
if [ "$#" -eq 0 -o "$#" -gt 2 ]; 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
;;
######################################
# 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 ../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
;;
######################################
# 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 iOS Realm
exit 0
;;
"ios-dynamic")
build_ios_combined "iOS Dynamic" Realm "-dynamic"
exit 0
;;
"ios-swift")
build_ios_combined RealmSwift RealmSwift '' "/swift-$REALM_SWIFT_VERSION"
cp -R build/ios-dynamic/Realm.framework build/ios/swift-$REALM_SWIFT_VERSION
exit 0
;;
"watchos")
build_watchos_combined "watchOS" Realm
exit 0
;;
"watchos-swift")
build_watchos_combined RealmSwift RealmSwift
exit 0
;;
"osx")
xcrealm "-scheme OSX -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")
xcrealmswift "-scheme 'RealmSwift' -configuration $CONFIGURATION build"
destination="build/osx/swift-$REALM_SWIFT_VERSION"
clean_retrieve "build/DerivedData/RealmSwift/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")
xcrealm "-scheme iOS -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 6' test"
shutdown_simulators
xcrealm "-scheme iOS -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 4s' test"
exit 0
;;
"test-ios7-static")
xcrealm "-scheme iOS -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 5S,OS=7.1' test"
shutdown_simulators
xcrealm "-scheme iOS -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 4s,OS=7.1' test"
exit 0
;;
"test-ios-dynamic")
xcrealm "-scheme 'iOS Dynamic' -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 6' test"
shutdown_simulators
xcrealm "-scheme 'iOS Dynamic' -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 4s' test"
exit 0
;;
"test-ios-swift")
xcrealmswift "-scheme RealmSwift -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 6' test"
shutdown_simulators
xcrealmswift "-scheme RealmSwift -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 4s' test"
exit 0
;;
"test-ios-devices")
failed=0
test_ios_devices xcrealm "iOS Device Tests" "$CONFIGURATION" || failed=1
# test_ios_devices xcrealmswift "RealmSwift" "$CONFIGURATION" || failed=1 # FIXME: Re-enable once fixed
exit $failed
;;
"test-osx")
COVERAGE_PARAMS=""
if [[ "$CONFIGURATION" == "Debug" ]]; then
COVERAGE_PARAMS="GCC_GENERATE_TEST_COVERAGE_FILES=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES"
fi
xcrealm "-scheme OSX -configuration $CONFIGURATION test $COVERAGE_PARAMS"
exit 0
;;
"test-osx-swift")
xcrealmswift "-scheme RealmSwift -configuration $CONFIGURATION test"
exit 0
;;
######################################
# Full verification
######################################
"verify")
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
sh build.sh verify-watchos
;;
"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")
sh build.sh test-ios-devices
exit 0
;;
"verify-docs")
sh scripts/build-docs.sh
if [ -s docs/swift_output/undocumented.txt ]; then
echo "Undocumented RealmSwift declarations:"
echo "$(cat docs/swift_output/undocumented.txt)"
exit 1
fi
exit 0
;;
"verify-watchos")
if [ $REALM_SWIFT_VERSION != '1.2' ]; then
sh build.sh watchos-swift
fi
exit 0
;;
######################################
# Docs
######################################
"docs")
sh scripts/build-docs.sh
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")
xc "-project examples/ios/objc/RealmExamples.xcodeproj -scheme Simple -configuration $CONFIGURATION build ${CODESIGN_PARAMS}"
xc "-project examples/ios/objc/RealmExamples.xcodeproj -scheme TableView -configuration $CONFIGURATION build ${CODESIGN_PARAMS}"
xc "-project examples/ios/objc/RealmExamples.xcodeproj -scheme Migration -configuration $CONFIGURATION build ${CODESIGN_PARAMS}"
xc "-project examples/ios/objc/RealmExamples.xcodeproj -scheme Backlink -configuration $CONFIGURATION build ${CODESIGN_PARAMS}"
xc "-project examples/ios/objc/RealmExamples.xcodeproj -scheme GroupedTableView -configuration $CONFIGURATION build ${CODESIGN_PARAMS}"
xc "-project examples/ios/objc/RealmExamples.xcodeproj -scheme Encryption -configuration $CONFIGURATION build ${CODESIGN_PARAMS}"
if [ ! -z "${JENKINS_HOME}" ]; then
xc "-project examples/ios/objc/RealmExamples.xcodeproj -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
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 -R "$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
cp -R core/include include
mkdir -p include/Realm
cp Realm/*.{h,hpp} include/Realm
cp Realm/ObjectStore/*.hpp include/Realm
touch include/Realm/RLMPlatform.h
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")
VERSION=$(file realm-objc-*.zip | grep -o '\d*\.\d*\.\d*')
unzip realm-objc-${VERSION}.zip
cp $0 realm-objc-${VERSION}
cp -r $(dirname $0)/scripts realm-objc-${VERSION}
cd realm-objc-${VERSION}
sh build.sh examples-ios
sh build.sh examples-osx
cd ..
rm -rf realm-objc-${VERSION}
unzip realm-swift-${VERSION}.zip
cp $0 realm-swift-${VERSION}
cp -r $(dirname $0)/scripts realm-swift-${VERSION}
cd realm-swift-${VERSION}
REALM_SWIFT_VERSION=1.2 sh build.sh examples-ios-swift
REALM_SWIFT_VERSION=2.0 sh build.sh examples-ios-swift
cd ..
rm -rf realm-swift-${VERSION}
;;
"package-ios-static")
cd tightdb_objc
sh build.sh test-ios-static
sh build.sh ios-static
cd build/ios
zip --symlinks -r realm-framework-ios.zip Realm.framework
;;
"package-ios-dynamic")
cd tightdb_objc
REALM_SWIFT_VERSION=2.0 sh build.sh ios-dynamic
cd build/ios-dynamic
zip --symlinks -r realm-dynamic-framework-ios.zip Realm.framework
;;
"package-osx")
cd tightdb_objc
REALM_SWIFT_VERSION=2.0 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.0; do
rm -rf build/ios-dynamic
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.0
;;
"package-osx-swift")
cd tightdb_objc
REALM_SWIFT_VERSION=1.2 sh build.sh osx-swift
REALM_SWIFT_VERSION=2.0 sh build.sh osx-swift
cd build/osx
zip --symlinks -r realm-swift-framework-osx.zip swift-1.2 swift-2.0
;;
"package-watchos")
cd tightdb_objc
REALM_SWIFT_VERSION=2.0 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.0 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
)
fi
(
cd ${WORKSPACE}/tightdb_objc
cp -R plugin ${FOLDER}
cp LICENSE ${FOLDER}/LICENSE.txt
if [[ "${LANG}" == "objc" ]]; then
cp Realm/Swift/RLMSupport.swift ${FOLDER}/Swift/
fi
)
(
cd ${FOLDER}
unzip ${WORKSPACE}/realm-examples.zip
cd examples
if [[ "${LANG}" == "objc" ]]; then
rm -rf ios/swift-1.2 ios/swift-2.0
else
rm -rf ios/objc ios/rubymotion osx
fi
)
cat > ${FOLDER}/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>https://realm.io/docs/${LANG}/${VERSION}</string>
</dict>
</plist>
EOF
(
cd ${TEMPDIR}
zip --symlinks -r realm-${LANG}-${VERSION}.zip realm-${LANG}-${VERSION}
mv realm-${LANG}-${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 -p "$WORKSPACE"
WORKSPACE="$(cd "$WORKSPACE" && pwd)"
export WORKSPACE
cd $WORKSPACE
git clone $REALM_SOURCE tightdb_objc
echo 'Packaging iOS static'
sh tightdb_objc/build.sh package-ios-static
cp tightdb_objc/build/ios/realm-framework-ios.zip .
echo 'Packaging iOS dynamic'
sh tightdb_objc/build.sh package-ios-dynamic
cp tightdb_objc/build/ios-dynamic/realm-dynamic-framework-ios.zip .
echo 'Packaging OS X'
sh tightdb_objc/build.sh package-osx
cp tightdb_objc/build/DerivedData/Realm/Build/Products/Release/realm-framework-osx.zip .
echo 'Packaging examples'
(
cd tightdb_objc/examples
git clean -xfd
)
sh tightdb_objc/build.sh package-examples
cp tightdb_objc/realm-examples.zip .
echo 'Packaging iOS Swift'
sh tightdb_objc/build.sh package-ios-swift
cp tightdb_objc/build/ios/realm-swift-framework-ios.zip .
echo 'Packaging OS X Swift'
sh tightdb_objc/build.sh package-osx-swift
cp tightdb_objc/build/osx/realm-swift-framework-osx.zip .
echo 'Packaging watchOS'
sh tightdb_objc/build.sh package-watchos
sh tightdb_objc/build.sh package-watchos-swift
cp tightdb_objc/build/watchos/realm-swift-framework-watchos.zip .
cp tightdb_objc/build/watchos/realm-framework-watchos.zip .
echo 'Building final release packages'
sh tightdb_objc/build.sh package-release objc
sh tightdb_objc/build.sh package-release swift
echo 'Testing packaged examples'
sh tightdb_objc/build.sh package-test-examples
;;
"github-release")
if [ -z "${GITHUB_ACCESS_TOKEN}" ]; then
echo 'GITHUB_ACCESS_TOKEN must be set to create GitHub releases'
exit 1
fi
./scripts/github_release.rb
;;
"add-empty-changelog")
empty_section=$(cat <<EOS
x.x.x Release notes (yyyy-MM-dd)
=============================================================
### API breaking changes
* None.
### Enhancements
* None.
### Bugfixes
* None.
EOS)
changelog=$(cat CHANGELOG.md)
echo "$empty_section" > CHANGELOG.md
echo >> CHANGELOG.md
echo "$changelog" >> CHANGELOG.md
;;
*)
echo "Unknown command '$COMMAND'"
usage
exit 1
;;
esac