#!/bin/bash set -o pipefail set -e usage() { cat < Cartfile else echo "github \"realm/realm-cocoa\" \"${sha:-master}\"" > Cartfile fi if [[ $PLATFORM == ios ]]; then carthage update --platform iOS elif [[ $PLATFORM == osx ]]; then carthage update --platform Mac elif [[ $PLATFORM == watchos ]]; then carthage update --platform watchOS fi ) elif [[ $NAME == SwiftPackageManager* ]]; then if [ -n "$sha" ]; then sed -i '' 's@branch = "master"@branch = "'"$sha"'"@' "$DIRECTORY/$NAME.xcodeproj/project.pbxproj" fi elif [[ $LANG == swift* ]]; then download_zip_if_needed swift else download_zip_if_needed "$LANG" fi local destination=() if [[ $PLATFORM == ios ]]; then simulator_id="$(xcrun simctl list devices | grep -v unavailable | grep -m 1 -o '[0-9A-F\-]\{36\}')" xcrun simctl boot "$simulator_id" destination=(-destination "id=$simulator_id") elif [[ $PLATFORM == watchos ]]; then destination=(-sdk watchsimulator) fi local project=(-project "$DIRECTORY/$NAME.xcodeproj") local workspace="$DIRECTORY/$NAME.xcworkspace" if [ -d "$workspace" ]; then project=(-workspace "$workspace") fi local code_signing_flags=('CODE_SIGN_IDENTITY=' 'CODE_SIGNING_REQUIRED=NO' 'AD_HOC_CODE_SIGNING_ALLOWED=YES') local scheme=(-scheme "$NAME") # Ensure that dynamic framework tests try to use the correct version of the prebuilt libraries. sed -i '' 's@/swift-[0-9.]*@/swift-'"${REALM_XCODE_VERSION}"'@' "$DIRECTORY/$NAME.xcodeproj/project.pbxproj" xcodebuild "${project[@]}" "${scheme[@]}" clean build "${destination[@]}" "${code_signing_flags[@]}" if [[ $PLATFORM != watchos ]]; then xcodebuild "${project[@]}" "${scheme[@]}" test "${destination[@]}" "${code_signing_flags[@]}" fi if [[ $PLATFORM != osx ]]; then [[ $PLATFORM == 'ios' ]] && SDK=iphoneos || SDK=$PLATFORM if [ -d "$workspace" ]; then [[ $LANG == 'swift' ]] && scheme=(-scheme RealmSwift) || scheme=(-scheme Realm) else scheme=() fi xcodebuild "${project[@]}" "${scheme[@]}" -sdk "$SDK" build "${code_signing_flags[@]}" fi } swiftpm() { PLATFORM="$1" cd SwiftPMExample xcrun swift build } # shellcheck source=../../scripts/swift-version.sh source "$(dirname "$0")/../../scripts/swift-version.sh" set_xcode_and_swift_versions # exports REALM_SWIFT_VERSION, REALM_XCODE_VERSION, and DEVELOPER_DIR variables if not already set PLATFORM=$(echo "$COMMAND" | cut -d - -f 2) LANGUAGE=$(echo "$COMMAND" | cut -d - -f 3) case "$COMMAND" in "test-all") for target in ios-swift-dynamic ios-swift-cocoapods osx-swift-dynamic ios-swift-carthage osx-swift-carthage; do ./build.sh test-$target || exit 1 done for target in ios osx; do ./build.sh test-$target-spm || exit 1 done ;; test-*-*-cocoapods) xctest "$PLATFORM" "$LANGUAGE" CocoaPodsExample ;; test-*-*-cocoapods-dynamic) xctest "$PLATFORM" "$LANGUAGE" CocoaPodsDynamicExample ;; test-*-*-static) xctest "$PLATFORM" "$LANGUAGE" StaticExample ;; test-*-*-dynamic) xctest "$PLATFORM" "$LANGUAGE" DynamicExample ;; test-*-*-xcframework) xctest "$PLATFORM" "$LANGUAGE" XCFrameworkExample ;; test-*-*-carthage) xctest "$PLATFORM" "$LANGUAGE" CarthageExample ;; test-ios-spm) # We have to "hide" the spm example from carthage because otherwise # it'll fetch the example's package dependencies as part of deciding # what to build from this repo. if ! [ -L ios/swift/SwiftPackageManagerExample/SwiftPackageManagerExample.xcodeproj/project.pbxproj ]; then mkdir -p ios/swift/SwiftPackageManagerExample/SwiftPackageManagerExample.xcodeproj ln -s ../project.pbxproj ios/swift/SwiftPackageManagerExample/SwiftPackageManagerExample.xcodeproj fi xctest "$PLATFORM" swift SwiftPackageManagerExample ;; test-*-spm) swiftpm "$PLATFORM" ;; *) echo "Unknown command '$COMMAND'" usage exit 1 ;; esac