3 ##################################################################################
4 # Custom build tool for Realm Objective-C binding.
6 # (C) Copyright 2011-2015 by realm.io.
7 ##################################################################################
9 # Warning: pipefail is not a POSIX compatible option, but on OS X it works just fine.
10 # OS X uses a POSIX complain version of bash as /bin/sh, but apparently it does
11 # not strip away this feature. Also, this will fail if somebody forces the script
16 source_root="$(dirname "$0")"
18 # You can override the version of the core library
19 : ${REALM_CORE_VERSION:=$(sed -n 's/^REALM_CORE_VERSION=\(.*\)$/\1/p' ${source_root}/dependencies.list)} # set to "current" to always use the current build
21 : ${REALM_SYNC_VERSION:=$(sed -n 's/^REALM_SYNC_VERSION=\(.*\)$/\1/p' ${source_root}/dependencies.list)}
23 : ${REALM_OBJECT_SERVER_VERSION:=$(sed -n 's/^REALM_OBJECT_SERVER_VERSION=\(.*\)$/\1/p' ${source_root}/dependencies.list)}
25 # You can override the xcmode used
26 : ${XCMODE:=xcodebuild} # must be one of: xcodebuild (default), xcpretty, xctool
28 # Provide a fallback value for TMPDIR, relevant for Xcode Bots
29 : ${TMPDIR:=$(getconf DARWIN_USER_TEMP_DIR)}
31 PATH=/usr/libexec:$PATH
33 if ! [ -z "${JENKINS_HOME}" ]; then
34 XCPRETTY_PARAMS="--no-utf --report junit --output build/reports/junit.xml"
35 CODESIGN_PARAMS="CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO"
40 Usage: sh $0 command [argument]
43 clean: clean up/remove all generated files
44 download-core: downloads core library (binary version)
45 download-object-server: downloads and installs the Realm Object Server
46 download-sync: downloads sync library (binary version, core+sync)
47 build: builds all iOS and OS X frameworks
48 ios-static: builds fat iOS static framework
49 ios-dynamic: builds iOS dynamic frameworks
50 ios-swift: builds RealmSwift frameworks for iOS
51 watchos: builds watchOS framwork
52 watchos-swift: builds RealmSwift framework for watchOS
53 tvos: builds tvOS framework
54 tvos-swift: builds RealmSwift framework for tvOS
55 osx: builds OS X framework
56 osx-swift: builds RealmSwift framework for OS X
57 analyze-osx: analyzes OS X framework
58 test: tests all iOS and OS X frameworks
59 test-all: tests all iOS and OS X frameworks in both Debug and Release configurations
60 test-ios-static: tests static iOS framework on 32-bit and 64-bit simulators
61 test-ios-dynamic: tests dynamic iOS framework on 32-bit and 64-bit simulators
62 test-ios-swift: tests RealmSwift iOS framework on 32-bit and 64-bit simulators
63 test-ios-devices: tests ObjC & Swift iOS frameworks on all attached iOS devices
64 test-ios-devices-objc: tests ObjC iOS framework on all attached iOS devices
65 test-ios-devices-swift: tests Swift iOS framework on all attached iOS devices
66 test-tvos: tests tvOS framework
67 test-tvos-swift: tests RealmSwift tvOS framework
68 test-tvos-devices: tests ObjC & Swift tvOS frameworks on all attached tvOS devices
69 test-osx: tests OS X framework
70 test-osx-swift: tests RealmSwift OS X framework
71 verify: verifies docs, osx, osx-swift, ios-static, ios-dynamic, ios-swift, ios-device in both Debug and Release configurations, swiftlint
72 verify-osx-object-server: downloads the Realm Object Server and runs the Objective-C and Swift integration tests
73 docs: builds docs in docs/output
74 examples: builds all examples
75 examples-ios: builds all static iOS examples
76 examples-ios-swift: builds all Swift iOS examples
77 examples-osx: builds all OS X examples
78 get-version: get the current version
79 set-version version: set the version
80 cocoapods-setup: download realm-core and create a stub RLMPlatform.h file to enable building via CocoaPods
84 version: version in the x.y.z format
86 environment variables:
87 XCMODE: xcodebuild (default), xcpretty or xctool
88 CONFIGURATION: Debug or Release (default)
89 REALM_CORE_VERSION: version in x.y.z format or "current" to use local build
90 REALM_EXTRA_BUILD_ARGUMENTS: additional arguments to pass to the build tool
91 REALM_XCODE_VERSION: the version number of Xcode to use (e.g.: 8.1)
95 ######################################
97 ######################################
99 xcode_version_major() {
100 echo "${REALM_XCODE_VERSION%%.*}"
104 mkdir -p build/DerivedData
105 CMD="xcodebuild -IDECustomDerivedDataLocation=build/DerivedData $@"
106 echo "Building with command:" $CMD
111 # Logs xcodebuild output in realtime
112 : ${NSUnbufferedIO:=YES}
113 args="$@ SWIFT_VERSION=$REALM_SWIFT_VERSION $REALM_EXTRA_BUILD_ARGUMENTS"
114 if [[ "$XCMODE" == "xcodebuild" ]]; then
116 elif [[ "$XCMODE" == "xcpretty" ]]; then
118 xcode "$args" | tee build/build.log | xcpretty -c ${XCPRETTY_PARAMS} || {
119 echo "The raw xcodebuild output is available in build/build.log"
122 elif [[ "$XCMODE" == "xctool" ]]; then
128 find "$1" -name '*.bcsymbolmap' -type f -exec cp {} "$2" \;
133 local module_name="$2"
136 local scope_suffix="$5"
137 local version_suffix="$6"
138 local config="$CONFIGURATION"
142 if [[ "$os" == "iphoneos" ]]; then
144 destination="iPhone 6"
145 elif [[ "$os" == "watchos" ]]; then
147 destination="Apple Watch - 42mm"
148 elif [[ "$os" == "appletvos" ]]; then
150 if (( $(xcode_version_major) >= 9 )); then
151 destination="Apple TV"
153 destination="Apple TV 1080p"
158 local build_products_path="build/DerivedData/Realm/Build/Products"
159 local product_name="$module_name.framework"
160 local binary_path="$module_name"
161 local os_path="$build_products_path/$config-$os$scope_suffix/$product_name"
162 local simulator_path="$build_products_path/$config-$simulator$scope_suffix/$product_name"
163 local out_path="build/$os_name$scope_suffix$version_suffix"
165 # Build for each platform
166 xc "-scheme '$scheme' -configuration $config -sdk $os"
167 xc "-scheme '$scheme' -configuration $config -sdk $simulator -destination 'name=$destination' ONLY_ACTIVE_ARCH=NO"
169 # Combine .swiftmodule
170 if [ -d $simulator_path/Modules/$module_name.swiftmodule ]; then
171 cp $simulator_path/Modules/$module_name.swiftmodule/* $os_path/Modules/$module_name.swiftmodule/
174 # Copy *.bcsymbolmap to .framework for submitting app with bitcode
175 copy_bcsymbolmap "$build_products_path/$config-$os$scope_suffix" "$os_path"
177 # Retrieve build products
178 clean_retrieve $os_path $out_path $product_name
180 # Combine ar archives
181 LIPO_OUTPUT="$out_path/$product_name/$module_name"
182 xcrun lipo -create "$simulator_path/$binary_path" "$os_path/$binary_path" -output "$LIPO_OUTPUT"
184 if [[ "$destination" != "" && "$config" == "Release" ]]; then
185 sh build.sh binary-has-bitcode "$LIPO_OUTPUT"
195 move_to_clean_dir() {
203 xc "-scheme 'Realm iOS static' -configuration $CONFIGURATION -sdk iphonesimulator -destination '$destination' build"
204 if (( $(xcode_version_major) < 9 )); then
205 xc "-scheme 'Realm iOS static' -configuration $CONFIGURATION -sdk iphonesimulator -destination '$destination' test 'ARCHS=\$(ARCHS_STANDARD_32_BIT)'"
208 # Xcode's depending tracking is lacking and it doesn't realize that the Realm static framework's static library
209 # needs to be recreated when the active architectures change. Help Xcode out by removing the static library.
210 settings=$(xcode "-scheme 'Realm iOS static' -configuration $CONFIGURATION -sdk iphonesimulator -destination '$destination' -showBuildSettings")
211 path=$(echo "$settings" | awk '/CONFIGURATION_BUILD_DIR/ { cbd = $3; } /EXECUTABLE_PATH/ { ep = $3; } END { printf "%s/%s\n", cbd, ep; }')
214 xc "-scheme 'Realm iOS static' -configuration $CONFIGURATION -sdk iphonesimulator -destination '$destination' test"
217 ######################################
219 ######################################
222 local serial_numbers=()
224 /^ +Vendor ID: / { is_apple = 0; }
225 /^ +Vendor ID: 0x05[aA][cC] / { is_apple = 1; }
226 /^ +Serial Number: / {
228 match(\$0, /^ +Serial Number: /);
229 print substr(\$0, RLENGTH + 1);
233 local serial_numbers_text=$(/usr/sbin/system_profiler SPUSBDataType | /usr/bin/awk "$awk_script")
234 while read -r number; do
235 if [[ "$number" != "" ]]; then
236 serial_numbers+=("$number")
238 done <<< "$serial_numbers_text"
239 if [[ ${#serial_numbers[@]} == 0 ]]; then
240 echo "At least one iOS/tvOS device must be connected to this computer to run device tests"
241 if [ -z "${JENKINS_HOME}" ]; then
242 # Don't fail if running locally and there's no device
249 local configuration="$3"
251 for device in "${serial_numbers[@]}"; do
252 xc "-scheme '$scheme' -configuration $configuration -destination 'id=$device' -sdk $sdk test" || failed=1
257 ######################################
259 ######################################
263 local version=$(sh build.sh get-version)
265 local xcodebuild_arguments="--objc,Realm/Realm.h,--,-x,objective-c,-isysroot,$(xcrun --show-sdk-path),-I,$(pwd)"
269 if [[ "$language" == "swift" ]]; then
270 sh build.sh set-swift-version
271 xcodebuild_arguments="-scheme,RealmSwift"
276 touch Realm/RLMPlatform.h # jazzy will fail if it can't find all public header files
281 --author_url https://realm.io \
282 --github_url https://github.com/realm/realm-cocoa \
283 --github-file-prefix https://github.com/realm/realm-cocoa/tree/v${version} \
284 --module-version ${version} \
285 --xcodebuild-arguments ${xcodebuild_arguments} \
287 --root-url https://realm.io/docs/${language}/${version}/api/ \
288 --output docs/${language}_output \
289 --head "$(cat docs/custom_head.html)"
291 rm Realm/RLMPlatform.h
294 ######################################
296 ######################################
298 if [ "$#" -eq 0 -o "$#" -gt 3 ]; then
303 ######################################
305 ######################################
307 kill_object_server() {
308 # Based on build.sh conventions we always run ROS from a path ending in 'ros/bin/ros'.
309 pkill -f ros/bin/ros\ start
312 download_object_server() {
313 rm -rf ./test-ros-instance
314 mkdir -p ./test-ros-instance/ros
315 chmod 777 ./test-ros-instance
316 /usr/local/bin/node /usr/local/bin/npm install --scripts-prepend-node-path=auto --prefix ./test-ros-instance/ros \
317 -g realm-object-server@${REALM_OBJECT_SERVER_VERSION}
321 local download_type=$1 tries_left=3 version url error temp_dir temp_path tar_path
323 if [ "$download_type" == "core" ]; then
324 version=$REALM_CORE_VERSION
325 url="https://static.realm.io/downloads/core/realm-core-${version}.tar.xz"
326 elif [ "$download_type" == "sync" ]; then
327 version=$REALM_SYNC_VERSION
328 url="https://static.realm.io/downloads/sync/realm-sync-cocoa-${version}.tar.xz"
330 echo "Unknown dowload_type: $download_type"
334 echo "Downloading dependency: ${download_type} ${version}"
336 if [ -z "$TMPDIR" ]; then
339 temp_dir=$(dirname "$TMPDIR/waste")/${download_type}_bin
341 tar_path="${temp_dir}/${download_type}-${version}.tar.xz"
342 temp_path="${tar_path}.tmp"
344 while [ 0 -lt $tries_left ] && [ ! -f "$tar_path" ]; do
345 if ! error=$(/usr/bin/curl --fail --silent --show-error --location "$url" --output "$temp_path" 2>&1); then
346 tries_left=$[$tries_left-1]
348 mv "$temp_path" "$tar_path"
352 if [ ! -f "$tar_path" ]; then
353 printf "Downloading ${download_type} failed:\n\t$url\n\t$error\n"
359 rm -rf "$download_type"
360 tar xf "$tar_path" --xz
361 mv core "${download_type}-${version}"
364 rm -rf "${download_type}-${version}" core
365 mv "${temp_dir}/${download_type}-${version}" .
366 ln -s "${download_type}-${version}" core
370 download_common "core"
374 download_common "sync"
377 ######################################
379 ######################################
383 # Use Debug config if command ends with -debug, otherwise default to Release
384 # Set IS_RUNNING_PACKAGING when running packaging steps to avoid running iOS static tests with Xcode 8.3.3
387 COMMAND="${COMMAND%-debug}"
388 CONFIGURATION="Debug"
391 IS_RUNNING_PACKAGING=1
394 export CONFIGURATION=${CONFIGURATION:-Release}
395 export IS_RUNNING_PACKAGING=${IS_RUNNING_PACKAGING:-0}
397 # Pre-choose Xcode and Swift versions for those operations that do not set them
398 REALM_XCODE_VERSION=${xcode_version:-$REALM_XCODE_VERSION}
399 REALM_SWIFT_VERSION=${swift_version:-$REALM_SWIFT_VERSION}
400 source "${source_root}/scripts/swift-version.sh"
401 set_xcode_and_swift_versions
403 ######################################
405 ######################################
409 ######################################
411 ######################################
413 find . -type d -name build -exec rm -r "{}" +
417 ######################################
419 ######################################
420 "download-object-server")
421 download_object_server
425 "reset-ros-server-state")
426 rm -rf "./test-ros-instance/data"
427 rm -rf "./test-ros-instance/realm-object-server"
431 "reset-ros-client-state")
432 rm -rf ~/Library/Application\ Support/xctest
433 rm -rf ~/Library/Application\ Support/io.realm.TestHost
434 rm -rf ~/Library/Application\ Support/xctest-child
438 "reset-object-server")
440 # Add a short delay, so file system doesn't complain about files in use
442 sh build.sh reset-ros-server-state
443 sh build.sh reset-ros-client-state
444 # Add another delay to ensure files are actually gone from file system
449 ######################################
451 ######################################
453 if [ "$REALM_CORE_VERSION" = "current" ]; then
454 echo "Using version of core already in core/ directory"
457 if [ -d core -a -d ../realm-core -a ! -L core ]; then
458 # Allow newer versions than expected for local builds as testing
459 # with unreleased versions is one of the reasons to use a local build
460 if ! $(grep -i "${REALM_CORE_VERSION} Release notes" core/release_notes.txt >/dev/null); then
461 echo "Local build of core is out of date."
464 echo "The core library seems to be up to date."
466 elif ! [ -L core ]; then
467 echo "core is not a symlink. Deleting..."
470 # With a prebuilt version we only want to check the first non-empty
471 # line so that checking out an older commit will download the
472 # appropriate version of core if the already-present version is too new
473 elif ! $(grep -m 1 . core/release_notes.txt | grep -i "${REALM_CORE_VERSION} RELEASE NOTES" >/dev/null); then
476 echo "The core library seems to be up to date."
481 ######################################
483 ######################################
485 if [ "$REALM_SYNC_VERSION" = "current" ]; then
486 echo "Using version of core already in core/ directory"
489 if [ -d core -a -d ../realm-core -a -d ../realm-sync -a ! -L core ]; then
490 echo "Using version of core already in core/ directory"
491 elif ! [ -L core ]; then
492 echo "core is not a symlink. Deleting..."
495 elif [[ "$(cat core/version.txt)" != "$REALM_SYNC_VERSION" ]]; then
498 echo "The core library seems to be up to date."
503 ######################################
505 ######################################
507 version=${2:-$REALM_SWIFT_VERSION}
509 SWIFT_VERSION_FILE="RealmSwift/SwiftVersion.swift"
510 CONTENTS="let swiftLanguageVersion = \"$version\""
511 if [ ! -f "$SWIFT_VERSION_FILE" ] || ! grep -q "$CONTENTS" "$SWIFT_VERSION_FILE"; then
512 echo "$CONTENTS" > "$SWIFT_VERSION_FILE"
518 "prelaunch-simulator")
519 sh ${source_root}/scripts/reset-simulators.sh
522 ######################################
524 ######################################
526 sh build.sh ios-static
527 sh build.sh ios-dynamic
528 sh build.sh ios-swift
530 sh build.sh watchos-swift
532 sh build.sh tvos-swift
534 sh build.sh osx-swift
539 build_combined 'Realm iOS static' Realm iphoneos iphonesimulator "-static"
544 build_combined Realm Realm iphoneos iphonesimulator
549 sh build.sh ios-dynamic
550 build_combined RealmSwift RealmSwift iphoneos iphonesimulator '' "/swift-$REALM_SWIFT_VERSION"
551 cp -R build/ios/Realm.framework build/ios/swift-$REALM_SWIFT_VERSION
556 build_combined Realm Realm watchos watchsimulator
562 build_combined RealmSwift RealmSwift watchos watchsimulator '' "/swift-$REALM_SWIFT_VERSION"
563 cp -R build/watchos/Realm.framework build/watchos/swift-$REALM_SWIFT_VERSION
568 build_combined Realm Realm appletvos appletvsimulator
574 build_combined RealmSwift RealmSwift appletvos appletvsimulator '' "/swift-$REALM_SWIFT_VERSION"
575 cp -R build/tvos/Realm.framework build/tvos/swift-$REALM_SWIFT_VERSION
580 xc "-scheme Realm -configuration $CONFIGURATION"
581 clean_retrieve "build/DerivedData/Realm/Build/Products/$CONFIGURATION/Realm.framework" "build/osx" "Realm.framework"
587 xc "-scheme 'RealmSwift' -configuration $CONFIGURATION build"
588 destination="build/osx/swift-$REALM_SWIFT_VERSION"
589 clean_retrieve "build/DerivedData/Realm/Build/Products/$CONFIGURATION/RealmSwift.framework" "$destination" "RealmSwift.framework"
590 cp -R build/osx/Realm.framework "$destination"
594 ######################################
596 ######################################
599 xc "-scheme Realm -configuration $CONFIGURATION analyze"
603 ######################################
605 ######################################
607 set +e # Run both sets of tests even if the first fails
609 sh build.sh test-ios-static || failed=1
610 sh build.sh test-ios-dynamic || failed=1
611 sh build.sh test-ios-swift || failed=1
612 sh build.sh test-ios-devices || failed=1
613 sh build.sh test-tvos-devices || failed=1
614 sh build.sh test-osx || failed=1
615 sh build.sh test-osx-swift || failed=1
622 sh build.sh test || failed=1
623 sh build.sh test-debug || failed=1
628 test_ios_static "name=iPhone 6"
633 xc "-scheme Realm -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 6' build"
634 if (( $(xcode_version_major) < 9 )); then
635 xc "-scheme Realm -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 6' test 'ARCHS=\$(ARCHS_STANDARD_32_BIT)'"
637 xc "-scheme Realm -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 6' test"
642 xc "-scheme RealmSwift -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 6' build"
643 if (( $(xcode_version_major) < 9 )); then
644 xc "-scheme RealmSwift -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 6' test 'ARCHS=\$(ARCHS_STANDARD_32_BIT)'"
646 xc "-scheme RealmSwift -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 6' test"
653 sh build.sh test-ios-devices-objc
654 sh build.sh test-ios-devices-swift
658 "test-ios-devices-objc")
659 test_devices iphoneos "Realm" "$CONFIGURATION"
663 "test-ios-devices-swift")
664 test_devices iphoneos "RealmSwift" "$CONFIGURATION"
669 if (( $(xcode_version_major) >= 9 )); then
670 destination="Apple TV"
672 destination="Apple TV 1080p"
674 xc "-scheme Realm -configuration $CONFIGURATION -sdk appletvsimulator -destination 'name=$destination' test"
679 if (( $(xcode_version_major) >= 9 )); then
680 destination="Apple TV"
682 destination="Apple TV 1080p"
684 xc "-scheme RealmSwift -configuration $CONFIGURATION -sdk appletvsimulator -destination 'name=$destination' test"
689 test_devices appletvos TestHost "$CONFIGURATION"
694 if [[ "$CONFIGURATION" == "Debug" ]]; then
695 COVERAGE_PARAMS="GCC_GENERATE_TEST_COVERAGE_FILES=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES"
697 xc "-scheme Realm -configuration $CONFIGURATION test $COVERAGE_PARAMS"
702 xc "-scheme RealmSwift -configuration $CONFIGURATION test"
706 "test-osx-object-server")
707 xc "-scheme 'Object Server Tests' -configuration $CONFIGURATION -sdk macosx test"
711 ######################################
713 ######################################
715 sh build.sh verify-cocoapods
716 sh build.sh verify-docs
717 sh build.sh verify-osx
718 sh build.sh verify-osx-debug
719 sh build.sh verify-osx-swift
720 sh build.sh verify-osx-swift-debug
721 sh build.sh verify-ios-static
722 sh build.sh verify-ios-static-debug
723 sh build.sh verify-ios-dynamic
724 sh build.sh verify-ios-dynamic-debug
725 sh build.sh verify-ios-swift
726 sh build.sh verify-ios-swift-debug
727 sh build.sh verify-ios-device-objc
728 sh build.sh verify-ios-device-swift
729 sh build.sh verify-watchos
730 sh build.sh verify-tvos
731 sh build.sh verify-tvos-debug
732 sh build.sh verify-tvos-device
733 sh build.sh verify-swiftlint
734 sh build.sh verify-osx-object-server
738 if [[ -d .git ]]; then
739 # Verify the current branch, unless one was already specified in the sha environment variable.
740 if [[ -z $sha ]]; then
741 export sha=$(git rev-parse --abbrev-ref HEAD)
744 if [[ $(git log -1 @{push}..) != "" ]] || ! git diff-index --quiet HEAD; then
745 echo "WARNING: verify-cocoapods will test the latest revision of $sha found on GitHub."
746 echo " Any unpushed local changes will not be tested."
752 cd examples/installation
753 sh build.sh test-ios-objc-cocoapods
754 sh build.sh test-ios-objc-cocoapods-dynamic
755 sh build.sh test-ios-swift-cocoapods
756 sh build.sh test-osx-objc-cocoapods
757 sh build.sh test-osx-swift-cocoapods
758 sh build.sh test-watchos-objc-cocoapods
759 sh build.sh test-watchos-swift-cocoapods
762 "verify-osx-encryption")
763 REALM_ENCRYPT_ALL=YES sh build.sh test-osx
769 sh build.sh analyze-osx
770 sh build.sh examples-osx
773 cd examples/osx/objc/build/DerivedData/RealmExamples/Build/Products/$CONFIGURATION
774 DYLD_FRAMEWORK_PATH=. ./JSONImport >/dev/null
780 sh build.sh test-osx-swift
785 sh build.sh test-ios-static
786 sh build.sh examples-ios
789 "verify-ios-dynamic")
790 sh build.sh test-ios-dynamic
794 sh build.sh test-ios-swift
795 sh build.sh examples-ios-swift
798 "verify-ios-device-objc")
799 sh build.sh test-ios-devices-objc
803 "verify-ios-device-swift")
804 sh build.sh test-ios-devices-swift
810 for lang in swift objc; do
811 undocumented="docs/${lang}_output/undocumented.json"
812 if ruby -rjson -e "j = JSON.parse(File.read('docs/${lang}_output/undocumented.json')); exit j['warnings'].length != 0"; then
813 echo "Undocumented Realm $lang declarations:"
822 sh build.sh watchos-swift
827 sh build.sh test-tvos
828 sh build.sh test-tvos-swift
829 sh build.sh examples-tvos
830 sh build.sh examples-tvos-swift
834 "verify-tvos-device")
835 sh build.sh test-tvos-devices
840 swiftlint lint --strict
844 "verify-osx-object-server")
845 sh build.sh download-object-server
846 sh build.sh test-osx-object-server
847 sh build.sh reset-object-server
851 ######################################
853 ######################################
860 ######################################
862 ######################################
865 sh build.sh examples-ios
866 sh build.sh examples-ios-swift
867 sh build.sh examples-osx
868 sh build.sh examples-tvos
869 sh build.sh examples-tvos-swift
874 sh build.sh prelaunch-simulator
875 workspace="examples/ios/objc/RealmExamples.xcworkspace"
876 pod install --project-directory="$workspace/.." --no-repo-update
877 xc "-workspace $workspace -scheme Simple -configuration $CONFIGURATION -destination 'name=iPhone 6' build ${CODESIGN_PARAMS}"
878 xc "-workspace $workspace -scheme TableView -configuration $CONFIGURATION -destination 'name=iPhone 6' build ${CODESIGN_PARAMS}"
879 xc "-workspace $workspace -scheme Migration -configuration $CONFIGURATION -destination 'name=iPhone 6' build ${CODESIGN_PARAMS}"
880 xc "-workspace $workspace -scheme Backlink -configuration $CONFIGURATION -destination 'name=iPhone 6' build ${CODESIGN_PARAMS}"
881 xc "-workspace $workspace -scheme GroupedTableView -configuration $CONFIGURATION -destination 'name=iPhone 6' build ${CODESIGN_PARAMS}"
882 xc "-workspace $workspace -scheme RACTableView -configuration $CONFIGURATION -destination 'name=iPhone 6' build ${CODESIGN_PARAMS}"
883 xc "-workspace $workspace -scheme Encryption -configuration $CONFIGURATION -destination 'name=iPhone 6' build ${CODESIGN_PARAMS}"
884 xc "-workspace $workspace -scheme Draw -configuration $CONFIGURATION -destination 'name=iPhone 6' build ${CODESIGN_PARAMS}"
886 if [ ! -z "${JENKINS_HOME}" ]; then
887 xc "-workspace $workspace -scheme Extension -configuration $CONFIGURATION -destination 'name=iPhone 6' build ${CODESIGN_PARAMS}"
893 "examples-ios-swift")
894 sh build.sh prelaunch-simulator
895 workspace="examples/ios/swift/RealmExamples.xcworkspace"
896 if [[ ! -d "$workspace" ]]; then
897 workspace="${workspace/swift/swift-$REALM_SWIFT_VERSION}"
900 xc "-workspace $workspace -scheme Simple -configuration $CONFIGURATION -destination 'name=iPhone 6' build ${CODESIGN_PARAMS}"
901 xc "-workspace $workspace -scheme TableView -configuration $CONFIGURATION -destination 'name=iPhone 6' build ${CODESIGN_PARAMS}"
902 xc "-workspace $workspace -scheme Migration -configuration $CONFIGURATION -destination 'name=iPhone 6' build ${CODESIGN_PARAMS}"
903 xc "-workspace $workspace -scheme Encryption -configuration $CONFIGURATION -destination 'name=iPhone 6' build ${CODESIGN_PARAMS}"
904 xc "-workspace $workspace -scheme Backlink -configuration $CONFIGURATION -destination 'name=iPhone 6' build ${CODESIGN_PARAMS}"
905 xc "-workspace $workspace -scheme GroupedTableView -configuration $CONFIGURATION -destination 'name=iPhone 6' build ${CODESIGN_PARAMS}"
910 xc "-workspace examples/osx/objc/RealmExamples.xcworkspace -scheme JSONImport -configuration ${CONFIGURATION} build ${CODESIGN_PARAMS}"
914 workspace="examples/tvos/objc/RealmExamples.xcworkspace"
915 if (( $(xcode_version_major) >= 9 )); then
916 destination="Apple TV"
918 destination="Apple TV 1080p"
921 xc "-workspace $workspace -scheme DownloadCache -configuration $CONFIGURATION -destination 'name=$destination' build ${CODESIGN_PARAMS}"
922 xc "-workspace $workspace -scheme PreloadedData -configuration $CONFIGURATION -destination 'name=$destination' build ${CODESIGN_PARAMS}"
926 "examples-tvos-swift")
927 workspace="examples/tvos/swift/RealmExamples.xcworkspace"
928 if [[ ! -d "$workspace" ]]; then
929 workspace="${workspace/swift/swift-$REALM_SWIFT_VERSION}"
932 if (( $(xcode_version_major) >= 9 )); then
933 destination="Apple TV"
935 destination="Apple TV 1080p"
938 xc "-workspace $workspace -scheme DownloadCache -configuration $CONFIGURATION -destination 'name=$destination' build ${CODESIGN_PARAMS}"
939 xc "-workspace $workspace -scheme PreloadedData -configuration $CONFIGURATION -destination 'name=$destination' build ${CODESIGN_PARAMS}"
943 ######################################
945 ######################################
947 version_file="Realm/Realm-Info.plist"
948 echo "$(PlistBuddy -c "Print :CFBundleShortVersionString" "$version_file")"
954 version_files="Realm/Realm-Info.plist"
956 if [ -z "$realm_version" ]; then
957 echo "You must specify a version."
960 # The bundle version can contain only three groups of digits separated by periods,
961 # so strip off any -beta.x tag from the end of the version string.
962 bundle_version=$(echo "$realm_version" | cut -d - -f 1)
963 for version_file in $version_files; do
964 PlistBuddy -c "Set :CFBundleVersion $bundle_version" "$version_file"
965 PlistBuddy -c "Set :CFBundleShortVersionString $realm_version" "$version_file"
967 sed -i '' "s/^VERSION=.*/VERSION=$realm_version/" dependencies.list
971 ######################################
973 ######################################
975 "binary-has-bitcode")
977 # Although grep has a '-q' flag to prevent logging to stdout, grep
978 # behaves differently when used, so redirect stdout to /dev/null.
979 if otool -l "$BINARY" | grep "segname __LLVM" > /dev/null 2>&1; then
982 # Work around rdar://21826157 by checking for bitcode in thin binaries
984 # Get architectures for binary
985 archs="$(lipo -info "$BINARY" | rev | cut -d ':' -f1 | rev)"
987 archs_array=( $archs )
988 if [[ ${#archs_array[@]} -lt 2 ]]; then
989 exit 1 # Early exit if not a fat binary
992 TEMPDIR=$(mktemp -d $TMPDIR/realm-bitcode-check.XXXX)
994 for arch in $archs; do
995 lipo -thin "$arch" "$BINARY" -output "$TEMPDIR/$arch"
996 if otool -l "$TEMPDIR/$arch" | grep -q "segname __LLVM"; then
1003 ######################################
1005 ######################################
1007 if [ ! -d core ]; then
1008 sh build.sh download-sync
1011 mv core/librealm-ios.a core/librealmcore-ios.a
1012 mv core/librealm-macosx.a core/librealmcore-macosx.a
1013 mv core/librealm-tvos.a core/librealmcore-tvos.a
1014 mv core/librealm-watchos.a core/librealmcore-watchos.a
1017 if [[ "$2" != "swift" ]]; then
1018 if [ ! -d Realm/ObjectStore/src ]; then
1022 ERROR: One of Realm's submodules is missing!
1024 If you're using Realm and/or RealmSwift from a git branch, please add 'submodules: true' to
1025 their entries in your Podfile.
1034 mv core/include include/core
1036 mkdir -p include/impl/apple include/util/apple include/sync/impl/apple
1037 cp Realm/*.hpp include
1038 cp Realm/ObjectStore/src/*.hpp include
1039 cp Realm/ObjectStore/src/sync/*.hpp include/sync
1040 cp Realm/ObjectStore/src/sync/impl/*.hpp include/sync/impl
1041 cp Realm/ObjectStore/src/sync/impl/apple/*.hpp include/sync/impl/apple
1042 cp Realm/ObjectStore/src/impl/*.hpp include/impl
1043 cp Realm/ObjectStore/src/impl/apple/*.hpp include/impl/apple
1044 cp Realm/ObjectStore/src/util/*.hpp include/util
1045 cp Realm/ObjectStore/src/util/apple/*.hpp include/util/apple
1047 touch Realm/RLMPlatform.h
1048 if [ -n "$COCOAPODS_VERSION" ]; then
1049 # This variable is set for the prepare_command available
1050 # from the 1.0 prereleases, which requires a different
1051 # header layout within the header_mappings_dir.
1052 cp Realm/*.h include
1054 # For CocoaPods < 1.0, we need to scope the headers within
1055 # the header_mappings_dir by another subdirectory to avoid
1056 # Clang from complaining about non-modular headers.
1057 mkdir -p include/Realm
1058 cp Realm/*.h include/Realm
1061 sh build.sh set-swift-version
1065 ######################################
1066 # Continuous Integration
1067 ######################################
1070 mkdir -p build/reports
1071 # FIXME: Re-enable once CI can properly unlock the keychain
1072 export REALM_DISABLE_METADATA_ENCRYPTION=1
1074 # strip off the ios|tvos version specifier, e.g. the last part of: `ios-device-objc-ios8`
1075 if [[ "$target" =~ ^((ios|tvos)-device(-(objc|swift))?)(-(ios|tvos)[[:digit:]]+)?$ ]]; then
1076 export target=${BASH_REMATCH[1]}
1079 if [ "$target" = "docs" ]; then
1080 sh build.sh set-swift-version
1081 sh build.sh verify-docs
1082 elif [ "$target" = "swiftlint" ]; then
1083 sh build.sh verify-swiftlint
1085 export sha=$GITHUB_PR_SOURCE_BRANCH
1086 export CONFIGURATION=$configuration
1087 export REALM_EXTRA_BUILD_ARGUMENTS='GCC_GENERATE_DEBUGGING_SYMBOLS=NO REALM_PREFIX_HEADER=Realm/RLMPrefix.h'
1088 sh build.sh prelaunch-simulator
1090 # Reset CoreSimulator.log
1091 mkdir -p ~/Library/Logs/CoreSimulator
1092 echo > ~/Library/Logs/CoreSimulator/CoreSimulator.log
1094 if [ -d ~/Library/Developer/CoreSimulator/Devices/ ]; then
1095 # Verify that no Realm files still exist
1096 ! find ~/Library/Developer/CoreSimulator/Devices/ -name '*.realm' | grep -q .
1100 sh build.sh verify-$target 2>&1 | tee build/build.log | xcpretty -r junit -o build/reports/junit.xml || failed=1
1101 if [ "$failed" = "1" ] && cat build/build.log | grep -E 'DTXProxyChannel|DTXChannel|out of date and needs to be rebuilt|operation never finished bootstrapping'; then
1102 echo "Known Xcode error detected. Running job again."
1103 if cat build/build.log | grep -E 'out of date and needs to be rebuilt'; then
1104 rm -rf build/DerivedData
1107 sh build.sh verify-$target | tee build/build.log | xcpretty -r junit -o build/reports/junit.xml || failed=1
1108 elif [ "$failed" = "1" ] && tail ~/Library/Logs/CoreSimulator/CoreSimulator.log | grep -E "Operation not supported|Failed to lookup com.apple.coreservices.lsuseractivity.simulatorsupport"; then
1109 echo "Known Xcode error detected. Running job again."
1111 sh build.sh verify-$target | tee build/build.log | xcpretty -r junit -o build/reports/junit.xml || failed=1
1113 if [ "$failed" = "1" ]; then
1114 echo "\n\n***\nbuild/build.log\n***\n\n" && cat build/build.log || true
1115 echo "\n\n***\nCoreSimulator.log\n***\n\n" && cat ~/Library/Logs/CoreSimulator/CoreSimulator.log
1120 if [ "$target" = "osx" ] && [ "$configuration" = "Debug" ]; then
1121 gcovr -r . -f ".*Realm.*" -e ".*Tests.*" -e ".*core.*" --xml > build/reports/coverage-report.xml
1122 WS=$(pwd | sed "s/\//\\\\\//g")
1123 sed -i ".bak" "s/<source>\./<source>${WS}/" build/reports/coverage-report.xml
1127 ######################################
1129 ######################################
1132 ./scripts/package_examples.rb
1133 zip --symlinks -r realm-examples.zip examples -x "examples/installation/*"
1136 "package-test-examples")
1137 if ! VERSION=$(echo realm-objc-*.zip | egrep -o '\d*\.\d*\.\d*-[a-z]*(\.\d*)?'); then
1138 VERSION=$(echo realm-objc-*.zip | egrep -o '\d*\.\d*\.\d*')
1140 OBJC="realm-objc-${VERSION}"
1141 SWIFT="realm-swift-${VERSION}"
1145 cp -r ${source_root}/scripts ${OBJC}
1147 sh build.sh examples-ios
1148 sh build.sh examples-tvos
1149 sh build.sh examples-osx
1156 cp -r ${source_root}/scripts ${SWIFT}
1158 sh build.sh examples-ios-swift
1159 sh build.sh examples-tvos-swift
1164 "package-ios-static")
1165 sh build.sh prelaunch-simulator
1166 sh build.sh ios-static
1169 zip --symlinks -r realm-framework-ios-static.zip Realm.framework
1173 sh build.sh prelaunch-simulator
1174 sh build.sh ios-dynamic
1176 zip --symlinks -r realm-framework-ios.zip Realm.framework
1182 cd build/DerivedData/Realm/Build/Products/Release
1183 zip --symlinks -r realm-framework-osx.zip Realm.framework
1186 "package-ios-swift")
1187 for version in 8.3.3 9.0 9.1 9.2; do
1188 REALM_XCODE_VERSION=$version
1189 REALM_SWIFT_VERSION=
1190 set_xcode_and_swift_versions
1191 sh build.sh prelaunch-simulator
1192 sh build.sh ios-swift
1196 ln -s swift-4.0 swift-3.2
1197 ln -s swift-4.0.2 swift-3.2.2
1198 ln -s swift-4.0.2 swift-3.2.3
1199 ln -s swift-4.0.2 swift-4.0.3
1200 zip --symlinks -r realm-swift-framework-ios.zip swift-3.1 swift-3.2 swift-3.2.2 swift-3.2.3 swift-4.0 swift-4.0.2 swift-4.0.3
1203 "package-osx-swift")
1204 for version in 8.3.3 9.0 9.1 9.2; do
1205 REALM_XCODE_VERSION=$version
1206 REALM_SWIFT_VERSION=
1207 set_xcode_and_swift_versions
1208 sh build.sh prelaunch-simulator
1209 sh build.sh osx-swift
1213 ln -s swift-4.0 swift-3.2
1214 ln -s swift-4.0.2 swift-3.2.2
1215 ln -s swift-4.0.2 swift-3.2.3
1216 ln -s swift-4.0.2 swift-4.0.3
1217 zip --symlinks -r realm-swift-framework-osx.zip swift-3.1 swift-3.2 swift-3.2.2 swift-3.2.3 swift-4.0 swift-4.0.2 swift-4.0.3
1221 sh build.sh prelaunch-simulator
1225 zip --symlinks -r realm-framework-watchos.zip Realm.framework
1228 "package-watchos-swift")
1229 for version in 8.3.3 9.0 9.1 9.2; do
1230 REALM_XCODE_VERSION=$version
1231 REALM_SWIFT_VERSION=
1232 set_xcode_and_swift_versions
1233 sh build.sh prelaunch-simulator
1234 sh build.sh watchos-swift
1238 ln -s swift-4.0 swift-3.2
1239 ln -s swift-4.0.2 swift-3.2.2
1240 ln -s swift-4.0.2 swift-3.2.3
1241 ln -s swift-4.0.2 swift-4.0.3
1242 zip --symlinks -r realm-swift-framework-watchos.zip swift-3.1 swift-3.2 swift-3.2.2 swift-3.2.3 swift-4.0 swift-4.0.2 swift-4.0.3
1246 sh build.sh prelaunch-simulator
1250 zip --symlinks -r realm-framework-tvos.zip Realm.framework
1253 "package-tvos-swift")
1254 for version in 8.3.3 9.0 9.1 9.2; do
1255 REALM_XCODE_VERSION=$version
1256 REALM_SWIFT_VERSION=
1257 set_xcode_and_swift_versions
1258 sh build.sh prelaunch-simulator
1259 sh build.sh tvos-swift
1263 ln -s swift-4.0 swift-3.2
1264 ln -s swift-4.0.2 swift-3.2.2
1265 ln -s swift-4.0.2 swift-3.2.3
1266 ln -s swift-4.0.2 swift-4.0.3
1267 zip --symlinks -r realm-swift-framework-tvos.zip swift-3.1 swift-3.2 swift-3.2.2 swift-3.2.3 swift-4.0 swift-4.0.2 swift-4.0.3
1270 package-*-swift-3.2)
1271 PLATFORM=$(echo $COMMAND | cut -d - -f 2)
1272 mkdir -p build/$PLATFORM
1274 ln -s swift-4.0 swift-3.2
1275 zip --symlinks -r realm-swift-framework-$PLATFORM-swift-3.2.zip swift-3.2
1278 package-*-swift-3.2.2)
1279 PLATFORM=$(echo $COMMAND | cut -d - -f 2)
1280 mkdir -p build/$PLATFORM
1282 ln -s swift-4.0.2 swift-3.2.2
1283 zip --symlinks -r realm-swift-framework-$PLATFORM-swift-3.2.2.zip swift-3.2.2
1286 package-*-swift-3.2.3)
1287 PLATFORM=$(echo $COMMAND | cut -d - -f 2)
1288 mkdir -p build/$PLATFORM
1290 ln -s swift-4.0.2 swift-3.2.3
1291 zip --symlinks -r realm-swift-framework-$PLATFORM-swift-3.2.3.zip swift-3.2.3
1294 package-*-swift-4.0.3)
1295 PLATFORM=$(echo $COMMAND | cut -d - -f 2)
1296 mkdir -p build/$PLATFORM
1298 ln -s swift-4.0.2 swift-4.0.3
1299 zip --symlinks -r realm-swift-framework-$PLATFORM-swift-4.0.3.zip swift-4.0.3
1303 PLATFORM=$(echo $COMMAND | cut -d - -f 2)
1304 REALM_SWIFT_VERSION=$(echo $COMMAND | cut -d - -f 4)
1305 REALM_XCODE_VERSION=
1307 set_xcode_and_swift_versions
1308 sh build.sh prelaunch-simulator
1309 sh build.sh $PLATFORM-swift
1312 zip --symlinks -r realm-swift-framework-$PLATFORM-swift-$REALM_SWIFT_VERSION.zip swift-$REALM_SWIFT_VERSION
1317 TEMPDIR=$(mktemp -d $TMPDIR/realm-release-package-${LANG}.XXXX)
1319 VERSION=$(sh build.sh get-version)
1321 FOLDER=${TEMPDIR}/realm-${LANG}-${VERSION}
1323 mkdir -p ${FOLDER}/osx ${FOLDER}/ios ${FOLDER}/watchos ${FOLDER}/tvos
1325 if [[ "${LANG}" == "objc" ]]; then
1326 mkdir -p ${FOLDER}/ios/static
1327 mkdir -p ${FOLDER}/ios/dynamic
1328 mkdir -p ${FOLDER}/Swift
1332 unzip ${WORKSPACE}/realm-framework-osx.zip
1336 cd ${FOLDER}/ios/static
1337 unzip ${WORKSPACE}/realm-framework-ios-static.zip
1341 cd ${FOLDER}/ios/dynamic
1342 unzip ${WORKSPACE}/realm-framework-ios.zip
1346 cd ${FOLDER}/watchos
1347 unzip ${WORKSPACE}/realm-framework-watchos.zip
1352 unzip ${WORKSPACE}/realm-framework-tvos.zip
1357 for f in ${WORKSPACE}/realm-swift-framework-osx-swift-*.zip; do
1364 for f in ${WORKSPACE}/realm-swift-framework-ios-swift-*.zip; do
1370 cd ${FOLDER}/watchos
1371 for f in ${WORKSPACE}/realm-swift-framework-watchos-swift-*.zip; do
1378 for f in ${WORKSPACE}/realm-swift-framework-tvos-swift-*.zip; do
1386 cp -R plugin ${FOLDER}
1387 cp LICENSE ${FOLDER}/LICENSE.txt
1388 if [[ "${LANG}" == "objc" ]]; then
1389 cp Realm/Swift/RLMSupport.swift ${FOLDER}/Swift/
1395 unzip ${WORKSPACE}/realm-examples.zip
1397 if [[ "${LANG}" == "objc" ]]; then
1398 rm -rf ios/swift-* tvos/swift-*
1400 rm -rf ios/objc ios/rubymotion osx tvos/objc
1404 cat > ${FOLDER}/docs.webloc <<EOF
1405 <?xml version="1.0" encoding="UTF-8"?>
1406 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
1407 <plist version="1.0">
1410 <string>https://realm.io/docs/${LANG}/${VERSION}</string>
1417 zip --symlinks -r realm-${LANG}-${VERSION}.zip realm-${LANG}-${VERSION}
1418 mv realm-${LANG}-${VERSION}.zip ${WORKSPACE}
1422 "test-package-release")
1423 # Generate a release package locally for testing purposes
1424 # Real releases should always be done via Jenkins
1425 if [ -z "${WORKSPACE}" ]; then
1426 echo 'WORKSPACE must be set to a directory to assemble the release in'
1429 if [ -d "${WORKSPACE}" ]; then
1430 echo 'WORKSPACE directory should not already exist'
1434 REALM_SOURCE="$(pwd)"
1435 mkdir -p "$WORKSPACE"
1436 WORKSPACE="$(cd "$WORKSPACE" && pwd)"
1439 git clone --recursive $REALM_SOURCE realm-cocoa
1442 echo 'Packaging iOS'
1443 sh build.sh package-ios-static
1444 cp build/ios-static/realm-framework-ios-static.zip ..
1445 sh build.sh package-ios
1446 cp build/ios/realm-framework-ios.zip ..
1447 sh build.sh package-ios-swift
1448 cp build/ios/realm-swift-framework-ios.zip ..
1450 echo 'Packaging OS X'
1451 sh build.sh package-osx
1452 cp build/DerivedData/Realm/Build/Products/Release/realm-framework-osx.zip ..
1453 sh build.sh package-osx-swift
1454 cp build/osx/realm-swift-framework-osx.zip ..
1456 echo 'Packaging watchOS'
1457 sh build.sh package-watchos
1458 cp build/watchos/realm-framework-watchos.zip ..
1459 sh build.sh package-watchos-swift
1460 cp build/watchos/realm-swift-framework-watchos.zip ..
1462 echo 'Packaging tvOS'
1463 sh build.sh package-tvos
1464 cp build/tvos/realm-framework-tvos.zip ..
1465 sh build.sh package-tvos-swift
1466 cp build/tvos/realm-swift-framework-tvos.zip ..
1468 echo 'Packaging examples'
1469 sh build.sh package-examples
1470 cp realm-examples.zip ..
1472 echo 'Building final release packages'
1473 sh build.sh package-release objc
1474 sh build.sh package-release swift
1476 echo 'Testing packaged examples'
1477 sh build.sh package-test-examples
1481 if [ -z "${GITHUB_ACCESS_TOKEN}" ]; then
1482 echo 'GITHUB_ACCESS_TOKEN must be set to create GitHub releases'
1485 ./scripts/github_release.rb
1488 "add-empty-changelog")
1489 empty_section=$(cat <<EOS
1490 x.x.x Release notes (yyyy-MM-dd)
1491 =============================================================
1493 ### Breaking Changes
1505 changelog=$(cat CHANGELOG.md)
1506 echo "$empty_section" > CHANGELOG.md
1507 echo >> CHANGELOG.md
1508 echo "$changelog" >> CHANGELOG.md
1512 echo "Unknown command '$COMMAND'"