-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
537 lines (476 loc) · 15.2 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
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
#!/usr/bin/env bash
function check_result {
if [ "0" -ne "$?" ]
then
(repo forall -c "git reset --hard") >/dev/null
rm -f .repo/local_manifests/dyn-*.xml
rm -f .repo/local_manifests/roomservice.xml
echo $1
exit 1
fi
}
if [ -z "$HOME" ]
then
echo HOME not in environment, guessing...
export HOME=$(awk -F: -v v="$USER" '{if ($1==v) print $6}' /etc/passwd)
fi
if [ -z "$WORKSPACE" ]
then
echo WORKSPACE not specified
exit 1
fi
if [ -z "$CLEAN" ]
then
echo CLEAN not specified
exit 1
fi
if [ -z "$REPO_BRANCH" ]
then
if [[ "$ROM" =~ "liquid" || $ROM =~ "LiquidSmooth" ]]; then
export REPO_BRANCH=jb2
export FOLDERPREFIX=liquid
elif [[ "$ROM" =~ "pa" || $ROM =~ "ParanoidAndroid" ]]; then
export REPO_BRANCH=jellybean-legacy
export FOLDERPREFIX=pa
elif [[ "$ROM" =~ "sb" || $ROM =~ "SlimBean" ]]; then
export REPO_BRANCH=jb4.2
export FOLDERPREFIX=sb
elif [[ "$ROM" =~ "cm" || $ROM =~ "CyanogenMod" ]]; then
export REPO_BRANCH=cm-10.1
export FOLDERPREFIX=cm
else
export REPO_BRANCH=cm-10.1
export FOLDERPREFIX=cm
fi
else
if [[ "$REPO_BRANCH" =~ "jellybean" || $REPO_BRANCH =~ "jellybean-legacy" ]]; then
export FOLDERPREFIX=pa
elif [[ "$REPO_BRANCH" =~ "cm-10.2" || $REPO_BRANCH =~ "cm-10.1" ]]; then
export FOLDERPREFIX=cm
else
echo notification: upload not supported in combination with branch $REPO_BRANCH
fi
fi
if [ -z "$LUNCH" ]
then
echo LUNCH not specified
exit 1
fi
if [ -z "$RELEASE_TYPE" ]
then
echo RELEASE_TYPE not specified
exit 1
fi
if [ -z "$SYNC_PROTO" ]
then
SYNC_PROTO=git
fi
if [ -z "$UPLOAD" ]
then
echo UPLOAD not specified
exit 1
fi
export PYTHONDONTWRITEBYTECODE=1
# colorization fix in Jenkins
export CL_RED="\"\033[31m\""
export CL_GRN="\"\033[32m\""
export CL_YLW="\"\033[33m\""
export CL_BLU="\"\033[34m\""
export CL_MAG="\"\033[35m\""
export CL_CYN="\"\033[36m\""
export CL_RST="\"\033[0m\""
cd $WORKSPACE
rm -rf archive
mkdir -p archive
export BUILD_NO=$BUILD_NUMBER
unset BUILD_NUMBER
export PATH=~/bin:$PATH
export USE_CCACHE=1
export CCACHE_NLEVELS=4
export BUILD_WITH_COLORS=0
platform=`uname -s`
if [ "$platform" = "Darwin" ]
then
export BUILD_MAC_SDK_EXPERIMENTAL=1
fi
REPO=$(which repo)
if [ -z "$REPO" ]
then
mkdir -p ~/bin
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
chmod a+x ~/bin/repo
fi
if [[ "$ROM" =~ "pa" || $ROM =~ "ParanoidAndroid" ]]; then
DEVICE=ace
export ROMPROJECT=ParanoidAndroid
export MANIFESTNAME=manifest
elif [[ "$ROM" =~ "liquid" || $ROM =~ "LiquidSmooth" ]]; then
export ROMPROJECT=LiquidSmooth
export MANIFESTNAME=android
elif [[ "$ROM" =~ "slim" || $ROM =~ "SlimBean" ]]; then
export ROMPROJECT=SlimRoms
export MANIFESTNAME=platform_manifest
elif [[ "$ROM" =~ "CyanogenMod" || $ROM =~ "CyanogenMod" ]]; then
export ROMPROJECT=CyanogenMod
export MANIFESTNAME=android
else
export ROMPROJECT=CyanogenMod
export MANIFESTNAME=android
fi
if [[ "$LUNCH" =~ "cm_ace-userdebug" || $LUNCH =~ "pa_ace-userdebug" || $LUNCH =~ "liquid_ace-userdebug" || $LUNCH =~ "slim_ace-userdebug" ]]; then
DEVICE=ace
export GITHUBUSER=yanniks
elif [[ "$LUNCH" =~ "cm_mako-userdebug" || $LUNCH =~ "pa_mako-userdebug" ]]; then
DEVICE=mako
export GITHUBUSER=CyanogenMod
else
JENKINS_BUILD_DIR=$REPO_BRANCH
export GITHUBUSER=CyanogenMod
fi
if [[ "$REPO_BRANCH" =~ "cm-10.1" || $REPO_BRANCH =~ "cm-10.1" ]]; then
JENKINS_BUILD_DIR=jellybean
export REPOLOCAL=cm-10.1
elif [[ "$REPO_BRANCH" =~ "cm-10.2" || $REPO_BRANCH =~ "cm-10.2" ]]; then
JENKINS_BUILD_DIR=jellybean-4.3
export REPOLOCAL=cm-10.2
elif [[ "$REPO_BRANCH" =~ "jb43" || $REPO_BRANCH =~ "jb43-legacy" ]]; then
JENKINS_BUILD_DIR=jb43
export REPOLOCAL=jb43
elif [[ "$REPO_BRANCH" =~ "jellybean" || $REPO_BRANCH =~ "jellybean-legacy" ]]; then
JENKINS_BUILD_DIR=paranoidandroid
export REPOLOCAL=jellybean-legacy
elif [[ "$REPO_BRANCH" =~ "jb2" || $REPO_BRANCH =~ "jb2" ]]; then
JENKINS_BUILD_DIR=liquidsmooth
export REPOLOCAL=jb2
elif [[ "$REPO_BRANCH" =~ "jb4.2" || $REPO_BRANCH =~ "jb4.2" ]]; then
JENKINS_BUILD_DIR=slimbean
export REPOLOCAL=jb4.2
else
JENKINS_BUILD_DIR=$REPO_BRANCH
fi
export DEVICE=$DEVICE
rm -f $JENKINS_BUILD_DIR/out/target/product/$DEVICE/system/build.prop
export JENKINS_BUILD_DIR
mkdir -p $JENKINS_BUILD_DIR
cd $JENKINS_BUILD_DIR
# always force a fresh repo init since we can build off different branches
# and the "default" upstream branch can get stuck on whatever was init first.
if [ -z "$CORE_BRANCH" ]
then
CORE_BRANCH=$REPO_BRANCH
fi
if [ ! -z "$RELEASE_MANIFEST" ]
then
MANIFEST="-m $RELEASE_MANIFEST"
else
RELEASE_MANIFEST=""
MANIFEST=""
fi
rm -rf .repo/manifests*
rm -rf .repo/local_manifests
rm -f .repo/local_manifests/*.xml
repo init -u $SYNC_PROTO://github.com/$ROMPROJECT/$MANIFESTNAME.git -b $CORE_BRANCH $MANIFEST
if [[ "$LUNCH" =~ "cm_ace-userdebug" || $LUNCH =~ "cm_ace-eng" ]]; then
mkdir .repo/local_manifests
curl -s -o .repo/local_manifests/ace_manifest.xml https://raw.github.com/yanniks/android/$REPOLOCAL/ace_manifest.xml
elif [[ "$LUNCH" =~ "pa_ace-userdebug" || $LUNCH =~ "pa_ace-eng" ]]; then
mkdir .repo/local_manifests
curl -s -o .repo/local_manifests/ace_manifest.xml https://raw.github.com/pa-ace/android/$REPOLOCAL/ace_manifest.xml
elif [[ "$LUNCH" =~ "cm_mako-userdebug" || $LUNCH =~ "cm_mako-eng" ]]; then
mkdir .repo/local_manifests
curl -s -o .repo/local_manifests/roomservice.xml https://raw.github.com/yanniks/android/$REPOLOCAL/mako_manifest.xml
elif [[ "$LUNCH" =~ "slim_ace-userdebug" || $LUNCH =~ "slim_ace-eng" ]]; then
mkdir .repo/local_manifests
curl -s -o .repo/local_manifests/ace_manifest.xml https://raw.github.com/yanniks/android/$REPOLOCAL/ace_manifest.xml
elif [[ "$LUNCH" =~ "liquid_ace-userdebug" || $LUNCH =~ "liquid_ace-eng" ]]; then
mkdir .repo/local_manifests
curl -s -o .repo/local_manifests/ace_manifest.xml https://raw.github.com/yanniks/android/$REPOLOCAL/ace_manifest.xml
else
echo not building for ace.
fi
check_result "repo init failed."
# make sure ccache is in PATH
if [[ "$REPO_BRANCH" =~ "jellybean" || $REPO_BRANCH =~ "cm-10" ]]
then
export PATH="$PATH:/opt/local/bin/:$PWD/prebuilts/misc/$(uname|awk '{print tolower($0)}')-x86/ccache"
export CCACHE_DIR=~/.jb_ccache
else
export PATH="$PATH:/opt/local/bin/:$PWD/prebuilt/$(uname|awk '{print tolower($0)}')-x86/ccache"
export CCACHE_DIR=~/.ics_ccache
fi
if [ -f ~/.jenkins_profile ]
then
. ~/.jenkins_profile
fi
mkdir -p .repo/local_manifests
rm -f .repo/local_manifest.xml
if [ -f $WORKSPACE/build_env/bootstrap.sh ]
then
bash $WORKSPACE/build_env/bootstrap.sh
fi
echo Core Manifest:
cat .repo/manifest.xml
## TEMPORARY: Some kernels are building _into_ the source tree and messing
## up posterior syncs due to changes
rm -rf kernel/*
if [[ "$SYNCREPO" =~ "false" || $SYNCREPO =~ "nein" ]]; then
echo Skipped sync.
else
echo Syncing...
repo sync -d -c > /dev/null
check_result "repo sync failed."
echo Sync complete.
fi
if [ "$RELEASE_TYPE" = "CM_RELEASE" ]
then
if [ -f $WORKSPACE/build_env/$REPO_BRANCH-release.xml ]
then
cp -f $WORKSPACE/build_env/$REPO_BRANCH-release.xml .repo/local_manifests/dyn-$REPO_BRANCH.xml
fi
fi
if [ -f $WORKSPACE/hudson/$REPO_BRANCH-setup.sh ]
then
$WORKSPACE/hudson/$REPO_BRANCH-setup.sh
else
$WORKSPACE/hudson/cm-setup.sh
fi
if [ -f .last_branch ]
then
LAST_BRANCH=$(cat .last_branch)
else
echo "Last build branch is unknown, assume clean build"
LAST_BRANCH=$REPO_BRANCH-$CORE_BRANCH$RELEASE_MANIFEST
fi
if [ "$LAST_BRANCH" != "$REPO_BRANCH-$CORE_BRANCH$RELEASE_MANIFEST" ]
then
echo "Branch has changed since the last build happened here. Forcing cleanup."
CLEAN="true"
fi
. build/envsetup.sh
# Workaround for failing translation checks in common hardware repositories
if [ ! -z "$GERRIT_XLATION_LINT" ]
then
LUNCH=$(echo $LUNCH@$DEVICEVENDOR | sed -f $WORKSPACE/hudson/shared-repo.map)
fi
lunch $LUNCH
check_result "lunch failed."
# save manifest used for build (saving revisions as current HEAD)
# include only the auto-generated locals
TEMPSTASH=$(mktemp -d)
# save it
repo manifest -o $WORKSPACE/archive/manifest.xml -r
# restore all local manifests
mv $TEMPSTASH/* .repo/local_manifests/ 2>/dev/null
rmdir $TEMPSTASH
rm -f $OUT/*.zip*
UNAME=$(uname)
if [ ! -z "$BUILD_USER_ID" ]
then
export RELEASE_TYPE=CM_EXPERIMENTAL
fi
export SIGN_BUILD=false
if [ "$RELEASE_TYPE" = "CM_NIGHTLY" ]
then
if [ "$REPO_BRANCH" = "gingerbread" ]
then
export CYANOGEN_NIGHTLY=true
else
export CM_NIGHTLY=true
fi
elif [ "$RELEASE_TYPE" = "CM_EXPERIMENTAL" ]
then
export CM_EXPERIMENTAL=true
elif [ "$RELEASE_TYPE" = "CM_RELEASE" ]
then
# gingerbread needs this
export CYANOGEN_RELEASE=true
# ics needs this
export CM_RELEASE=true
if [ "$SIGNED" = "true" ]
then
SIGN_BUILD=true
fi
elif [ "$RELEASE_TYPE" = "CM_SNAPSHOT" ]
then
export CM_SNAPSHOT=true
if [ "$SIGNED" = "true" ]
then
SIGN_BUILD=true
fi
fi
if [ ! -z "$CM_EXTRAVERSION" ]
then
export CM_EXPERIMENTAL=true
fi
if [ ! -z "$GERRIT_CHANGES" ]
then
export CM_EXPERIMENTAL=true
IS_HTTP=$(echo $GERRIT_CHANGES | grep http)
if [ -z "$IS_HTTP" ]
then
python $WORKSPACE/hudson/repopick.py $GERRIT_CHANGES
check_result "gerrit picks failed."
else
python $WORKSPACE/hudson/repopick.py $(curl $GERRIT_CHANGES)
check_result "gerrit picks failed."
fi
if [ ! -z "$GERRIT_XLATION_LINT" ]
then
python $WORKSPACE/hudson/xlationlint.py $GERRIT_CHANGES
check_result "basic XML lint failed."
fi
fi
if [ ! "$(ccache -s|grep -E 'max cache size'|awk '{print $4}')" = "100.0" ]
then
ccache -M 100G
fi
rm -f $WORKSPACE/changecount
WORKSPACE=$WORKSPACE LUNCH=$LUNCH bash $WORKSPACE/hudson/changes/buildlog.sh 2>&1
if [ -f $WORKSPACE/changecount ]
then
CHANGE_COUNT=$(cat $WORKSPACE/changecount)
rm -f $WORKSPACE/changecount
if [ $CHANGE_COUNT -eq "0" ]
then
echo "Zero changes since last build, aborting"
exit 0
fi
fi
LAST_CLEAN=0
if [ -f .clean ]
then
LAST_CLEAN=$(date -r .clean +%s)
fi
TIME_SINCE_LAST_CLEAN=$(expr $(date +%s) - $LAST_CLEAN)
# convert this to hours
TIME_SINCE_LAST_CLEAN=$(expr $TIME_SINCE_LAST_CLEAN / 60 / 60)
if [ $TIME_SINCE_LAST_CLEAN -gt "24" -o $CLEAN = "true" ]
then
echo "Cleaning!"
touch .clean
make clobber
else
echo "Skipping clean: $TIME_SINCE_LAST_CLEAN hours since last clean."
fi
echo "$REPO_BRANCH-$CORE_BRANCH$RELEASE_MANIFEST" > .last_branch
if [ "$ROM" = "LiquidSmooth" ]
then
time make
else
time mka bacon
fi
check_result "Build failed."
if [ "$SIGN_BUILD" = "true" ]
then
MODVERSION=$(cat $OUT/system/build.prop | grep ro.modversion | cut -d = -f 2)
if [ ! -z "$MODVERSION" -a -f $OUT/obj/PACKAGING/target_files_intermediates/$TARGET_PRODUCT-target_files-$BUILD_NUMBER.zip ]
then
./build/tools/releasetools/sign_target_files_apks -e Term.apk= -d vendor/cm-priv/keys $OUT/obj/PACKAGING/target_files_intermediates/$TARGET_PRODUCT-target_files-$BUILD_NUMBER.zip $OUT/$MODVERSION-signed-intermediate.zip
./build/tools/releasetools/ota_from_target_files -k vendor/cm-priv/keys/releasekey $OUT/$MODVERSION-signed-intermediate.zip $WORKSPACE/archive/cm-$MODVERSION-signed.zip
else
echo "Unable to find target files to sign"
exit 1
fi
else
for f in $(ls $OUT/*.zip*)
do
ln $f $WORKSPACE/archive/$(basename $f)
done
fi
if [ -f $OUT/utilties/update.zip ]
then
cp $OUT/utilties/update.zip $WORKSPACE/archive/recovery.zip
fi
if [ -f $OUT/recovery.img ]
then
cp $OUT/recovery.img $WORKSPACE/archive
fi
# archive the build.prop as well
ZIP=$(ls $WORKSPACE/archive/*.zip)
unzip -p $ZIP system/build.prop > $WORKSPACE/archive/build.prop
# CORE: save manifest used for build (saving revisions as current HEAD)
rm -f .repo/local_manifests/dyn-$REPO_BRANCH.xml
rm -f .repo/local_manifests/roomservice.xml
# Stash away other possible manifests
TEMPSTASH=$(mktemp -d)
mv .repo/local_manifests $TEMPSTASH
repo manifest -o $WORKSPACE/archive/core.xml -r
mv $TEMPSTASH/local_manifests .repo
rmdir $TEMPSTASH
# chmod the files in case UMASK blocks permissions
chmod -R ugo+r $WORKSPACE/archive
CMCP=$(which cmcp)
if [ ! -z "$CMCP" -a ! -z "$CM_RELEASE" ]
then
MODVERSION=$(cat $WORKSPACE/archive/build.prop | grep ro.modversion | cut -d = -f 2)
if [ -z "$MODVERSION" ]
then
MODVERSION=$(cat $WORKSPACE/archive/build.prop | grep ro.cm.version | cut -d = -f 2)
fi
if [ -z "$MODVERSION" ]
then
echo "Unable to detect ro.modversion or ro.cm.version."
exit 1
fi
echo Archiving release to S3.
for f in $(ls $WORKSPACE/archive)
do
cmcp $WORKSPACE/archive/$f release/$MODVERSION/$f > /dev/null 2> /dev/null
check_result "Failure archiving $f"
done
fi
rm /home/yannik/workspace/android/$JENKINS_BUILD_DIR/out/target/product/$DEVICE/*ota-eng*.zip
if [[ "$UPLOAD" =~ "true" || $UPLOAD =~ "ja" ]]; then
if [ "$APPLYUPDATE" = "true" ]
then
adb shell rm /sdcard/Download/rom-update.zip
adb push /home/yannik/workspace/android/$JENKINS_BUILD_DIR/out/target/product/$DEVICE/*.zip /sdcard/Download/rom-update.zip
adb shell su -c "mkdir -p /cache/recovery"
adb shell su -c "echo 'boot-recovery' > /cache/recovery/command"
adb shell su -c "echo '--update_package=/sdcard/Download/rom-update.zip' >> /cache/recovery/command"
adb reboot recovery
else
echo skipped test installation!
fi
cd /home/yannik/workspace/android/$JENKINS_BUILD_DIR/out/target/product/$DEVICE/
if [ "$REPO_BRANCH" = "cm-10.2" ]
then
mv /home/yannik/workspace/android/$JENKINS_BUILD_DIR/out/target/product/$DEVICE/*zip* $UPLOADPATH/$FOLDERPREFIX-$DEVICE-buildbot-4.3
else
mv /home/yannik/workspace/android/$JENKINS_BUILD_DIR/out/target/product/$DEVICE/*zip* $UPLOADPATH/$FOLDERPREFIX-$DEVICE-buildbot
fi
if [ "$RELEASE_TYPE" = "CM_RELEASE" ]
then
if [ "$platform" = "Darwin" ]
then
/Users/yannik/cm-changes.sh
else
/home/yannik/cm-changes.sh
fi
else
echo not a release build!
fi
elif [[ "$UPLOAD" =~ "testcompile" || $UPLOAD =~ "sofortloeschen" ]]; then
rm $OUT/*.zip*
else
if [ "$APPLYUPDATE" = "true" ]
then
adb shell rm /sdcard/Download/rom-update.zip
adb push /home/yannik/workspace/android/$JENKINS_BUILD_DIR/out/target/product/$DEVICE/*.zip /sdcard/Download/rom-update.zip
adb shell su -c "mkdir -p /cache/recovery"
adb shell su -c "echo 'boot-recovery' > /cache/recovery/command"
adb shell su -c "echo '--update_package=/sdcard/Download/rom-update.zip' >> /cache/recovery/command"
adb reboot recovery
else
echo skipped test installation!
fi
echo not uploading
fi
if [ "$DELETEOUT" = "true" ]
then
echo deleting build directory...
rm -rf /home/yannik/workspace/android/$JENKINS_BUILD_DIR/out
echo done!
else
echo not deleting build directory.
fi