-
Notifications
You must be signed in to change notification settings - Fork 779
/
Copy pathbuild-bundles.sh
executable file
·228 lines (195 loc) · 6.58 KB
/
build-bundles.sh
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/bash
set -euo pipefail
if [[ $EUID -eq 0 ]]; then
echo "ERROR: running as root is not supported"
echo "Please run 'export UID' before running docker-compose!"
exit 1
fi
if [ ! -v UNITY_USERNAME ]; then
echo "ERROR: UNITY_USERNAME environment variable is not set"
exit 1
fi
if [ ! -v UNITY_PASSWORD ]; then
echo "ERROR: UNITY_PASSWORD environment variable is not set"
exit 1
fi
if [ ! -v UNITY_SERIAL ]; then
echo "ERROR: UNITY_SERIAL environment variable is not set"
exit 1
fi
if [ ! -v UNITY_VERSION ]; then
echo "ERROR: UNITY_VERSION environment variable is not set"
exit 1
fi
if [ -z ${SIM_ENVIRONMENTS+x} ] && [ -z ${SIM_VEHICLES+x} ] && [ -z ${SIM_SENSORS+x} ] && [ -z ${SIM_BRIDGES+x} ]; then
echo All environments, vehicles, sensors and bridges are up to date!
exit 0
fi
function getAssets()
{
ASSETS=
local DELIM=
while read -r LINE; do
local ITEMS=( ${LINE} )
local NAME="${ITEMS[1]}"
ASSETS="${ASSETS}${DELIM}${NAME}"
DELIM=" "
done <<< "$1"
}
CHECK_UNITY_LOG=$(readlink -f "$(dirname $0)/check-unity-log.sh")
function check_unity_log {
${CHECK_UNITY_LOG} $@
}
export HOME=/tmp
cd /mnt
UNITY=/usr/bin/unity-editor
if [ ! -x "${UNITY}" ] ; then
echo "ERROR: ${UNITY} doesn't exist or isn't executable"
exit 1
fi
###
function get_unity_license {
echo "Fetching unity license"
for i in `seq 1 3`; do
if ! ${UNITY} \
-batchmode \
-serial ${UNITY_SERIAL} \
-username ${UNITY_USERNAME} \
-password ${UNITY_PASSWORD} \
-silent-crashes \
-projectPath /mnt \
-logFile /dev/stdout \
-quit; then
echo "WARN: Fetching unity license failed, attempt ${i} in 3, trying again"
else
echo "INFO: Fetching unity license attempt ${i} seems to be successful"
break
fi
done
}
function build_bundle {
# Move the source for individual bundles from Assets/External-All to Assets/External
# to prevent Unity importing all the available assets when we went to build just one
# of them
echo "Building bundle (${BUNDLE}/${BUNDLES}) $*"
if [ ! -d .external-assets/$1/$2 ] ; then
echo "ERROR: Bundle source doesn't exist in .external-assets/$1/$2"
else
mkdir -p Assets/External/$1
mv .external-assets/$1/$2 Assets/External/$1
fi
for i in `seq 1 3`; do
if ! ${UNITY} \
-force-vulkan \
-silent-crashes \
-projectPath /mnt \
-executeMethod Simulator.Editor.Build.Run \
-buildBundles \
-build$1 $2 \
-logFile /dev/stdout; then
echo "WARN: Bundle $1 $2 failed to build, attempt ${i} in 3, trying again"
else
echo "INFO: Bundle $1 $2 bundle attempt ${i} seems to be successful"
break
fi
done
mv Assets/External/$1/$2 .external-assets/$1/$2
if [ ! -f AssetBundles/$1/*_$2 ] ; then
echo "ERROR: Bundle $1 $2 wasn't created in AssetBundles/$1/*_$2"
else
echo "INFO: Bundle $1 $2 succeeded to build"
fi
}
function finish
{
${UNITY} \
-batchmode \
-force-vulkan \
-silent-crashes \
-quit \
-returnlicense
}
trap finish EXIT
get_unity_license
PREFIX=svlsimulator
if [ -v GIT_TAG ]; then
SUFFIX=${GIT_TAG}
elif [ -v JENKINS_BUILD_ID ]; then
SUFFIX=${JENKINS_BUILD_ID}
else
SUFFIX=
fi
echo "I: Cleanup AssetBundles before build"
rm -Rf /mnt/AssetBundles unity-build-bundles*log || true
BUNDLES=0
if [ ! -z ${SIM_ENVIRONMENTS+x} ]; then
echo "INFO: going to build $(echo "${SIM_ENVIRONMENTS=}" | wc -l) Environments"
BUNDLES=$(expr ${BUNDLES} + $(echo "${SIM_ENVIRONMENTS=}" | wc -l))
fi
if [ ! -z ${SIM_VEHICLES+x} ]; then
echo "INFO: going to build $(echo "${SIM_VEHICLES=}" | wc -l) Vehicles"
BUNDLES=$(expr ${BUNDLES} + $(echo "${SIM_VEHICLES=}" | wc -l))
fi
if [ ! -z ${SIM_SENSORS+x} ]; then
echo "INFO: going to build $(echo "${SIM_SENSORS=}" | wc -l) Sensors"
BUNDLES=$(expr ${BUNDLES} + $(echo "${SIM_SENSORS=}" | wc -l))
fi
if [ ! -z ${SIM_BRIDGES+x} ]; then
echo "INFO: going to build $(echo "${SIM_BRIDGES=}" | wc -l) Bridges"
BUNDLES=$(expr ${BUNDLES} + $(echo "${SIM_BRIDGES=}" | wc -l))
fi
BUNDLE=0
if [ ! -z ${SIM_ENVIRONMENTS+x} ]; then
getAssets "${SIM_ENVIRONMENTS}"
for A in ${ASSETS}; do
BUNDLE=$(expr ${BUNDLE} + 1)
build_bundle Environments ${A} 2>&1 | tee -a unity-build-bundles-Environments.log
done
fi
if [ ! -z ${SIM_VEHICLES+x} ]; then
getAssets "${SIM_VEHICLES}"
for A in ${ASSETS}; do
BUNDLE=$(expr ${BUNDLE} + 1)
build_bundle Vehicles ${A} 2>&1 | tee -a unity-build-bundles-Vehicles.log
done
fi
if [ ! -z ${SIM_SENSORS+x} ]; then
getAssets "${SIM_SENSORS}"
for A in ${ASSETS}; do
BUNDLE=$(expr ${BUNDLE} + 1)
build_bundle Sensors ${A} 2>&1 | tee -a unity-build-bundles-Sensors.log
done
fi
if [ ! -z ${SIM_BRIDGES+x} ]; then
getAssets "${SIM_BRIDGES}"
for A in ${ASSETS}; do
BUNDLE=$(expr ${BUNDLE} + 1)
build_bundle Bridges ${A} 2>&1 | tee -a unity-build-bundles-Bridges.log
done
fi
RESULT=0
OK=0
# maybe drop -e before the next section, because "|| true" is needed after
# each grep which doesn't match anything (including grep -c), and also after
# expr 0 + 0, which prints 0, but returns 1 as return status
echo
echo
echo "Build bundles summary:"
for assetType in Environments Vehicles Sensors Bridges; do
if [ -f unity-build-bundles-${assetType}.log ] ; then
echo "== ${assetType} built successfully =="
grep "^INFO: .* succeeded to build" unity-build-bundles-${assetType}.log || true
OK=$(expr ${OK} + $(grep -c "^INFO: .* succeeded to build" unity-build-bundles-${assetType}.log || true) || true)
echo "== ${assetType} built with errors =="
grep "^ERROR:" unity-build-bundles-${assetType}.log || true
RESULT=$(expr ${RESULT} + $(grep -c "^ERROR:" unity-build-bundles-${assetType}.log || true) || true)
echo "== ${assetType} built with warnings =="
grep "^WARN:" unity-build-bundles-${assetType}.log || true
echo "== ${assetType} other possible issues detected by check_unity_log =="
Jenkins/check-unity-log.sh unity-build-bundles-${assetType}.log || RESULT=$(expr ${RESULT} + 1)
else
echo "No ${assetType} were built (unity-build-bundles-${assetType}.log doesn't exist)"
fi
done
echo "${OK} from ${BUNDLES} bundles were built successfully, there were ${RESULT} issues"
exit ${RESULT}