forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arm32_ci_script.sh
331 lines (289 loc) · 10.5 KB
/
arm32_ci_script.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/bin/bash
#Usage message
function usage {
echo 'ARM Emulator Cross Build Script'
echo 'This script cross builds core-setup source'
echo ''
echo 'Typical usage:'
echo ' core-setup source is at ~/core-setup'
echo '$ cd ~/core-setup'
echo '$ ./scripts/arm32_ci_script.sh'
echo ' --buildConfig=Release'
echo ' --armel'
echo ' --verbose'
echo ''
echo 'Required Arguments:'
echo ' --buildConfig=<config> : The value of config should be either Debug or Release'
echo ' Any other value is not accepted'
echo 'Optional Arguments:'
echo ' --mode=<mode> : docker (default) or emulator'
echo ' --arm : Build as arm (default)'
echo ' --armel : Build as armel'
echo ' --linuxCodeName=<name> : Code name for Linux: For arm, trusty (default) and xenial. For armel, tizen'
echo ' --skipRootFS : Skip building rootfs'
echo ' --emulatorPath=<path> : Path of the emulator folder (without ending /)'
echo ' <path>/platform/rootfs-t30.ext4 should exist'
echo ' --mountPath=<path> : The desired path for mounting the emulator rootfs (without ending /)'
echo ' This path is created if not already present'
echo ' -v --verbose : Build made verbose'
echo ' -h --help : Prints this usage message and exits'
echo ''
echo 'Any other argument triggers an error and this usage message is displayed'
exit 1
}
#Display error message and exit
function exit_with_error {
set +x
local errorMessage="$1"
local printUsage=$2
echo "ERROR: $errorMessage"
if [ "$printUsage" == "true" ]; then
echo ''
usage
fi
exit 1
}
#Exit if input string is empty
function exit_if_empty {
local inputString="$1"
local errorMessage="$2"
local printUsage=$3
if [ -z "$inputString" ]; then
exit_with_error "$errorMessage" $printUsage
fi
}
#Exit if the input path does not exist
function exit_if_path_absent {
local path="$1"
local errorMessage="$2"
local printUsage=$3
if [ ! -f "$path" -a ! -d "$path" ]; then
exit_with_error "$errorMessage" $printUsage
fi
}
#Check if the git changes were reverted completely
function check_git_head {
local currentGitHead=`git rev-parse --verify HEAD`
if [[ "$__initialGitHead" != "$currentGitHead" ]]; then
exit_with_error "Some changes made to the code history were not completely reverted. Intial Git HEAD: $__initialGitHead, current Git HEAD: $currentGitHead" false
fi
}
function unmount_rootfs {
local rootfsFolder="$1"
#Check if there are any open files in this directory.
if [ -d $rootfsFolder ]; then
#If we find information about the file
if sudo lsof +D $rootfsFolder; then
(set +x; echo 'See above for lsof information. Continuing with the build.')
fi
fi
if mountpoint -q -- "$rootfsFolder"; then
sudo umount "$rootfsFolder"
fi
}
#Unmount the emulator file systems
function unmount_emulator {
(set +x; echo 'Unmounting emulator...')
#Unmount all the mounted emulator file systems
unmount_rootfs "$__ARMRootfsMountPath/proc"
unmount_rootfs "$__ARMRootfsMountPath/dev/pts"
unmount_rootfs "$__ARMRootfsMountPath/dev"
unmount_rootfs "$__ARMRootfsMountPath/run/shm"
unmount_rootfs "$__ARMRootfsMountPath/sys"
unmount_rootfs "$__ARMRootfsMountPath"
}
#Clean the changes made to the environment by the script
function clean_env {
#Check for revert of git changes
check_git_head
}
#Trap Ctrl-C and handle it
function handle_ctrl_c {
set +x
echo 'ERROR: Ctrl-C handled. Script aborted before complete execution.'
exit 1
}
trap handle_ctrl_c INT
#Trap Exit and handle it
function handle_exit {
set +x
echo 'The script is exited. Cleaning environment..'
clean_env
}
trap handle_exit EXIT
#Mount with checking to be already existed
function mount_with_checking {
set +x
local options="$1"
local from="$2"
local rootfsFolder="$3"
if mountpoint -q -- "$rootfsFolder"; then
(set +x; echo "$rootfsFolder is already mounted.")
else {
(set -x; sudo mount $options "$from" "$rootfsFolder")
}
fi
}
#Mount emulator to the target mount path
function mount_emulator {
#Check if the mount path exists and create if neccessary
if [ ! -d "$__ARMRootfsMountPath" ]; then
sudo mkdir -p "$__ARMRootfsMountPath"
fi
set +x
mount_with_checking "" "$__ARMEmulPath/platform/$__ARMRootfsImageBase" "$__ARMRootfsMountPath"
mount_with_checking "-t proc" "/proc" "$__ARMRootfsMountPath/proc"
mount_with_checking "-o bind" "/dev/" "$__ARMRootfsMountPath/dev"
mount_with_checking "-o bind" "/dev/pts" "$__ARMRootfsMountPath/dev/pts"
mount_with_checking "-t tmpfs" "shm" "$__ARMRootfsMountPath/run/shm"
mount_with_checking "-o bind" "/sys" "$__ARMRootfsMountPath/sys"
}
# Cross builds core-setup using Docker image
function cross_build_core_setup_with_docker {
__currentWorkingDirectory=`pwd`
# Check build configuration and choose Docker image
if [ "$__buildArch" == "arm" ]; then
# TODO: For arm, we are going to embed RootFS inside Docker image.
case $__linuxCodeName in
trusty)
__dockerImage=" microsoft/dotnet-buildtools-prereqs:ubuntu-14.04-cross-0cd4667-20172211042239"
__runtimeOS="ubuntu.14.04"
;;
xenial)
__dockerImage=" microsoft/dotnet-buildtools-prereqs:ubuntu-16.04-cross-ef0ac75-20175511035548"
__runtimeOS="ubuntu.16.04"
;;
*)
exit_with_error "ERROR: $__linuxCodeName is not a supported linux name for $__buildArch" false
;;
esac
elif [ "$__buildArch" == "armel" ]; then
# For armel Tizen, we are going to construct RootFS on the fly.
case $__linuxCodeName in
tizen)
__dockerImage=" tizendotnet/dotnet-buildtools-prereqs:ubuntu-16.04-cross-e435274-20180426002255-tizen-rootfs-5.0m1"
__runtimeOS="tizen.5.0.0"
;;
*)
echo "ERROR: $__linuxCodeName is not a supported linux name for $__buildArch"
exit_with_error "ERROR: $__linuxCodeName is not a supported linux name for $__buildArch" false
;;
esac
else
exit_with_error "ERROR: unknown buildArch $__buildArch" false
fi
__dockerCmd="sudo docker run --privileged -i --rm -v $__currentWorkingDirectory:/opt/core-setup -w /opt/core-setup $__dockerImage"
if [ $__skipRootFS == 0 ]; then
# Build rootfs
__buildRootfsCmd="./eng/common/cross/build-rootfs.sh $__buildArch $__linuxCodeName --skipunmount"
(set +x; echo "Build RootFS for $__buildArch $__linuxCodeName")
$__dockerCmd $__buildRootfsCmd
sudo chown -R $(id -u -n) cross/rootfs
__rootfsDir="/opt/core-setup/eng/common/cross/rootfs/$__buildArch"
fi
# Cross building core-setup with rootfs in Docker
__buildCmd="./build.sh --configuration $__buildConfig --env-vars DISABLE_CROSSGEN=1,TARGETPLATFORM=$__buildArch,OUTPUTRID=$__runtimeOS-$__buildArch,CROSS=1,ROOTFS_DIR=$__rootfsDir"
$__dockerCmd $__buildCmd
}
#Define script variables
__ciMode="docker"
__ARMEmulPath="/opt/linux-arm-emulator"
__ARMRootfsImageBase="rootfs-u1404.ext4"
__ARMRootfsMountPath="/opt/linux-arm-emulator-root"
__buildConfig="Release"
__verboseFlag=
__buildArch="arm"
__linuxCodeName="trusty"
__skipRootFS=0
__rootfsDir=
__initialGitHead=`git rev-parse --verify HEAD`
#Parse command line arguments
for arg in "$@"
do
case $arg in
--emulatorPath=*)
__ARMEmulPath=${arg#*=}
;;
--mountPath=*)
__ARMRootfsMountPath=${arg#*=}
;;
--buildConfig=*)
__buildConfig="$(echo ${arg#*=} | awk '{print tolower($0)}')"
if [[ "$__buildConfig" == "release" ]]; then
__buildConfig="Release"
else
if [[ "$__buildConfig" == "debug" ]]; then
__buildConfig="Debug"
else
exit_with_error "--buildConfig can be only Debug or Release" true
fi
fi
;;
--mode=*)
__ciMode=${arg#*=}
;;
--arm)
__ARMRootfsImageBase="rootfs-u1404.ext4"
__buildArch="arm"
__skipRootFS=1
__rootfsDir="/crossrootfs/arm"
;;
--armel)
__ARMRootfsImageBase="rootfs-t30.ext4"
__buildArch="armel"
__skipRootFS=1
__rootfsDir="/crossrootfs/armel.tizen.build"
__linuxCodeName="tizen"
;;
--linuxCodeName=*)
__linuxCodeName=${arg#*=}
;;
--skipRootFS)
__skipRootFS=1
;;
-v|--verbose)
__verboseFlag="verbose"
;;
-h|--help)
usage
;;
*)
exit_with_error "$arg not a recognized argument" true
;;
esac
done
if [[ $__linuxCodeName == "tizen" ]]; then
# This case does not support CI build yet.
# Will be enabled ASAP.
exit 0
fi
#Check if there are any uncommited changes in the source directory as git adds and removes patches
if [[ $(git status -s) != "" ]]; then
echo 'ERROR: There are some uncommited changes. To avoid losing these changes commit them and try again.'
echo ''
git status
exit 1
fi
exit_if_empty "$__buildConfig" "--buildConfig is a mandatory argument, not provided" true
if [ "$__ciMode" == "emulator" ]; then
#Check if the compulsory arguments have been presented to the script and if the input paths exist
exit_if_empty "$__ARMEmulPath" "--emulatorPath is a mandatory argument, not provided" true
exit_if_empty "$__ARMRootfsMountPath" "--mountPath is a mandatory argument, not provided" true
exit_if_path_absent "$__ARMEmulPath/platform/$__ARMRootfsImageBase" "Path specified in --emulatorPath does not have the rootfs" false
__ARMRootfsMountPath="${__ARMRootfsMountPath}_${__buildArch}"
fi
set -x
set -e
## Begin cross build
(set +x; echo "Git HEAD @ $__initialGitHead")
#Complete the cross build
(set +x; echo 'Building core-setup...')
if [ "$__ciMode" == "docker" ]; then
cross_build_core_setup_with_docker
else
exit_with_error "Not supported emulator mode"
fi
#Clean the environment
(set +x; echo 'Cleaning environment...')
clean_env
(set +x; echo 'Build complete')