build.sh 47 KB

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