build.sh 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365
  1. #!/bin/bash
  2. ##################################################################################
  3. # Custom build tool for Realm Objective-C binding.
  4. #
  5. # (C) Copyright 2011-2022 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. : "${REALM_CORE_VERSION:=$(sed -n 's/^REALM_CORE_VERSION=\(.*\)$/\1/p' "${source_root}/dependencies.list")}" # set to "current" to always use the current build
  15. # Provide a fallback value for TMPDIR, relevant for Xcode Bots
  16. : "${TMPDIR:=$(getconf DARWIN_USER_TEMP_DIR)}"
  17. PATH=/usr/libexec:$PATH
  18. if [ -n "${CI}" ]; then
  19. CODESIGN_PARAMS=(CODE_SIGN_IDENTITY='' CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO)
  20. fi
  21. if [ -n "${CI_XCODE_CLOUD}" ]; then
  22. DERIVED_DATA="$CI_DERIVED_DATA_PATH"
  23. ROOT_WORKSPACE="$CI_WORKSPACE"
  24. BRANCH="$CI_BRANCH"
  25. elif [ -n "${GITHUB_WORKSPACE}" ]; then
  26. DERIVED_DATA="$GITHUB_WORKSPACE/build/DerivedData/Realm"
  27. ROOT_WORKSPACE="$GITHUB_WORKSPACE"
  28. BRANCH="$GITHUB_REF"
  29. else
  30. ROOT_WORKSPACE="$(pwd)"
  31. DERIVED_DATA="$ROOT_WORKSPACE/build/DerivedData/Realm"
  32. BRANCH="$(git branch --show-current)"
  33. fi
  34. usage() {
  35. cat <<EOF
  36. Usage: sh $0 command [argument]
  37. command:
  38. clean: clean up/remove all generated files
  39. download-core: downloads core library (binary version)
  40. build [platforms]: builds xcframeworks for Realm and RealmSwift for given platforms (default all)
  41. build-static [plats]: builds static xcframework for Realm platforms (default all)
  42. analyze-osx: analyzes macOS framework
  43. test: tests all iOS and macOS frameworks
  44. test-all: tests all iOS and macOS frameworks in both Debug and Release configurations
  45. test-ios-static: tests static iOS framework on 32-bit and 64-bit simulators
  46. test-ios-dynamic: tests dynamic iOS framework on 32-bit and 64-bit simulators
  47. test-ios-swift: tests RealmSwift iOS framework on 32-bit and 64-bit simulators
  48. test-ios-devices: tests ObjC & Swift iOS frameworks on all attached iOS devices
  49. test-ios-devices-objc: tests ObjC iOS framework on all attached iOS devices
  50. test-ios-devices-swift: tests Swift iOS framework on all attached iOS devices
  51. test-tvos: tests tvOS framework
  52. test-tvos-swift: tests RealmSwift tvOS framework
  53. test-tvos-devices: tests ObjC & Swift tvOS frameworks on all attached tvOS devices
  54. test-osx: tests macOS framework
  55. test-osx-swift: tests RealmSwift macOS framework
  56. test-catalyst: tests Mac Catalyst framework
  57. test-catalyst-swift: tests RealmSwift Mac Catalyst framework
  58. test-swiftpm: tests ObjC and Swift macOS frameworks via SwiftPM
  59. test-ios-swiftui: tests SwiftUI framework UI tests
  60. test-swiftuiserver-osx: tests Server Sync in SwiftUI
  61. verify: verifies docs, cocoapods, swiftpm, xcframework, swiftuiserver-osx, swiftlint, spm-ios, objectserver-osx, watchos in both Debug and Release configurations
  62. docs: builds docs in docs/output
  63. examples: builds all examples
  64. examples-ios: builds all objc iOS examples
  65. examples-ios-swift: builds all Swift iOS examples
  66. examples-osx: builds all macOS examples
  67. examples-tvos: builds all objc tvOS examples
  68. examples-tvos-swift: builds all Swift tvOS examples
  69. get-version: get the current version
  70. get-ioplatformuuid: get io platform uuid
  71. set-version version: set the version
  72. set-core-version version: set the version of core to use
  73. release-package-examples: build release package the examples
  74. release-package-docs: build release package the docs
  75. release-package-*: build release package for the given platform, configuration and target (this is executed in XCode Cloud)
  76. release-create-xcframework_[xcode-version] [platform]: creates an xcframework from the framework build by the previous step
  77. release-package: creates the final packages
  78. release-package-test-examples: test a built examples release package
  79. test-package-release: locally build a complete release package for all platforms
  80. publish-github: create a Github release for the currently checked-out tag
  81. publish-docs: publish a built docs release to the website
  82. publish-update-checker: publish cocoa file with a version to check for update logic
  83. publish-cocoapods [tag]: publish the requested tag to CocoaPods
  84. prepare-publish-changelog: creates a changelog file to be used in Slack
  85. argument:
  86. version: version in the x.y.z format
  87. platform: exactly one of "osx ios watchos tvos visionos"
  88. platforms: one or more of "osx ios watchos tvos visionos"
  89. environment variables:
  90. XCMODE: xcodebuild (default), xctool
  91. CONFIGURATION: Debug, Release (default), or Static
  92. LINKAGE: Static
  93. REALM_CORE_VERSION: version in x.y.z format or "current" to use local build
  94. REALM_EXTRA_BUILD_ARGUMENTS: additional arguments to pass to the build tool
  95. REALM_XCODE_VERSION: the version number of Xcode to use (e.g.: 13.3.1)
  96. REALM_XCODE_OLDEST_VERSION: the version number of oldest available Xcode to use (e.g.: 12.4)
  97. REALM_XCODE_LATEST_VERSION: the version number of latest available Xcode to use (e.g.: 13.3.1)
  98. EOF
  99. }
  100. ######################################
  101. # Xcode Helpers
  102. ######################################
  103. xcode_version_major() {
  104. echo "${REALM_XCODE_VERSION%%.*}"
  105. }
  106. xcode() {
  107. mkdir -p build/DerivedData
  108. CMD="xcodebuild -IDECustomDerivedDataLocation=build/DerivedData"
  109. echo "Building with command: $CMD $*"
  110. xcodebuild -IDECustomDerivedDataLocation=build/DerivedData "$@"
  111. }
  112. xc() {
  113. # Logs xcodebuild output in realtime
  114. : "${NSUnbufferedIO:=YES}"
  115. xcode "$@" ${REALM_EXTRA_BUILD_ARGUMENTS[@]}
  116. }
  117. xctest() {
  118. local scheme="$1"
  119. xc -scheme "$scheme" "${@:2}" build-for-testing
  120. xc -scheme "$scheme" "${@:2}" test-without-building
  121. }
  122. build_combined() {
  123. local product="$1"
  124. local platform="$2"
  125. local config="$CONFIGURATION"
  126. local config_suffix simulator_suffix destination build_args
  127. case "$platform" in
  128. osx)
  129. destination='generic/platform=macOS'
  130. config_suffix=
  131. ;;
  132. ios)
  133. destination='generic/platform=iOS'
  134. config_suffix=-iphoneos
  135. simulator_suffix=iphonesimulator
  136. ;;
  137. watchos)
  138. destination='generic/platform=watchOS'
  139. config_suffix=-watchos
  140. simulator_suffix=watchsimulator
  141. ;;
  142. tvos)
  143. destination='generic/platform=tvOS'
  144. config_suffix=-appletvos
  145. simulator_suffix=appletvsimulator
  146. ;;
  147. visionos)
  148. destination='generic/platform=visionOS'
  149. config_suffix=-xros
  150. simulator_suffix=xrsimulator
  151. ;;
  152. catalyst)
  153. destination='generic/platform=macOS,variant=Mac Catalyst'
  154. config_suffix=-maccatalyst
  155. ;;
  156. esac
  157. build_args=(-scheme "$product" -configuration "$config" build REALM_HIDE_SYMBOLS=YES)
  158. # Derive build paths
  159. local build_products_path="$DERIVED_DATA/Build/Products"
  160. local product_name="$product.framework"
  161. local os_path="$build_products_path/$config${config_suffix}/$product_name"
  162. local simulator_path="$build_products_path/$config-$simulator_suffix/$product_name"
  163. local out_path="build/$config/$platform"
  164. local xcframework_path="$out_path/$product.xcframework"
  165. # Build for each platform
  166. xc -destination "$destination" "${build_args[@]}"
  167. simulator_framework=()
  168. if [[ -n "$simulator_suffix" ]]; then
  169. xc -destination "$destination Simulator" "${build_args[@]}"
  170. simulator_framework+=(-framework "$simulator_path")
  171. fi
  172. # Create the xcframework
  173. rm -rf "$xcframework_path"
  174. xcodebuild -create-xcframework -allow-internal-distribution -output "$xcframework_path" \
  175. -framework "$os_path" "${simulator_framework[@]}"
  176. }
  177. # To be used with Github actions runner
  178. build_platform() {
  179. local product="$1"
  180. local platform="$2"
  181. local config="$CONFIGURATION"
  182. local destination build_args config_suffix
  183. case "$platform" in
  184. osx)
  185. config_suffix=
  186. destination='generic/platform=macOS'
  187. ;;
  188. ios)
  189. config_suffix=-iphoneos
  190. destination='generic/platform=iOS'
  191. ;;
  192. watchos)
  193. config_suffix=-watchos
  194. destination='generic/platform=watchOS'
  195. ;;
  196. tvos)
  197. config_suffix=-appletvos
  198. destination='generic/platform=tvOS'
  199. ;;
  200. visionos)
  201. config_suffix=-xros
  202. destination='generic/platform=visionOS'
  203. ;;
  204. catalyst)
  205. config_suffix=-maccatalyst
  206. destination='generic/platform=macOS,variant=Mac Catalyst'
  207. ;;
  208. osx)
  209. destination='generic/platform=macOS'
  210. ;;
  211. iossimulator)
  212. config_suffix=-iphonesimulator
  213. destination='generic/platform=iOS'
  214. ;;
  215. watchossimulator)
  216. config_suffix=-watchsimulator
  217. destination='generic/platform=watchOS'
  218. ;;
  219. tvossimulator)
  220. config_suffix=-appletvsimulator
  221. destination='generic/platform=tvOS'
  222. ;;
  223. visionossimulator)
  224. config_suffix=-xrsimulator
  225. destination='generic/platform=visionOS'
  226. ;;
  227. esac
  228. build_products_path="$DERIVED_DATA/Build/Products"
  229. build_path="$build_products_path/$config${config_suffix}"
  230. build_args=(-scheme "$product" -configuration "$config" build REALM_HIDE_SYMBOLS=YES)
  231. if [[ "$platform" = *"simulator" ]]; then
  232. xc -destination "$destination Simulator" "${build_args[@]}"
  233. else
  234. xc -destination "$destination" "${build_args[@]}"
  235. fi
  236. # This is only for test, and simulates how it is packaged by XCode Cloud
  237. number="$((10000 + $RANDOM % 99999))"
  238. folder_name="RealmSwift Build $number Build Products for $product on iOS"
  239. dir="$folder_name/$config${config_suffix}"
  240. mkdir -p "$dir"
  241. cp -a "$build_path/." "$dir"
  242. config_name="$(tr [A-Z] [a-z] <<< "$config")"
  243. zip -r product.zip "$dir"
  244. rm -rf "$folder_name"
  245. }
  246. create_xcframework() {
  247. local product="$1"
  248. local config="$2"
  249. local platform="$3"
  250. local out_path="$ROOT_WORKSPACE/$config/$platform/$product.xcframework"
  251. find "$ROOT_WORKSPACE" -path "*/$config*/$product.framework" \
  252. | sed 's/.*/-framework &/' \
  253. | xargs xcodebuild -create-xcframework -allow-internal-distribution -output "$out_path"
  254. }
  255. # Artifacts are zipped by the artifacts store so they're endup nested zipped, so we need to unzip this zip.
  256. unzip_artifact() {
  257. initial_path="$1"
  258. file_name=${initial_path%.*}
  259. unzip "$file_name.zip" -d "$file_name"
  260. rm "$file_name.zip"
  261. mv "$file_name/$file_name.zip" "$file_name.zip"
  262. rm -rf "$file_name"
  263. }
  264. clean_retrieve() {
  265. mkdir -p "$2"
  266. rm -rf "$2/$3"
  267. cp -R "$1" "$2"
  268. }
  269. plist_get() {
  270. /usr/libexec/PlistBuddy -c "Print :$2" "$1" 2> /dev/null
  271. }
  272. ######################################
  273. # Device Test Helper
  274. ######################################
  275. test_devices() {
  276. local serial_numbers=()
  277. local awk_script="
  278. /^ +Vendor ID: / { is_apple = 0; }
  279. /^ +Vendor ID: 0x05[aA][cC] / { is_apple = 1; }
  280. /^ +Serial Number: / {
  281. if (is_apple) {
  282. match(\$0, /^ +Serial Number: /);
  283. print substr(\$0, RLENGTH + 1);
  284. }
  285. }
  286. "
  287. local serial_numbers_text=$(/usr/sbin/system_profiler SPUSBDataType | /usr/bin/awk "$awk_script")
  288. while read -r number; do
  289. if [[ "$number" != "" ]]; then
  290. serial_numbers+=("$number")
  291. fi
  292. done <<< "$serial_numbers_text"
  293. if [[ ${#serial_numbers[@]} == 0 ]]; then
  294. echo "At least one iOS/tvOS device must be connected to this computer to run device tests"
  295. if [ -z "${JENKINS_HOME}" ]; then
  296. # Don't fail if running locally and there's no device
  297. exit 0
  298. fi
  299. exit 1
  300. fi
  301. local sdk="$1"
  302. local scheme="$2"
  303. local configuration="$3"
  304. local failed=0
  305. for device in "${serial_numbers[@]}"; do
  306. xc -scheme "$scheme" -configuration "$configuration" -destination "id=$device" -sdk "$sdk" test || failed=1
  307. done
  308. return $failed
  309. }
  310. ######################################
  311. # Docs
  312. ######################################
  313. build_docs() {
  314. local language="$1"
  315. local version=$(sh build.sh get-version)
  316. local xcodebuild_arguments="--objc,Realm/Realm.h,--,-x,objective-c,-isysroot,$(xcrun --show-sdk-path),-I,$(pwd)"
  317. local module="Realm"
  318. local objc="--objc"
  319. if [[ "$language" == "swift" ]]; then
  320. xcodebuild_arguments="-scheme,RealmSwift"
  321. module="RealmSwift"
  322. objc=""
  323. fi
  324. echo ">>> RUN JAZZY"
  325. jazzy \
  326. "${objc}" \
  327. --clean \
  328. --author Realm \
  329. --author_url https://docs.mongodb.com/realm-sdks \
  330. --github_url https://github.com/realm/realm-swift \
  331. --github-file-prefix "https://github.com/realm/realm-swift/tree/v${version}" \
  332. --module-version "${version}" \
  333. --xcodebuild-arguments "${xcodebuild_arguments}" \
  334. --module "${module}" \
  335. --root-url "https://docs.mongodb.com/realm-sdks/${language}/${version}/" \
  336. --output "docs/${language}_output" \
  337. --head "$(cat docs/custom_head.html)" \
  338. --exclude 'RealmSwift/Impl/*'
  339. }
  340. ######################################
  341. # Input Validation
  342. ######################################
  343. if [ "$#" -eq 0 ] || [ "$#" -gt 3 ]; then
  344. usage
  345. exit 1
  346. fi
  347. ######################################
  348. # Variables
  349. ######################################
  350. COMMAND="$1"
  351. LINKAGE="dynamic"
  352. # Use Debug config if command ends with -debug, otherwise default to Release
  353. case "$COMMAND" in
  354. *-debug)
  355. COMMAND="${COMMAND%-debug}"
  356. CONFIGURATION="Debug"
  357. ;;
  358. *-static)
  359. COMMAND="${COMMAND%-static}"
  360. LINKAGE="static"
  361. CONFIGURATION="Static"
  362. ;;
  363. esac
  364. export CONFIGURATION=${CONFIGURATION:-Release}
  365. # Pre-choose Xcode version for those operations that do not override it
  366. REALM_XCODE_VERSION=${xcode_version:-$REALM_XCODE_VERSION}
  367. source "${source_root}/scripts/swift-version.sh"
  368. set_xcode_version
  369. ######################################
  370. # Commands
  371. ######################################
  372. case "$COMMAND" in
  373. ######################################
  374. # Clean
  375. ######################################
  376. "clean")
  377. find . -type d -name build -exec rm -r "{}" +
  378. exit 0
  379. ;;
  380. ######################################
  381. # Dependencies
  382. ######################################
  383. "download-core")
  384. sh scripts/download-core.sh
  385. exit 0
  386. ;;
  387. "setup-baas")
  388. ruby Realm/ObjectServerTests/setup_baas.rb
  389. exit 0
  390. ;;
  391. ######################################
  392. # Building
  393. ######################################
  394. "build")
  395. sh build.sh xcframework
  396. exit 0
  397. ;;
  398. "ios")
  399. build_combined Realm ios
  400. exit 0
  401. ;;
  402. "ios-swift")
  403. build_combined Realm ios
  404. build_combined RealmSwift ios
  405. exit 0
  406. ;;
  407. "watchos")
  408. build_combined Realm watchos
  409. exit 0
  410. ;;
  411. "watchos-swift")
  412. build_combined Realm watchos
  413. build_combined RealmSwift watchos
  414. exit 0
  415. ;;
  416. "tvos")
  417. build_combined Realm tvos
  418. exit 0
  419. ;;
  420. "tvos-swift")
  421. build_combined Realm tvos
  422. build_combined RealmSwift tvos
  423. exit 0
  424. ;;
  425. "osx")
  426. build_combined Realm osx
  427. exit 0
  428. ;;
  429. "osx-swift")
  430. build_combined Realm osx
  431. build_combined RealmSwift osx
  432. exit 0
  433. ;;
  434. "catalyst")
  435. build_combined Realm catalyst
  436. ;;
  437. "catalyst-swift")
  438. build_combined Realm catalyst
  439. build_combined RealmSwift catalyst
  440. ;;
  441. "visionos")
  442. build_combined Realm visionos
  443. ;;
  444. "visionos-swift")
  445. build_combined Realm visionos
  446. build_combined RealmSwift visionos
  447. ;;
  448. "xcframework")
  449. # Build all of the requested frameworks
  450. shift
  451. if (( $(xcode_version_major) < 15 )); then
  452. PLATFORMS="${*:-osx ios watchos tvos catalyst}"
  453. else
  454. PLATFORMS="${*:-osx ios watchos tvos catalyst visionos}"
  455. fi
  456. for platform in $PLATFORMS; do
  457. sh build.sh "$platform-swift"
  458. done
  459. # Assemble them into xcframeworks
  460. rm -rf "$DERIVED_DATA/Build/Products"*.xcframework
  461. find "$DERIVED_DATA/Build/Products" -name 'Realm.framework' \
  462. | sed 's/.*/-framework &/' \
  463. | xargs xcodebuild -create-xcframework -allow-internal-distribution -output "build/$CONFIGURATION/Realm.xcframework"
  464. find "$DERIVED_DATA/Build/Products" -name 'RealmSwift.framework' \
  465. | sed 's/.*/-framework &/' \
  466. | xargs xcodebuild -create-xcframework -allow-internal-distribution -output "build/$CONFIGURATION/RealmSwift.xcframework"
  467. # Because we have a module named Realm and a type named Realm we need to manually resolve the naming
  468. # collisions that are happening. These collisions create a red herring which tells the user the xcframework
  469. # was compiled with an older Swift version and is not compatible with the current compiler.
  470. find "build/$CONFIGURATION/RealmSwift.xcframework" -name "*.swiftinterface" \
  471. -exec sed -i '' 's/Realm\.//g' {} \; \
  472. -exec sed -i '' 's/import Private/import Realm.Private\nimport Realm.Swift/g' {} \; \
  473. -exec sed -i '' 's/RealmSwift.Configuration/RealmSwift.Realm.Configuration/g' {} \; \
  474. -exec sed -i '' 's/extension Configuration/extension Realm.Configuration/g' {} \; \
  475. -exec sed -i '' 's/RealmSwift.Error[[:>:]]/RealmSwift.Realm.Error/g' {} \; \
  476. -exec sed -i '' 's/extension Error/extension Realm.Error/g' {} \; \
  477. -exec sed -i '' 's/RealmSwift.AsyncOpenTask/RealmSwift.Realm.AsyncOpenTask/g' {} \; \
  478. -exec sed -i '' 's/RealmSwift.UpdatePolicy/RealmSwift.Realm.UpdatePolicy/g' {} \; \
  479. -exec sed -i '' 's/RealmSwift.Notification[[:>:]]/RealmSwift.Realm.Notification/g' {} \; \
  480. -exec sed -i '' 's/RealmSwift.OpenBehavior/RealmSwift.Realm.OpenBehavior/g' {} \; \
  481. -exec sed -i '' 's/τ_1_0/V/g' {} \; # Generics will use τ_1_0 which needs to be changed to the correct type name.
  482. exit 0
  483. ;;
  484. ######################################
  485. # Analysis
  486. ######################################
  487. "analyze-osx")
  488. xc -scheme Realm -configuration "$CONFIGURATION" analyze
  489. exit 0
  490. ;;
  491. ######################################
  492. # Testing
  493. ######################################
  494. "test")
  495. set +e # Run both sets of tests even if the first fails
  496. failed=0
  497. sh build.sh test-ios || failed=1
  498. sh build.sh test-ios-swift || failed=1
  499. sh build.sh test-ios-devices || failed=1
  500. sh build.sh test-tvos-devices || failed=1
  501. sh build.sh test-osx || failed=1
  502. sh build.sh test-osx-swift || failed=1
  503. sh build.sh test-catalyst || failed=1
  504. sh build.sh test-catalyst-swift || failed=1
  505. exit $failed
  506. ;;
  507. "test-all")
  508. set +e
  509. failed=0
  510. sh build.sh test || failed=1
  511. sh build.sh test-debug || failed=1
  512. exit $failed
  513. ;;
  514. "test-ios")
  515. xctest Realm -configuration "$CONFIGURATION" -sdk iphonesimulator -destination 'name=iPhone 14'
  516. exit 0
  517. ;;
  518. "test-ios-swift")
  519. xctest RealmSwift -configuration "$CONFIGURATION" -sdk iphonesimulator -destination 'name=iPhone 14'
  520. exit 0
  521. ;;
  522. "test-ios-devices")
  523. failed=0
  524. trap "failed=1" ERR
  525. sh build.sh test-ios-devices-objc
  526. sh build.sh test-ios-devices-swift
  527. exit $failed
  528. ;;
  529. "test-ios-devices-objc")
  530. test_devices iphoneos "Realm" "$CONFIGURATION"
  531. exit $?
  532. ;;
  533. "test-ios-devices-swift")
  534. test_devices iphoneos "RealmSwift" "$CONFIGURATION"
  535. exit $?
  536. ;;
  537. "test-tvos")
  538. destination="Apple TV"
  539. xctest Realm -configuration "$CONFIGURATION" -sdk appletvsimulator -destination "name=$destination"
  540. exit $?
  541. ;;
  542. "test-tvos-swift")
  543. destination="Apple TV"
  544. xctest RealmSwift -configuration "$CONFIGURATION" -sdk appletvsimulator -destination "name=$destination"
  545. exit $?
  546. ;;
  547. "test-tvos-devices")
  548. test_devices appletvos TestHost "$CONFIGURATION"
  549. ;;
  550. "test-osx")
  551. xctest Realm -configuration "$CONFIGURATION" -destination "platform=macOS,arch=$(uname -m)"
  552. exit 0
  553. ;;
  554. "test-osx-swift")
  555. xctest RealmSwift -configuration "$CONFIGURATION" -destination "platform=macOS,arch=$(uname -m)"
  556. exit 0
  557. ;;
  558. "test-objectserver-osx")
  559. xctest 'Object Server Tests' -configuration "$CONFIGURATION" -sdk macosx -destination "platform=macOS,arch=$(uname -m)"
  560. exit 0
  561. ;;
  562. test-swiftpm*)
  563. SANITIZER=$(echo "$COMMAND" | cut -d - -f 3)
  564. # FIXME: throwing an exception from a property getter corrupts Swift's
  565. # runtime exclusivity checking state. Unfortunately, this is something
  566. # we do a lot in tests.
  567. SWIFT_TEST_FLAGS=(-Xcc -g0 -Xswiftc -enforce-exclusivity=none)
  568. if [ -n "$SANITIZER" ]; then
  569. SWIFT_TEST_FLAGS+=(--sanitize "$SANITIZER")
  570. export ASAN_OPTIONS='check_initialization_order=true:detect_stack_use_after_return=true'
  571. fi
  572. xcrun swift package resolve
  573. xcrun swift test --configuration "$(echo "$CONFIGURATION" | tr "[:upper:]" "[:lower:]")" "${SWIFT_TEST_FLAGS[@]}"
  574. exit 0
  575. ;;
  576. "test-ios-swiftui")
  577. xctest 'SwiftUITestHost' -configuration "$CONFIGURATION" -sdk iphonesimulator -destination 'name=iPhone 11'
  578. exit 0
  579. ;;
  580. "test-catalyst")
  581. xctest Realm -configuration "$CONFIGURATION" -destination 'platform=macOS,variant=Mac Catalyst' CODE_SIGN_IDENTITY=''
  582. exit 0
  583. ;;
  584. "test-catalyst-swift")
  585. xctest RealmSwift -configuration "$CONFIGURATION" -destination 'platform=macOS,variant=Mac Catalyst' CODE_SIGN_IDENTITY=''
  586. exit 0
  587. ;;
  588. "test-swiftuiserver-osx")
  589. xctest 'SwiftUISyncTestHost' -configuration "$CONFIGURATION" -sdk macosx -destination 'platform=macOS'
  590. exit 0
  591. ;;
  592. ######################################
  593. # Full verification
  594. ######################################
  595. "verify")
  596. sh build.sh verify-cocoapods
  597. sh build.sh verify-docs
  598. sh build.sh verify-spm-ios
  599. sh build.sh verify-objectserver-osx
  600. sh build.sh verify-swiftlint
  601. sh build.sh verify-swiftpm
  602. sh build.sh verify-watchos
  603. sh buils.sh verify-xcframework
  604. sh build.sh verify-swiftuiserver-osx
  605. sh build.sh verify-osx
  606. sh build.sh verify-osx-debug
  607. sh build.sh verify-osx-swift
  608. sh build.sh verify-osx-swift-debug
  609. sh build.sh verify-ios-static
  610. sh build.sh verify-ios-static-debug
  611. sh build.sh verify-ios-dynamic
  612. sh build.sh verify-ios-dynamic-debug
  613. sh build.sh verify-ios-swift
  614. sh build.sh verify-ios-swift-debug
  615. sh build.sh verify-ios-device-objc
  616. sh build.sh verify-ios-device-swift
  617. sh build.sh verify-tvos
  618. sh build.sh verify-tvos-debug
  619. sh build.sh verify-tvos-device
  620. sh build.sh verify-catalyst
  621. sh build.sh verify-catalyst-swift
  622. sh build.sh verify-ios-swiftui
  623. ;;
  624. "verify-cocoapods")
  625. export REALM_TEST_BRANCH="$sha"
  626. if [[ -d .git ]]; then
  627. # Verify the current branch, unless one was already specified in the sha environment variable.
  628. if [[ -z $sha ]]; then
  629. export REALM_TEST_BRANCH=$(git rev-parse --abbrev-ref HEAD)
  630. fi
  631. if [[ $(git log -1 '@{push}..') != "" ]] || ! git diff-index --quiet HEAD; then
  632. echo "WARNING: verify-cocoapods will test the latest revision of $sha found on GitHub."
  633. echo " Any unpushed local changes will not be tested."
  634. echo ""
  635. sleep 1
  636. fi
  637. fi
  638. cd examples/installation
  639. ./build.rb ios cocoapods static
  640. ./build.rb ios cocoapods dynamic
  641. ./build.rb osx cocoapods
  642. ./build.rb tvos cocoapods
  643. ./build.rb watchos cocoapods
  644. ./build.rb catalyst cocoapods
  645. ;;
  646. verify-cocoapods-*)
  647. PLATFORM=$(echo "$COMMAND" | cut -d - -f 3)
  648. cd examples/installation
  649. REALM_TEST_BRANCH="$sha" ./build.rb "$PLATFORM" cocoapods "$LINKAGE"
  650. ;;
  651. "verify-docs")
  652. sh build.sh docs
  653. for lang in swift objc; do
  654. undocumented="docs/${lang}_output/undocumented.json"
  655. if ruby -rjson -e "j = JSON.parse(File.read('docs/${lang}_output/undocumented.json')); exit j['warnings'].length != 0"; then
  656. echo "Undocumented Realm $lang declarations:"
  657. cat "$undocumented"
  658. exit 1
  659. fi
  660. done
  661. exit 0
  662. ;;
  663. "verify-spm")
  664. export REALM_TEST_BRANCH="$sha"
  665. if [[ -d .git ]]; then
  666. # Verify the current branch, unless one was already specified in the sha environment variable.
  667. if [[ -z $sha ]]; then
  668. export REALM_TEST_BRANCH=$(git rev-parse --abbrev-ref HEAD)
  669. fi
  670. if [[ $(git log -1 '@{push}..') != "" ]] || ! git diff-index --quiet HEAD; then
  671. echo "WARNING: verify-spm will test the latest revision of $sha found on GitHub."
  672. echo " Any unpushed local changes will not be tested."
  673. echo ""
  674. sleep 1
  675. fi
  676. fi
  677. cd examples/installation
  678. ./build.rb ios spm static
  679. ./build.rb ios spm dynamic
  680. ./build.rb osx spm
  681. ./build.rb watchos spm
  682. ./build.rb tvos spm
  683. ./build.rb catalyst spm
  684. exit 0
  685. ;;
  686. verify-spm-*)
  687. PLATFORM=$(echo "$COMMAND" | cut -d - -f 3)
  688. cd examples/installation
  689. REALM_TEST_BRANCH="$sha" ./build.rb "$PLATFORM" spm "$LINKAGE"
  690. exit 0
  691. ;;
  692. "verify-objectserver-osx")
  693. REALM_TEST_BRANCH="$sha" sh build.sh test-objectserver-osx
  694. exit 0
  695. ;;
  696. "verify-swiftlint")
  697. swiftlint lint --strict
  698. exit 0
  699. ;;
  700. verify-swiftpm*)
  701. sh build.sh "test-$(echo "$COMMAND" | cut -d - -f 2-)"
  702. exit 0
  703. ;;
  704. "verify-watchos")
  705. sh build.sh watchos-swift
  706. exit 0
  707. ;;
  708. "verify-xcframework")
  709. sh build.sh xcframework osx
  710. exit 0
  711. ;;
  712. "verify-osx-encryption")
  713. REALM_ENCRYPT_ALL=YES sh build.sh test-osx
  714. exit 0
  715. ;;
  716. "verify-osx")
  717. REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS -workspace examples/osx/objc/RealmExamples.xcworkspace" \
  718. sh build.sh test-osx
  719. sh build.sh examples-osx
  720. (
  721. DERIVED_EXAMPLE_DATA=${DERIVED_DATA:-examples/osx/objc/build/DerivedData/RealmExamples}
  722. cd $DERIVED_EXAMPLE_DATA/Build/Products/$CONFIGURATION
  723. DYLD_FRAMEWORK_PATH=. ./JSONImport >/dev/null
  724. )
  725. exit 0
  726. ;;
  727. "verify-osx-swift-evolution")
  728. export REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS REALM_BUILD_LIBRARY_FOR_DISTRIBUTION=YES"
  729. sh build.sh test-osx-swift
  730. exit 0
  731. ;;
  732. "verify-ios")
  733. REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS -workspace examples/ios/objc/RealmExamples.xcworkspace" \
  734. sh build.sh test-ios
  735. sh build.sh examples-ios
  736. ;;
  737. "verify-ios-swift")
  738. REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS -workspace examples/ios/swift/RealmExamples.xcworkspace" \
  739. sh build.sh test-ios-swift
  740. sh build.sh examples-ios-swift
  741. ;;
  742. "verify-ios-swift-evolution")
  743. export REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS REALM_BUILD_LIBRARY_FOR_DISTRIBUTION=YES"
  744. sh build.sh test-ios-swift
  745. exit 0
  746. ;;
  747. "verify-tvos")
  748. REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS -workspace examples/tvos/objc/RealmExamples.xcworkspace" \
  749. sh build.sh test-tvos
  750. sh build.sh examples-tvos
  751. exit 0
  752. ;;
  753. "verify-tvos-swift")
  754. REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS -workspace examples/tvos/swift/RealmExamples.xcworkspace" \
  755. sh build.sh test-tvos-swift
  756. sh build.sh examples-tvos-swift
  757. exit 0
  758. ;;
  759. "verify-tvos-swift-evolution")
  760. export REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS REALM_BUILD_LIBRARY_FOR_DISTRIBUTION=YES"
  761. sh build.sh test-tvos-swift
  762. exit 0
  763. ;;
  764. "verify-xcframework-evolution-mode")
  765. export REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS REALM_BUILD_LIBRARY_FOR_DISTRIBUTION=YES"
  766. unset REALM_SWIFT_VERSION
  767. # Build with the oldest supported Xcode version
  768. REALM_XCODE_VERSION=$REALM_XCODE_OLDEST_VERSION sh build.sh xcframework osx
  769. # Try to import the built framework using the newest supported version
  770. cd examples/installation
  771. REALM_XCODE_VERSION=$REALM_XCODE_LATEST_VERSION ./build.rb osx xcframework
  772. exit 0
  773. ;;
  774. verify-*)
  775. sh build.sh "test-$(echo "$COMMAND" | cut -d - -f 2-)"
  776. exit 0
  777. ;;
  778. ######################################
  779. # Docs
  780. ######################################
  781. "docs")
  782. build_docs objc
  783. build_docs swift
  784. exit 0
  785. ;;
  786. ######################################
  787. # Examples
  788. ######################################
  789. "examples")
  790. sh build.sh clean
  791. sh build.sh examples-ios
  792. sh build.sh examples-ios-swift
  793. sh build.sh examples-osx
  794. sh build.sh examples-tvos
  795. sh build.sh examples-tvos-swift
  796. exit 0
  797. ;;
  798. "examples-ios")
  799. workspace="examples/ios/objc/RealmExamples.xcworkspace"
  800. examples="Simple TableView Migration Backlink GroupedTableView Encryption Draw"
  801. versions="0 1 2 3 4 5"
  802. for example in $examples; do
  803. if [ "$example" = "Migration" ]; then
  804. # The migration example needs to be built for each schema version to ensure each compiles.
  805. for version in $versions; do
  806. xc -workspace "$workspace" -scheme "$example" -configuration "$CONFIGURATION" -sdk iphonesimulator "${CODESIGN_PARAMS[@]}" GCC_PREPROCESSOR_DEFINITIONS="\$(GCC_PREPROCESSOR_DEFINITIONS) SCHEMA_VERSION_$version"
  807. done
  808. else
  809. xc -workspace "$workspace" -scheme "$example" -configuration "$CONFIGURATION" -sdk iphonesimulator "${CODESIGN_PARAMS[@]}"
  810. fi
  811. done
  812. if [ -n "$CI" ]; then
  813. xc -workspace "$workspace" -scheme Extension -configuration "$CONFIGURATION" -sdk iphonesimulator "${CODESIGN_PARAMS[@]}"
  814. fi
  815. exit 0
  816. ;;
  817. "examples-ios-swift")
  818. workspace="examples/ios/swift/RealmExamples.xcworkspace"
  819. if [[ ! -d "$workspace" ]]; then
  820. workspace="${workspace/swift/swift-$REALM_XCODE_VERSION}"
  821. fi
  822. examples="Simple TableView Migration Backlink GroupedTableView Encryption AppClip AppClipParent"
  823. versions="0 1 2 3 4 5"
  824. for example in $examples; do
  825. if [ "$example" = "Migration" ]; then
  826. # The migration example needs to be built for each schema version to ensure each compiles.
  827. for version in $versions; do
  828. xc -workspace "$workspace" -scheme "$example" -configuration "$CONFIGURATION" -sdk iphonesimulator "${CODESIGN_PARAMS[@]}" OTHER_SWIFT_FLAGS="\$(OTHER_SWIFT_FLAGS) -DSCHEMA_VERSION_$version"
  829. done
  830. else
  831. xc -workspace "$workspace" -scheme "$example" -configuration "$CONFIGURATION" -sdk iphonesimulator "${CODESIGN_PARAMS[@]}"
  832. fi
  833. done
  834. exit 0
  835. ;;
  836. "examples-osx")
  837. workspace="examples/osx/objc/RealmExamples.xcworkspace"
  838. xc -workspace "$workspace" \
  839. -scheme JSONImport -configuration "${CONFIGURATION}" \
  840. -destination "platform=macOS,arch=$(uname -m)" \
  841. build "${CODESIGN_PARAMS[@]}"
  842. ;;
  843. "examples-tvos")
  844. workspace="examples/tvos/objc/RealmExamples.xcworkspace"
  845. examples="DownloadCache PreloadedData"
  846. for example in $examples; do
  847. xc -workspace "$workspace" -scheme "$example" -configuration "$CONFIGURATION" -sdk appletvsimulator "${CODESIGN_PARAMS[@]}"
  848. done
  849. exit 0
  850. ;;
  851. "examples-tvos-swift")
  852. workspace="examples/tvos/swift/RealmExamples.xcworkspace"
  853. if [[ ! -d "$workspace" ]]; then
  854. workspace="${workspace/swift/swift-$REALM_XCODE_VERSION}"
  855. fi
  856. examples="DownloadCache PreloadedData"
  857. for example in $examples; do
  858. xc -workspace "$workspace" -scheme "$example" -configuration "$CONFIGURATION" -sdk appletvsimulator "${CODESIGN_PARAMS[@]}"
  859. done
  860. exit 0
  861. ;;
  862. ######################################
  863. # Versioning
  864. ######################################
  865. "get-version")
  866. plist_get 'Realm/Realm-Info.plist' 'CFBundleShortVersionString'
  867. exit 0
  868. ;;
  869. "get-ioplatformuuid")
  870. ioreg -d2 -c IOPlatformExpertDevice | awk -F\" '/IOPlatformUUID/{print $(NF-1)}'
  871. exit 0
  872. ;;
  873. "set-version")
  874. realm_version="$2"
  875. version_files="Realm/Realm-Info.plist"
  876. if [ -z "$realm_version" ]; then
  877. echo "You must specify a version."
  878. exit 1
  879. fi
  880. # The bundle version can contain only three groups of digits separated by periods,
  881. # so strip off any -beta.x tag from the end of the version string.
  882. bundle_version=$(echo "$realm_version" | cut -d - -f 1)
  883. for version_file in $version_files; do
  884. PlistBuddy -c "Set :CFBundleVersion $bundle_version" "$version_file"
  885. PlistBuddy -c "Set :CFBundleShortVersionString $realm_version" "$version_file"
  886. done
  887. sed -i '' "s/^VERSION=.*/VERSION=$realm_version/" dependencies.list
  888. sed -i '' "s/^let cocoaVersion =.*/let cocoaVersion = Version(\"$realm_version\")/" Package.swift
  889. sed -i '' "s/x.y.z Release notes (yyyy-MM-dd)/$realm_version Release notes ($(date '+%Y-%m-%d'))/" CHANGELOG.md
  890. exit 0
  891. ;;
  892. "set-core-version")
  893. new_version="$2"
  894. old_version="$(sed -n 's/^REALM_CORE_VERSION=\(.*\)$/\1/p' "${source_root}/dependencies.list")"
  895. sed -i '' "s/^REALM_CORE_VERSION=.*/REALM_CORE_VERSION=$new_version/" dependencies.list
  896. sed -i '' "s/^let coreVersion =.*/let coreVersion = Version(\"$new_version\")/" Package.swift
  897. sed -i '' "s/Upgraded realm-core from ? to ?/Upgraded realm-core from $old_version to $new_version/" CHANGELOG.md
  898. exit 0
  899. ;;
  900. ######################################
  901. # Continuous Integration PR
  902. ######################################
  903. "ci-pr")
  904. echo "Building with Xcode Version $(xcodebuild -version)"
  905. export sha="$BRANCH"
  906. export REALM_EXTRA_BUILD_ARGUMENTS='GCC_GENERATE_DEBUGGING_SYMBOLS=NO -allowProvisioningUpdates'
  907. target=$(echo "$CI_WORKFLOW" | cut -f1 -d_)
  908. sh build.sh "verify-$target"
  909. ;;
  910. ######################################
  911. # Release packaging
  912. ######################################
  913. "release-package-examples")
  914. ./scripts/package_examples.rb
  915. zip --symlinks -r realm-examples.zip examples -x "examples/installation/*"
  916. ;;
  917. "release-package-docs")
  918. sh build.sh docs
  919. zip -r docs/realm-docs.zip docs/objc_output docs/swift_output
  920. ;;
  921. release-create-xcframework-*)
  922. platform="$2"
  923. xcode_version=$(echo "$COMMAND" | cut -d- -f4)
  924. # Artifacts are nested zips so need to be extracted twice
  925. find . -name 'build-*.zip' -exec unzip {} \;
  926. find . -name 'xcode-cloud-build-*.zip' -exec unzip {} \;
  927. # Spaces with xargs are complicated so get rid of them
  928. for dir in "RealmSwift Build "*; do
  929. mv "$dir" build-$(echo "$dir" | cut -d' ' -f3)
  930. done
  931. create_xcframework Realm Release "$platform"
  932. create_xcframework RealmSwift Release "$platform"
  933. if [ "$platform" = "ios" ]; then
  934. create_xcframework Realm Static "$platform"
  935. else
  936. mkdir -p "Static/$platform"
  937. fi
  938. zip --symlinks -r "realm-$platform-$xcode_version.zip" "Release/$platform" "Static/$platform"
  939. exit 0
  940. ;;
  941. "release-package")
  942. version="$(sed -n 's/^VERSION=\(.*\)$/\1/p' "${source_root}/dependencies.list")"
  943. find . -name 'realm-*-1*' -maxdepth 1 \
  944. | sed 's@./realm-[a-z]*-\(.*\)@\1@' \
  945. | sort -u --version-sort \
  946. | xargs ./scripts/create-release-package.rb "${ROOT_WORKSPACE}/pkg" "${version}"
  947. ;;
  948. "release-test-examples")
  949. VERSION="$(sed -n 's/^VERSION=\(.*\)$/\1/p' "${source_root}/dependencies.list")"
  950. filename="realm-swift-${VERSION}"
  951. unzip "${filename}"
  952. cp "$0" "${filename}"
  953. cp -r "${source_root}/scripts" "${filename}"
  954. cp "dependencies.list" "${filename}"
  955. cd "${filename}"
  956. sh build.sh examples-ios
  957. sh build.sh examples-tvos
  958. sh build.sh examples-osx
  959. sh build.sh examples-ios-swift
  960. sh build.sh examples-tvos-swift
  961. cd ..
  962. rm -rf "${filename}"
  963. exit 0
  964. ;;
  965. ######################################
  966. # Release tests
  967. ######################################
  968. # Should select xcode version `xcode-select` first.
  969. # Pass xcode version as argument
  970. # This simulates what is done in XCode Cloud
  971. "test-create-frameworks")
  972. xcode_version="$2"
  973. targets="Realm RealmSwift"
  974. platforms=("ios" "iossimulator" "osx" "tvos" "tvossimulator" "watchos" "watchossimulator" "catalyst")
  975. if [ "$xcode_version" == "15.2" ]; then
  976. platforms+=("visionos" "visionossimulator")
  977. fi
  978. for platform in "${platforms[@]}"; do
  979. for target in $targets; do
  980. echo "Building $platform and $target release"
  981. ./build.sh "release-package-$platform-$xcode_version-$target-release"
  982. ./build.sh "release-build_$platform-$xcode_version-$target-release"
  983. # Only generates Realm framework for Static configuration and ios platform
  984. if [[ "$platform" == "ios" || "$platform" == "iossimulator" ]] && [[ "$target" == "Realm" ]]; then
  985. echo "Building $platform and $target static"
  986. ./build.sh "release-package-$platform-$xcode_version-$target-static"
  987. ./build.sh "release-package-build_$platform-$xcode_version-$target-static"
  988. fi
  989. done
  990. done
  991. ;;
  992. "test-build-product-workflow-xcode-cloud")
  993. issuer_id=""
  994. key_id=""
  995. pk_path=""
  996. token=$(ruby ./scripts/xcode_cloud_helper.rb --issuer-id $issuer_id --key-id $key_id --pk-path $pk_path get-token)
  997. echo "Authentication token -> $token"
  998. # Test parameters
  999. platform="ios"
  1000. target="RealmSwift"
  1001. xcode_version="15.2"
  1002. configuration="release"
  1003. workflow_id=$(ruby ./scripts/xcode_cloud_helper.rb create-workflow release-package-build $platform $xcode_version $target $configuration -t $token)
  1004. echo "Created workflow -> $workflow_id"
  1005. build_run_id=$(ruby ./scripts/xcode_cloud_helper.rb build-workflow $workflow_id dp/new_migration_branch -t $token)
  1006. echo "Build Run -> $build_run_id"
  1007. while [ "$status" != 'COMPLETE' ]
  1008. do
  1009. token=$(ruby ./scripts/xcode_cloud_helper.rb --issuer-id $issuer_id --key-id $key_id --pk-path $pk_path get-token)
  1010. status=$(ruby ./scripts/xcode_cloud_helper.rb get-build-status $build_run_id -t $token)
  1011. echo "Status $status" | ts
  1012. sleep 20
  1013. done
  1014. completion_status=$(ruby ./scripts/xcode_cloud_helper.rb get-build-result $build_run_id -t $token)
  1015. echo "Completion Status $completion_status" | ts
  1016. if [ "$completion_status" != 'SUCCEEDED' ]; then
  1017. echo "XCode build failed"
  1018. ruby ./scripts/xcode_cloud_helper.rb print-build-logs $build_run_id -t $token
  1019. exit 1
  1020. fi
  1021. ruby ./scripts/xcode_cloud_helper.rb print-build-logs $build_run_id -t $token
  1022. ruby ./scripts/xcode_cloud_helper.rb download-artifact $build_run_id -t $token
  1023. ruby ./scripts/xcode_cloud_helper.rb delete-workflow $workflow_id -t $token
  1024. ;;
  1025. # Pass xcode version as argument
  1026. # For this to work, product builds should be located in the root of the project
  1027. "test-create-platform-xcframeworks")
  1028. xcode_version="$2"
  1029. platforms=("ios" "osx" "tvos" "watchos" "catalyst")
  1030. if [ "$xcode_version" == "15.1" ]; then
  1031. platforms+=("visionos")
  1032. fi
  1033. for platform in "${platforms[@]}"; do
  1034. ./build.sh release-create-xcframework_$xcode_version $platform
  1035. rm -rf "$ROOT_WORKSPACE/Release"
  1036. rm -rf "$ROOT_WORKSPACE/Static"
  1037. done
  1038. ;;
  1039. "test-package-examples")
  1040. VERSION="$(sed -n 's/^VERSION=\(.*\)$/\1/p' "${source_root}/dependencies.list")"
  1041. dir="realm-swift-${VERSION}"
  1042. # Unzip it
  1043. unzip "${dir}.zip"
  1044. # Copy the build.sh file into the downloaded directory
  1045. cp "$0" "${dir}"
  1046. # Copy the scripts into the downloaded directory
  1047. cp -r "${ROOT_WORKSPACE}/scripts" "${dir}"
  1048. # Copy dependencies.list
  1049. cp -r "${ROOT_WORKSPACE}/dependencies.list" "${dir}"
  1050. cd "${dir}"
  1051. # Test Examples
  1052. sh build.sh examples-ios
  1053. sh build.sh examples-tvos
  1054. sh build.sh examples-osx
  1055. sh build.sh examples-ios-swift
  1056. sh build.sh examples-tvos-swift
  1057. ;;
  1058. # This is used for test or if we want to use Github Actions to build each framework
  1059. release-package-build_*)
  1060. filename="Configuration/Release.xcconfig"
  1061. sed -i '' "s/REALM_HIDE_SYMBOLS = NO;/REALM_HIDE_SYMBOLS = YES;/" "$filename"
  1062. # Remove the identifier of the command, so we can obtain the parameters from the command
  1063. build_command=${COMMAND#"release-package-build_"}
  1064. parameters=(${build_command//-/ })
  1065. platform=${parameters[0]}
  1066. target=${parameters[1]}
  1067. build_platform "$target" "$platform"
  1068. exit 0
  1069. ;;
  1070. ######################################
  1071. # Publish
  1072. ######################################
  1073. "publish-github")
  1074. sha="$2"
  1075. VERSION="$(sed -n 's/^VERSION=\(.*\)$/\1/p' "${source_root}/dependencies.list")"
  1076. ./scripts/github_release.rb download-artifacts release-package "${sha}"
  1077. unzip release-package.zip -d release-package
  1078. ./scripts/github_release.rb create-release "$VERSION"
  1079. exit 0
  1080. ;;
  1081. "publish-docs")
  1082. sha="$2"
  1083. ./scripts/github_release.rb download-artifacts realm-docs "${sha}"
  1084. unzip_artifact realm-docs.zip
  1085. unzip realm-docs.zip
  1086. VERSION="$(sed -n 's/^VERSION=\(.*\)$/\1/p' "${source_root}/dependencies.list")"
  1087. PRERELEASE_REGEX='alpha|beta|rc|preview'
  1088. if [[ $VERSION =~ $PRERELEASE_REGEX ]]; then
  1089. echo "Pre-release version"
  1090. exit 0
  1091. fi
  1092. s3cmd put --no-mime-magic --guess-mime-type --recursive --acl-public docs/swift_output/ s3://realm-sdks/docs/realm-sdks/swift/${VERSION}/
  1093. s3cmd put --no-mime-magic --guess-mime-type --recursive --acl-public docs/swift_output/ s3://realm-sdks/docs/realm-sdks/swift/latest/
  1094. s3cmd put --no-mime-magic --guess-mime-type --recursive --acl-public docs/objc_output/ s3://realm-sdks/docs/realm-sdks/objc/${VERSION}/
  1095. s3cmd put --no-mime-magic --guess-mime-type --recursive --acl-public docs/objc_output/ s3://realm-sdks/docs/realm-sdks/objc/latest/
  1096. ;;
  1097. "publish-update-checker")
  1098. VERSION="$(sed -n 's/^VERSION=\(.*\)$/\1/p' "${source_root}/dependencies.list")"
  1099. PRERELEASE_REGEX='alpha|beta|rc|preview'
  1100. if [[ $VERSION =~ $PRERELEASE_REGEX ]]; then
  1101. exit 0
  1102. fi
  1103. # update static.realm.io/update/cocoa
  1104. printf "%s" "${VERSION}" > cocoa
  1105. s3cmd put --acl-public cocoa s3://static.realm.io/update/
  1106. exit 0
  1107. ;;
  1108. "publish-cocoapods")
  1109. cd "${ROOT_WORKSPACE}"
  1110. pod trunk push Realm.podspec --verbose --allow-warnings
  1111. pod trunk push RealmSwift.podspec --verbose --allow-warnings --synchronous
  1112. exit 0
  1113. ;;
  1114. "prepare-publish-changelog")
  1115. VERSION="$(sed -n 's/^VERSION=\(.*\)$/\1/p' "${source_root}/dependencies.list")"
  1116. ./scripts/github_release.rb package-release-notes "$VERSION"
  1117. exit 0
  1118. ;;
  1119. "add-empty-changelog")
  1120. empty_section=$(cat <<EOS
  1121. x.y.z Release notes (yyyy-MM-dd)
  1122. =============================================================
  1123. ### Enhancements
  1124. * None.
  1125. ### Fixed
  1126. * <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-swift/issues/????), since v?.?.?)
  1127. * None.
  1128. <!-- ### Breaking Changes - ONLY INCLUDE FOR NEW MAJOR version -->
  1129. ### Compatibility
  1130. * Realm Studio: 14.0.1 or later.
  1131. * APIs are backwards compatible with all previous releases in the 10.x.y series.
  1132. * Carthage release for Swift is built with Xcode 15.3.0.
  1133. * CocoaPods: 1.10 or later.
  1134. * Xcode: 14.2-15.3.0.
  1135. ### Internal
  1136. * Upgraded realm-core from ? to ?
  1137. EOS)
  1138. changelog=$(cat CHANGELOG.md)
  1139. echo "$empty_section" > CHANGELOG.md
  1140. echo >> CHANGELOG.md
  1141. echo "$changelog" >> CHANGELOG.md
  1142. ;;
  1143. *)
  1144. echo "Unknown command '$COMMAND'"
  1145. usage
  1146. exit 1
  1147. ;;
  1148. esac