2015-08-01 15:00:38 +03:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
RESET="\033[0m"
|
|
|
|
|
BLACK="\033[30m"
|
|
|
|
|
RED="\033[31m"
|
|
|
|
|
GREEN="\033[32m"
|
|
|
|
|
YELLOW="\033[33m"
|
|
|
|
|
BLUE="\033[34m"
|
|
|
|
|
MAGENTA="\033[35m"
|
|
|
|
|
CYAN="\033[36m"
|
|
|
|
|
WHITE="\033[37m"
|
|
|
|
|
BOLDBLACK="\033[1m\033[30m"
|
|
|
|
|
BOLDRED="\033[1m\033[31m"
|
|
|
|
|
BOLDGREEN="\033[1m\033[32m"
|
|
|
|
|
BOLDYELLOW="\033[1m\033[33m"
|
|
|
|
|
BOLDBLUE="\033[1m\033[34m"
|
|
|
|
|
BOLDMAGENTA="\033[1m\033[35m"
|
|
|
|
|
BOLDCYAN="\033[1m\033[36m"
|
|
|
|
|
BOLDWHITE="\033[1m\033[37m"
|
|
|
|
|
|
|
|
|
|
# make sure all tests are passing
|
|
|
|
|
|
2017-07-02 22:07:03 +03:00
|
|
|
|
if [[ `uname` == "Darwin" ]]; then
|
|
|
|
|
if [ `xcrun simctl list runtimes | grep com.apple.CoreSimulator.SimRuntime.iOS-10-3 | wc -l` -eq 1 ]; then
|
|
|
|
|
DEFAULT_IOS_SIMULATOR=RxSwiftTest/iPhone-6/iOS/10.3
|
2017-07-18 20:55:06 +03:00
|
|
|
|
elif [ `xcrun simctl list runtimes | grep com.apple.CoreSimulator.SimRuntime.iOS-11-0 | wc -l` -eq 1 ]; then
|
|
|
|
|
DEFAULT_IOS_SIMULATOR=RxSwiftTest/iPhone-6/iOS/11.0
|
2017-07-02 22:07:03 +03:00
|
|
|
|
else
|
|
|
|
|
DEFAULT_IOS_SIMULATOR=RxSwiftTest/iPhone-6/iOS/10.0
|
|
|
|
|
fi
|
2016-10-28 23:45:38 +03:00
|
|
|
|
|
2017-07-02 22:07:03 +03:00
|
|
|
|
if [ `xcrun simctl list runtimes | grep com.apple.CoreSimulator.SimRuntime.watchOS-3-2 | wc -l` -eq 1 ]; then
|
|
|
|
|
DEFAULT_WATCHOS_SIMULATOR=RxSwiftTest/Apple-Watch-38mm/watchOS/3.2
|
2017-07-18 20:55:06 +03:00
|
|
|
|
elif [ `xcrun simctl list runtimes | grep com.apple.CoreSimulator.SimRuntime.watchOS-4-0 | wc -l` -eq 1 ]; then
|
|
|
|
|
DEFAULT_WATCHOS_SIMULATOR=RxSwiftTest/Apple-Watch-38mm/watchOS/4.0
|
2017-07-02 22:07:03 +03:00
|
|
|
|
else
|
|
|
|
|
DEFAULT_WATCHOS_SIMULATOR=RxSwiftTest/Apple-Watch-38mm/watchOS/3.0
|
|
|
|
|
fi
|
2016-10-28 23:45:38 +03:00
|
|
|
|
|
2017-07-02 22:07:03 +03:00
|
|
|
|
if [ `xcrun simctl list runtimes | grep com.apple.CoreSimulator.SimRuntime.tvOS-10-2 | wc -l` -eq 1 ]; then
|
|
|
|
|
DEFAULT_TVOS_SIMULATOR=RxSwiftTest/Apple-TV-1080p/tvOS/10.2
|
2017-07-18 20:55:06 +03:00
|
|
|
|
elif [ `xcrun simctl list runtimes | grep com.apple.CoreSimulator.SimRuntime.tvOS-11-0 | wc -l` -eq 1 ]; then
|
|
|
|
|
DEFAULT_TVOS_SIMULATOR=RxSwiftTest/Apple-TV-1080p/tvOS/11.0
|
2017-07-02 22:07:03 +03:00
|
|
|
|
else
|
|
|
|
|
DEFAULT_TVOS_SIMULATOR=RxSwiftTest/Apple-TV-1080p/tvOS/10.0
|
|
|
|
|
fi
|
2016-07-04 03:48:41 +03:00
|
|
|
|
fi
|
2016-11-02 00:23:59 +03:00
|
|
|
|
RUN_SIMULATOR_BY_NAME=0
|
2015-10-01 22:02:09 +03:00
|
|
|
|
|
|
|
|
|
function runtime_available() {
|
|
|
|
|
if [ `xcrun simctl list runtimes | grep "${1}" | wc -l` -eq 1 ]; then
|
|
|
|
|
return 0
|
|
|
|
|
else
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# used to check simulator name
|
|
|
|
|
function contains() {
|
2016-11-26 19:17:53 +03:00
|
|
|
|
string="$1"
|
|
|
|
|
substring="$2"
|
|
|
|
|
if [[ $string == *"$substring"* ]]
|
|
|
|
|
then
|
|
|
|
|
return 0 # $substring is in $string
|
|
|
|
|
else
|
|
|
|
|
return 1 # $substring is not in $string
|
|
|
|
|
fi
|
2015-10-01 22:02:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-20 17:34:26 +03:00
|
|
|
|
function simulator_ids() {
|
|
|
|
|
SIMULATOR=$1
|
|
|
|
|
xcrun simctl list | grep "${SIMULATOR}" | cut -d "(" -f 2 | cut -d ")" -f 1 | sort | uniq
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-01 22:02:09 +03:00
|
|
|
|
function simulator_available() {
|
2016-11-26 19:17:53 +03:00
|
|
|
|
SIMULATOR=$1
|
|
|
|
|
if [ `simulator_ids "${SIMULATOR}" | wc -l` -eq 0 ]; then
|
|
|
|
|
return -1
|
|
|
|
|
elif [ `simulator_ids "${SIMULATOR}" | wc -l` -gt 1 ]; then
|
|
|
|
|
echo "Multiple simulators ${SIMULATOR} found"
|
|
|
|
|
xcrun simctl list | grep "${SIMULATOR}"
|
|
|
|
|
exit -1
|
|
|
|
|
elif [ `xcrun simctl list | grep "${SIMULATOR}" | grep "unavailable" | wc -l` -gt 0 ]; then
|
|
|
|
|
xcrun simctl list | grep "${SIMULATOR}" | grep "unavailable"
|
|
|
|
|
exit -1
|
|
|
|
|
else
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
2015-10-01 22:02:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 20:33:28 +03:00
|
|
|
|
function is_real_device() {
|
|
|
|
|
contains "$1" "’s "
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 16:55:57 +03:00
|
|
|
|
function ensure_simulator_available() {
|
|
|
|
|
SIMULATOR=$1
|
|
|
|
|
|
|
|
|
|
if simulator_available "${SIMULATOR}"; then
|
|
|
|
|
echo "${SIMULATOR} exists"
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
DEVICE=`echo "${SIMULATOR}" | cut -d "/" -f 2`
|
|
|
|
|
OS=`echo "${SIMULATOR}" | cut -d "/" -f 3`
|
|
|
|
|
VERSION_SUFFIX=`echo "${SIMULATOR}" | cut -d "/" -f 4 | sed -e "s/\./-/"`
|
2015-10-01 22:02:09 +03:00
|
|
|
|
|
2015-10-03 16:55:57 +03:00
|
|
|
|
RUNTIME="com.apple.CoreSimulator.SimRuntime.${OS}-${VERSION_SUFFIX}"
|
|
|
|
|
|
2015-12-20 16:03:34 +03:00
|
|
|
|
echo "Creating new simulator with runtime=${RUNTIME}"
|
|
|
|
|
xcrun simctl create "${SIMULATOR}" "com.apple.CoreSimulator.SimDeviceType.${DEVICE}" "${RUNTIME}"
|
2016-10-28 23:45:38 +03:00
|
|
|
|
|
|
|
|
|
SIMULATOR_ID=`simulator_ids "${SIMULATOR}"`
|
2016-11-26 19:17:53 +03:00
|
|
|
|
echo "Warming up ${SIMULATOR_ID} ..."
|
2016-10-28 23:45:38 +03:00
|
|
|
|
open -a "Simulator" --args -CurrentDeviceUDID "${SIMULATOR_ID}"
|
2016-11-26 19:17:53 +03:00
|
|
|
|
sleep 120
|
2015-10-03 16:55:57 +03:00
|
|
|
|
}
|
2015-10-01 22:02:09 +03:00
|
|
|
|
|
2015-08-06 02:35:23 +03:00
|
|
|
|
BUILD_DIRECTORY=build
|
2015-08-02 13:00:39 +03:00
|
|
|
|
|
2015-08-06 02:35:23 +03:00
|
|
|
|
function rx() {
|
2015-12-20 16:03:34 +03:00
|
|
|
|
action Rx.xcworkspace "$1" "$2" "$3" "$4"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function action() {
|
|
|
|
|
WORKSPACE=$1
|
|
|
|
|
SCHEME=$2
|
|
|
|
|
CONFIGURATION=$3
|
|
|
|
|
SIMULATOR=$4
|
|
|
|
|
ACTION=$5
|
2015-08-06 02:35:23 +03:00
|
|
|
|
|
2015-08-01 15:00:38 +03:00
|
|
|
|
echo
|
2015-09-30 15:02:41 +03:00
|
|
|
|
printf "${GREEN}${ACTION} ${BOLDCYAN}$SCHEME - $CONFIGURATION ($SIMULATOR)${RESET}\n"
|
2015-08-01 15:00:38 +03:00
|
|
|
|
echo
|
|
|
|
|
|
2015-08-06 02:35:23 +03:00
|
|
|
|
DESTINATION=""
|
2015-10-03 16:55:57 +03:00
|
|
|
|
if [ "${SIMULATOR}" != "" ]; then
|
2016-11-26 19:17:53 +03:00
|
|
|
|
#if it's a real device
|
|
|
|
|
if is_real_device "${SIMULATOR}"; then
|
|
|
|
|
DESTINATION='name='${SIMULATOR}
|
2015-10-03 20:33:28 +03:00
|
|
|
|
#else it's just a simulator
|
2016-11-26 19:17:53 +03:00
|
|
|
|
else
|
|
|
|
|
OS=`echo $SIMULATOR | cut -d '/' -f 3`
|
|
|
|
|
if [ "${RUN_SIMULATOR_BY_NAME}" -eq 1 ]; then
|
|
|
|
|
SIMULATOR_NAME=`echo $SIMULATOR | cut -d '/' -f 1`
|
|
|
|
|
DESTINATION='platform='$OS' Simulator,name='$SIMULATOR_NAME''
|
2015-10-03 20:33:28 +03:00
|
|
|
|
else
|
2016-11-26 19:17:53 +03:00
|
|
|
|
ensure_simulator_available "${SIMULATOR}"
|
|
|
|
|
SIMULATOR_GUID=`simulator_ids "${SIMULATOR}"`
|
|
|
|
|
DESTINATION='platform='$OS' Simulator,OS='$OS',id='$SIMULATOR_GUID''
|
2015-10-03 20:33:28 +03:00
|
|
|
|
fi
|
2016-11-26 19:17:53 +03:00
|
|
|
|
echo "Running on ${DESTINATION}"
|
|
|
|
|
fi
|
2015-08-06 02:35:23 +03:00
|
|
|
|
else
|
2016-11-26 19:17:53 +03:00
|
|
|
|
DESTINATION='platform=macOS,arch=x86_64'
|
2015-08-06 02:35:23 +03:00
|
|
|
|
fi
|
|
|
|
|
|
2016-11-26 19:17:53 +03:00
|
|
|
|
set -x
|
2017-04-30 20:57:13 +03:00
|
|
|
|
mkdir -p build
|
2016-11-26 19:17:53 +03:00
|
|
|
|
killall Simulator || true
|
2015-12-20 16:03:34 +03:00
|
|
|
|
xcodebuild -workspace "${WORKSPACE}" \
|
2016-11-26 19:17:53 +03:00
|
|
|
|
-scheme "${SCHEME}" \
|
|
|
|
|
-configuration "${CONFIGURATION}" \
|
|
|
|
|
-derivedDataPath "${BUILD_DIRECTORY}" \
|
|
|
|
|
-destination "$DESTINATION" \
|
|
|
|
|
$ACTION | tee build/last-build-output.txt | xcpretty -c
|
|
|
|
|
exitIfLastStatusWasUnsuccessful
|
|
|
|
|
set +x
|
2016-06-08 16:45:29 +03:00
|
|
|
|
}
|
2015-08-06 02:35:23 +03:00
|
|
|
|
|
2016-06-08 16:45:29 +03:00
|
|
|
|
function exitIfLastStatusWasUnsuccessful() {
|
2016-11-26 19:17:53 +03:00
|
|
|
|
STATUS=${PIPESTATUS[0]}
|
2015-08-06 02:35:23 +03:00
|
|
|
|
if [ $STATUS -ne 0 ]; then
|
|
|
|
|
echo $STATUS
|
2016-11-26 19:17:53 +03:00
|
|
|
|
exit $STATUS
|
2015-08-06 02:35:23 +03:00
|
|
|
|
fi
|
2015-08-01 15:00:38 +03:00
|
|
|
|
}
|