-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·290 lines (260 loc) · 8.13 KB
/
build.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
#!/bin/bash
# Copyright (C) 2017 Vincent Zvikaramba
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# source 'script' functions
. $(dirname $0)/common/source.sh
# source common scripts
source_common
# file transfer retry count
UPLOAD_RETRY_COUNT=3
#changelog
CHANGELOG_DAYS=5
CURL="curl --silent -connect-timeout=10"
# file extraction function names
COPY_FUNCTIONS=();
SILENT=0
LOCAL_REPO_PICKS=
LINEAGE_REPO_PICKS=
LOCAL_REPO_TOPICS=
LINEAGE_REPO_TOPICS=
SYNC_DEPTH=0
function validate_arg {
valid=$(echo $1 | sed s'/^[\-][a-z0-9A-Z\-]*/valid/'g)
[ "x$1" == "x$0" ] && return 0;
[ "x$1" == "x" ] && return 0;
[ "$valid" == "valid" ] && return 0 || return 1;
}
function print_help {
log "Usage: `basename $0` [OPTION]";
log " -d, --distribution\tdistribution name" ;
log " --description\tDescription for use in notifications" ;
log " --job-url\tURL to the job on jenkins" ;
log " -t, --target\twhere target is one of bootimage|recoveryimage|otapackage" ;
log " -e, --type\twhere type is one of user|userdebug|eng" ;
log " --device\tdevice name" ;
log " -H, --host\trsync/ssh host details. In the form [user@]hostname";
log " -p, --path\tbuild top path" ;
log " -o, --output\toutput path (path to jenkins archive dir)";
log "\nOptional commands:";
log " -b\tbuild number";
log "--prefix \t Prefix build artifacts with this string.";
log "--pick-lineage --pick-lineage-topic \t Pick specified lineage gerrit changes.";
log "--pick --pick-topic \t Pick specified local (msm8916) gerrit changes.";
log " \tChanges can be comma separated, or the flag";
log " \tcan be called repeatedly with each change. ";
log " -s, --silent\tdon't publish to Telegram";
log " --days\tNumber of days of changelogs to generate";
log " -r, --clean\tclean build directory on completion";
log " --make-args\tArguments to pass to make at build time.";
log " -U, --upload-retry\tRetry file upload this many times upon failure before giving up.";
log " \tDefault is 3 ";
log " -a, --sync_all\tSync entire build tree";
log " -v, --sync\tSync device/kernel/vendor trees";
log " --sync-depth\tRepo sync depth. Any number < 1 will trigger full sync. DEfault is 0";
log " -u, --su\tAdd SU to build";
log " -j\tnumber of parallel make jobs to run";
exit
}
prev_arg=
while [ "$1" != "" ]; do
cur_arg=$1
# find arguments of the form --arg=val and split to --arg val
if [ -n "`echo $cur_arg | grep -o =`" ]; then
cur_arg=`echo $1 | cut -d'=' -f 1`
next_arg=`echo $1 | cut -d'=' -f 2`
else
cur_arg=$1
next_arg=$2
fi
case $cur_arg in
-a | --sync-all )
SYNC_ALL=1
;;
-b )
JOB_BUILD_NUMBER=$next_arg
;;
--clean )
CLEAN_TARGET_OUT=1
;;
-d )
DISTRIBUTION=$next_arg
;;
--days )
CHANGELOG_DAYS=$next_arg
;;
--device )
DEVICE_NAME=$next_arg
;;
--description )
JOB_DESCRIPTION=$next_arg
;;
--distro )
DISTRIBUTION=$next_arg
;;
--job-url )
JOB_URL=$next_arg
;;
-e | --type )
BUILD_VARIANT=$next_arg
;;
-j | --jobs )
MAX_JOB_NUMBER=$next_arg
;;
-h | --help )
print_help
;;
-H | --host )
SYNC_HOST=$next_arg
;;
--make-args )
logb "\t\tmake argument $next_arg specified"
MAKE_ARGS="$MAKE_ARGS $next_arg "
;;
--manifest )
MANIFEST_NAME=$next_arg
;;
-o | --output )
OUTPUT_DIR=$next_arg
;;
-p | --path )
BUILD_TOP=`realpath $next_arg`
;;
--prefix )
ARTIFACT_PREFIX="$next_arg"
;;
--pick )
logb "\t\tChange(s) $next_arg specified"
LOCAL_REPO_PICKS="${LOCAL_REPO_PICKS} `echo $next_arg|sed s'/,/ /'g`"
;;
--pick-lineage )
logb "\t\tLineage change(s) $next_arg specified"
LINEAGE_REPO_PICKS="${LINEAGE_REPO_PICKS} `echo $next_arg|sed s'/,/ /'g`"
;;
--pick-lineage-topic )
logb "\t\tLineage topic(s) $next_arg specified"
LINEAGE_REPO_TOPICS="${LINEAGE_REPO_TOPICS} `echo $next_arg|sed s'/,/ /'g`"
;;
--pick-topic )
logb "\t\tTopic(s) $next_arg specified"
LOCAL_REPO_TOPICS="${LOCAL_REPO_TOPICS} `echo $next_arg|sed s'/,/ /'g`"
;;
-r)
CLEAN_TARGET_OUT=1
;;
-s | --silent )
SILENT=1
;;
--sync)
SYNC_VENDOR=1
;;
--sync-depth)
SYNC_DEPTH=$next_arg
;;
-t | --target )
BUILD_TARGET=$next_arg
;;
-U | --upload-retry )
UPLOAD_RETRY_COUNT=$next_arg
;;
-u | --su )
WITH_SU=true
;;
-v)
SYNC_VENDOR=1
;;
*)
validate_arg $cur_arg;
if [ $? -eq 0 ]; then
logr "Unrecognised option $cur_arg passed"
print_help
else
validate_arg $prev_arg
if [ $? -eq 1 ]; then
logr "Argument $cur_arg passed without flag option"
print_help
fi
fi
;;
esac
prev_arg=$1
shift
done
if [ "x${BUILD_TOP}" == "x" ]; then
logr "No android source directory specified!"
exit 1
fi
if [ "x$SYNC_ALL" == "x" ] && [ "x$SYNC_VENDOR" == "x" ]; then
if [ "x${DEVICE_NAME}" == "x" ]; then
logr "No device name specified!"
exit 1
fi
if [ "x${BUILD_VARIANT}" == "x" ]; then
logr "No build variant specified!"
exit 1
fi
if [ "x${BUILD_TARGET}" == "x" ]; then
logr "No build target specified!"
exit 1
fi
fi
# create a temprary working dir
BUILD_TEMP=$(mktemp -d /tmp/build.tmp.XXXXXXX)
ARTIFACT_OUT_DIR=${BUILD_TEMP}/builds
# update the repo
update_repo
# source common scripts
source_common
# source build functions
source_build
# setup env vars
bootstrap "$@"
# check if any other builds are running
acquire_build_lock
# get the platform info
get_platform_info
# clean build top
clean_out
# sync manifests
sync_manifests
# sync the repos
sync_vendor_trees "$@"
sync_all_trees "$@"
if [ "x${BUILD_TARGET}" != "x" ] && [ "x${BUILD_VARIANT}" != "x" ] && [ "x${DEVICE_NAME}" != "x" ]; then
# apply repopicks
apply_repopicks
# setup the build environment
setup_env "$@"
# print the build start text
print_start_build
# make the targets
make_targets
# copy the files
copy_files
# generate the changes
generate_changes
# remove lock
remove_build_lock
# upload build artifacts
upload_artifacts
# end the build
print_end_build
fi
# remove lock
remove_build_lock
# remove temp dir
remove_temp_dir
END_TIME=$( date +%s )
# PRINT RESULT TO USER
echoTextGreen "SCRIPT COMPLETED!"
echo -e ${RED}"TIME: $(format_time ${END_TIME} ${START_TIME})"${RESTORE}; newLine