build.sh 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467
  1. #!/bin/bash
  2. ##################################################################################
  3. # Custom build tool for Realm Objective-C binding.
  4. #
  5. # (C) Copyright 2011-2015 by realm.io.
  6. ##################################################################################
  7. # Warning: pipefail is not a POSIX compatible option, but on macOS it works just fine.
  8. # macOS uses a POSIX complain version of bash as /bin/sh, but apparently it does
  9. # not strip away this feature. Also, this will fail if somebody forces the script
  10. # to be run with zsh.
  11. set -o pipefail
  12. set -e
  13. source_root="$(dirname "$0")"
  14. # You can override the version of the core library
  15. : ${REALM_BASE_URL:="https://static.realm.io/downloads"} # set it if you need to use a remote repo
  16. : ${REALM_CORE_VERSION:=$(sed -n 's/^REALM_CORE_VERSION=\(.*\)$/\1/p' ${source_root}/dependencies.list)} # set to "current" to always use the current build
  17. : ${REALM_SYNC_VERSION:=$(sed -n 's/^REALM_SYNC_VERSION=\(.*\)$/\1/p' ${source_root}/dependencies.list)}
  18. : ${REALM_OBJECT_SERVER_VERSION:=$(sed -n 's/^REALM_OBJECT_SERVER_VERSION=\(.*\)$/\1/p' ${source_root}/dependencies.list)}
  19. # You can override the xcmode used
  20. : ${XCMODE:=xcodebuild} # must be one of: xcodebuild (default), xcpretty, xctool
  21. # Provide a fallback value for TMPDIR, relevant for Xcode Bots
  22. : ${TMPDIR:=$(getconf DARWIN_USER_TEMP_DIR)}
  23. PATH=/usr/libexec:$PATH
  24. if ! [ -z "${JENKINS_HOME}" ]; then
  25. XCPRETTY_PARAMS="--no-utf --report junit --output build/reports/junit.xml"
  26. CODESIGN_PARAMS="CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO"
  27. fi
  28. usage() {
  29. cat <<EOF
  30. Usage: sh $0 command [argument]
  31. command:
  32. clean: clean up/remove all generated files
  33. download-core: downloads core library (binary version)
  34. download-sync: downloads sync library (binary version, core+sync)
  35. build: builds all iOS and macOS frameworks
  36. ios-static: builds fat iOS static framework
  37. ios-dynamic: builds iOS dynamic frameworks
  38. ios-swift: builds RealmSwift frameworks for iOS
  39. watchos: builds watchOS framwork
  40. watchos-swift: builds RealmSwift framework for watchOS
  41. tvos: builds tvOS framework
  42. tvos-swift: builds RealmSwift framework for tvOS
  43. osx: builds macOS framework
  44. osx-swift: builds RealmSwift framework for macOS
  45. analyze-osx: analyzes macOS framework
  46. test: tests all iOS and macOS frameworks
  47. test-all: tests all iOS and macOS frameworks in both Debug and Release configurations
  48. test-ios-static: tests static iOS framework on 32-bit and 64-bit simulators
  49. test-ios-dynamic: tests dynamic iOS framework on 32-bit and 64-bit simulators
  50. test-ios-swift: tests RealmSwift iOS framework on 32-bit and 64-bit simulators
  51. test-ios-devices: tests ObjC & Swift iOS frameworks on all attached iOS devices
  52. test-ios-devices-objc: tests ObjC iOS framework on all attached iOS devices
  53. test-ios-devices-swift: tests Swift iOS framework on all attached iOS devices
  54. test-tvos: tests tvOS framework
  55. test-tvos-swift: tests RealmSwift tvOS framework
  56. test-tvos-devices: tests ObjC & Swift tvOS frameworks on all attached tvOS devices
  57. test-osx: tests macOS framework
  58. test-osx-swift: tests RealmSwift macOS framework
  59. test-swiftpm: tests ObjC and Swift macOS frameworks via SwiftPM
  60. verify: verifies docs, osx, osx-swift, ios-static, ios-dynamic, ios-swift, ios-device in both Debug and Release configurations, swiftlint
  61. verify-osx-object-server: downloads the Realm Object Server and runs the Objective-C and Swift integration tests
  62. docs: builds docs in docs/output
  63. examples: builds all examples
  64. examples-ios: builds all static iOS examples
  65. examples-ios-swift: builds all Swift iOS examples
  66. examples-osx: builds all macOS examples
  67. get-version: get the current version
  68. set-version version: set the version
  69. cocoapods-setup: download realm-core and create a stub RLMPlatform.h file to enable building via CocoaPods
  70. argument:
  71. version: version in the x.y.z format
  72. environment variables:
  73. XCMODE: xcodebuild (default), xcpretty or xctool
  74. CONFIGURATION: Debug or Release (default)
  75. REALM_CORE_VERSION: version in x.y.z format or "current" to use local build
  76. REALM_EXTRA_BUILD_ARGUMENTS: additional arguments to pass to the build tool
  77. REALM_XCODE_VERSION: the version number of Xcode to use (e.g.: 8.1)
  78. EOF
  79. }
  80. ######################################
  81. # Xcode Helpers
  82. ######################################
  83. xcode_version_major() {
  84. echo "${REALM_XCODE_VERSION%%.*}"
  85. }
  86. xcode() {
  87. mkdir -p build/DerivedData
  88. CMD="xcodebuild -IDECustomDerivedDataLocation=build/DerivedData $@"
  89. echo "Building with command:" $CMD
  90. eval "$CMD"
  91. }
  92. xc() {
  93. # Logs xcodebuild output in realtime
  94. : ${NSUnbufferedIO:=YES}
  95. args="$@ SWIFT_VERSION=$REALM_SWIFT_VERSION $REALM_EXTRA_BUILD_ARGUMENTS"
  96. if [[ "$XCMODE" == "xcodebuild" ]]; then
  97. xcode "$args"
  98. elif [[ "$XCMODE" == "xcpretty" ]]; then
  99. mkdir -p build
  100. xcode "$args" | tee build/build.log | xcpretty -c ${XCPRETTY_PARAMS} || {
  101. echo "The raw xcodebuild output is available in build/build.log"
  102. exit 1
  103. }
  104. elif [[ "$XCMODE" == "xctool" ]]; then
  105. xctool "$args"
  106. fi
  107. }
  108. xctest() {
  109. xc "$@" build-for-testing
  110. xc "$@" test
  111. }
  112. copy_bcsymbolmap() {
  113. find "$1" -name '*.bcsymbolmap' -type f -exec cp {} "$2" \;
  114. }
  115. build_combined() {
  116. local scheme="$1"
  117. local module_name="$2"
  118. local os="$3"
  119. local simulator="$4"
  120. local scope_suffix="$5"
  121. local version_suffix="$6"
  122. local config="$CONFIGURATION"
  123. local destination=""
  124. local os_name=""
  125. if [[ "$os" == "iphoneos" ]]; then
  126. os_name="ios"
  127. destination="iPhone 8"
  128. elif [[ "$os" == "watchos" ]]; then
  129. os_name="$os"
  130. if (( $(xcode_version_major) >= 10 )); then
  131. destination="Apple Watch Series 3 - 42mm"
  132. else
  133. destination="Apple Watch - 42mm"
  134. fi
  135. elif [[ "$os" == "appletvos" ]]; then
  136. os_name="tvos"
  137. destination="Apple TV"
  138. fi
  139. # Derive build paths
  140. local build_products_path="build/DerivedData/Realm/Build/Products"
  141. local build_intermediates_path="build/DerivedData/Realm/Build/Intermediates.noindex"
  142. local product_name="$module_name.framework"
  143. local binary_path="$module_name"
  144. local os_path="$build_products_path/$config-$os$scope_suffix/$product_name"
  145. local simulator_path="$build_products_path/$config-$simulator$scope_suffix/$product_name"
  146. local out_path="build/$os_name$scope_suffix$version_suffix"
  147. # Build for each platform
  148. xc "-scheme '$scheme' -configuration $config -sdk $os"
  149. xc "-scheme '$scheme' -configuration $config -sdk $simulator -destination 'name=$destination' ONLY_ACTIVE_ARCH=NO"
  150. if (( $(xcode_version_major) < 11 )); then
  151. # Combine .swiftmodule
  152. if [ -d $simulator_path/Modules/$module_name.swiftmodule ]; then
  153. cp $simulator_path/Modules/$module_name.swiftmodule/* $os_path/Modules/$module_name.swiftmodule/
  154. fi
  155. # Xcode 10.2 merges the generated headers together with ifdef guards for
  156. # each of the target platforms. This doesn't handle merging
  157. # device/simulator builds, so we need to take care of that ourselves.
  158. # Currently all platforms have identical headers, so we just pick one and
  159. # use that rather than merging, but this may change in the future.
  160. if [ -f $os_path/Headers/$module_name-Swift.h ]; then
  161. unique_headers=$(find $build_intermediates_path -name $module_name-Swift.h -exec shasum {} \; | cut -d' ' -f 1 | uniq | grep -c '^')
  162. if [ $unique_headers != "1" ]; then
  163. echo "Platform-specific Swift generated headers are not identical. Merging them is required and is not yet implemented."
  164. exit 1
  165. fi
  166. find $build_intermediates_path -name $module_name-Swift.h -exec cp {} $os_path/Headers \; -quit
  167. fi
  168. # Copy *.bcsymbolmap to .framework for submitting app with bitcode
  169. copy_bcsymbolmap "$build_products_path/$config-$os$scope_suffix" "$os_path"
  170. # Retrieve build products
  171. clean_retrieve $os_path $out_path $product_name
  172. # Combine ar archives
  173. LIPO_OUTPUT="$out_path/$product_name/$module_name"
  174. xcrun lipo -create "$simulator_path/$binary_path" "$os_path/$binary_path" -output "$LIPO_OUTPUT"
  175. # Verify that the combined library has bitcode and we didn't accidentally
  176. # remove it somewhere along the line
  177. if [[ "$destination" != "" && "$config" == "Release" ]]; then
  178. sh build.sh binary-has-bitcode "$LIPO_OUTPUT"
  179. fi
  180. else
  181. rm -rf "$out_path/$module_name.xcframework"
  182. xcodebuild -create-xcframework \
  183. -framework $simulator_path \
  184. -framework $os_path \
  185. -output "$out_path/$module_name.xcframework"
  186. fi
  187. }
  188. copy_realm_framework() {
  189. local platform="$1"
  190. local extension="xcframework"
  191. if (( $(xcode_version_major) < 11 )); then
  192. extension="framework"
  193. fi
  194. rm -rf build/$platform/swift-$REALM_XCODE_VERSION/Realm.$extension
  195. cp -R build/$platform/Realm.$extension build/$platform/swift-$REALM_XCODE_VERSION
  196. }
  197. clean_retrieve() {
  198. mkdir -p "$2"
  199. rm -rf "$2/$3"
  200. cp -R "$1" "$2"
  201. }
  202. move_to_clean_dir() {
  203. rm -rf "$2"
  204. mkdir -p "$2"
  205. mv "$1" "$2"
  206. }
  207. test_ios_static() {
  208. destination="$1"
  209. xc "-scheme 'Realm iOS static' -configuration $CONFIGURATION -sdk iphonesimulator -destination '$destination' build-for-testing"
  210. xc "-scheme 'Realm iOS static' -configuration $CONFIGURATION -sdk iphonesimulator -destination '$destination' test"
  211. }
  212. ######################################
  213. # Device Test Helper
  214. ######################################
  215. test_devices() {
  216. local serial_numbers=()
  217. local awk_script="
  218. /^ +Vendor ID: / { is_apple = 0; }
  219. /^ +Vendor ID: 0x05[aA][cC] / { is_apple = 1; }
  220. /^ +Serial Number: / {
  221. if (is_apple) {
  222. match(\$0, /^ +Serial Number: /);
  223. print substr(\$0, RLENGTH + 1);
  224. }
  225. }
  226. "
  227. local serial_numbers_text=$(/usr/sbin/system_profiler SPUSBDataType | /usr/bin/awk "$awk_script")
  228. while read -r number; do
  229. if [[ "$number" != "" ]]; then
  230. serial_numbers+=("$number")
  231. fi
  232. done <<< "$serial_numbers_text"
  233. if [[ ${#serial_numbers[@]} == 0 ]]; then
  234. echo "At least one iOS/tvOS device must be connected to this computer to run device tests"
  235. if [ -z "${JENKINS_HOME}" ]; then
  236. # Don't fail if running locally and there's no device
  237. exit 0
  238. fi
  239. exit 1
  240. fi
  241. local sdk="$1"
  242. local scheme="$2"
  243. local configuration="$3"
  244. local failed=0
  245. for device in "${serial_numbers[@]}"; do
  246. xc "-scheme '$scheme' -configuration $configuration -destination 'id=$device' -sdk $sdk test" || failed=1
  247. done
  248. return $failed
  249. }
  250. ######################################
  251. # Docs
  252. ######################################
  253. build_docs() {
  254. local language="$1"
  255. local version=$(sh build.sh get-version)
  256. local xcodebuild_arguments="--objc,Realm/Realm.h,--,-x,objective-c,-isysroot,$(xcrun --show-sdk-path),-I,$(pwd)"
  257. local module="Realm"
  258. local objc="--objc"
  259. if [[ "$language" == "swift" ]]; then
  260. sh build.sh set-swift-version
  261. xcodebuild_arguments="-scheme,RealmSwift"
  262. module="RealmSwift"
  263. objc=""
  264. fi
  265. touch Realm/RLMPlatform.h # jazzy will fail if it can't find all public header files
  266. jazzy \
  267. ${objc} \
  268. --clean \
  269. --author Realm \
  270. --author_url https://realm.io \
  271. --github_url https://github.com/realm/realm-cocoa \
  272. --github-file-prefix https://github.com/realm/realm-cocoa/tree/v${version} \
  273. --module-version ${version} \
  274. --xcodebuild-arguments ${xcodebuild_arguments} \
  275. --module ${module} \
  276. --root-url https://realm.io/docs/${language}/${version}/api/ \
  277. --output docs/${language}_output \
  278. --head "$(cat docs/custom_head.html)"
  279. rm Realm/RLMPlatform.h
  280. }
  281. ######################################
  282. # Input Validation
  283. ######################################
  284. if [ "$#" -eq 0 -o "$#" -gt 3 ]; then
  285. usage
  286. exit 1
  287. fi
  288. ######################################
  289. # Downloading
  290. ######################################
  291. download_common() {
  292. local download_type=$1 tries_left=3 version url error temp_dir temp_path tar_path
  293. if [ "$download_type" == "core" ]; then
  294. version=$REALM_CORE_VERSION
  295. url="${REALM_BASE_URL}/core/realm-core-${version}.tar.xz"
  296. elif [ "$download_type" == "sync" ]; then
  297. version=$REALM_SYNC_VERSION
  298. url="${REALM_BASE_URL}/sync/realm-sync-cocoa-${version}.tar.xz"
  299. else
  300. echo "Unknown dowload_type: $download_type"
  301. exit 1
  302. fi
  303. echo "Downloading dependency: ${download_type} ${version} from ${url}"
  304. if [ -z "$TMPDIR" ]; then
  305. TMPDIR='/tmp'
  306. fi
  307. temp_dir=$(dirname "$TMPDIR/waste")/${download_type}_bin
  308. mkdir -p "$temp_dir"
  309. tar_path="${temp_dir}/${download_type}-${version}.tar.xz"
  310. temp_path="${tar_path}.tmp"
  311. while [ 0 -lt $tries_left ] && [ ! -f "$tar_path" ]; do
  312. if ! error=$(/usr/bin/curl --fail --silent --show-error --location "$url" --output "$temp_path" 2>&1); then
  313. tries_left=$[$tries_left-1]
  314. else
  315. mv "$temp_path" "$tar_path"
  316. fi
  317. done
  318. if [ ! -f "$tar_path" ]; then
  319. printf "Downloading ${download_type} failed:\n\t$url\n\t$error\n"
  320. exit 1
  321. fi
  322. (
  323. cd "$temp_dir"
  324. rm -rf "$download_type"
  325. tar xf "$tar_path" --xz
  326. mv core "${download_type}-${version}"
  327. )
  328. rm -rf "${download_type}-${version}" core
  329. mv "${temp_dir}/${download_type}-${version}" .
  330. ln -s "${download_type}-${version}" core
  331. }
  332. download_core() {
  333. download_common "core"
  334. }
  335. download_sync() {
  336. download_common "sync"
  337. }
  338. ######################################
  339. # Variables
  340. ######################################
  341. COMMAND="$1"
  342. # Use Debug config if command ends with -debug, otherwise default to Release
  343. # Set IS_RUNNING_PACKAGING when running packaging steps to avoid running iOS static tests with Xcode 8.3.3
  344. case "$COMMAND" in
  345. *-debug)
  346. COMMAND="${COMMAND%-debug}"
  347. CONFIGURATION="Debug"
  348. ;;
  349. package-*)
  350. IS_RUNNING_PACKAGING=1
  351. ;;
  352. esac
  353. export CONFIGURATION=${CONFIGURATION:-Release}
  354. export IS_RUNNING_PACKAGING=${IS_RUNNING_PACKAGING:-0}
  355. # Pre-choose Xcode and Swift versions for those operations that do not set them
  356. REALM_XCODE_VERSION=${xcode_version:-$REALM_XCODE_VERSION}
  357. REALM_SWIFT_VERSION=${swift_version:-$REALM_SWIFT_VERSION}
  358. source "${source_root}/scripts/swift-version.sh"
  359. set_xcode_and_swift_versions
  360. ######################################
  361. # Commands
  362. ######################################
  363. case "$COMMAND" in
  364. ######################################
  365. # Clean
  366. ######################################
  367. "clean")
  368. find . -type d -name build -exec rm -r "{}" +
  369. exit 0
  370. ;;
  371. ######################################
  372. # Core
  373. ######################################
  374. "download-core")
  375. if [ "$REALM_CORE_VERSION" = "current" ]; then
  376. echo "Using version of core already in core/ directory"
  377. exit 0
  378. fi
  379. if [ -d core -a -d ../realm-core -a ! -L core ]; then
  380. # Allow newer versions than expected for local builds as testing
  381. # with unreleased versions is one of the reasons to use a local build
  382. if ! $(grep -i "${REALM_CORE_VERSION} Release notes" core/release_notes.txt >/dev/null); then
  383. echo "Local build of core is out of date."
  384. exit 1
  385. else
  386. echo "The core library seems to be up to date."
  387. fi
  388. elif ! [ -L core ]; then
  389. echo "core is not a symlink. Deleting..."
  390. rm -rf core
  391. download_core
  392. # With a prebuilt version we only want to check the first non-empty
  393. # line so that checking out an older commit will download the
  394. # appropriate version of core if the already-present version is too new
  395. elif ! $(grep -m 1 . core/release_notes.txt | grep -i "${REALM_CORE_VERSION} RELEASE NOTES" >/dev/null); then
  396. download_core
  397. else
  398. echo "The core library seems to be up to date."
  399. fi
  400. exit 0
  401. ;;
  402. ######################################
  403. # Sync
  404. ######################################
  405. "download-sync")
  406. if [ "$REALM_SYNC_VERSION" = "current" ]; then
  407. echo "Using version of core already in core/ directory"
  408. exit 0
  409. fi
  410. if [ -d core -a -d ../realm-core -a -d ../realm-sync -a ! -L core ]; then
  411. echo "Using version of core already in core/ directory"
  412. elif ! [ -L core ]; then
  413. echo "core is not a symlink. Deleting..."
  414. rm -rf core
  415. download_sync
  416. elif [[ "$(cat core/version.txt)" != "$REALM_SYNC_VERSION" ]]; then
  417. download_sync
  418. else
  419. echo "The core library seems to be up to date."
  420. fi
  421. exit 0
  422. ;;
  423. ######################################
  424. # Swift versioning
  425. ######################################
  426. "set-swift-version")
  427. version=${2:-$REALM_SWIFT_VERSION}
  428. SWIFT_VERSION_FILE="RealmSwift/SwiftVersion.swift"
  429. CONTENTS="let swiftLanguageVersion = \"$version\""
  430. if [ ! -f "$SWIFT_VERSION_FILE" ] || ! grep -q "$CONTENTS" "$SWIFT_VERSION_FILE"; then
  431. echo "$CONTENTS" > "$SWIFT_VERSION_FILE"
  432. fi
  433. exit 0
  434. ;;
  435. "prelaunch-simulator")
  436. sh ${source_root}/scripts/reset-simulators.sh
  437. ;;
  438. ######################################
  439. # Building
  440. ######################################
  441. "build")
  442. sh build.sh ios-static
  443. sh build.sh ios-dynamic
  444. sh build.sh ios-swift
  445. sh build.sh watchos
  446. sh build.sh watchos-swift
  447. sh build.sh tvos
  448. sh build.sh tvos-swift
  449. sh build.sh osx
  450. sh build.sh osx-swift
  451. if (( $(xcode_version_major) >= 11 )); then
  452. rm -rf "build/*.xcframework"
  453. find build/DerivedData -name 'Realm.framework' \
  454. | grep -v '\-static' \
  455. | sed 's/.*/-framework &/' \
  456. | xargs xcodebuild -create-xcframework -output build/Realm.xcframework
  457. find build/DerivedData -name 'RealmSwift.framework' \
  458. | sed 's/.*/-framework &/' \
  459. | xargs xcodebuild -create-xcframework -output build/RealmSwift.xcframework
  460. fi
  461. exit 0
  462. ;;
  463. "ios-static")
  464. build_combined 'Realm iOS static' Realm iphoneos iphonesimulator "-static"
  465. exit 0
  466. ;;
  467. "ios-dynamic")
  468. build_combined Realm Realm iphoneos iphonesimulator
  469. exit 0
  470. ;;
  471. "ios-swift")
  472. sh build.sh ios-dynamic
  473. build_combined RealmSwift RealmSwift iphoneos iphonesimulator '' "/swift-$REALM_XCODE_VERSION"
  474. copy_realm_framework ios
  475. exit 0
  476. ;;
  477. "watchos")
  478. build_combined Realm Realm watchos watchsimulator
  479. exit 0
  480. ;;
  481. "watchos-swift")
  482. sh build.sh watchos
  483. build_combined RealmSwift RealmSwift watchos watchsimulator '' "/swift-$REALM_XCODE_VERSION"
  484. copy_realm_framework watchos
  485. exit 0
  486. ;;
  487. "tvos")
  488. build_combined Realm Realm appletvos appletvsimulator
  489. exit 0
  490. ;;
  491. "tvos-swift")
  492. sh build.sh tvos
  493. build_combined RealmSwift RealmSwift appletvos appletvsimulator '' "/swift-$REALM_XCODE_VERSION"
  494. copy_realm_framework tvos
  495. exit 0
  496. ;;
  497. "osx")
  498. xc "-scheme Realm -configuration $CONFIGURATION"
  499. clean_retrieve "build/DerivedData/Realm/Build/Products/$CONFIGURATION/Realm.framework" "build/osx" "Realm.framework"
  500. exit 0
  501. ;;
  502. "osx-swift")
  503. sh build.sh osx
  504. xc "-scheme 'RealmSwift' -configuration $CONFIGURATION build"
  505. destination="build/osx/swift-$REALM_XCODE_VERSION"
  506. clean_retrieve "build/DerivedData/Realm/Build/Products/$CONFIGURATION/RealmSwift.framework" "$destination" "RealmSwift.framework"
  507. rm -rf "$destination/Realm.framework"
  508. cp -R build/osx/Realm.framework "$destination"
  509. exit 0
  510. ;;
  511. ######################################
  512. # Analysis
  513. ######################################
  514. "analyze-osx")
  515. xc "-scheme Realm -configuration $CONFIGURATION analyze"
  516. exit 0
  517. ;;
  518. ######################################
  519. # Testing
  520. ######################################
  521. "test")
  522. set +e # Run both sets of tests even if the first fails
  523. failed=0
  524. sh build.sh test-ios-static || failed=1
  525. sh build.sh test-ios-dynamic || failed=1
  526. sh build.sh test-ios-swift || failed=1
  527. sh build.sh test-ios-devices || failed=1
  528. sh build.sh test-tvos-devices || failed=1
  529. sh build.sh test-osx || failed=1
  530. sh build.sh test-osx-swift || failed=1
  531. exit $failed
  532. ;;
  533. "test-all")
  534. set +e
  535. failed=0
  536. sh build.sh test || failed=1
  537. sh build.sh test-debug || failed=1
  538. exit $failed
  539. ;;
  540. "test-ios-static")
  541. test_ios_static "name=iPhone 8"
  542. exit 0
  543. ;;
  544. "test-ios-dynamic")
  545. xc "-scheme Realm -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 8' build-for-testing"
  546. xc "-scheme Realm -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 8' test"
  547. exit 0
  548. ;;
  549. "test-ios-swift")
  550. xc "-scheme RealmSwift -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 8' build-for-testing"
  551. xc "-scheme RealmSwift -configuration $CONFIGURATION -sdk iphonesimulator -destination 'name=iPhone 8' test"
  552. exit 0
  553. ;;
  554. "test-ios-devices")
  555. failed=0
  556. trap "failed=1" ERR
  557. sh build.sh test-ios-devices-objc
  558. sh build.sh test-ios-devices-swift
  559. exit $failed
  560. ;;
  561. "test-ios-devices-objc")
  562. test_devices iphoneos "Realm" "$CONFIGURATION"
  563. exit $?
  564. ;;
  565. "test-ios-devices-swift")
  566. test_devices iphoneos "RealmSwift" "$CONFIGURATION"
  567. exit $?
  568. ;;
  569. "test-tvos")
  570. destination="Apple TV"
  571. xctest "-scheme Realm -configuration $CONFIGURATION -sdk appletvsimulator -destination 'name=$destination'"
  572. exit $?
  573. ;;
  574. "test-tvos-swift")
  575. destination="Apple TV"
  576. xctest "-scheme RealmSwift -configuration $CONFIGURATION -sdk appletvsimulator -destination 'name=$destination'"
  577. exit $?
  578. ;;
  579. "test-tvos-devices")
  580. test_devices appletvos TestHost "$CONFIGURATION"
  581. ;;
  582. "test-osx")
  583. COVERAGE_PARAMS=""
  584. if [[ "$CONFIGURATION" == "Debug" ]]; then
  585. COVERAGE_PARAMS="GCC_GENERATE_TEST_COVERAGE_FILES=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES"
  586. fi
  587. xctest "-scheme Realm -configuration $CONFIGURATION $COVERAGE_PARAMS"
  588. exit 0
  589. ;;
  590. "test-osx-swift")
  591. xctest "-scheme RealmSwift -configuration $CONFIGURATION"
  592. exit 0
  593. ;;
  594. "test-osx-object-server")
  595. xctest "-scheme 'Object Server Tests' -configuration $CONFIGURATION -sdk macosx"
  596. exit 0
  597. ;;
  598. "test-swiftpm")
  599. xcrun swift test --configuration $(echo $CONFIGURATION | tr "[:upper:]" "[:lower:]")
  600. exit 0
  601. ;;
  602. ######################################
  603. # Full verification
  604. ######################################
  605. "verify")
  606. sh build.sh verify-cocoapods
  607. sh build.sh verify-docs
  608. sh build.sh verify-osx
  609. sh build.sh verify-osx-debug
  610. sh build.sh verify-osx-swift
  611. sh build.sh verify-osx-swift-debug
  612. sh build.sh verify-ios-static
  613. sh build.sh verify-ios-static-debug
  614. sh build.sh verify-ios-dynamic
  615. sh build.sh verify-ios-dynamic-debug
  616. sh build.sh verify-ios-swift
  617. sh build.sh verify-ios-swift-debug
  618. sh build.sh verify-ios-device-objc
  619. sh build.sh verify-ios-device-swift
  620. sh build.sh verify-watchos
  621. sh build.sh verify-tvos
  622. sh build.sh verify-tvos-debug
  623. sh build.sh verify-tvos-device
  624. sh build.sh verify-swiftlint
  625. sh build.sh verify-swiftpm
  626. sh build.sh verify-osx-object-server
  627. ;;
  628. "verify-cocoapods")
  629. if [[ -d .git ]]; then
  630. # Verify the current branch, unless one was already specified in the sha environment variable.
  631. if [[ -z $sha ]]; then
  632. export sha=$(git rev-parse --abbrev-ref HEAD)
  633. fi
  634. if [[ $(git log -1 @{push}..) != "" ]] || ! git diff-index --quiet HEAD; then
  635. echo "WARNING: verify-cocoapods will test the latest revision of $sha found on GitHub."
  636. echo " Any unpushed local changes will not be tested."
  637. echo ""
  638. sleep 1
  639. fi
  640. fi
  641. sh build.sh verify-cocoapods-ios
  642. sh build.sh verify-cocoapods-osx
  643. sh build.sh verify-cocoapods-watchos
  644. # https://github.com/CocoaPods/CocoaPods/issues/7708
  645. export EXPANDED_CODE_SIGN_IDENTITY=''
  646. cd examples/installation
  647. sh build.sh test-ios-objc-cocoapods
  648. sh build.sh test-ios-objc-cocoapods-dynamic
  649. sh build.sh test-ios-swift-cocoapods
  650. sh build.sh test-osx-objc-cocoapods
  651. sh build.sh test-osx-swift-cocoapods
  652. sh build.sh test-watchos-objc-cocoapods
  653. sh build.sh test-watchos-swift-cocoapods
  654. ;;
  655. verify-cocoapods-*)
  656. PLATFORM=$(echo $COMMAND | cut -d - -f 3)
  657. # https://github.com/CocoaPods/CocoaPods/issues/7708
  658. export EXPANDED_CODE_SIGN_IDENTITY=''
  659. cd examples/installation
  660. sh build.sh test-$PLATFORM-objc-cocoapods
  661. sh build.sh test-$PLATFORM-swift-cocoapods
  662. if [[ $PLATFORM = "ios" ]]; then
  663. sh build.sh test-ios-objc-cocoapods-dynamic
  664. fi
  665. ;;
  666. "verify-osx-encryption")
  667. REALM_ENCRYPT_ALL=YES sh build.sh test-osx
  668. exit 0
  669. ;;
  670. "verify-osx")
  671. sh build.sh test-osx
  672. sh build.sh examples-osx
  673. (
  674. cd examples/osx/objc/build/DerivedData/RealmExamples/Build/Products/$CONFIGURATION
  675. DYLD_FRAMEWORK_PATH=. ./JSONImport >/dev/null
  676. )
  677. exit 0
  678. ;;
  679. "verify-osx-swift")
  680. sh build.sh test-osx-swift
  681. exit 0
  682. ;;
  683. "verify-ios-static")
  684. sh build.sh test-ios-static
  685. sh build.sh examples-ios
  686. ;;
  687. "verify-ios-dynamic")
  688. sh build.sh test-ios-dynamic
  689. ;;
  690. "verify-ios-swift")
  691. sh build.sh test-ios-swift
  692. sh build.sh examples-ios-swift
  693. ;;
  694. "verify-ios-device-objc")
  695. sh build.sh test-ios-devices-objc
  696. exit 0
  697. ;;
  698. "verify-ios-device-swift")
  699. sh build.sh test-ios-devices-swift
  700. exit 0
  701. ;;
  702. "verify-docs")
  703. sh build.sh docs
  704. for lang in swift objc; do
  705. undocumented="docs/${lang}_output/undocumented.json"
  706. if ruby -rjson -e "j = JSON.parse(File.read('docs/${lang}_output/undocumented.json')); exit j['warnings'].length != 0"; then
  707. echo "Undocumented Realm $lang declarations:"
  708. cat "$undocumented"
  709. exit 1
  710. fi
  711. done
  712. exit 0
  713. ;;
  714. "verify-watchos")
  715. sh build.sh watchos-swift
  716. exit 0
  717. ;;
  718. "verify-tvos")
  719. sh build.sh test-tvos
  720. sh build.sh test-tvos-swift
  721. sh build.sh examples-tvos
  722. sh build.sh examples-tvos-swift
  723. exit 0
  724. ;;
  725. "verify-tvos-device")
  726. sh build.sh test-tvos-devices
  727. exit 0
  728. ;;
  729. "verify-swiftlint")
  730. swiftlint lint --strict
  731. exit 0
  732. ;;
  733. "verify-swiftpm")
  734. if (( $(xcode_version_major) >= 10 )); then
  735. sh build.sh test-swiftpm
  736. fi
  737. exit 0
  738. ;;
  739. "verify-osx-object-server")
  740. sh build.sh test-osx-object-server
  741. exit 0
  742. ;;
  743. ######################################
  744. # Docs
  745. ######################################
  746. "docs")
  747. build_docs objc
  748. build_docs swift
  749. exit 0
  750. ;;
  751. ######################################
  752. # Examples
  753. ######################################
  754. "examples")
  755. sh build.sh clean
  756. sh build.sh examples-ios
  757. sh build.sh examples-ios-swift
  758. sh build.sh examples-osx
  759. sh build.sh examples-tvos
  760. sh build.sh examples-tvos-swift
  761. exit 0
  762. ;;
  763. "examples-ios")
  764. sh build.sh prelaunch-simulator
  765. workspace="examples/ios/objc/RealmExamples.xcworkspace"
  766. pod install --project-directory="$workspace/.." --no-repo-update
  767. xc "-workspace $workspace -scheme Simple -configuration $CONFIGURATION -destination 'name=iPhone 8' build ${CODESIGN_PARAMS}"
  768. xc "-workspace $workspace -scheme TableView -configuration $CONFIGURATION -destination 'name=iPhone 8' build ${CODESIGN_PARAMS}"
  769. xc "-workspace $workspace -scheme Migration -configuration $CONFIGURATION -destination 'name=iPhone 8' build ${CODESIGN_PARAMS}"
  770. xc "-workspace $workspace -scheme Backlink -configuration $CONFIGURATION -destination 'name=iPhone 8' build ${CODESIGN_PARAMS}"
  771. xc "-workspace $workspace -scheme GroupedTableView -configuration $CONFIGURATION -destination 'name=iPhone 8' build ${CODESIGN_PARAMS}"
  772. xc "-workspace $workspace -scheme RACTableView -configuration $CONFIGURATION -destination 'name=iPhone 8' build ${CODESIGN_PARAMS}"
  773. xc "-workspace $workspace -scheme Encryption -configuration $CONFIGURATION -destination 'name=iPhone 8' build ${CODESIGN_PARAMS}"
  774. xc "-workspace $workspace -scheme Draw -configuration $CONFIGURATION -destination 'name=iPhone 8' build ${CODESIGN_PARAMS}"
  775. if [ ! -z "${JENKINS_HOME}" ]; then
  776. xc "-workspace $workspace -scheme Extension -configuration $CONFIGURATION -destination 'name=iPhone 8' build ${CODESIGN_PARAMS}"
  777. fi
  778. exit 0
  779. ;;
  780. "examples-ios-swift")
  781. sh build.sh prelaunch-simulator
  782. workspace="examples/ios/swift/RealmExamples.xcworkspace"
  783. if [[ ! -d "$workspace" ]]; then
  784. workspace="${workspace/swift/swift-$REALM_XCODE_VERSION}"
  785. fi
  786. xc "-workspace $workspace -scheme Simple -configuration $CONFIGURATION -destination 'name=iPhone 8' build ${CODESIGN_PARAMS}"
  787. xc "-workspace $workspace -scheme TableView -configuration $CONFIGURATION -destination 'name=iPhone 8' build ${CODESIGN_PARAMS}"
  788. xc "-workspace $workspace -scheme Migration -configuration $CONFIGURATION -destination 'name=iPhone 8' build ${CODESIGN_PARAMS}"
  789. xc "-workspace $workspace -scheme Encryption -configuration $CONFIGURATION -destination 'name=iPhone 8' build ${CODESIGN_PARAMS}"
  790. xc "-workspace $workspace -scheme Backlink -configuration $CONFIGURATION -destination 'name=iPhone 8' build ${CODESIGN_PARAMS}"
  791. xc "-workspace $workspace -scheme GroupedTableView -configuration $CONFIGURATION -destination 'name=iPhone 8' build ${CODESIGN_PARAMS}"
  792. exit 0
  793. ;;
  794. "examples-osx")
  795. xc "-workspace examples/osx/objc/RealmExamples.xcworkspace -scheme JSONImport -configuration ${CONFIGURATION} build ${CODESIGN_PARAMS}"
  796. ;;
  797. "examples-tvos")
  798. workspace="examples/tvos/objc/RealmExamples.xcworkspace"
  799. destination="Apple TV"
  800. xc "-workspace $workspace -scheme DownloadCache -configuration $CONFIGURATION -destination 'name=$destination' build ${CODESIGN_PARAMS}"
  801. xc "-workspace $workspace -scheme PreloadedData -configuration $CONFIGURATION -destination 'name=$destination' build ${CODESIGN_PARAMS}"
  802. exit 0
  803. ;;
  804. "examples-tvos-swift")
  805. workspace="examples/tvos/swift/RealmExamples.xcworkspace"
  806. if [[ ! -d "$workspace" ]]; then
  807. workspace="${workspace/swift/swift-$REALM_XCODE_VERSION}"
  808. fi
  809. destination="Apple TV"
  810. xc "-workspace $workspace -scheme DownloadCache -configuration $CONFIGURATION -destination 'name=$destination' build ${CODESIGN_PARAMS}"
  811. xc "-workspace $workspace -scheme PreloadedData -configuration $CONFIGURATION -destination 'name=$destination' build ${CODESIGN_PARAMS}"
  812. exit 0
  813. ;;
  814. ######################################
  815. # Versioning
  816. ######################################
  817. "get-version")
  818. version_file="Realm/Realm-Info.plist"
  819. echo "$(PlistBuddy -c "Print :CFBundleShortVersionString" "$version_file")"
  820. exit 0
  821. ;;
  822. "set-version")
  823. realm_version="$2"
  824. version_files="Realm/Realm-Info.plist"
  825. if [ -z "$realm_version" ]; then
  826. echo "You must specify a version."
  827. exit 1
  828. fi
  829. # The bundle version can contain only three groups of digits separated by periods,
  830. # so strip off any -beta.x tag from the end of the version string.
  831. bundle_version=$(echo "$realm_version" | cut -d - -f 1)
  832. for version_file in $version_files; do
  833. PlistBuddy -c "Set :CFBundleVersion $bundle_version" "$version_file"
  834. PlistBuddy -c "Set :CFBundleShortVersionString $realm_version" "$version_file"
  835. done
  836. sed -i '' "s/^VERSION=.*/VERSION=$realm_version/" dependencies.list
  837. sed -i '' "s/^let coreVersionStr =.*/let coreVersionStr = \"$REALM_CORE_VERSION\"/" Package.swift
  838. sed -i '' "s/^let cocoaVersionStr =.*/let cocoaVersionStr = \"$realm_version\"/" Package.swift
  839. exit 0
  840. ;;
  841. ######################################
  842. # Bitcode Detection
  843. ######################################
  844. "binary-has-bitcode")
  845. # Disable pipefail as grep -q will make otool fail due to exiting
  846. # before reading all the output
  847. set +o pipefail
  848. BINARY="$2"
  849. if otool -l "$BINARY" | grep -q "segname __LLVM"; then
  850. exit 0
  851. fi
  852. # Work around rdar://21826157 by checking for bitcode in thin binaries
  853. # Get architectures for binary
  854. archs="$(lipo -info "$BINARY" | rev | cut -d ':' -f1 | rev)"
  855. archs_array=( $archs )
  856. if [[ ${#archs_array[@]} -lt 2 ]]; then
  857. echo 'Error: Built library is not a fat binary'
  858. exit 1 # Early exit if not a fat binary
  859. fi
  860. TEMPDIR=$(mktemp -d $TMPDIR/realm-bitcode-check.XXXX)
  861. for arch in $archs; do
  862. lipo -thin "$arch" "$BINARY" -output "$TEMPDIR/$arch"
  863. if otool -l "$TEMPDIR/$arch" | grep -q "segname __LLVM"; then
  864. exit 0
  865. fi
  866. done
  867. echo 'Error: Built library does not contain bitcode'
  868. exit 1
  869. ;;
  870. ######################################
  871. # CocoaPods
  872. ######################################
  873. "cocoapods-setup")
  874. if [ ! -d core ]; then
  875. sh build.sh download-sync
  876. rm core
  877. mv sync-* core
  878. mv core/librealm-ios.a core/librealmcore-ios.a
  879. mv core/librealm-macosx.a core/librealmcore-macosx.a
  880. mv core/librealm-tvos.a core/librealmcore-tvos.a
  881. mv core/librealm-watchos.a core/librealmcore-watchos.a
  882. fi
  883. if [[ "$2" != "swift" ]]; then
  884. if [ ! -d Realm/ObjectStore/src ]; then
  885. cat >&2 <<EOM
  886. ERROR: One of Realm's submodules is missing!
  887. If you're using Realm and/or RealmSwift from a git branch, please add 'submodules: true' to
  888. their entries in your Podfile.
  889. EOM
  890. exit 1
  891. fi
  892. rm -rf include
  893. mkdir -p include
  894. mv core/include include/core
  895. mkdir -p include/impl/apple include/util/apple include/sync/impl/apple
  896. cp Realm/*.hpp include
  897. cp Realm/ObjectStore/src/*.hpp include
  898. cp Realm/ObjectStore/src/sync/*.hpp include/sync
  899. cp Realm/ObjectStore/src/sync/impl/*.hpp include/sync/impl
  900. cp Realm/ObjectStore/src/sync/impl/apple/*.hpp include/sync/impl/apple
  901. cp Realm/ObjectStore/src/impl/*.hpp include/impl
  902. cp Realm/ObjectStore/src/impl/apple/*.hpp include/impl/apple
  903. cp Realm/ObjectStore/src/util/*.hpp include/util
  904. cp Realm/ObjectStore/src/util/apple/*.hpp include/util/apple
  905. echo '' > Realm/RLMPlatform.h
  906. if [ -n "$COCOAPODS_VERSION" ]; then
  907. # This variable is set for the prepare_command available
  908. # from the 1.0 prereleases, which requires a different
  909. # header layout within the header_mappings_dir.
  910. cp Realm/*.h include
  911. else
  912. # For CocoaPods < 1.0, we need to scope the headers within
  913. # the header_mappings_dir by another subdirectory to avoid
  914. # Clang from complaining about non-modular headers.
  915. mkdir -p include/Realm
  916. cp Realm/*.h include/Realm
  917. fi
  918. else
  919. sh build.sh set-swift-version
  920. fi
  921. ;;
  922. ######################################
  923. # Continuous Integration
  924. ######################################
  925. "ci-pr")
  926. mkdir -p build/reports
  927. export REALM_DISABLE_ANALYTICS=1
  928. export REALM_DISABLE_UPDATE_CHECKER=1
  929. # FIXME: Re-enable once CI can properly unlock the keychain
  930. export REALM_DISABLE_METADATA_ENCRYPTION=1
  931. # strip off the ios|tvos version specifier, e.g. the last part of: `ios-device-objc-ios8`
  932. if [[ "$target" =~ ^((ios|tvos)-device(-(objc|swift))?)(-(ios|tvos)[[:digit:]]+)?$ ]]; then
  933. export target=${BASH_REMATCH[1]}
  934. fi
  935. if [ "$target" = "docs" ]; then
  936. sh build.sh set-swift-version
  937. sh build.sh verify-docs
  938. elif [ "$target" = "swiftlint" ]; then
  939. sh build.sh verify-swiftlint
  940. else
  941. export sha=$GITHUB_PR_SOURCE_BRANCH
  942. export CONFIGURATION=$configuration
  943. export REALM_EXTRA_BUILD_ARGUMENTS='GCC_GENERATE_DEBUGGING_SYMBOLS=NO -allowProvisioningUpdates'
  944. if [[ ${target} != *"osx"* ]];then
  945. sh build.sh prelaunch-simulator
  946. fi
  947. source $(brew --prefix nvm)/nvm.sh
  948. export REALM_NODE_PATH="$(nvm which 8)"
  949. # Reset CoreSimulator.log
  950. mkdir -p ~/Library/Logs/CoreSimulator
  951. echo > ~/Library/Logs/CoreSimulator/CoreSimulator.log
  952. if [ -d ~/Library/Developer/CoreSimulator/Devices/ ]; then
  953. # Verify that no Realm files still exist
  954. ! find ~/Library/Developer/CoreSimulator/Devices/ -name '*.realm' | grep -q .
  955. fi
  956. failed=0
  957. sh build.sh verify-$target 2>&1 | tee build/build.log | xcpretty -r junit -o build/reports/junit.xml || failed=1
  958. if [ "$failed" = "1" ] && cat build/build.log | grep -E 'DTXProxyChannel|DTXChannel|out of date and needs to be rebuilt|operation never finished bootstrapping'; then
  959. echo "Known Xcode error detected. Running job again."
  960. if cat build/build.log | grep -E 'out of date and needs to be rebuilt'; then
  961. rm -rf build/DerivedData
  962. fi
  963. failed=0
  964. sh build.sh verify-$target | tee build/build.log | xcpretty -r junit -o build/reports/junit.xml || failed=1
  965. elif [ "$failed" = "1" ] && tail ~/Library/Logs/CoreSimulator/CoreSimulator.log | grep -E "Operation not supported|Failed to lookup com.apple.coreservices.lsuseractivity.simulatorsupport"; then
  966. echo "Known Xcode error detected. Running job again."
  967. failed=0
  968. sh build.sh verify-$target | tee build/build.log | xcpretty -r junit -o build/reports/junit.xml || failed=1
  969. fi
  970. if [ "$failed" = "1" ]; then
  971. echo "\n\n***\nbuild/build.log\n***\n\n" && cat build/build.log || true
  972. echo "\n\n***\nCoreSimulator.log\n***\n\n" && cat ~/Library/Logs/CoreSimulator/CoreSimulator.log
  973. exit 1
  974. fi
  975. fi
  976. if [ "$target" = "osx" ] && [ "$configuration" = "Debug" ]; then
  977. gcovr -r . -f ".*Realm.*" -e ".*Tests.*" -e ".*core.*" --xml > build/reports/coverage-report.xml
  978. WS=$(pwd | sed "s/\//\\\\\//g")
  979. sed -i ".bak" "s/<source>\./<source>${WS}/" build/reports/coverage-report.xml
  980. fi
  981. ;;
  982. ######################################
  983. # Release packaging
  984. ######################################
  985. "package-examples")
  986. ./scripts/package_examples.rb
  987. zip --symlinks -r realm-examples.zip examples -x "examples/installation/*"
  988. ;;
  989. "package-test-examples")
  990. if ! VERSION=$(echo realm-objc-*.zip | egrep -o '\d*\.\d*\.\d*-[a-z]*(\.\d*)?'); then
  991. VERSION=$(echo realm-objc-*.zip | egrep -o '\d*\.\d*\.\d*')
  992. fi
  993. OBJC="realm-objc-${VERSION}"
  994. SWIFT="realm-swift-${VERSION}"
  995. unzip ${OBJC}.zip
  996. cp $0 ${OBJC}
  997. cp -r ${source_root}/scripts ${OBJC}
  998. cd ${OBJC}
  999. sh build.sh examples-ios
  1000. sh build.sh examples-tvos
  1001. sh build.sh examples-osx
  1002. cd ..
  1003. rm -rf ${OBJC}
  1004. unzip ${SWIFT}.zip
  1005. cp $0 ${SWIFT}
  1006. cp -r ${source_root}/scripts ${SWIFT}
  1007. cd ${SWIFT}
  1008. sh build.sh examples-ios-swift
  1009. sh build.sh examples-tvos-swift
  1010. cd ..
  1011. rm -rf ${SWIFT}
  1012. ;;
  1013. "package-ios-static")
  1014. sh build.sh prelaunch-simulator
  1015. sh build.sh ios-static
  1016. cd build/ios-static
  1017. zip --symlinks -r realm-framework-ios-static.zip Realm.framework
  1018. ;;
  1019. "package-ios")
  1020. sh build.sh prelaunch-simulator
  1021. sh build.sh ios-dynamic
  1022. cd build/ios
  1023. zip --symlinks -r realm-framework-ios.zip Realm.framework
  1024. ;;
  1025. "package-osx")
  1026. sh build.sh osx
  1027. cd build/DerivedData/Realm/Build/Products/Release
  1028. zip --symlinks -r realm-framework-osx.zip Realm.framework
  1029. ;;
  1030. "package-watchos")
  1031. sh build.sh prelaunch-simulator
  1032. sh build.sh watchos
  1033. # If we're building the obj-c library with an Xcode version older than
  1034. # 10, we need to also build the arm64_32 slice with Xcode 10 and lipo
  1035. # it in
  1036. if (( $(xcode_version_major) < 10 )); then
  1037. (
  1038. REALM_XCODE_VERSION=10.0
  1039. REALM_SWIFT_VERSION=
  1040. set_xcode_and_swift_versions
  1041. sh build.sh prelaunch-simulator
  1042. xc "-scheme Realm -configuration $CONFIGURATION -sdk watchos ARCHS='arm64_32'"
  1043. cp build/DerivedData/Realm/Build/Products/Release-watchos/Realm.framework/*.bcsymbolmap build/watchos/Realm.framework
  1044. xcrun lipo \
  1045. -create build/watchos/Realm.framework/Realm build/DerivedData/Realm/Build/Products/Release-watchos/Realm.framework/Realm \
  1046. -output build/watchos-tmp
  1047. mv build/watchos-tmp build/watchos/Realm.framework/Realm
  1048. )
  1049. fi
  1050. cd build/watchos
  1051. zip --symlinks -r realm-framework-watchos.zip Realm.framework
  1052. ;;
  1053. "package-tvos")
  1054. sh build.sh prelaunch-simulator
  1055. sh build.sh tvos
  1056. cd build/tvos
  1057. zip --symlinks -r realm-framework-tvos.zip Realm.framework
  1058. ;;
  1059. package-*-swift)
  1060. PLATFORM=$(echo $COMMAND | cut -d - -f 2)
  1061. for version in 9.2 9.3 9.4 10.0 10.1 10.2.1; do
  1062. REALM_XCODE_VERSION=$version
  1063. REALM_SWIFT_VERSION=
  1064. set_xcode_and_swift_versions
  1065. sh build.sh prelaunch-simulator
  1066. sh build.sh $PLATFORM-swift
  1067. done
  1068. cd build/$PLATFORM
  1069. zip --symlinks -r realm-swift-framework-$PLATFORM.zip swift-9.2 swift-9.2 swift-9.4 swift-10.0 swift-10.1 swift-10.2.1
  1070. ;;
  1071. package-*-swift-*)
  1072. PLATFORM=$(echo $COMMAND | cut -d - -f 2)
  1073. REALM_XCODE_VERSION=$(echo $COMMAND | cut -d - -f 4)
  1074. REALM_SWIFT_VERSION=
  1075. set_xcode_and_swift_versions
  1076. sh build.sh prelaunch-simulator
  1077. sh build.sh $PLATFORM-swift
  1078. cd build/$PLATFORM
  1079. zip --symlinks -r realm-swift-framework-$PLATFORM-swift-$REALM_XCODE_VERSION.zip swift-$REALM_XCODE_VERSION
  1080. ;;
  1081. "package-release")
  1082. LANG="$2"
  1083. TEMPDIR=$(mktemp -d $TMPDIR/realm-release-package-${LANG}.XXXX)
  1084. VERSION=$(sh build.sh get-version)
  1085. FOLDER=${TEMPDIR}/realm-${LANG}-${VERSION}
  1086. mkdir -p ${FOLDER}/osx ${FOLDER}/ios ${FOLDER}/watchos ${FOLDER}/tvos
  1087. if [[ "${LANG}" == "objc" ]]; then
  1088. mkdir -p ${FOLDER}/ios/static
  1089. mkdir -p ${FOLDER}/ios/dynamic
  1090. mkdir -p ${FOLDER}/Swift
  1091. (
  1092. cd ${FOLDER}/osx
  1093. unzip ${WORKSPACE}/realm-framework-osx.zip
  1094. )
  1095. (
  1096. cd ${FOLDER}/ios/static
  1097. unzip ${WORKSPACE}/realm-framework-ios-static.zip
  1098. )
  1099. (
  1100. cd ${FOLDER}/ios/dynamic
  1101. unzip ${WORKSPACE}/realm-framework-ios.zip
  1102. )
  1103. (
  1104. cd ${FOLDER}/watchos
  1105. unzip ${WORKSPACE}/realm-framework-watchos.zip
  1106. )
  1107. (
  1108. cd ${FOLDER}/tvos
  1109. unzip ${WORKSPACE}/realm-framework-tvos.zip
  1110. )
  1111. else
  1112. (
  1113. cd ${FOLDER}/osx
  1114. for f in ${WORKSPACE}/realm-swift-framework-osx-swift-*.zip; do
  1115. unzip "$f"
  1116. done
  1117. )
  1118. (
  1119. cd ${FOLDER}/ios
  1120. for f in ${WORKSPACE}/realm-swift-framework-ios-swift-*.zip; do
  1121. unzip "$f"
  1122. done
  1123. )
  1124. (
  1125. cd ${FOLDER}/watchos
  1126. for f in ${WORKSPACE}/realm-swift-framework-watchos-swift-*.zip; do
  1127. unzip "$f"
  1128. done
  1129. )
  1130. (
  1131. cd ${FOLDER}/tvos
  1132. for f in ${WORKSPACE}/realm-swift-framework-tvos-swift-*.zip; do
  1133. unzip "$f"
  1134. done
  1135. )
  1136. fi
  1137. (
  1138. cd ${WORKSPACE}
  1139. cp -R plugin ${FOLDER}
  1140. cp LICENSE ${FOLDER}/LICENSE.txt
  1141. if [[ "${LANG}" == "objc" ]]; then
  1142. cp Realm/Swift/RLMSupport.swift ${FOLDER}/Swift/
  1143. fi
  1144. )
  1145. (
  1146. cd ${FOLDER}
  1147. unzip ${WORKSPACE}/realm-examples.zip
  1148. cd examples
  1149. if [[ "${LANG}" == "objc" ]]; then
  1150. rm -rf ios/swift-* tvos/swift-*
  1151. else
  1152. rm -rf ios/objc ios/rubymotion osx tvos/objc
  1153. fi
  1154. )
  1155. cat > ${FOLDER}/docs.webloc <<EOF
  1156. <?xml version="1.0" encoding="UTF-8"?>
  1157. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  1158. <plist version="1.0">
  1159. <dict>
  1160. <key>URL</key>
  1161. <string>https://realm.io/docs/${LANG}/${VERSION}</string>
  1162. </dict>
  1163. </plist>
  1164. EOF
  1165. (
  1166. cd ${TEMPDIR}
  1167. zip --symlinks -r realm-${LANG}-${VERSION}.zip realm-${LANG}-${VERSION}
  1168. mv realm-${LANG}-${VERSION}.zip ${WORKSPACE}
  1169. )
  1170. ;;
  1171. "test-package-release")
  1172. # Generate a release package locally for testing purposes
  1173. # Real releases should always be done via Jenkins
  1174. if [ -z "${WORKSPACE}" ]; then
  1175. echo 'WORKSPACE must be set to a directory to assemble the release in'
  1176. exit 1
  1177. fi
  1178. if [ -d "${WORKSPACE}" ]; then
  1179. echo 'WORKSPACE directory should not already exist'
  1180. exit 1
  1181. fi
  1182. REALM_SOURCE="$(pwd)"
  1183. mkdir -p "$WORKSPACE"
  1184. WORKSPACE="$(cd "$WORKSPACE" && pwd)"
  1185. export WORKSPACE
  1186. cd $WORKSPACE
  1187. git clone --recursive $REALM_SOURCE realm-cocoa
  1188. cd realm-cocoa
  1189. echo 'Packaging iOS'
  1190. sh build.sh package-ios-static
  1191. cp build/ios-static/realm-framework-ios-static.zip ..
  1192. sh build.sh package-ios
  1193. cp build/ios/realm-framework-ios.zip ..
  1194. sh build.sh package-ios-swift
  1195. cp build/ios/realm-swift-framework-ios.zip ..
  1196. echo 'Packaging macOS'
  1197. sh build.sh package-osx
  1198. cp build/DerivedData/Realm/Build/Products/Release/realm-framework-osx.zip ..
  1199. sh build.sh package-osx-swift
  1200. cp build/osx/realm-swift-framework-osx.zip ..
  1201. echo 'Packaging watchOS'
  1202. sh build.sh package-watchos
  1203. cp build/watchos/realm-framework-watchos.zip ..
  1204. sh build.sh package-watchos-swift
  1205. cp build/watchos/realm-swift-framework-watchos.zip ..
  1206. echo 'Packaging tvOS'
  1207. sh build.sh package-tvos
  1208. cp build/tvos/realm-framework-tvos.zip ..
  1209. sh build.sh package-tvos-swift
  1210. cp build/tvos/realm-swift-framework-tvos.zip ..
  1211. echo 'Packaging examples'
  1212. sh build.sh package-examples
  1213. cp realm-examples.zip ..
  1214. echo 'Building final release packages'
  1215. sh build.sh package-release objc
  1216. sh build.sh package-release swift
  1217. echo 'Testing packaged examples'
  1218. sh build.sh package-test-examples
  1219. ;;
  1220. "github-release")
  1221. if [ -z "${GITHUB_ACCESS_TOKEN}" ]; then
  1222. echo 'GITHUB_ACCESS_TOKEN must be set to create GitHub releases'
  1223. exit 1
  1224. fi
  1225. ./scripts/github_release.rb
  1226. ;;
  1227. "add-empty-changelog")
  1228. empty_section=$(cat <<EOS
  1229. x.y.z Release notes (yyyy-MM-dd)
  1230. =============================================================
  1231. ### Enhancements
  1232. * None.
  1233. ### Fixed
  1234. * <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-js/issues/????), since v?.?.?)
  1235. * None.
  1236. <!-- ### Breaking Changes - ONLY INCLUDE FOR NEW MAJOR version -->
  1237. ### Compatibility
  1238. * File format: Generates Realms with format v9 (Reads and upgrades all previous formats)
  1239. * Realm Object Server: 3.21.0 or later.
  1240. * APIs are backwards compatible with all previous releases in the 3.x.y series.
  1241. * Carthage release for Swift is built with Xcode 10.2.1.
  1242. EOS)
  1243. changelog=$(cat CHANGELOG.md)
  1244. echo "$empty_section" > CHANGELOG.md
  1245. echo >> CHANGELOG.md
  1246. echo "$changelog" >> CHANGELOG.md
  1247. ;;
  1248. *)
  1249. echo "Unknown command '$COMMAND'"
  1250. usage
  1251. exit 1
  1252. ;;
  1253. esac