build.sh 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  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: tests SwiftUI framework UI tests
  61. verify: verifies docs, osx, osx-swift, ios-static, ios-dynamic, ios-swift, ios-device 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 -destination 'name=iPhone 12' build-for-testing"
  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")
  572. xctest 'SwiftUITestHost' -sdk iphonesimulator -destination 'name=iPhone 12'
  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. ;;
  613. "verify-cocoapods")
  614. if [[ -d .git ]]; then
  615. # Verify the current branch, unless one was already specified in the sha environment variable.
  616. if [[ -z $sha ]]; then
  617. export sha=$(git rev-parse --abbrev-ref HEAD)
  618. fi
  619. if [[ $(git log -1 '@{push}..') != "" ]] || ! git diff-index --quiet HEAD; then
  620. echo "WARNING: verify-cocoapods will test the latest revision of $sha found on GitHub."
  621. echo " Any unpushed local changes will not be tested."
  622. echo ""
  623. sleep 1
  624. fi
  625. fi
  626. sh build.sh verify-cocoapods-ios
  627. sh build.sh verify-cocoapods-ios-dynamic
  628. sh build.sh verify-cocoapods-osx
  629. sh build.sh verify-cocoapods-watchos
  630. # https://github.com/CocoaPods/CocoaPods/issues/7708
  631. export EXPANDED_CODE_SIGN_IDENTITY=''
  632. cd examples/installation
  633. sh build.sh test-ios-objc-cocoapods
  634. sh build.sh test-ios-objc-cocoapods-dynamic
  635. sh build.sh test-ios-swift-cocoapods
  636. sh build.sh test-osx-objc-cocoapods
  637. sh build.sh test-osx-swift-cocoapods
  638. sh build.sh test-catalyst-objc-cocoapods
  639. sh build.sh test-catalyst-objc-cocoapods-dynamic
  640. sh build.sh test-catalyst-swift-cocoapods
  641. sh build.sh test-watchos-objc-cocoapods
  642. sh build.sh test-watchos-swift-cocoapods
  643. ;;
  644. verify-cocoapods-ios-dynamic)
  645. PLATFORM=$(echo "$COMMAND" | cut -d - -f 3)
  646. # https://github.com/CocoaPods/CocoaPods/issues/7708
  647. export EXPANDED_CODE_SIGN_IDENTITY=''
  648. cd examples/installation
  649. sh build.sh test-ios-objc-cocoapods-dynamic
  650. ;;
  651. verify-cocoapods-*)
  652. PLATFORM=$(echo "$COMMAND" | cut -d - -f 3)
  653. # https://github.com/CocoaPods/CocoaPods/issues/7708
  654. export EXPANDED_CODE_SIGN_IDENTITY=''
  655. cd examples/installation
  656. sh build.sh "test-$PLATFORM-swift-cocoapods"
  657. ;;
  658. "verify-osx-encryption")
  659. REALM_ENCRYPT_ALL=YES sh build.sh test-osx
  660. exit 0
  661. ;;
  662. "verify-osx")
  663. REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS -workspace examples/osx/objc/RealmExamples.xcworkspace" \
  664. sh build.sh test-osx
  665. sh build.sh examples-osx
  666. (
  667. cd examples/osx/objc/build/DerivedData/RealmExamples/Build/Products/$CONFIGURATION
  668. DYLD_FRAMEWORK_PATH=. ./JSONImport >/dev/null
  669. )
  670. exit 0
  671. ;;
  672. "verify-osx-swift")
  673. sh build.sh test-osx-swift
  674. exit 0
  675. ;;
  676. "verify-swiftui")
  677. sh build.sh test-swiftui
  678. exit 0
  679. ;;
  680. "verify-osx-swift-evolution")
  681. export REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS REALM_BUILD_LIBRARY_FOR_DISTRIBUTION=YES"
  682. sh build.sh test-osx-swift
  683. exit 0
  684. ;;
  685. "verify-ios-static")
  686. REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS -workspace examples/ios/objc/RealmExamples.xcworkspace" \
  687. sh build.sh test-ios-static
  688. sh build.sh examples-ios
  689. ;;
  690. "verify-ios-dynamic")
  691. sh build.sh test-ios-dynamic
  692. ;;
  693. "verify-ios-swift")
  694. REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS -workspace examples/ios/swift/RealmExamples.xcworkspace" \
  695. sh build.sh test-ios-swift
  696. sh build.sh examples-ios-swift
  697. ;;
  698. "verify-ios-swift-evolution")
  699. export REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS REALM_BUILD_LIBRARY_FOR_DISTRIBUTION=YES"
  700. sh build.sh test-ios-swift
  701. exit 0
  702. ;;
  703. "verify-ios-device-objc")
  704. sh build.sh test-ios-devices-objc
  705. exit 0
  706. ;;
  707. "verify-ios-device-swift")
  708. sh build.sh test-ios-devices-swift
  709. exit 0
  710. ;;
  711. "verify-docs")
  712. sh build.sh docs
  713. for lang in swift objc; do
  714. undocumented="docs/${lang}_output/undocumented.json"
  715. if ruby -rjson -e "j = JSON.parse(File.read('docs/${lang}_output/undocumented.json')); exit j['warnings'].length != 0"; then
  716. echo "Undocumented Realm $lang declarations:"
  717. cat "$undocumented"
  718. exit 1
  719. fi
  720. done
  721. exit 0
  722. ;;
  723. "verify-watchos")
  724. sh build.sh watchos-swift
  725. exit 0
  726. ;;
  727. "verify-tvos")
  728. REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS -workspace examples/tvos/objc/RealmExamples.xcworkspace" \
  729. sh build.sh test-tvos
  730. sh build.sh examples-tvos
  731. exit 0
  732. ;;
  733. "verify-tvos-swift")
  734. REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS -workspace examples/tvos/swift/RealmExamples.xcworkspace" \
  735. sh build.sh test-tvos-swift
  736. sh build.sh examples-tvos-swift
  737. exit 0
  738. ;;
  739. "verify-tvos-swift-evolution")
  740. export REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS REALM_BUILD_LIBRARY_FOR_DISTRIBUTION=YES"
  741. sh build.sh test-tvos-swift
  742. exit 0
  743. ;;
  744. "verify-tvos-device")
  745. sh build.sh test-tvos-devices
  746. exit 0
  747. ;;
  748. "verify-swiftlint")
  749. swiftlint lint --strict
  750. exit 0
  751. ;;
  752. verify-swiftpm*)
  753. sh build.sh "test-$(echo "$COMMAND" | cut -d - -f 2-)"
  754. exit 0
  755. ;;
  756. "verify-osx-object-server")
  757. sh build.sh test-osx-object-server
  758. exit 0
  759. ;;
  760. "verify-catalyst")
  761. sh build.sh test-catalyst
  762. exit 0
  763. ;;
  764. "verify-catalyst-swift")
  765. sh build.sh test-catalyst-swift
  766. exit 0
  767. ;;
  768. "verify-xcframework")
  769. sh build.sh xcframework
  770. exit 0
  771. ;;
  772. ######################################
  773. # Docs
  774. ######################################
  775. "docs")
  776. build_docs objc
  777. build_docs swift
  778. exit 0
  779. ;;
  780. ######################################
  781. # Examples
  782. ######################################
  783. "examples")
  784. sh build.sh clean
  785. sh build.sh prelaunch-simulator
  786. export REALM_SKIP_PRELAUNCH=1
  787. sh build.sh examples-ios
  788. sh build.sh examples-ios-swift
  789. sh build.sh examples-osx
  790. sh build.sh examples-tvos
  791. sh build.sh examples-tvos-swift
  792. exit 0
  793. ;;
  794. "examples-ios")
  795. workspace="examples/ios/objc/RealmExamples.xcworkspace"
  796. pod install --project-directory="$workspace/.." --no-repo-update
  797. examples="Simple TableView Migration Backlink GroupedTableView RACTableView Encryption Draw"
  798. versions="0 1 2 3 4 5"
  799. for example in $examples; do
  800. if [ "$example" = "Migration" ]; then
  801. # The migration example needs to be built for each schema version to ensure each compiles.
  802. for version in $versions; do
  803. xc -workspace "$workspace" -scheme "$example" -configuration "$CONFIGURATION" -sdk iphonesimulator build ARCHS=x86_64 "${CODESIGN_PARAMS[@]}" GCC_PREPROCESSOR_DEFINITIONS="\$(GCC_PREPROCESSOR_DEFINITIONS) SCHEMA_VERSION_$version"
  804. done
  805. else
  806. xc -workspace "$workspace" -scheme "$example" -configuration "$CONFIGURATION" -sdk iphonesimulator build ARCHS=x86_64 "${CODESIGN_PARAMS[@]}"
  807. fi
  808. done
  809. if [ -n "${JENKINS_HOME}" ]; then
  810. xc -workspace "$workspace" -scheme Extension -configuration "$CONFIGURATION" -sdk iphonesimulator build ARCHS=x86_64 "${CODESIGN_PARAMS[@]}"
  811. fi
  812. exit 0
  813. ;;
  814. "examples-ios-swift")
  815. workspace="examples/ios/swift/RealmExamples.xcworkspace"
  816. if [[ ! -d "$workspace" ]]; then
  817. workspace="${workspace/swift/swift-$REALM_XCODE_VERSION}"
  818. fi
  819. examples="Simple TableView Migration Backlink GroupedTableView Encryption"
  820. versions="0 1 2 3 4 5"
  821. for example in $examples; do
  822. if [ "$example" = "Migration" ]; then
  823. # The migration example needs to be built for each schema version to ensure each compiles.
  824. for version in $versions; do
  825. xc -workspace "$workspace" -scheme "$example" -configuration "$CONFIGURATION" -sdk iphonesimulator build ARCHS=x86_64 "${CODESIGN_PARAMS[@]}" OTHER_SWIFT_FLAGS="\$(OTHER_SWIFT_FLAGS) -DSCHEMA_VERSION_$version"
  826. done
  827. else
  828. xc -workspace "$workspace" -scheme "$example" -configuration "$CONFIGURATION" -sdk iphonesimulator build ARCHS=x86_64 "${CODESIGN_PARAMS[@]}"
  829. fi
  830. done
  831. exit 0
  832. ;;
  833. "examples-osx")
  834. xc -workspace examples/osx/objc/RealmExamples.xcworkspace -scheme JSONImport -configuration "${CONFIGURATION}" build "${CODESIGN_PARAMS[@]}"
  835. ;;
  836. "examples-tvos")
  837. workspace="examples/tvos/objc/RealmExamples.xcworkspace"
  838. examples="DownloadCache PreloadedData"
  839. for example in $examples; do
  840. xc -workspace "$workspace" -scheme "$example" -configuration "$CONFIGURATION" -sdk appletvsimulator build ARCHS=x86_64 "${CODESIGN_PARAMS[@]}"
  841. done
  842. exit 0
  843. ;;
  844. "examples-tvos-swift")
  845. workspace="examples/tvos/swift/RealmExamples.xcworkspace"
  846. if [[ ! -d "$workspace" ]]; then
  847. workspace="${workspace/swift/swift-$REALM_XCODE_VERSION}"
  848. fi
  849. examples="DownloadCache PreloadedData"
  850. for example in $examples; do
  851. xc -workspace "$workspace" -scheme "$example" -configuration "$CONFIGURATION" -sdk appletvsimulator build ARCHS=x86_64 "${CODESIGN_PARAMS[@]}"
  852. done
  853. exit 0
  854. ;;
  855. ######################################
  856. # Versioning
  857. ######################################
  858. "get-version")
  859. plist_get 'Realm/Realm-Info.plist' 'CFBundleShortVersionString'
  860. exit 0
  861. ;;
  862. "set-version")
  863. realm_version="$2"
  864. version_files="Realm/Realm-Info.plist"
  865. if [ -z "$realm_version" ]; then
  866. echo "You must specify a version."
  867. exit 1
  868. fi
  869. # The bundle version can contain only three groups of digits separated by periods,
  870. # so strip off any -beta.x tag from the end of the version string.
  871. bundle_version=$(echo "$realm_version" | cut -d - -f 1)
  872. for version_file in $version_files; do
  873. PlistBuddy -c "Set :CFBundleVersion $bundle_version" "$version_file"
  874. PlistBuddy -c "Set :CFBundleShortVersionString $realm_version" "$version_file"
  875. done
  876. sed -i '' "s/^VERSION=.*/VERSION=$realm_version/" dependencies.list
  877. sed -i '' "s/^let coreVersionStr =.*/let coreVersionStr = \"$REALM_CORE_VERSION\"/" Package.swift
  878. sed -i '' "s/^let cocoaVersionStr =.*/let cocoaVersionStr = \"$realm_version\"/" Package.swift
  879. sed -i '' "s/x.y.z Release notes (yyyy-MM-dd)/$realm_version Release notes ($(date '+%Y-%m-%d'))/" CHANGELOG.md
  880. exit 0
  881. ;;
  882. ######################################
  883. # Bitcode Detection
  884. ######################################
  885. "binary-has-bitcode")
  886. # Disable pipefail as grep -q will make otool fail due to exiting
  887. # before reading all the output
  888. set +o pipefail
  889. BINARY="$2"
  890. if otool -l "$BINARY" | grep -q "segname __LLVM"; then
  891. exit 0
  892. fi
  893. # Work around rdar://21826157 by checking for bitcode in thin binaries
  894. # Get architectures for binary
  895. archs="$(lipo -info "$BINARY" | rev | cut -d ':' -f1 | rev)"
  896. archs_array=( $archs )
  897. if [[ ${#archs_array[@]} -lt 2 ]]; then
  898. echo 'Error: Built library is not a fat binary'
  899. exit 1 # Early exit if not a fat binary
  900. fi
  901. TEMPDIR=$(mktemp -d $TMPDIR/realm-bitcode-check.XXXX)
  902. for arch in $archs; do
  903. lipo -thin "$arch" "$BINARY" -output "$TEMPDIR/$arch"
  904. if otool -l "$TEMPDIR/$arch" | grep -q "segname __LLVM"; then
  905. exit 0
  906. fi
  907. done
  908. echo 'Error: Built library does not contain bitcode'
  909. exit 1
  910. ;;
  911. ######################################
  912. # CocoaPods
  913. ######################################
  914. "cocoapods-setup")
  915. if [ ! -f core/version.txt ]; then
  916. sh build.sh download-core
  917. fi
  918. rm -rf include
  919. mkdir -p include
  920. cp -R core/realm-monorepo.xcframework/ios-armv7_arm64/Headers include/core
  921. mkdir -p include
  922. echo '' > Realm/RLMPlatform.h
  923. cp Realm/*.h Realm/*.hpp include
  924. ;;
  925. ######################################
  926. # Continuous Integration
  927. ######################################
  928. "ci-pr")
  929. mkdir -p build/reports
  930. export REALM_DISABLE_ANALYTICS=1
  931. export REALM_DISABLE_UPDATE_CHECKER=1
  932. # FIXME: Re-enable once CI can properly unlock the keychain
  933. export REALM_DISABLE_METADATA_ENCRYPTION=1
  934. # Make sure there aren't any lingering server processes from previous jobs
  935. pkill -9 mongo stitch || true
  936. # strip off the ios|tvos version specifier, e.g. the last part of: `ios-device-objc-ios8`
  937. if [[ "$target" =~ ^((ios|tvos)-device(-(objc|swift))?)(-(ios|tvos)[[:digit:]]+)?$ ]]; then
  938. export target=${BASH_REMATCH[1]}
  939. fi
  940. if [ "$target" = "docs" ]; then
  941. sh build.sh verify-docs
  942. elif [ "$target" = "swiftlint" ]; then
  943. sh build.sh verify-swiftlint
  944. else
  945. export sha=$GITHUB_PR_SOURCE_BRANCH
  946. export REALM_EXTRA_BUILD_ARGUMENTS='GCC_GENERATE_DEBUGGING_SYMBOLS=NO -allowProvisioningUpdates'
  947. if [[ "$target" = *ios* ]] || [[ "$target" = *tvos* ]] || [[ "$target" = *watchos* ]]; then
  948. sh build.sh prelaunch-simulator "$target"
  949. fi
  950. export REALM_SKIP_PRELAUNCH=1
  951. if [[ "$target" = *"server"* ]] || [[ "$target" = "swiftpm"* ]]; then
  952. source "$(brew --prefix nvm)/nvm.sh" --no-use
  953. nvm install 8.11.2
  954. sh build.sh setup-baas
  955. fi
  956. # Reset CoreSimulator.log
  957. mkdir -p ~/Library/Logs/CoreSimulator
  958. echo > ~/Library/Logs/CoreSimulator/CoreSimulator.log
  959. failed=0
  960. sh build.sh "verify-$target" 2>&1 | tee build/build.log | xcpretty -r junit -o build/reports/junit.xml || failed=1
  961. if [ "$failed" = "1" ] && grep -E 'DTXProxyChannel|DTXChannel|out of date and needs to be rebuilt|operation never finished bootstrapping' build/build.log ; then
  962. echo "Known Xcode error detected. Running job again."
  963. if grep -E 'out of date and needs to be rebuilt' build/build.log; then
  964. rm -rf build/DerivedData
  965. fi
  966. failed=0
  967. sh build.sh "verify-$target" | tee build/build.log | xcpretty -r junit -o build/reports/junit.xml || failed=1
  968. elif [ "$failed" = "1" ] && tail ~/Library/Logs/CoreSimulator/CoreSimulator.log | grep -E "Operation not supported|Failed to lookup com.apple.coreservices.lsuseractivity.simulatorsupport"; then
  969. echo "Known Xcode error detected. Running job again."
  970. failed=0
  971. sh build.sh "verify-$target" | tee build/build.log | xcpretty -r junit -o build/reports/junit.xml || failed=1
  972. fi
  973. if [ "$failed" = "1" ]; then
  974. set +e
  975. printf "%s" "\n\n***\nbuild/build.log\n***\n\n" && cat build/build.log
  976. printf "%s" "\n\n***\nCoreSimulator.log\n***\n\n" && cat ~/Library/Logs/CoreSimulator/CoreSimulator.log
  977. exit 1
  978. fi
  979. fi
  980. if [ "$target" = "osx" ] && [ "$configuration" = "Debug" ]; then
  981. gcovr -r . -f ".*Realm.*" -e ".*Tests.*" -e ".*core.*" --xml > build/reports/coverage-report.xml
  982. WS=$(pwd | sed "s/\//\\\\\//g")
  983. sed -i ".bak" "s/<source>\./<source>${WS}/" build/reports/coverage-report.xml
  984. fi
  985. ;;
  986. ######################################
  987. # Release packaging
  988. ######################################
  989. "package-examples")
  990. ./scripts/package_examples.rb
  991. zip --symlinks -r realm-examples.zip examples -x "examples/installation/*"
  992. ;;
  993. "package-test-examples-objc")
  994. if ! VERSION=$(echo realm-objc-*.zip | grep -E -o '\d*\.\d*\.\d*-[a-z]*(\.\d*)?'); then
  995. VERSION=$(echo realm-objc-*.zip | grep -E -o '\d*\.\d*\.\d*')
  996. fi
  997. OBJC="realm-objc-${VERSION}"
  998. unzip "${OBJC}.zip"
  999. cp "$0" "${OBJC}"
  1000. cp -r "${source_root}/scripts" "${OBJC}"
  1001. cd "${OBJC}"
  1002. sh build.sh examples-ios
  1003. sh build.sh examples-tvos
  1004. sh build.sh examples-osx
  1005. cd ..
  1006. rm -rf "${OBJC}"
  1007. ;;
  1008. "package-test-examples-swift")
  1009. if ! VERSION=$(echo realm-swift-*.zip | grep -E -o '\d*\.\d*\.\d*-[a-z]*(\.\d*)?'); then
  1010. VERSION=$(echo realm-swift-*.zip | grep -E -o '\d*\.\d*\.\d*')
  1011. fi
  1012. SWIFT="realm-swift-${VERSION}"
  1013. unzip "${SWIFT}.zip"
  1014. cp "$0" "${SWIFT}"
  1015. cp -r "${source_root}/scripts" "${SWIFT}"
  1016. cd "${SWIFT}"
  1017. sh build.sh examples-ios-swift
  1018. sh build.sh examples-tvos-swift
  1019. cd ..
  1020. rm -rf "${SWIFT}"
  1021. ;;
  1022. "package-ios-static")
  1023. sh build.sh prelaunch-simulator
  1024. sh build.sh ios-static
  1025. cd build/ios-static
  1026. zip --symlinks -r realm-framework-ios-static.zip Realm.xcframework
  1027. ;;
  1028. "package")
  1029. PLATFORM="$2"
  1030. REALM_SWIFT_VERSION=
  1031. set_xcode_and_swift_versions
  1032. sh build.sh "$PLATFORM-swift"
  1033. cd "build/$PLATFORM"
  1034. zip --symlinks -r "realm-framework-$PLATFORM-$REALM_XCODE_VERSION.zip" "swift-$REALM_XCODE_VERSION"
  1035. ;;
  1036. "package-release")
  1037. LANG="$2"
  1038. tempdir="$(mktemp -d "$TMPDIR"/realm-release-package-"${LANG}".XXXX)"
  1039. extract_dir="$(mktemp -d "$TMPDIR"/realm-release-package-"${LANG}".XXXX)"
  1040. version="$(sh build.sh get-version)"
  1041. package_dir="${tempdir}/realm-${LANG}-${version}"
  1042. mkdir -p "${package_dir}"
  1043. if [[ "${LANG}" == "objc" ]]; then
  1044. mkdir -p "${extract_dir}"
  1045. unzip "${WORKSPACE}/realm-framework-ios-static.zip" -d "${package_dir}/ios-static"
  1046. for platform in osx ios watchos tvos catalyst; do
  1047. unzip "${WORKSPACE}/realm-framework-${platform}-${REALM_XCODE_VERSION}.zip" -d "${extract_dir}/${platform}"
  1048. done
  1049. find "${extract_dir}" -name 'Realm.framework' \
  1050. | sed 's/.*/-framework &/' \
  1051. | xargs xcodebuild -create-xcframework -allow-internal-distribution -output "${package_dir}/Realm.xcframework"
  1052. cp "${WORKSPACE}/Realm/Swift/RLMSupport.swift" "${package_dir}"
  1053. rm -r "${extract_dir}"
  1054. else
  1055. xcode_versions=$(find . -name 'realm-framework-*-1*' | sed 's@./realm-framework-[a-z]*-\(.*\).zip@\1@' | sort -u)
  1056. for xcode_version in $xcode_versions; do
  1057. mkdir -p "${extract_dir}"
  1058. for platform in osx ios watchos tvos catalyst; do
  1059. unzip "realm-framework-$platform-$xcode_version.zip" -d "${extract_dir}/${platform}"
  1060. done
  1061. find "${extract_dir}" -name 'Realm.framework' \
  1062. | sed 's/.*/-framework &/' \
  1063. | xargs xcodebuild -create-xcframework -allow-internal-distribution -output "${package_dir}/${xcode_version}/Realm.xcframework"
  1064. find "${extract_dir}" -name 'RealmSwift.framework' \
  1065. | sed 's/.*/-framework &/' \
  1066. | xargs xcodebuild -create-xcframework -allow-internal-distribution -output "${package_dir}/${xcode_version}/RealmSwift.xcframework"
  1067. rm -r "${extract_dir}"
  1068. done
  1069. fi
  1070. (
  1071. cd "${WORKSPACE}"
  1072. cp -R plugin LICENSE "${package_dir}"
  1073. )
  1074. (
  1075. cd "${package_dir}"
  1076. unzip "${WORKSPACE}/realm-examples.zip"
  1077. cd examples
  1078. if [[ "${LANG}" == "objc" ]]; then
  1079. rm -rf ios/swift-* tvos/swift-*
  1080. else
  1081. rm -rf ios/objc osx tvos/objc
  1082. fi
  1083. )
  1084. cat > "${package_dir}"/docs.webloc <<EOF
  1085. <?xml version="1.0" encoding="UTF-8"?>
  1086. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  1087. <plist version="1.0">
  1088. <dict>
  1089. <key>URL</key>
  1090. <string>https://realm.io/docs/${LANG}/${version}</string>
  1091. </dict>
  1092. </plist>
  1093. EOF
  1094. (
  1095. cd "${tempdir}"
  1096. zip --symlinks -r "realm-${LANG}-${version}.zip" "realm-${LANG}-${version}"
  1097. mv "realm-${LANG}-${version}.zip" "${WORKSPACE}"
  1098. )
  1099. ;;
  1100. "test-package-release")
  1101. # Generate a release package locally for testing purposes
  1102. # Real releases should always be done via Jenkins
  1103. if [ -z "${WORKSPACE}" ]; then
  1104. echo 'WORKSPACE must be set to a directory to assemble the release in'
  1105. exit 1
  1106. fi
  1107. if [ -d "${WORKSPACE}" ]; then
  1108. echo 'WORKSPACE directory should not already exist'
  1109. exit 1
  1110. fi
  1111. REALM_SOURCE="$(pwd)"
  1112. mkdir -p "$WORKSPACE"
  1113. WORKSPACE="$(cd "$WORKSPACE" && pwd)"
  1114. export WORKSPACE
  1115. cd "$WORKSPACE"
  1116. git clone --recursive "$REALM_SOURCE" realm-cocoa
  1117. cd realm-cocoa
  1118. echo 'Packaging iOS'
  1119. sh build.sh package-ios-static
  1120. cp build/ios-static/realm-framework-ios-static.zip .
  1121. sh build.sh package ios
  1122. cp "build/ios/realm-framework-ios-$REALM_XCODE_VERSION.zip" .
  1123. echo 'Packaging macOS'
  1124. sh build.sh package osx
  1125. cp "build/osx/realm-framework-osx-$REALM_XCODE_VERSION.zip" .
  1126. echo 'Packaging watchOS'
  1127. sh build.sh package watchos
  1128. cp "build/watchos/realm-framework-watchos-$REALM_XCODE_VERSION.zip" .
  1129. echo 'Packaging tvOS'
  1130. sh build.sh package tvos
  1131. cp "build/tvos/realm-framework-tvos-$REALM_XCODE_VERSION.zip" .
  1132. echo 'Packaging Catalyst'
  1133. sh build.sh package catalyst
  1134. cp "build/catalyst/realm-framework-catalyst-$REALM_XCODE_VERSION.zip" .
  1135. echo 'Packaging examples'
  1136. sh build.sh package-examples
  1137. echo 'Building final release packages'
  1138. export WORKSPACE="${WORKSPACE}/realm-cocoa"
  1139. sh build.sh package-release objc
  1140. sh build.sh package-release swift
  1141. echo 'Testing packaged examples'
  1142. sh build.sh package-test-examples-objc
  1143. sh build.sh package-test-examples-swift
  1144. ;;
  1145. "github-release")
  1146. if [ -z "${GITHUB_ACCESS_TOKEN}" ]; then
  1147. echo 'GITHUB_ACCESS_TOKEN must be set to create GitHub releases'
  1148. exit 1
  1149. fi
  1150. ./scripts/github_release.rb
  1151. ;;
  1152. "add-empty-changelog")
  1153. empty_section=$(cat <<EOS
  1154. x.y.z Release notes (yyyy-MM-dd)
  1155. =============================================================
  1156. ### Enhancements
  1157. * None.
  1158. ### Fixed
  1159. * <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-cocoa/issues/????), since v?.?.?)
  1160. * None.
  1161. <!-- ### Breaking Changes - ONLY INCLUDE FOR NEW MAJOR version -->
  1162. ### Compatibility
  1163. * Realm Studio: 10.0.0 or later.
  1164. * APIs are backwards compatible with all previous releases in the 10.x.y series.
  1165. * Carthage release for Swift is built with Xcode 12.4.
  1166. * CocoaPods: 1.10 or later.
  1167. ### Internal
  1168. * Upgraded realm-core from ? to ?
  1169. EOS)
  1170. changelog=$(cat CHANGELOG.md)
  1171. echo "$empty_section" > CHANGELOG.md
  1172. echo >> CHANGELOG.md
  1173. echo "$changelog" >> CHANGELOG.md
  1174. ;;
  1175. *)
  1176. echo "Unknown command '$COMMAND'"
  1177. usage
  1178. exit 1
  1179. ;;
  1180. esac