forked from phhusson/treble_experimentations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-dakkar.sh
391 lines (347 loc) · 11.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
#!/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
read -p "Do you want to sync? (y/N) " choice
function help() {
cat <<EOF
Syntax:
$myname [-j 2] <rom type> <variant>...
Options:
-j number of parallel make workers (defaults to $jobs)
ROM types:
aosp80
aosp81
aosp90
carbon
e-0.2
lineage151
lineage160
rr
pixel81
pixel90
crdroid
mokee
aicp
aokp
aex
slim
havoc
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=""
;;
aosp81)
mainrepo="https://android.googlesource.com/platform/manifest.git"
mainbranch="android-8.1.0_r48"
localManifestBranch="android-8.1"
treble_generate=""
extra_make_options=""
;;
aosp90)
mainrepo="https://android.googlesource.com/platform/manifest.git"
mainbranch="android-9.0.0_r21"
localManifestBranch="android-9.0"
treble_generate=""
extra_make_options=""
;;
carbon)
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"
;;
e-0.2)
mainrepo="https://gitlab.e.foundation/e/os/android/"
mainbranch="eelo-0.2"
localManifestBranch="android-9.0"
treble_generate="lineage"
extra_make_options="WITHOUT_CHECK_API=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"
;;
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"
;;
rr)
mainrepo="https://github.com/ResurrectionRemix/platform_manifest.git"
mainbranch="oreo"
localManifestBranch="android-8.1"
treble_generate="rr"
extra_make_options="WITHOUT_CHECK_API=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"
;;
pixel90)
mainrepo="https://github.com/PixelExperience/manifest.git"
mainbranch="pie"
localManifestBranch="android-9.0"
treble_generate="pixel"
extra_make_options="WITHOUT_CHECK_API=true"
;;
crdroid)
mainrepo="https://github.com/crdroidandroid/android.git"
mainbranch="8.1"
localManifestBranch="android-8.1"
treble_generate="crdroid"
extra_make_options="WITHOUT_CHECK_API=true"
;;
mokee)
mainrepo="https://github.com/MoKee/android.git"
mainbranch="mko-mr1"
localManifestBranch="android-8.1"
treble_generate="mokee"
extra_make_options="WITHOUT_CHECK_API=true"
;;
aicp)
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"
;;
aokp)
mainrepo="https://github.com/AOKP/platform_manifest.git"
mainbranch="oreo"
localManifestBranch="android-8.1"
treble_generate="aokp"
extra_make_options="WITHOUT_CHECK_API=true"
;;
aex)
mainrepo="https://github.com/AospExtended/manifest.git"
mainbranch="9.x"
localManifestBranch="android-9.0"
treble_generate="aex"
extra_make_options="WITHOUT_CHECK_API=true"
;;
slim)
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"
;;
havoc)
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"
;;
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
}
function init_patches() {
if [[ -n "$treble_generate" ]]; then
clone_or_checkout patches treble_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
}
function sync_repo() {
repo sync -c -j "$jobs" -f --force-sync --no-tag --no-clone-bundle --optimized-fetch --prune
}
function patch_things() {
if [[ -n "$treble_generate" ]]; then
rm -f device/*/sepolicy/common/private/genfs_contexts
(
cd device/phh/treble
if [[ $choice == *"y"* ]];then
git clean -fdx
fi
bash generate.sh "$treble_generate"
)
bash "$(dirname "$0")/apply-patches.sh" patches
else
(
cd device/phh/treble
git clean -fdx
bash generate.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 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
}
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 [[ $choice == *"y"* ]];then
init_main_repo
init_local_manifest
init_patches
sync_repo
fi
patch_things
jack_env
. build/envsetup.sh
for (( idx=0; idx < ${#variant_codes[*]}; idx++ )); do
build_variant "${variant_codes[$idx]}" "${variant_names[$idx]}"
done