forked from phhusson/treble_experimentations
-
Notifications
You must be signed in to change notification settings - Fork 31
/
build-dakkar.sh
557 lines (506 loc) · 17.2 KB
/
build-dakkar.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
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
#!/bin/bash
set -e
if [ -z "$USER" ];then
export USER="$(id -un)"
fi
export LC_ALL=C
export GAPPS_SOURCES_PATH=vendor/opengapps/sources/
## set defaults
rom_fp="$(date +%y%m%d)"
myname="$(basename "$0")"
if [[ $(uname -s) = "Darwin" ]];then
jobs=$(sysctl -n hw.ncpu)
elif [[ $(uname -s) = "Linux" ]];then
jobs=$(nproc)
fi
## handle command line arguments
if [[ -v build_dakkar_choice ]]
then
echo "Using exported choice"
else
read -p "Do you want to sync? (y/N) " build_dakkar_choice
fi
function help() {
cat <<EOF
Syntax:
$myname [-j 2] <rom type> <variant>...
Options:
-j number of parallel make workers (defaults to $jobs)
ROM types:
aex-pie
aicp-oreo
aokp-oreo
aosmp-pie
aosp80
aosp81
aosp90
aosp10
aquarios
carbon-oreo
crdroid-oreo
e-pie
e-oreo
havoc-pie
komodo-pie
lineage151
lineage160
mokee-oreo
pixel81
pixel90
potato-pie
rebellion-pie
rr-oreo
slim-oreo
graphene9
graphene10
Variants are dash-joined combinations of (in order):
* processor type
* "arm" for ARM 32 bit
* "arm64" for ARM 64 bit
* "a64" for ARM 32 bit system with 64 bit binder
* A or A/B partition layout ("aonly" or "ab")
* GApps selection
* "vanilla" to not include GApps
* "gapps" to include opengapps
* "go" to include gapps go
* "floss" to include floss
* SU selection ("su" or "nosu")
* Build variant selection (optional)
* "eng" for eng build
* "user" for prod build
* "userdebug" for debug build (default)
for example:
* arm-aonly-vanilla-nosu-user
* arm64-ab-gapps-su
* a64-aonly-go-nosu
EOF
}
function get_rom_type() {
while [[ $# -gt 0 ]]; do
case "$1" in
aosp80)
mainrepo="https://android.googlesource.com/platform/manifest.git"
mainbranch="android-vts-8.0_r4"
localManifestBranch="master"
treble_generate=""
extra_make_options=""
jack_enabled="true"
;;
aosp81)
mainrepo="https://android.googlesource.com/platform/manifest.git"
mainbranch="android-8.1.0_r48"
localManifestBranch="android-8.1"
treble_generate=""
extra_make_options=""
jack_enabled="true"
;;
aosp90)
mainrepo="https://android.googlesource.com/platform/manifest.git"
mainbranch="android-9.0.0_r21"
localManifestBranch="android-9.0"
treble_generate=""
extra_make_options=""
jack_enabled="false"
;;
aosp10)
mainrepo="https://android.googlesource.com/platform/manifest.git"
mainbranch="android-10.0.0_r41"
localManifestBranch="android-10.0"
treble_generate=""
extra_make_options=""
jack_enabled="false"
;;
carbon-oreo)
mainrepo="https://github.com/CarbonROM/android.git"
mainbranch="cr-6.1"
localManifestBranch="android-8.1"
treble_generate="carbon"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="true"
;;
e-pie)
mainrepo="https://gitlab.e.foundation/e/os/android/"
mainbranch="v1-pie"
localManifestBranch="android-9.0"
treble_generate="lineage"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="false"
;;
e-oreo)
mainrepo="https://gitlab.e.foundation/e/os/android/"
mainbranch="v1-oreo"
localManifestBranch="android-8.1"
treble_generate="lineage"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="true"
;;
lineage151)
mainrepo="https://github.com/LineageOS/android.git"
mainbranch="lineage-15.1"
localManifestBranch="android-8.1"
treble_generate="lineage"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="true"
;;
lineage160)
mainrepo="https://github.com/LineageOS/android.git"
mainbranch="lineage-16.0"
localManifestBranch="android-9.0"
treble_generate="lineage"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="false"
;;
rr-oreo)
mainrepo="https://github.com/ResurrectionRemix/platform_manifest.git"
mainbranch="oreo"
localManifestBranch="android-8.1"
treble_generate="rr"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="true"
;;
pixel81)
mainrepo="https://github.com/PixelExperience/manifest.git"
mainbranch="oreo-mr1"
localManifestBranch="android-8.1"
treble_generate="pixel"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="true"
;;
pixel90)
mainrepo="https://github.com/PixelExperience/manifest.git"
mainbranch="pie"
localManifestBranch="android-9.0"
treble_generate="pixel"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="false"
;;
potato-pie)
mainrepo="https://github.com/PotatoProject/manifest.git"
mainbranch="baked-release"
localManifestBranch="android-9.0"
treble_generate="potato"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="false"
;;
crdroid-oreo)
mainrepo="https://github.com/crdroidandroid/android.git"
mainbranch="8.1"
localManifestBranch="android-8.1"
treble_generate="crdroid"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="true"
;;
mokee-oreo)
mainrepo="https://github.com/mokee/android.git"
mainbranch="mko-mr1"
localManifestBranch="android-8.1"
treble_generate="mokee"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="true"
;;
aicp-oreo)
mainrepo="https://github.com/AICP/platform_manifest.git"
mainbranch="o8.1"
localManifestBranch="android-8.1"
treble_generate="aicp"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="true"
;;
aokp-oreo)
mainrepo="https://github.com/AOKP/platform_manifest.git"
mainbranch="oreo"
localManifestBranch="android-8.1"
treble_generate="aokp"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="true"
;;
aex-pie)
mainrepo="https://github.com/AospExtended/manifest.git"
mainbranch="9.x"
localManifestBranch="android-9.0"
treble_generate="aex"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="false"
;;
slim-oreo)
mainrepo="https://github.com/SlimRoms/platform_manifest.git"
mainbranch="or8.1"
localManifestBranch="android-8.1"
treble_generate="slim"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="true"
;;
havoc-pie)
mainrepo="https://github.com/Havoc-OS/android_manifest.git"
mainbranch="pie"
localManifestBranch="android-9.0"
treble_generate="havoc"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="false"
;;
komodo-pie)
mainrepo="https://github.com/KomodOS-Rom/platform_manifest.git"
mainbranch="pie"
localManifestBranch="android-9.0"
treble_generate="komodo"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="false"
;;
rebellion-pie)
mainrepo="https://github.com/RebellionOS/manifest.git"
mainbranch="pie"
localManifestBranch="android-9.0"
treble_generate="rebellion"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="false"
;;
aquarios)
mainrepo="https://github.com/aquarios/manifest.git"
mainbranch="a9"
localManifestBranch="android-9.0"
treble_generate="aquarios"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="false"
;;
aosmp-pie)
mainrepo="https://gitlab.com/AOSmP/android_manifest.git"
mainbranch="pie"
localManifestBranch="android-9.0"
treble_generate="aosmp"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="false"
;;
graphene10)
mainrepo="https://github.com/GrapheneOS/platform_manifest.git"
mainbranch="10"
localManifestBranch="android-10.0"
treble_generate="graphene"
extra_make_options="WITHOUT_CHECK_API=true"
jack_enabled="false"
esac
shift
done
}
function parse_options() {
while [[ $# -gt 0 ]]; do
case "$1" in
-j)
jobs="$2";
shift;
;;
esac
shift
done
}
declare -A partition_layout_map
partition_layout_map[aonly]=a
partition_layout_map[ab]=b
declare -A gapps_selection_map
gapps_selection_map[vanilla]=v
gapps_selection_map[gapps]=g
gapps_selection_map[go]=o
gapps_selection_map[floss]=f
declare -A su_selection_map
su_selection_map[su]=S
su_selection_map[nosu]=N
function parse_variant() {
local -a pieces
IFS=- pieces=( $1 )
local processor_type=${pieces[0]}
local partition_layout=${partition_layout_map[${pieces[1]}]}
local gapps_selection=${gapps_selection_map[${pieces[2]}]}
local su_selection=${su_selection_map[${pieces[3]}]}
local build_type_selection=${pieces[4]}
if [[ -z "$processor_type" || -z "$partition_layout" || -z "$gapps_selection" || -z "$su_selection" ]]; then
>&2 echo "Invalid variant '$1'"
>&2 help
exit 2
fi
echo "treble_${processor_type}_${partition_layout}${gapps_selection}${su_selection}-${build_type_selection}"
}
declare -a variant_codes
declare -a variant_names
function get_variants() {
while [[ $# -gt 0 ]]; do
case "$1" in
*-*-*-*-*)
variant_codes[${#variant_codes[*]}]=$(parse_variant "$1")
variant_names[${#variant_names[*]}]="$1"
;;
*-*-*-*)
variant_codes[${#variant_codes[*]}]=$(parse_variant "$1-userdebug")
variant_names[${#variant_names[*]}]="$1"
;;
esac
shift
done
}
## function that actually do things
function init_release() {
mkdir -p release/"$rom_fp"
}
function init_main_repo() {
repo init -u "$mainrepo" -b "$mainbranch"
}
function clone_or_checkout() {
local dir="$1"
local repo="$2"
if [[ -d "$dir" ]];then
(
cd "$dir"
git fetch
git reset --hard
git checkout origin/"$localManifestBranch"
)
else
git clone https://github.com/phhusson/"$repo" "$dir" -b "$localManifestBranch"
fi
}
function init_local_manifest() {
clone_or_checkout .repo/local_manifests treble_manifest
}
download_patches() {
echo "Downloading Patches..."
if [[ $localManifestBranch == android-10.0 ]];then
githubMatch=v2..
elif [[ $localManifestBranch == android-9.0 ]];then
githubMatch=v1..
else
githubMatch=v..
fi
jq --help > /dev/null
wantedRelease="$(curl --silent https://api.github.com/repos/phhusson/treble_experimentations/releases |jq -r '.[] | .tag_name' |grep -E "$githubMatch\$" |sort -V | tail -n 1)"
wget "https://github.com/phhusson/treble_experimentations/releases/download/$wantedRelease/patches.zip" -O patches.zip
rm -Rf patches
unzip patches.zip -d patches
echo " ...done Downloading Patches"
}
function init_patches() {
echo "Initializing Patches..."
echo " ...treble_generate="$treble_generate
if [[ -n "$treble_generate" ]]; then
download_patches
# We don't want to replace from AOSP since we'll be applying
# patches by hand
rm -f .repo/local_manifests/replace.xml
# Remove exfat entry from local_manifest if it exists in ROM manifest
if grep -rqF exfat .repo/manifests || grep -qF exfat .repo/manifest.xml;then
sed -i -E '/external\/exfat/d' .repo/local_manifests/manifest.xml
fi
# should I do this? will it interfere with building non-gapps images?
# rm -f .repo/local_manifests/opengapps.xml
fi
echo " ...done Initializing Patches"
}
function sync_repo() {
repo sync -c -j "$jobs" -f --force-sync --no-tag --no-clone-bundle --optimized-fetch --prune
}
function patch_things() {
echo "Patching Things..."
echo " ...treble_generate="$treble_generate
if [[ -n "$treble_generate" ]]; then
echo " ...removing sepolicies"
rm -f device/*/sepolicy/common/private/genfs_contexts
(
cd device/phh/treble
if [[ $build_dakkar_choice == *"y"* ]];then
git clean -fdx
fi
bash generate.sh "$treble_generate"
)
bash "$(dirname "$0")/apply-patches.sh" patches
else
echo " ...generating Makefiles"
(
cd device/phh/treble
git clean -fdx
bash generate.sh
)
echo " ...calling list-patches.sh"
repo manifest -r > release/"$rom_fp"/manifest.xml
bash "$(dirname "$0")"/list-patches.sh
cp patches.zip release/"$rom_fp"/patches.zip
fi
}
function fix_missings() {
if [[ "$localManifestBranch" == *"9"* ]]; then
rm -rf vendor/*/packages/overlays/NoCutout*
# fix kernel source missing (on pie)
sed 's;.*KERNEL_;//&;' -i vendor/*/build/soong/Android.bp 2>/dev/null || true
mkdir -p device/sample/etc
cd device/sample/etc/
curl "https://android.googlesource.com/device/sample/+/refs/tags/android-9.0.0_r59/etc/apns-full-conf.xml?format=TEXT"| base64 --decode > apns-full-conf.xml
cd ../../..
fi
if [[ "$localManifestBranch" == *"10"* ]]; then
rm -rf vendor/*/packages/overlays/NoCutout*
# fix kernel source missing (on Q)
sed 's;.*KERNEL_;//&;' -i vendor/*/build/soong/Android.bp 2>/dev/null || true
mkdir -p device/sample/etc
cd device/sample/etc
curl "https://raw.githubusercontent.com/LineageOS/android_vendor_lineage/lineage-17.1/prebuilt/common/etc/apns-conf.xml" > apns-conf.xml
cd ../../..
mkdir -p device/generic/common/nfc
cd device/generic/common/nfc
curl "https://android.googlesource.com/device/generic/common/+/refs/tags/android-10.0.0_r40/nfc/libnfc-nci.conf?format=TEXT"| base64 --decode > libnfc-nci.conf
cd ../../../..
sed -i '/Copies the APN/,/include $(BUILD_PREBUILT)/{/include $(BUILD_PREBUILT)/ s/.*/ /; t; d}' vendor/*/prebuilt/common/Android.mk 2>/dev/null || true
fi
}
function build_variant() {
lunch "$1"
make $extra_make_options BUILD_NUMBER="$rom_fp" installclean
make $extra_make_options BUILD_NUMBER="$rom_fp" -j "$jobs" systemimage
make $extra_make_options BUILD_NUMBER="$rom_fp" vndk-test-sepolicy
cp "$OUT"/system.img release/"$rom_fp"/system-"$2".img
}
function jack_env() {
RAM=$(free | awk '/^Mem:/{ printf("%0.f", $2/(1024^2))}') #calculating how much RAM (wow, such ram)
if [[ "$RAM" -lt 16 ]];then #if we're poor guys with less than 16gb
export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx"$((RAM -1))"G"
fi
}
function clean_build() {
make installclean
rm -rf "$OUT"
}
parse_options "$@"
get_rom_type "$@"
get_variants "$@"
if [[ -z "$mainrepo" || ${#variant_codes[*]} -eq 0 ]]; then
>&2 help
exit 1
fi
# Use a python2 virtualenv if system python is python3
python=$(python -V | awk '{print $2}' | head -c2)
if [[ $python == "3." ]]; then
if [ ! -d .venv ]; then
virtualenv2 .venv
fi
. .venv/bin/activate
fi
init_release
if [[ $build_dakkar_choice == *"y"* ]];then
init_main_repo
init_local_manifest
init_patches
sync_repo
fix_missings
fi
patch_things
if [[ $jack_enabled == "true" ]]; then
jack_env
fi
if [[ -v build_dakkar_clean ]]
then
echo "Using exported clean choice"
else
read -p "Do you want to clean? (y/N) " build_dakkar_clean
fi
if [[ $build_dakkar_clean == *"y"* ]];then
clean_build
fi
. build/envsetup.sh
for (( idx=0; idx < ${#variant_codes[*]}; idx++ )); do
build_variant "${variant_codes[$idx]}" "${variant_names[$idx]}"
done