123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- #!/bin/bash
- set -o pipefail
- set -e
- usage() {
- cat <<EOF
- Usage: sh $0 command [argument]
- command:
- test-all: tests all projects in this repo.
- test-ios-objc-static: tests iOS Objective-C static example.
- test-ios-objc-dynamic: tests iOS Objective-C dynamic example.
- test-ios-objc-cocoapods: tests iOS Objective-C CocoaPods example.
- test-ios-objc-cocoapods-dynamic: tests iOS Objective-C CocoaPods Dynamic example.
- test-ios-objc-carthage: tests iOS Objective-C Carthage example.
- test-ios-swift-dynamic: tests iOS Swift dynamic example.
- test-ios-swift-cocoapods: tests iOS Swift CocoaPods example.
- test-ios-swift-carthage: tests iOS Swift Carthage example.
- test-ios-spm: tests iOS Swift Package Manager example.
- test-osx-objc-dynamic: tests macOS Objective-C dynamic example.
- test-osx-objc-cocoapods: tests macOS Objective-C CocoaPods example.
- test-osx-objc-carthage: tests macOS Objective-C Carthage example.
- test-osx-swift-dynamic: tests macOS Swift dynamic example.
- test-osx-swift-cocoapods: tests macOS Swift CocoaPods example.
- test-osx-swift-carthage: tests macOS Swift Carthage example.
- test-osx-spm: tests macOS Swift Package Manager example.
- test-watchos-objc-dynamic: tests watchOS Objective-C dynamic example.
- test-watchos-objc-cocoapods: tests watchOS Objective-C CocoaPods example.
- test-watchos-objc-carthage: tests watchOS Objective-C Carthage example.
- test-watchos-swift-dynamic: tests watchOS Swift dynamic example.
- test-watchos-swift-cocoapods: tests watchOS Swift CocoaPods example.
- test-watchos-swift-carthage: tests watchOS Swift Carthage example.
- test-watchos-spm: tests watchOS Swift Package Manager example.
- test-tvos-spm: tests tvOS Swift Package Manager example.
- EOF
- }
- COMMAND="$1"
- # https://github.com/CocoaPods/CocoaPods/issues/7708
- export EXPANDED_CODE_SIGN_IDENTITY=''
- download_zip_if_needed() {
- LANG="$1"
- DIRECTORY=realm-$LANG-latest
- if [ ! -d $DIRECTORY ]; then
- curl -o $DIRECTORY.zip -L https://static.realm.io/downloads/$LANG/latest
- unzip $DIRECTORY.zip
- rm $DIRECTORY.zip
- mv realm-$LANG-* $DIRECTORY
- fi
- }
- xcode_version_major() {
- echo "${REALM_XCODE_VERSION%%.*}"
- }
- xctest() {
- PLATFORM="$1"
- LANG="$2"
- NAME="$3"
- DIRECTORY="$PLATFORM/$LANG/$NAME"
- if [[ ! -d "$DIRECTORY" ]]; then
- DIRECTORY="${DIRECTORY/swift/swift-$REALM_SWIFT_VERSION}"
- fi
- PROJECT="$DIRECTORY/$NAME.xcodeproj"
- WORKSPACE="$DIRECTORY/$NAME.xcworkspace"
- if [[ $PLATFORM == ios ]]; then
- sh "$(dirname "$0")/../../scripts/reset-simulators.sh"
- fi
- if [[ $NAME == CocoaPods* ]]; then
- pod install --project-directory="$DIRECTORY"
- elif [[ $NAME == Carthage* ]]; then
- (
- cd "$DIRECTORY"
- if [ -n "$REALM_BUILD_USING_LATEST_RELEASE" ]; then
- echo "github \"realm/realm-cocoa\"" > 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 [[ $LANG == swift* ]]; then
- download_zip_if_needed swift
- else
- download_zip_if_needed $LANG
- fi
- 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
- if xcrun simctl list devicetypes | grep -q 'iPhone Xs'; then
- DESTINATION="-destination id=$(xcrun simctl list devices | grep -v unavailable | grep 'iPhone Xs' | grep -m 1 -o '[0-9A-F\-]\{36\}')"
- fi
- fi
- CMD="-project $PROJECT"
- if [ -d $WORKSPACE ]; then
- CMD="-workspace $WORKSPACE"
- fi
- ACTION=""
- if [[ $PLATFORM == watchos ]]; then
- ACTION="build"
- else
- ACTION="build test"
- fi
- if [[ $PLATFORM == ios ]]; then
- xcodebuild $CMD -scheme $NAME clean $ACTION $DESTINATION CODE_SIGN_IDENTITY=
- else
- xcodebuild $CMD -scheme $NAME clean $ACTION $DESTINATION CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO
- fi
- }
- swiftpm() {
- PLATFORM="$1"
- cd SwiftPMExample
- xcrun swift build
- }
- 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
- if (( $(xcode_version_major) >= 11 )); then
- for target in ios osx watchos tvos; do
- ./build.sh test-$target-spm || exit 1
- done
- fi
- ;;
- test-*-*-static)
- xctest $PLATFORM $LANGUAGE StaticExample
- ;;
- test-*-*-dynamic)
- xctest $PLATFORM $LANGUAGE DynamicExample
- ;;
- test-*-*-cocoapods)
- xctest $PLATFORM $LANGUAGE CocoaPodsExample
- ;;
- test-*-*-cocoapods-dynamic)
- xctest $PLATFORM $LANGUAGE CocoaPodsDynamicExample
- ;;
- test-*-*-carthage)
- xctest $PLATFORM $LANGUAGE CarthageExample
- ;;
- test-*-spm)
- swiftpm $PLATFORM
- ;;
- *)
- echo "Unknown command '$COMMAND'"
- usage
- exit 1
- ;;
- esac
|