build.sh 50 KB

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