forked from realm/realm-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·1387 lines (1181 loc) · 46.5 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/bash
##################################################################################
# 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 macOS it works just fine.
# macOS 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
readonly source_root="$(dirname "$0")"
# You can override the version of the core library
: "${REALM_BASE_URL:="https://static.realm.io/downloads"}" # set it if you need to use a remote repo
: "${REALM_CORE_VERSION:=$(sed -n 's/^REALM_CORE_VERSION=\(.*\)$/\1/p' "${source_root}/dependencies.list")}" # 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
# Provide a fallback value for TMPDIR, relevant for Xcode Bots
: "${TMPDIR:=$(getconf DARWIN_USER_TEMP_DIR)}"
PATH=/usr/libexec:$PATH
if [ -n "${JENKINS_HOME}" ]; then
XCPRETTY_PARAMS=(--no-utf --report junit --output build/reports/junit.xml)
CODESIGN_PARAMS=(CODE_SIGN_IDENTITY='' CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO)
fi
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 macOS 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
tvos: builds tvOS framework
tvos-swift: builds RealmSwift framework for tvOS
osx: builds macOS framework
osx-swift: builds RealmSwift framework for macOS
xcframework [plats]: builds xcframeworks for Realm and RealmSwift for given platforms
analyze-osx: analyzes macOS framework
test: tests all iOS and macOS frameworks
test-all: tests all iOS and macOS 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-tvos: tests tvOS framework
test-tvos-swift: tests RealmSwift tvOS framework
test-tvos-devices: tests ObjC & Swift tvOS frameworks on all attached tvOS devices
test-osx: tests macOS framework
test-osx-swift: tests RealmSwift macOS framework
test-catalyst: tests Mac Catalyst framework
test-catalyst-swift: tests RealmSwift Mac Catalyst framework
test-swiftpm: tests ObjC and Swift macOS frameworks via SwiftPM
test-swiftui-ios: tests SwiftUI framework UI tests
test-swiftui-server-osx: tests Server Sync in SwiftUI
verify: verifies docs, osx, osx-swift, ios-static, ios-dynamic, ios-swift, ios-device, swiftui-ios in both Debug and Release configurations, swiftlint
verify-osx-object-server: downloads the Realm Object Server and runs the Objective-C and Swift integration tests
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 macOS 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
REALM_XCODE_VERSION: the version number of Xcode to use (e.g.: 8.1)
EOF
}
######################################
# Xcode Helpers
######################################
xcode_version_major() {
echo "${REALM_XCODE_VERSION%%.*}"
}
xcode() {
mkdir -p build/DerivedData
CMD="xcodebuild -IDECustomDerivedDataLocation=build/DerivedData"
echo "Building with command: $CMD $*"
xcodebuild -IDECustomDerivedDataLocation=build/DerivedData "$@"
}
xc() {
# Logs xcodebuild output in realtime
: "${NSUnbufferedIO:=YES}"
args=("SWIFT_VERSION=$REALM_SWIFT_VERSION" $REALM_EXTRA_BUILD_ARGUMENTS)
if [[ "$XCMODE" == "xcodebuild" ]]; then
xcode "$@" "${args[@]}"
elif [[ "$XCMODE" == "xcpretty" ]]; then
mkdir -p build
xcode "$@" "${args[@]}" | 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 "$@" "${args[@]}"
fi
}
xctest() {
local scheme="$1"
xc -scheme "$scheme" "${@:2}" build-for-testing
xc -scheme "$scheme" "${@:2}" test-without-building
}
build_combined() {
local scheme="$1"
local module_name="$2"
local os="$3"
local simulator="$4"
local scope_suffix="$5"
local version_suffix="$6"
local config="$CONFIGURATION"
local os_name=""
if [[ "$os" == "iphoneos" ]]; then
os_name="ios"
elif [[ "$os" == "watchos" ]]; then
os_name="$os"
elif [[ "$os" == "appletvos" ]]; then
os_name="tvos"
fi
# Derive build paths
local build_products_path="build/DerivedData/Realm/Build/Products"
local product_name="$module_name.framework"
local os_path="$build_products_path/$config-$os$scope_suffix/$product_name"
local simulator_path="$build_products_path/$config-$simulator$scope_suffix/$product_name"
local out_path="build/$os_name$scope_suffix$version_suffix"
local xcframework_path="$out_path/$module_name.xcframework"
# Build for each platform
xc -scheme "$scheme" -configuration "$config" -sdk "$os" build
xc -scheme "$scheme" -configuration "$config" -sdk "$simulator" build ONLY_ACTIVE_ARCH=NO
# Create the xcframework
rm -rf "$xcframework_path"
xcodebuild -create-xcframework -allow-internal-distribution -output "$xcframework_path" \
-framework "$os_path" -framework "$simulator_path"
}
copy_realm_framework() {
local platform="$1"
rm -rf "build/$platform/swift-$REALM_XCODE_VERSION/Realm.xcframework"
cp -R "build/$platform/Realm.xcframework" "build/$platform/swift-$REALM_XCODE_VERSION"
}
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"
}
test_ios_static() {
xctest 'Realm iOS static' -configuration "$CONFIGURATION" -sdk iphonesimulator -destination "$1"
}
plist_get() {
/usr/libexec/PlistBuddy -c "Print :$2" "$1" 2> /dev/null
}
######################################
# Device Test Helper
######################################
test_devices() {
local serial_numbers=()
local awk_script="
/^ +Vendor ID: / { is_apple = 0; }
/^ +Vendor ID: 0x05[aA][cC] / { is_apple = 1; }
/^ +Serial Number: / {
if (is_apple) {
match(\$0, /^ +Serial Number: /);
print substr(\$0, RLENGTH + 1);
}
}
"
local serial_numbers_text=$(/usr/sbin/system_profiler SPUSBDataType | /usr/bin/awk "$awk_script")
while read -r number; do
if [[ "$number" != "" ]]; then
serial_numbers+=("$number")
fi
done <<< "$serial_numbers_text"
if [[ ${#serial_numbers[@]} == 0 ]]; then
echo "At least one iOS/tvOS 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
local sdk="$1"
local scheme="$2"
local configuration="$3"
local failed=0
for device in "${serial_numbers[@]}"; do
xc -scheme "$scheme" -configuration "$configuration" -destination "id=$device" -sdk "$sdk" 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
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-swift \
--github-file-prefix "https://github.com/realm/realm-swift/tree/v${version}" \
--module-version "${version}" \
--xcodebuild-arguments "${xcodebuild_arguments}" \
--module "${module}" \
--root-url "https://docs.mongodb.com/realm-sdks/${language}/${version}/" \
--output "docs/${language}_output" \
--head "$(cat docs/custom_head.html)" \
--exclude 'RealmSwift/Impl/*'
rm Realm/RLMPlatform.h
}
######################################
# Input Validation
######################################
if [ "$#" -eq 0 ] || [ "$#" -gt 3 ]; then
usage
exit 1
fi
######################################
# Downloading
######################################
copy_core() {
local src="$1"
rm -rf core
mkdir core
ditto "$src" core
# XCFramework processing only copies the "realm" headers, so put the third-party ones in a known location
mkdir -p core/include
find "$src" -name external -exec ditto "{}" core/include/external \; -quit
}
download_common() {
local tries_left=3 version url error suffix
suffix='-xcframework'
version=$REALM_CORE_VERSION
url="${REALM_BASE_URL}/core/realm-monorepo-xcframework-v${version}.tar.xz"
# First check if we need to do anything
if [ -e core ]; then
if [ -e core/version.txt ]; then
if [ "$(cat core/version.txt)" == "$version" ]; then
echo "Version ${version} already present"
exit 0
else
echo "Switching from version $(cat core/version.txt) to ${version}"
fi
else
if [ "$(find core -name librealm-monorepo.a)" ]; then
echo 'Using existing custom core build without checking version'
exit 0
fi
fi
fi
# We may already have this version downloaded and just need to set it as
# the active one
local versioned_dir="realm-core-${version}${suffix}"
if [ -e "$versioned_dir/version.txt" ]; then
echo "Setting ${version} as the active version"
copy_core "$versioned_dir"
exit 0
fi
echo "Downloading dependency: ${version} from ${url}"
if [ -z "$TMPDIR" ]; then
TMPDIR='/tmp'
fi
local temp_dir=$(dirname "$TMPDIR/waste")/realm-core-tmp
mkdir -p "$temp_dir"
local tar_path="${temp_dir}/${versioned_dir}.tar.xz"
local temp_path="${tar_path}.tmp"
while [ 0 -lt $tries_left ] && [ ! -f "$tar_path" ]; do
if ! error=$(/usr/bin/curl --fail --silent --show-error --location "$url" --output "$temp_path" 2>&1); then
tries_left=$((tries_left-1))
else
mv "$temp_path" "$tar_path"
fi
done
if [ ! -f "$tar_path" ]; then
printf "Downloading core failed:\n\t%s\n\t%s\n" "$url" "$error"
exit 1
fi
(
cd "$temp_dir"
rm -rf core
tar xf "$tar_path" --xz
if [ ! -f core/version.txt ]; then
printf %s "${version}" > core/version.txt
fi
mv core "${versioned_dir}"
)
rm -rf "${versioned_dir}"
mv "${temp_dir}/${versioned_dir}" .
copy_core "$versioned_dir"
}
######################################
# Variables
######################################
COMMAND="$1"
# Use Debug config if command ends with -debug, otherwise default to Release
case "$COMMAND" in
*-debug)
COMMAND="${COMMAND%-debug}"
CONFIGURATION="Debug"
;;
esac
export CONFIGURATION=${CONFIGURATION:-Release}
# Pre-choose Xcode and Swift versions for those operations that do not set them
REALM_XCODE_VERSION=${xcode_version:-$REALM_XCODE_VERSION}
REALM_SWIFT_VERSION=${swift_version:-$REALM_SWIFT_VERSION}
source "${source_root}/scripts/swift-version.sh"
set_xcode_and_swift_versions
######################################
# Commands
######################################
case "$COMMAND" in
######################################
# Clean
######################################
"clean")
find . -type d -name build -exec rm -r "{}" +
exit 0
;;
######################################
# Dependencies
######################################
"download-core")
download_common
exit 0
;;
"setup-baas")
ruby Realm/ObjectServerTests/setup_baas.rb
exit 0
;;
"prelaunch-simulator")
if [ -z "$REALM_SKIP_PRELAUNCH" ]; then
sh "${source_root}/scripts/reset-simulators.sh" "$1"
fi
;;
######################################
# 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 tvos
sh build.sh tvos-swift
sh build.sh osx
sh build.sh osx-swift
exit 0
;;
"ios-static")
build_combined 'Realm iOS static' Realm iphoneos iphonesimulator "-static"
exit 0
;;
"ios-dynamic")
build_combined Realm Realm iphoneos iphonesimulator
exit 0
;;
"ios-swift")
sh build.sh ios-dynamic
build_combined RealmSwift RealmSwift iphoneos iphonesimulator '' "/swift-$REALM_XCODE_VERSION"
copy_realm_framework ios
exit 0
;;
"watchos")
build_combined Realm Realm watchos watchsimulator
exit 0
;;
"watchos-swift")
sh build.sh watchos
build_combined RealmSwift RealmSwift watchos watchsimulator '' "/swift-$REALM_XCODE_VERSION"
copy_realm_framework watchos
exit 0
;;
"tvos")
build_combined Realm Realm appletvos appletvsimulator
exit 0
;;
"tvos-swift")
sh build.sh tvos
build_combined RealmSwift RealmSwift appletvos appletvsimulator '' "/swift-$REALM_XCODE_VERSION"
copy_realm_framework tvos
exit 0
;;
"osx")
xc -scheme Realm -configuration "$CONFIGURATION"
clean_retrieve "build/DerivedData/Realm/Build/Products/$CONFIGURATION/Realm.framework" "build/osx" "Realm.framework"
exit 0
;;
"osx-swift")
sh build.sh osx
xc -scheme RealmSwift -configuration "$CONFIGURATION" build
destination="build/osx/swift-$REALM_XCODE_VERSION"
clean_retrieve "build/DerivedData/Realm/Build/Products/$CONFIGURATION/RealmSwift.framework" "$destination" "RealmSwift.framework"
clean_retrieve "build/osx/Realm.framework" "$destination" "Realm.framework"
exit 0
;;
"swiftui")
xc -scheme SwiftUITestHost -configuration $CONFIGURATION -sdk iphonesimulator build
;;
"catalyst")
export REALM_SDKROOT=iphoneos
xc -scheme Realm -configuration "$CONFIGURATION" -destination variant='Mac Catalyst'
clean_retrieve "build/DerivedData/Realm/Build/Products/$CONFIGURATION-maccatalyst/Realm.framework" "build/catalyst" "Realm.framework"
;;
"catalyst-swift")
sh build.sh catalyst
export REALM_SDKROOT=iphoneos
xc -scheme 'RealmSwift' -configuration "$CONFIGURATION" -destination variant='Mac Catalyst' build
destination="build/catalyst/swift-$REALM_XCODE_VERSION"
clean_retrieve "build/DerivedData/Realm/Build/Products/$CONFIGURATION-maccatalyst/RealmSwift.framework" "$destination" "RealmSwift.framework"
clean_retrieve "build/catalyst/Realm.framework" "$destination" "Realm.framework"
;;
"xcframework")
# Build all of the requested frameworks
shift
PLATFORMS="${*:-osx ios watchos tvos catalyst}"
for platform in $PLATFORMS; do
sh build.sh "$platform-swift"
done
# Assemble them into xcframeworks
rm -rf build/*.xcframework
find build/DerivedData/Realm/Build/Products -name 'Realm.framework' \
| grep -v '\-static' \
| sed 's/.*/-framework &/' \
| xargs xcodebuild -create-xcframework -allow-internal-distribution -output build/Realm.xcframework
find build/DerivedData/Realm/Build/Products -name 'RealmSwift.framework' \
| sed 's/.*/-framework &/' \
| xargs xcodebuild -create-xcframework -allow-internal-distribution -output build/RealmSwift.xcframework
exit 0
;;
######################################
# Analysis
######################################
"analyze-osx")
xc -scheme Realm -configuration "$CONFIGURATION" analyze
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-tvos-devices || failed=1
sh build.sh test-osx || failed=1
sh build.sh test-osx-swift || failed=1
sh build.sh test-catalyst || failed=1
sh build.sh test-catalyst-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")
test_ios_static "name=iPhone 8"
exit 0
;;
"test-ios-dynamic")
xctest Realm -configuration "$CONFIGURATION" -sdk iphonesimulator -destination 'name=iPhone 8'
exit 0
;;
"test-ios-swift")
xctest RealmSwift -configuration "$CONFIGURATION" -sdk iphonesimulator -destination 'name=iPhone 8'
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_devices iphoneos "Realm" "$CONFIGURATION"
exit $?
;;
"test-ios-devices-swift")
test_devices iphoneos "RealmSwift" "$CONFIGURATION"
exit $?
;;
"test-tvos")
destination="Apple TV"
xctest Realm -configuration "$CONFIGURATION" -sdk appletvsimulator -destination "name=$destination"
exit $?
;;
"test-tvos-swift")
destination="Apple TV"
xctest RealmSwift -configuration "$CONFIGURATION" -sdk appletvsimulator -destination "name=$destination"
exit $?
;;
"test-tvos-devices")
test_devices appletvos TestHost "$CONFIGURATION"
;;
"test-osx")
COVERAGE_PARAMS=()
if [[ "$CONFIGURATION" == "Debug" ]]; then
COVERAGE_PARAMS=(GCC_GENERATE_TEST_COVERAGE_FILES=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES)
fi
xctest Realm -configuration "$CONFIGURATION" "${COVERAGE_PARAMS[@]}"
exit 0
;;
"test-osx-swift")
xctest RealmSwift -configuration $CONFIGURATION
exit 0
;;
"test-osx-object-server")
xctest 'Object Server Tests' -configuration "$CONFIGURATION" -sdk macosx
exit 0
;;
test-swiftpm-ios)
cd examples/installation
sh build.sh test-ios-swift-spm
exit 0
;;
test-swiftpm*)
SANITIZER=$(echo "$COMMAND" | cut -d - -f 3)
SWIFT_TEST_FLAGS=(-Xcc -g0)
if [ -n "$SANITIZER" ]; then
SWIFT_TEST_FLAGS+=(--sanitize "$SANITIZER")
export ASAN_OPTIONS='check_initialization_order=true:detect_stack_use_after_return=true'
fi
xcrun swift package resolve
xcrun swift test --configuration "$(echo "$CONFIGURATION" | tr "[:upper:]" "[:lower:]")" "${SWIFT_TEST_FLAGS[@]}"
exit 0
;;
"test-swiftui-ios")
xctest 'SwiftUITestHost' -configuration "$CONFIGURATION" -sdk iphonesimulator -destination 'name=iPhone 8'
exit 0
;;
"test-catalyst")
export REALM_SDKROOT=iphoneos
xctest Realm -configuration "$CONFIGURATION" -destination 'platform=macOS,variant=Mac Catalyst' CODE_SIGN_IDENTITY=''
exit 0
;;
"test-catalyst-swift")
export REALM_SDKROOT=iphoneos
xctest RealmSwift -configuration "$CONFIGURATION" -destination 'platform=macOS,variant=Mac Catalyst' CODE_SIGN_IDENTITY=''
exit 0
;;
"test-swiftui-server-osx")
xctest 'SwiftUISyncTestHost' -configuration "$CONFIGURATION" -sdk macosx -destination 'platform=macOS'
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-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-tvos
sh build.sh verify-tvos-debug
sh build.sh verify-tvos-device
sh build.sh verify-swiftlint
sh build.sh verify-swiftpm
sh build.sh verify-osx-object-server
sh build.sh verify-catalyst
sh build.sh verify-catalyst-swift
sh build.sh verify-swiftui-ios
sh build.sh verify-swiftui-server-osx
;;
"verify-cocoapods")
if [[ -d .git ]]; then
# Verify the current branch, unless one was already specified in the sha environment variable.
if [[ -z $sha ]]; then
export sha=$(git rev-parse --abbrev-ref HEAD)
fi
if [[ $(git log -1 '@{push}..') != "" ]] || ! git diff-index --quiet HEAD; then
echo "WARNING: verify-cocoapods will test the latest revision of $sha found on GitHub."
echo " Any unpushed local changes will not be tested."
echo ""
sleep 1
fi
fi
sh build.sh verify-cocoapods-ios
sh build.sh verify-cocoapods-ios-dynamic
sh build.sh verify-cocoapods-osx
sh build.sh verify-cocoapods-watchos
# https://github.com/CocoaPods/CocoaPods/issues/7708
export EXPANDED_CODE_SIGN_IDENTITY=''
cd examples/installation
sh build.sh test-ios-objc-cocoapods
sh build.sh test-ios-objc-cocoapods-dynamic
sh build.sh test-ios-swift-cocoapods
sh build.sh test-osx-objc-cocoapods
sh build.sh test-osx-swift-cocoapods
sh build.sh test-catalyst-objc-cocoapods
sh build.sh test-catalyst-objc-cocoapods-dynamic
sh build.sh test-catalyst-swift-cocoapods
sh build.sh test-watchos-objc-cocoapods
sh build.sh test-watchos-swift-cocoapods
;;
verify-cocoapods-ios-dynamic)
PLATFORM=$(echo "$COMMAND" | cut -d - -f 3)
# https://github.com/CocoaPods/CocoaPods/issues/7708
export EXPANDED_CODE_SIGN_IDENTITY=''
cd examples/installation
sh build.sh test-ios-objc-cocoapods-dynamic
;;
verify-cocoapods-*)
PLATFORM=$(echo "$COMMAND" | cut -d - -f 3)
# https://github.com/CocoaPods/CocoaPods/issues/7708
export EXPANDED_CODE_SIGN_IDENTITY=''
cd examples/installation
sh build.sh "test-$PLATFORM-swift-cocoapods"
;;
"verify-osx-encryption")
REALM_ENCRYPT_ALL=YES sh build.sh test-osx
exit 0
;;
"verify-osx")
REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS -workspace examples/osx/objc/RealmExamples.xcworkspace" \
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 0
;;
"verify-osx-swift")
sh build.sh test-osx-swift
exit 0
;;
"verify-swiftui-ios")
sh build.sh test-swiftui-ios
exit 0
;;
"verify-swiftui-server-osx")
sh build.sh test-swiftui-server-osx
exit 0
;;
"verify-osx-swift-evolution")
export REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS REALM_BUILD_LIBRARY_FOR_DISTRIBUTION=YES"
sh build.sh test-osx-swift
exit 0
;;
"verify-ios-static")
REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS -workspace examples/ios/objc/RealmExamples.xcworkspace" \
sh build.sh test-ios-static
sh build.sh examples-ios
;;
"verify-ios-dynamic")
sh build.sh test-ios-dynamic
;;
"verify-ios-swift")
REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS -workspace examples/ios/swift/RealmExamples.xcworkspace" \
sh build.sh test-ios-swift
sh build.sh examples-ios-swift
;;
"verify-ios-swift-evolution")
export REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS REALM_BUILD_LIBRARY_FOR_DISTRIBUTION=YES"
sh build.sh test-ios-swift
exit 0
;;
"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.json"
if ruby -rjson -e "j = JSON.parse(File.read('docs/${lang}_output/undocumented.json')); exit j['warnings'].length != 0"; then
echo "Undocumented Realm $lang declarations:"
cat "$undocumented"
exit 1
fi
done
exit 0
;;
"verify-watchos")
sh build.sh watchos-swift
exit 0
;;
"verify-tvos")
REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS -workspace examples/tvos/objc/RealmExamples.xcworkspace" \
sh build.sh test-tvos
sh build.sh examples-tvos
exit 0
;;
"verify-tvos-swift")
REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS -workspace examples/tvos/swift/RealmExamples.xcworkspace" \
sh build.sh test-tvos-swift
sh build.sh examples-tvos-swift
exit 0
;;
"verify-tvos-swift-evolution")
export REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS REALM_BUILD_LIBRARY_FOR_DISTRIBUTION=YES"
sh build.sh test-tvos-swift
exit 0
;;
"verify-tvos-device")
sh build.sh test-tvos-devices
exit 0
;;
"verify-swiftlint")
swiftlint lint --strict
exit 0
;;
verify-swiftpm*)
sh build.sh "test-$(echo "$COMMAND" | cut -d - -f 2-)"
exit 0
;;
"verify-osx-object-server")
sh build.sh test-osx-object-server
exit 0
;;
"verify-catalyst")
sh build.sh test-catalyst
exit 0
;;
"verify-catalyst-swift")
sh build.sh test-catalyst-swift
exit 0
;;
"verify-xcframework")
sh build.sh xcframework
exit 0
;;
######################################
# Docs
######################################
"docs")
build_docs objc
build_docs swift
exit 0
;;
######################################
# Examples
######################################
"examples")
sh build.sh clean
sh build.sh prelaunch-simulator
export REALM_SKIP_PRELAUNCH=1
sh build.sh examples-ios
sh build.sh examples-ios-swift
sh build.sh examples-osx
sh build.sh examples-tvos
sh build.sh examples-tvos-swift
exit 0
;;
"examples-ios")
workspace="examples/ios/objc/RealmExamples.xcworkspace"
pod install --project-directory="$workspace/.." --no-repo-update
examples="Simple TableView Migration Backlink GroupedTableView RACTableView Encryption Draw"
versions="0 1 2 3 4 5"
for example in $examples; do
if [ "$example" = "Migration" ]; then
# The migration example needs to be built for each schema version to ensure each compiles.
for version in $versions; do
xc -workspace "$workspace" -scheme "$example" -configuration "$CONFIGURATION" -sdk iphonesimulator build ARCHS=x86_64 "${CODESIGN_PARAMS[@]}" GCC_PREPROCESSOR_DEFINITIONS="\$(GCC_PREPROCESSOR_DEFINITIONS) SCHEMA_VERSION_$version"
done
else
xc -workspace "$workspace" -scheme "$example" -configuration "$CONFIGURATION" -sdk iphonesimulator build ARCHS=x86_64 "${CODESIGN_PARAMS[@]}"
fi
done
if [ -n "${JENKINS_HOME}" ]; then
xc -workspace "$workspace" -scheme Extension -configuration "$CONFIGURATION" -sdk iphonesimulator build ARCHS=x86_64 "${CODESIGN_PARAMS[@]}"
fi
exit 0
;;
"examples-ios-swift")
workspace="examples/ios/swift/RealmExamples.xcworkspace"
if [[ ! -d "$workspace" ]]; then
workspace="${workspace/swift/swift-$REALM_XCODE_VERSION}"
fi
examples="Simple TableView Migration Backlink GroupedTableView Encryption AppClip AppClipParent"
versions="0 1 2 3 4 5"
for example in $examples; do
if [ "$example" = "Migration" ]; then
# The migration example needs to be built for each schema version to ensure each compiles.
for version in $versions; do
xc -workspace "$workspace" -scheme "$example" -configuration "$CONFIGURATION" -sdk iphonesimulator build ARCHS=x86_64 "${CODESIGN_PARAMS[@]}" OTHER_SWIFT_FLAGS="\$(OTHER_SWIFT_FLAGS) -DSCHEMA_VERSION_$version"
done
else
xc -workspace "$workspace" -scheme "$example" -configuration "$CONFIGURATION" -sdk iphonesimulator build ARCHS=x86_64 "${CODESIGN_PARAMS[@]}"
fi
done
exit 0
;;
"examples-osx")
xc -workspace examples/osx/objc/RealmExamples.xcworkspace -scheme JSONImport -configuration "${CONFIGURATION}" build "${CODESIGN_PARAMS[@]}"
;;
"examples-tvos")
workspace="examples/tvos/objc/RealmExamples.xcworkspace"
examples="DownloadCache PreloadedData"
for example in $examples; do
xc -workspace "$workspace" -scheme "$example" -configuration "$CONFIGURATION" -sdk appletvsimulator build ARCHS=x86_64 "${CODESIGN_PARAMS[@]}"
done
exit 0
;;
"examples-tvos-swift")
workspace="examples/tvos/swift/RealmExamples.xcworkspace"
if [[ ! -d "$workspace" ]]; then
workspace="${workspace/swift/swift-$REALM_XCODE_VERSION}"
fi
examples="DownloadCache PreloadedData"
for example in $examples; do
xc -workspace "$workspace" -scheme "$example" -configuration "$CONFIGURATION" -sdk appletvsimulator build ARCHS=x86_64 "${CODESIGN_PARAMS[@]}"
done
exit 0
;;
######################################
# Versioning