-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Expand file tree
/
Copy pathcommon.sh
More file actions
executable file
·183 lines (161 loc) · 4.71 KB
/
Copy pathcommon.sh
File metadata and controls
executable file
·183 lines (161 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/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
if [[ `uname` == "Darwin" ]]; then
# Detect Xcode version to determine which simulators to use
XCODE_VERSION=$(xcodebuild -version | head -1 | sed 's/Xcode //')
XCODE_MAJOR=$(echo $XCODE_VERSION | cut -d. -f1)
if [ "$XCODE_MAJOR" -ge 26 ]; then
echo "Running Xcode $XCODE_VERSION (iOS 26 / watchOS 26 / tvOS 26)"
DEFAULT_IOS_SIMULATOR=RxSwiftTest/iPhone-17/iOS/26.2
DEFAULT_WATCHOS_SIMULATOR=RxSwiftTest/Apple-Watch-Series-11-46mm/watchOS/26.2
DEFAULT_TVOS_SIMULATOR=RxSwiftTest/Apple-TV-1080p/tvOS/26.2
elif [ "$XCODE_MAJOR" -ge 16 ]; then
echo "Running Xcode $XCODE_VERSION (iOS 18.5 / watchOS 11.5 / tvOS 18.5)"
DEFAULT_IOS_SIMULATOR=RxSwiftTest/iPhone-16/iOS/18.5
DEFAULT_WATCHOS_SIMULATOR=RxSwiftTest/Apple-Watch-Series-10-46mm/watchOS/11.5
DEFAULT_TVOS_SIMULATOR=RxSwiftTest/Apple-TV-1080p/tvOS/18.5
else
echo "Unsupported Xcode version: $XCODE_VERSION"
exit -1
fi
fi
RUN_SIMULATOR_BY_NAME=0
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() {
string="$1"
substring="$2"
if [[ $string == *"$substring"* ]]
then
return 0 # $substring is in $string
else
return 1 # $substring is not in $string
fi
}
function simulator_ids() {
SIMULATOR=$1
xcrun simctl list | grep "${SIMULATOR}" | cut -d "(" -f 2 | cut -d ")" -f 1 | sort | uniq
}
function simulator_available() {
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
}
function is_real_device() {
contains "$1" "’s "
}
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/\./-/"`
RUNTIME="com.apple.CoreSimulator.SimRuntime.${OS}-${VERSION_SUFFIX}"
echo "Creating new simulator with runtime=${RUNTIME}"
if ! xcrun simctl create "${SIMULATOR}" "com.apple.CoreSimulator.SimDeviceType.${DEVICE}" "${RUNTIME}"; then
echo ""
echo "Failed to create simulator. Available runtimes:"
xcrun simctl list runtimes
echo ""
echo "Available device types:"
xcrun simctl list devicetypes
exit 1
fi
SIMULATOR_ID=`simulator_ids "${SIMULATOR}"`
echo "Warming up ${SIMULATOR_ID} ..."
xcrun simctl boot "${SIMULATOR_ID}"
open -a "Simulator" --args -CurrentDeviceUDID "${SIMULATOR_ID}" || true
sleep 120
}
BUILD_DIRECTORY=build
function rx() {
action Rx.xcworkspace "$1" "$2" "$3" "$4"
}
function action() {
WORKSPACE=$1
SCHEME=$2
CONFIGURATION=$3
SIMULATOR=$4
ACTION=$5
echo
printf "${GREEN}${ACTION} ${BOLDCYAN}$SCHEME - $CONFIGURATION ($SIMULATOR)${RESET}\n"
echo
DESTINATION=""
if [ "${SIMULATOR}" == "macCatalyst" ]; then
DESTINATION='platform=macOS,variant=Mac Catalyst'
elif [ "${SIMULATOR}" != "" ]; then
#if it's a real device
if is_real_device "${SIMULATOR}"; then
DESTINATION='name='${SIMULATOR}
#else it's just a simulator
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''
else
ensure_simulator_available "${SIMULATOR}"
SIMULATOR_GUID=`simulator_ids "${SIMULATOR}"`
DESTINATION='platform='$OS' Simulator,OS='$OS',id='$SIMULATOR_GUID''
fi
echo "Running on ${DESTINATION}"
fi
else
DESTINATION='platform=macOS'
fi
set -x
mkdir -p build
killall Simulator || true
LINT=1 xcodebuild -workspace "${WORKSPACE}" \
-scheme "${SCHEME}" \
-configuration "${CONFIGURATION}" \
-derivedDataPath "${BUILD_DIRECTORY}" \
-destination "$DESTINATION" \
$ACTION | tee build/last-build-output.txt | xcbeautify
exitIfLastStatusWasUnsuccessful
set +x
}
function exitIfLastStatusWasUnsuccessful() {
STATUS=${PIPESTATUS[0]}
if [ $STATUS -ne 0 ]; then
echo $STATUS
exit $STATUS
fi
}