forked from Lumi-Academy/android_device_samsung_m23xq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_utils_local.sh
2003 lines (1787 loc) · 66.5 KB
/
extract_utils_local.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
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
# Copyright (C) 2016 The CyanogenMod Project
# Copyright (C) 2017-2023 The LineageOS Project
#
# SPDX-License-Identifier: Apache-2.0
#
PRODUCT_COPY_FILES_LIST=()
PRODUCT_COPY_FILES_HASHES=()
PRODUCT_COPY_FILES_FIXUP_HASHES=()
PRODUCT_PACKAGES_LIST=()
PRODUCT_PACKAGES_HASHES=()
PRODUCT_PACKAGES_FIXUP_HASHES=()
PACKAGE_LIST=()
EXTRACT_SRC=
EXTRACT_STATE=-1
VENDOR_STATE=-1
VENDOR_RADIO_STATE=-1
COMMON=-1
ARCHES=
FULLY_DEODEXED=-1
KEEP_DUMP=${KEEP_DUMP:-0}
SKIP_CLEANUP=${SKIP_CLEANUP:-0}
EXTRACT_TMP_DIR=$(mktemp -d)
HOST="$(uname | tr '[:upper:]' '[:lower:]')"
#
# cleanup
#
# kill our tmpfiles with fire on exit
#
function cleanup() {
if [ "$SKIP_CLEANUP" == "true" ] || [ "$SKIP_CLEANUP" == "1" ]; then
echo "Skipping cleanup of $EXTRACT_TMP_DIR"
else
rm -rf "${EXTRACT_TMP_DIR:?}"
fi
}
trap cleanup 0
#
# setup_vendor_deps
#
# $1: Android root directory
# Sets up common dependencies for extraction
#
function setup_vendor_deps() {
export ANDROID_ROOT="$1"
if [ ! -d "$ANDROID_ROOT" ]; then
echo "\$ANDROID_ROOT must be set and valid before including this script!"
exit 1
fi
export BINARIES_LOCATION="$ANDROID_ROOT"/prebuilts/extract-tools/${HOST}-x86/bin
export SIMG2IMG="$BINARIES_LOCATION"/simg2img
export LPUNPACK="$BINARIES_LOCATION"/lpunpack
export SIGSCAN="$BINARIES_LOCATION"/SigScan
for version in 0_8 0_9 0_17_2; do
export PATCHELF_${version}="$BINARIES_LOCATION"/patchelf-"${version}"
done
if [ -z "$PATCHELF_VERSION" ]; then
export PATCHELF_VERSION=0_9
fi
if [ -z "$PATCHELF" ]; then
local patchelf_variable="PATCHELF_${PATCHELF_VERSION}"
export PATCHELF=${!patchelf_variable}
fi
}
#
# setup_vendor
#
# $1: device name
# $2: vendor name
# $3: Android root directory
# $4: is common device - optional, default to false
# $5: cleanup - optional, default to true
# $6: custom vendor makefile name - optional, default to false
#
# Must be called before any other functions can be used. This
# sets up the internal state for a new vendor configuration.
#
function setup_vendor() {
local DEVICE="$1"
if [ -z "$DEVICE" ]; then
echo "\$DEVICE must be set before including this script!"
exit 1
fi
local VENDOR="$2"
if [ -z "$VENDOR" ]; then
echo "\$VENDOR must be set before including this script!"
exit 1
fi
export ANDROID_ROOT="$3"
if [ ! -d "$ANDROID_ROOT" ]; then
echo "\$ANDROID_ROOT must be set and valid before including this script!"
exit 1
fi
export OUTDIR=vendor/"$VENDOR"/"$DEVICE"
if [ ! -d "$ANDROID_ROOT/$OUTDIR" ]; then
mkdir -p "$ANDROID_ROOT/$OUTDIR"
fi
VNDNAME="$6"
if [ -z "$VNDNAME" ]; then
VNDNAME="$DEVICE"
fi
export PRODUCTMK="$ANDROID_ROOT"/"$OUTDIR"/"$VNDNAME"-vendor.mk
export ANDROIDBP="$ANDROID_ROOT"/"$OUTDIR"/Android.bp
export ANDROIDMK="$ANDROID_ROOT"/"$OUTDIR"/Android.mk
export BOARDMK="$ANDROID_ROOT"/"$OUTDIR"/BoardConfigVendor.mk
if [ "$4" == "true" ] || [ "$4" == "1" ]; then
COMMON=1
else
COMMON=0
fi
if [ "$5" == "false" ] || [ "$5" == "0" ]; then
VENDOR_STATE=1
VENDOR_RADIO_STATE=1
else
VENDOR_STATE=0
VENDOR_RADIO_STATE=0
fi
setup_vendor_deps "$ANDROID_ROOT"
}
# Helper functions for parsing a spec.
# notes: an optional "|SHA1" that may appear in the format is stripped
# early from the spec in the parse_file_list function, and
# should not be present inside the input parameter passed
# to these functions.
#
# input: spec in the form of "src[:dst][;args]"
# output: "src"
#
function src_file() {
local SPEC="$1"
local SPLIT=(${SPEC//:/ })
local ARGS="$(target_args ${SPEC})"
# Regardless of there being a ":" delimiter or not in the spec,
# the source file is always either the first, or the only entry.
local SRC="${SPLIT[0]}"
# Remove target_args suffix, if present
echo "${SRC%;${ARGS}}"
}
#
# input: spec in the form of "src[:dst][;args]"
# output: "dst" if present, "src" otherwise.
#
function target_file() {
local SPEC="${1%%;*}"
local SPLIT=(${SPEC//:/ })
local ARGS="$(target_args ${SPEC})"
local DST=
case ${#SPLIT[@]} in
1)
# The spec doesn't have a : delimiter
DST="${SPLIT[0]}"
;;
*)
# The spec actually has a src:dst format
DST="${SPLIT[1]}"
;;
esac
# Remove target_args suffix, if present
echo "${DST%;${ARGS}}"
}
#
# input: spec in the form of "src[:dst][;args]"
# output: "args" if present, "" otherwise.
#
function target_args() {
local SPEC="$1"
local SPLIT=(${SPEC//;/ })
local ARGS=
case ${#SPLIT[@]} in
1)
# No ";" delimiter in the spec.
;;
*)
# The "args" are whatever comes after the ";" character.
# Basically the spec stripped of whatever is to the left of ";".
ARGS="${SPEC#${SPLIT[0]};}"
;;
esac
echo "${ARGS}"
}
#
# prefix_match:
#
# input:
# - $1: prefix
# - (global variable) PRODUCT_PACKAGES_LIST: array of [src:]dst[;args] specs.
# output:
# - new array consisting of dst[;args] entries where $1 is a prefix of ${dst}.
#
function prefix_match() {
local PREFIX="$1"
for LINE in "${PRODUCT_PACKAGES_LIST[@]}"; do
local FILE=$(target_file "$LINE")
if [[ "$FILE" =~ ^"$PREFIX" ]]; then
local ARGS=$(target_args "$LINE")
if [ -z "${ARGS}" ]; then
echo "${FILE#$PREFIX}"
else
echo "${FILE#$PREFIX};${ARGS}"
fi
fi
done
}
#
# prefix_match_file:
#
# $1: the prefix to match on
# $2: the file to match the prefix for
#
# Internal function which returns true if a filename contains the
# specified prefix.
#
function prefix_match_file() {
local PREFIX="$1"
local FILE="$2"
if [[ "$FILE" =~ ^"$PREFIX" ]]; then
return 0
else
return 1
fi
}
#
# suffix_match_file:
#
# $1: the suffix to match on
# $2: the file to match the suffix for
#
# Internal function which returns true if a filename contains the
# specified suffix.
#
function suffix_match_file() {
local SUFFIX="$1"
local FILE="$2"
if [[ "$FILE" = *"$SUFFIX" ]]; then
return 0
else
return 1
fi
}
#
# truncate_file
#
# $1: the filename to truncate
# $2: the argument to output the truncated filename to
#
# Internal function which truncates a filename by removing the first dir
# in the path. ex. vendor/lib/libsdmextension.so -> lib/libsdmextension.so
#
function truncate_file() {
local FILE="$1"
RETURN_FILE="$2"
local FIND="${FILE%%/*}"
local LOCATION="${#FIND}+1"
echo ${FILE:$LOCATION}
}
#
# write_product_copy_files:
#
# $1: make treble compatible makefile - optional and deprecated, default to true
#
# Creates the PRODUCT_COPY_FILES section in the product makefile for all
# items in the list which do not start with a dash (-).
#
function write_product_copy_files() {
local COUNT=${#PRODUCT_COPY_FILES_LIST[@]}
local TARGET=
local FILE=
local LINEEND=
local TREBLE_COMPAT=$1
if [ "$COUNT" -eq "0" ]; then
return 0
fi
printf '%s\n' "PRODUCT_COPY_FILES += \\" >> "$PRODUCTMK"
for (( i=1; i<COUNT+1; i++ )); do
FILE="${PRODUCT_COPY_FILES_LIST[$i-1]}"
LINEEND=" \\"
if [ "$i" -eq "$COUNT" ]; then
LINEEND=""
fi
TARGET=$(target_file "$FILE")
if prefix_match_file "product/" $TARGET ; then
local OUTTARGET=$(truncate_file $TARGET)
printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s%s\n' \
"$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
elif prefix_match_file "system/product/" $TARGET ; then
local OUTTARGET=$(truncate_file $TARGET)
printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s%s\n' \
"$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
elif prefix_match_file "system_ext/" $TARGET ; then
local OUTTARGET=$(truncate_file $TARGET)
printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM_EXT)/%s%s\n' \
"$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
elif prefix_match_file "system/system_ext/" $TARGET ; then
local OUTTARGET=$(truncate_file $TARGET)
printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM_EXT)/%s%s\n' \
"$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
elif prefix_match_file "odm/" $TARGET ; then
local OUTTARGET=$(truncate_file $TARGET)
printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \
"$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
elif prefix_match_file "vendor/odm/" $TARGET ; then
local OUTTARGET=$(truncate_file $TARGET)
printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \
"$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
elif prefix_match_file "system/vendor/odm/" $TARGET ; then
local OUTTARGET=$(truncate_file $TARGET)
printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \
"$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
elif prefix_match_file "vendor/" $TARGET ; then
local OUTTARGET=$(truncate_file $TARGET)
printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR)/%s%s\n' \
"$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
elif prefix_match_file "vendor_dlkm/" $TARGET ; then
local OUTTARGET=$(truncate_file $TARGET)
printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR_DLKM)/%s%s\n' \
"$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
elif prefix_match_file "system/vendor/" $TARGET ; then
local OUTTARGET=$(truncate_file $TARGET)
printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR)/%s%s\n' \
"$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
elif prefix_match_file "system/" $TARGET ; then
local OUTTARGET=$(truncate_file $TARGET)
printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM)/%s%s\n' \
"$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
elif prefix_match_file "recovery/" $TARGET ; then
local OUTTARGET=$(truncate_file $TARGET)
printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_RECOVERY)/%s%s\n' \
"$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
elif prefix_match_file "vendor_ramdisk/" $TARGET ; then
local OUTTARGET=$(truncate_file $TARGET)
printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR_RAMDISK)/%s%s\n' \
"$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
else
printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM)/%s%s\n' \
"$OUTDIR" "$TARGET" "$TARGET" "$LINEEND" >> "$PRODUCTMK"
fi
done
return 0
}
#
# write_blueprint_packages:
#
# $1: The LOCAL_MODULE_CLASS for the given module list
# $2: /system, /odm, /product, /system_ext, or /vendor partition
# $3: type-specific extra flags
# $4: Name of the array holding the target list
#
# Internal function which writes out the BUILD_PREBUILT stanzas
# for all modules in the list. This is called by write_product_packages
# after the modules are categorized.
#
function write_blueprint_packages() {
local CLASS="$1"
local PARTITION="$2"
local EXTRA="$3"
# Yes, this is a horrible hack - we create a new array using indirection
local ARR_NAME="$4[@]"
local FILELIST=("${!ARR_NAME}")
local FILE=
local ARGS=
local BASENAME=
local EXTENSION=
local PKGNAME=
local SRC=
local STEM=
local OVERRIDEPKG=
[ "$COMMON" -eq 1 ] && local VENDOR="${VENDOR_COMMON:-$VENDOR}"
for P in "${FILELIST[@]}"; do
FILE=$(target_file "$P")
ARGS=$(target_args "$P")
ARGS=(${ARGS//;/ })
BASENAME=$(basename "$FILE")
DIRNAME=$(dirname "$FILE")
EXTENSION=${BASENAME##*.}
PKGNAME=${BASENAME%.*}
if [ "$CLASS" = "EXECUTABLES" ] && [ "$EXTENSION" != "sh" ]; then
PKGNAME="$BASENAME"
EXTENSION=""
fi
# Allow overriding module name
STEM=
for ARG in "${ARGS[@]}"; do
if [[ "$ARG" =~ "MODULE" ]]; then
STEM="$PKGNAME"
PKGNAME=${ARG#*=}
fi
done
# Add to final package list
PACKAGE_LIST+=("$PKGNAME")
SRC="proprietary"
if [ "$PARTITION" = "system" ]; then
SRC+="/system"
elif [ "$PARTITION" = "vendor" ]; then
SRC+="/vendor"
elif [ "$PARTITION" = "product" ]; then
SRC+="/product"
elif [ "$PARTITION" = "system_ext" ]; then
SRC+="/system_ext"
elif [ "$PARTITION" = "odm" ]; then
SRC+="/odm"
fi
if [ "$CLASS" = "SHARED_LIBRARIES" ]; then
printf 'cc_prebuilt_library_shared {\n'
printf '\tname: "%s",\n' "$PKGNAME"
if [ ! -z "$STEM" ]; then
printf '\tstem: "%s",\n' "$STEM"
fi
printf '\towner: "%s",\n' "$VENDOR"
printf '\tstrip: {\n'
printf '\t\tnone: true,\n'
printf '\t},\n'
printf '\ttarget: {\n'
if [ "$EXTRA" = "both" ]; then
printf '\t\tandroid_arm: {\n'
printf '\t\t\tsrcs: ["%s/lib/%s"],\n' "$SRC" "$FILE"
printf '\t\t},\n'
printf '\t\tandroid_arm64: {\n'
printf '\t\t\tsrcs: ["%s/lib64/%s"],\n' "$SRC" "$FILE"
printf '\t\t},\n'
elif [ "$EXTRA" = "64" ]; then
printf '\t\tandroid_arm64: {\n'
printf '\t\t\tsrcs: ["%s/lib64/%s"],\n' "$SRC" "$FILE"
printf '\t\t},\n'
else
printf '\t\tandroid_arm: {\n'
printf '\t\t\tsrcs: ["%s/lib/%s"],\n' "$SRC" "$FILE"
printf '\t\t},\n'
fi
printf '\t},\n'
if [ "$EXTRA" != "none" ]; then
printf '\tcompile_multilib: "%s",\n' "$EXTRA"
fi
printf '\tcheck_elf_files: false,\n'
elif [ "$CLASS" = "APEX" ]; then
printf 'prebuilt_apex {\n'
printf '\tname: "%s",\n' "$PKGNAME"
printf '\towner: "%s",\n' "$VENDOR"
SRC="$SRC/apex"
printf '\tsrc: "%s/%s",\n' "$SRC" "$FILE"
printf '\tfilename: "%s",\n' "$FILE"
elif [ "$CLASS" = "APPS" ]; then
printf 'android_app_import {\n'
printf '\tname: "%s",\n' "$PKGNAME"
printf '\towner: "%s",\n' "$VENDOR"
if [ "$EXTRA" = "priv-app" ]; then
SRC="$SRC/priv-app"
else
SRC="$SRC/app"
fi
printf '\tapk: "%s/%s",\n' "$SRC" "$FILE"
USE_PLATFORM_CERTIFICATE="true"
for ARG in "${ARGS[@]}"; do
if [ "$ARG" = "PRESIGNED" ]; then
USE_PLATFORM_CERTIFICATE="false"
printf '\tpresigned: true,\n'
elif [[ "$ARG" =~ "OVERRIDES" ]]; then
OVERRIDEPKG=${ARG#*=}
OVERRIDEPKG=${OVERRIDEPKG//,/\", \"}
printf '\toverrides: ["%s"],\n' "$OVERRIDEPKG"
elif [ ! -z "$ARG" ]; then
USE_PLATFORM_CERTIFICATE="false"
printf '\tcertificate: "%s",\n' "$ARG"
fi
done
if [ "$USE_PLATFORM_CERTIFICATE" = "true" ]; then
printf '\tcertificate: "platform",\n'
fi
elif [ "$CLASS" = "JAVA_LIBRARIES" ]; then
printf 'dex_import {\n'
printf '\tname: "%s",\n' "$PKGNAME"
printf '\towner: "%s",\n' "$VENDOR"
printf '\tjars: ["%s/framework/%s"],\n' "$SRC" "$FILE"
elif [ "$CLASS" = "ETC" ]; then
if [ "$EXTENSION" = "xml" ]; then
printf 'prebuilt_etc_xml {\n'
else
printf 'prebuilt_etc {\n'
fi
printf '\tname: "%s",\n' "$PKGNAME"
printf '\towner: "%s",\n' "$VENDOR"
printf '\tsrc: "%s/etc/%s",\n' "$SRC" "$FILE"
printf '\tfilename_from_src: true,\n'
elif [ "$CLASS" = "EXECUTABLES" ]; then
if [ "$EXTENSION" = "sh" ]; then
printf 'sh_binary {\n'
else
printf 'cc_prebuilt_binary {\n'
fi
printf '\tname: "%s",\n' "$PKGNAME"
printf '\towner: "%s",\n' "$VENDOR"
if [ "$EXTENSION" != "sh" ]; then
printf '\tsrcs: ["%s/bin/%s"],\n' "$SRC" "$FILE"
printf '\tcheck_elf_files: false,\n'
printf '\tstrip: {\n'
printf '\t\tnone: true,\n'
printf '\t},\n'
printf '\tprefer: true,\n'
else
printf '\tsrc: "%s/bin/%s",\n' "$SRC" "$FILE"
fi
unset EXTENSION
else
printf '\tsrcs: ["%s/%s"],\n' "$SRC" "$FILE"
fi
if [ "$CLASS" = "APPS" ]; then
printf '\tdex_preopt: {\n'
printf '\t\tenabled: false,\n'
printf '\t},\n'
fi
if [ "$CLASS" = "SHARED_LIBRARIES" ] || [ "$CLASS" = "EXECUTABLES" ] ; then
if [ "$DIRNAME" != "." ]; then
printf '\trelative_install_path: "%s",\n' "$DIRNAME"
fi
fi
if [ "$CLASS" = "ETC" ] ; then
if [ "$DIRNAME" != "." ]; then
printf '\tsub_dir: "%s",\n' "$DIRNAME"
fi
fi
if [ "$CLASS" = "SHARED_LIBRARIES" ]; then
printf '\tprefer: true,\n'
fi
if [ "$EXTRA" = "priv-app" ]; then
printf '\tprivileged: true,\n'
fi
if [ "$PARTITION" = "vendor" ]; then
printf '\tsoc_specific: true,\n'
elif [ "$PARTITION" = "product" ]; then
printf '\tproduct_specific: true,\n'
elif [ "$PARTITION" = "system_ext" ]; then
printf '\tsystem_ext_specific: true,\n'
elif [ "$PARTITION" = "odm" ]; then
printf '\tdevice_specific: true,\n'
fi
printf '}\n\n'
done
}
#
# write_product_packages:
#
# This function will create prebuilt entries in the
# Android.bp and associated PRODUCT_PACKAGES list in the
# product makefile for all files in the blob list which
# start with a single dash (-) character.
#
function write_product_packages() {
PACKAGE_LIST=()
# Sort the package list for comm
PRODUCT_PACKAGES_LIST=($( printf '%s\n' "${PRODUCT_PACKAGES_LIST[@]}" | LC_ALL=C sort))
local COUNT=${#PRODUCT_PACKAGES_LIST[@]}
if [ "$COUNT" = "0" ]; then
return 0
fi
# Figure out what's 32-bit, what's 64-bit, and what's multilib
# I really should not be doing this in bash due to shitty array passing :(
local T_LIB32=( $(prefix_match "lib/") )
local T_LIB64=( $(prefix_match "lib64/") )
local MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${T_LIB64[@]}")) )
local LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${MULTILIBS[@]}")) )
local LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_LIB64[@]}") <(printf '%s\n' "${MULTILIBS[@]}")) )
if [ "${#MULTILIBS[@]}" -gt "0" ]; then
write_blueprint_packages "SHARED_LIBRARIES" "" "both" "MULTILIBS" >> "$ANDROIDBP"
fi
if [ "${#LIB32[@]}" -gt "0" ]; then
write_blueprint_packages "SHARED_LIBRARIES" "" "32" "LIB32" >> "$ANDROIDBP"
fi
if [ "${#LIB64[@]}" -gt "0" ]; then
write_blueprint_packages "SHARED_LIBRARIES" "" "64" "LIB64" >> "$ANDROIDBP"
fi
local T_S_LIB32=( $(prefix_match "system/lib/") )
local T_S_LIB64=( $(prefix_match "system/lib64/") )
local S_MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_S_LIB32[@]}") <(printf '%s\n' "${T_S_LIB64[@]}")) )
local S_LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_S_LIB32[@]}") <(printf '%s\n' "${S_MULTILIBS[@]}")) )
local S_LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_S_LIB64[@]}") <(printf '%s\n' "${S_MULTILIBS[@]}")) )
if [ "${#S_MULTILIBS[@]}" -gt "0" ]; then
write_blueprint_packages "SHARED_LIBRARIES" "system" "both" "S_MULTILIBS" >> "$ANDROIDBP"
fi
if [ "${#S_LIB32[@]}" -gt "0" ]; then
write_blueprint_packages "SHARED_LIBRARIES" "system" "32" "S_LIB32" >> "$ANDROIDBP"
fi
if [ "${#S_LIB64[@]}" -gt "0" ]; then
write_blueprint_packages "SHARED_LIBRARIES" "system" "64" "S_LIB64" >> "$ANDROIDBP"
fi
local T_V_LIB32=( $(prefix_match "vendor/lib/") )
local T_V_LIB64=( $(prefix_match "vendor/lib64/") )
local V_MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${T_V_LIB64[@]}")) )
local V_LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${V_MULTILIBS[@]}")) )
local V_LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_V_LIB64[@]}") <(printf '%s\n' "${V_MULTILIBS[@]}")) )
if [ "${#V_MULTILIBS[@]}" -gt "0" ]; then
write_blueprint_packages "SHARED_LIBRARIES" "vendor" "both" "V_MULTILIBS" >> "$ANDROIDBP"
fi
if [ "${#V_LIB32[@]}" -gt "0" ]; then
write_blueprint_packages "SHARED_LIBRARIES" "vendor" "32" "V_LIB32" >> "$ANDROIDBP"
fi
if [ "${#V_LIB64[@]}" -gt "0" ]; then
write_blueprint_packages "SHARED_LIBRARIES" "vendor" "64" "V_LIB64" >> "$ANDROIDBP"
fi
local T_P_LIB32=( $(prefix_match "product/lib/") )
local T_P_LIB64=( $(prefix_match "product/lib64/") )
local P_MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_P_LIB32[@]}") <(printf '%s\n' "${T_P_LIB64[@]}")) )
local P_LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_P_LIB32[@]}") <(printf '%s\n' "${P_MULTILIBS[@]}")) )
local P_LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_P_LIB64[@]}") <(printf '%s\n' "${P_MULTILIBS[@]}")) )
if [ "${#P_MULTILIBS[@]}" -gt "0" ]; then
write_blueprint_packages "SHARED_LIBRARIES" "product" "both" "P_MULTILIBS" >> "$ANDROIDBP"
fi
if [ "${#P_LIB32[@]}" -gt "0" ]; then
write_blueprint_packages "SHARED_LIBRARIES" "product" "32" "P_LIB32" >> "$ANDROIDBP"
fi
if [ "${#P_LIB64[@]}" -gt "0" ]; then
write_blueprint_packages "SHARED_LIBRARIES" "product" "64" "P_LIB64" >> "$ANDROIDBP"
fi
local T_SE_LIB32=( $(prefix_match "system_ext/lib/") )
local T_SE_LIB64=( $(prefix_match "system_ext/lib64/") )
local SE_MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_SE_LIB32[@]}") <(printf '%s\n' "${T_SE_LIB64[@]}")) )
local SE_LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_SE_LIB32[@]}") <(printf '%s\n' "${SE_MULTILIBS[@]}")) )
local SE_LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_SE_LIB64[@]}") <(printf '%s\n' "${SE_MULTILIBS[@]}")) )
if [ "${#SE_MULTILIBS[@]}" -gt "0" ]; then
write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "both" "SE_MULTILIBS" >> "$ANDROIDBP"
fi
if [ "${#SE_LIB32[@]}" -gt "0" ]; then
write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "32" "SE_LIB32" >> "$ANDROIDBP"
fi
if [ "${#SE_LIB64[@]}" -gt "0" ]; then
write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "64" "SE_LIB64" >> "$ANDROIDBP"
fi
local T_O_LIB32=( $(prefix_match "odm/lib/") )
local T_O_LIB64=( $(prefix_match "odm/lib64/") )
local O_MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_O_LIB32[@]}") <(printf '%s\n' "${T_O_LIB64[@]}")) )
local O_LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_O_LIB32[@]}") <(printf '%s\n' "${O_MULTILIBS[@]}")) )
local O_LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_O_LIB64[@]}") <(printf '%s\n' "${O_MULTILIBS[@]}")) )
if [ "${#O_MULTILIBS[@]}" -gt "0" ]; then
write_blueprint_packages "SHARED_LIBRARIES" "odm" "both" "O_MULTILIBS" >> "$ANDROIDBP"
fi
if [ "${#O_LIB32[@]}" -gt "0" ]; then
write_blueprint_packages "SHARED_LIBRARIES" "odm" "32" "O_LIB32" >> "$ANDROIDBP"
fi
if [ "${#O_LIB64[@]}" -gt "0" ]; then
write_blueprint_packages "SHARED_LIBRARIES" "odm" "64" "O_LIB64" >> "$ANDROIDBP"
fi
# APEX
local APEX=( $(prefix_match "apex/") )
if [ "${#APEX[@]}" -gt "0" ]; then
write_blueprint_packages "APEX" "" "" "APEX" >> "$ANDROIDBP"
fi
local S_APEX=( $(prefix_match "system/apex/") )
if [ "${#S_APEX[@]}" -gt "0" ]; then
write_blueprint_packages "APEX" "system" "" "S_APEX" >> "$ANDROIDBP"
fi
local V_APEX=( $(prefix_match "vendor/apex/") )
if [ "${#V_APEX[@]}" -gt "0" ]; then
write_blueprint_packages "APEX" "vendor" "" "V_APEX" >> "$ANDROIDBP"
fi
local SE_APEX=( $(prefix_match "system_ext/apex/") )
if [ "${#SE_APEX[@]}" -gt "0" ]; then
write_blueprint_packages "APEX" "system_ext" "" "SE_APEX" >> "$ANDROIDBP"
fi
# Apps
local APPS=( $(prefix_match "app/") )
if [ "${#APPS[@]}" -gt "0" ]; then
write_blueprint_packages "APPS" "" "" "APPS" >> "$ANDROIDBP"
fi
local PRIV_APPS=( $(prefix_match "priv-app/") )
if [ "${#PRIV_APPS[@]}" -gt "0" ]; then
write_blueprint_packages "APPS" "" "priv-app" "PRIV_APPS" >> "$ANDROIDBP"
fi
local S_APPS=( $(prefix_match "system/app/") )
if [ "${#S_APPS[@]}" -gt "0" ]; then
write_blueprint_packages "APPS" "system" "" "S_APPS" >> "$ANDROIDBP"
fi
local S_PRIV_APPS=( $(prefix_match "system/priv-app/") )
if [ "${#S_PRIV_APPS[@]}" -gt "0" ]; then
write_blueprint_packages "APPS" "system" "priv-app" "S_PRIV_APPS" >> "$ANDROIDBP"
fi
local V_APPS=( $(prefix_match "vendor/app/") )
if [ "${#V_APPS[@]}" -gt "0" ]; then
write_blueprint_packages "APPS" "vendor" "" "V_APPS" >> "$ANDROIDBP"
fi
local V_PRIV_APPS=( $(prefix_match "vendor/priv-app/") )
if [ "${#V_PRIV_APPS[@]}" -gt "0" ]; then
write_blueprint_packages "APPS" "vendor" "priv-app" "V_PRIV_APPS" >> "$ANDROIDBP"
fi
local P_APPS=( $(prefix_match "product/app/") )
if [ "${#P_APPS[@]}" -gt "0" ]; then
write_blueprint_packages "APPS" "product" "" "P_APPS" >> "$ANDROIDBP"
fi
local P_PRIV_APPS=( $(prefix_match "product/priv-app/") )
if [ "${#P_PRIV_APPS[@]}" -gt "0" ]; then
write_blueprint_packages "APPS" "product" "priv-app" "P_PRIV_APPS" >> "$ANDROIDBP"
fi
local SE_APPS=( $(prefix_match "system_ext/app/") )
if [ "${#SE_APPS[@]}" -gt "0" ]; then
write_blueprint_packages "APPS" "system_ext" "" "SE_APPS" >> "$ANDROIDBP"
fi
local SE_PRIV_APPS=( $(prefix_match "system_ext/priv-app/") )
if [ "${#SE_PRIV_APPS[@]}" -gt "0" ]; then
write_blueprint_packages "APPS" "system_ext" "priv-app" "SE_PRIV_APPS" >> "$ANDROIDBP"
fi
local O_APPS=( $(prefix_match "odm/app/") )
if [ "${#O_APPS[@]}" -gt "0" ]; then
write_blueprint_packages "APPS" "odm" "" "O_APPS" >> "$ANDROIDBP"
fi
local O_PRIV_APPS=( $(prefix_match "odm/priv-app/") )
if [ "${#O_PRIV_APPS[@]}" -gt "0" ]; then
write_blueprint_packages "APPS" "odm" "priv-app" "O_PRIV_APPS" >> "$ANDROIDBP"
fi
# Framework
local FRAMEWORK=( $(prefix_match "framework/") )
if [ "${#FRAMEWORK[@]}" -gt "0" ]; then
write_blueprint_packages "JAVA_LIBRARIES" "" "" "FRAMEWORK" >> "$ANDROIDBP"
fi
local S_FRAMEWORK=( $(prefix_match "system/framework/") )
if [ "${#S_FRAMEWORK[@]}" -gt "0" ]; then
write_blueprint_packages "JAVA_LIBRARIES" "system" "" "S_FRAMEWORK" >> "$ANDROIDBP"
fi
local V_FRAMEWORK=( $(prefix_match "vendor/framework/") )
if [ "${#V_FRAMEWORK[@]}" -gt "0" ]; then
write_blueprint_packages "JAVA_LIBRARIES" "vendor" "" "V_FRAMEWORK" >> "$ANDROIDBP"
fi
local P_FRAMEWORK=( $(prefix_match "product/framework/") )
if [ "${#P_FRAMEWORK[@]}" -gt "0" ]; then
write_blueprint_packages "JAVA_LIBRARIES" "product" "" "P_FRAMEWORK" >> "$ANDROIDBP"
fi
local SE_FRAMEWORK=( $(prefix_match "system_ext/framework/") )
if [ "${#SE_FRAMEWORK[@]}" -gt "0" ]; then
write_blueprint_packages "JAVA_LIBRARIES" "system_ext" "" "SE_FRAMEWORK" >> "$ANDROIDBP"
fi
local O_FRAMEWORK=( $(prefix_match "odm/framework/") )
if [ "${#O_FRAMEWORK[@]}" -gt "0" ]; then
write_blueprint_packages "JAVA_LIBRARIES" "odm" "" "O_FRAMEWORK" >> "$ANDROIDBP"
fi
# Etc
local ETC=( $(prefix_match "etc/") )
if [ "${#ETC[@]}" -gt "0" ]; then
write_blueprint_packages "ETC" "" "" "ETC" >> "$ANDROIDBP"
fi
local S_ETC=( $(prefix_match "system/etc/") )
if [ "${#S_ETC[@]}" -gt "0" ]; then
write_blueprint_packages "ETC" "system" "" "S_ETC" >> "$ANDROIDBP"
fi
local V_ETC=( $(prefix_match "vendor/etc/") )
if [ "${#V_ETC[@]}" -gt "0" ]; then
write_blueprint_packages "ETC" "vendor" "" "V_ETC" >> "$ANDROIDBP"
fi
local P_ETC=( $(prefix_match "product/etc/") )
if [ "${#P_ETC[@]}" -gt "0" ]; then
write_blueprint_packages "ETC" "product" "" "P_ETC" >> "$ANDROIDBP"
fi
local SE_ETC=( $(prefix_match "system_ext/etc/") )
if [ "${#SE_ETC[@]}" -gt "0" ]; then
write_blueprint_packages "ETC" "system_ext" "" "SE_ETC" >> "$ANDROIDBP"
fi
local O_ETC=( $(prefix_match "odm/etc/") )
if [ "${#O_ETC[@]}" -gt "0" ]; then
write_blueprint_packages "ETC" "odm" "" "O_ETC" >> "$ANDROIDBP"
fi
# Executables
local BIN=( $(prefix_match "bin/") )
if [ "${#BIN[@]}" -gt "0" ]; then
write_blueprint_packages "EXECUTABLES" "" "" "BIN" >> "$ANDROIDBP"
fi
local S_BIN=( $(prefix_match "system/bin/") )
if [ "${#S_BIN[@]}" -gt "0" ]; then
write_blueprint_packages "EXECUTABLES" "system" "" "S_BIN" >> "$ANDROIDBP"
fi
local V_BIN=( $(prefix_match "vendor/bin/") )
if [ "${#V_BIN[@]}" -gt "0" ]; then
write_blueprint_packages "EXECUTABLES" "vendor" "" "V_BIN" >> "$ANDROIDBP"
fi
local P_BIN=( $(prefix_match "product/bin/") )
if [ "${#P_BIN[@]}" -gt "0" ]; then
write_blueprint_packages "EXECUTABLES" "product" "" "P_BIN" >> "$ANDROIDBP"
fi
local SE_BIN=( $(prefix_match "system_ext/bin/") )
if [ "${#SE_BIN[@]}" -gt "0" ]; then
write_blueprint_packages "EXECUTABLES" "system_ext" "" "SE_BIN" >> "$ANDROIDBP"
fi
local O_BIN=( $(prefix_match "odm/bin/") )
if [ "${#O_BIN[@]}" -gt "0" ]; then
write_blueprint_packages "EXECUTABLES" "odm" "" "O_BIN" >> "$ANDROIDBP"
fi
# Actually write out the final PRODUCT_PACKAGES list
local PACKAGE_COUNT=${#PACKAGE_LIST[@]}
if [ "$PACKAGE_COUNT" -eq "0" ]; then
return 0
fi
printf '\n%s\n' "PRODUCT_PACKAGES += \\" >> "$PRODUCTMK"
for (( i=1; i<PACKAGE_COUNT+1; i++ )); do
local LINEEND=" \\"
if [ "$i" -eq "$PACKAGE_COUNT" ]; then
LINEEND=""
fi
printf ' %s%s\n' "${PACKAGE_LIST[$i-1]}" "$LINEEND" >> "$PRODUCTMK"
done
}
#
# write_single_product_copy_files:
#
# $1: the file to be copied
#
# Creates a PRODUCT_COPY_FILES section in the product makefile for the
# item provided in $1.
#
function write_single_product_copy_files() {
local FILE="$1"
if [ -z "$FILE" ]; then
echo "A file must be provided to write_single_product_copy_files()!"
exit 1
fi
local TARGET=$(target_file "$FILE")
local OUTTARGET=$(truncate_file $TARGET)
printf '%s\n' "PRODUCT_COPY_FILES += \\" >> "$PRODUCTMK"
printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s\n' \
"$OUTDIR" "$TARGET" "$OUTTARGET" >> "$PRODUCTMK"
}
#
# write_single_product_packages:
#
# $1: the package to be built
#
# Creates a PRODUCT_PACKAGES section in the product makefile for the
# item provided in $1.
#
function write_single_product_packages() {
local PACKAGE="$1"
if [ -z "$PACKAGE" ]; then
echo "A package must be provided to write_single_product_packages()!"
exit 1
fi
printf '\n%s\n' "PRODUCT_PACKAGES += \\" >> "$PRODUCTMK"
printf ' %s%s\n' "$PACKAGE" >> "$PRODUCTMK"
}
#
# write_rro_androidmanifest:
#
# $2: target package for the RRO overlay
#
# Creates an AndroidManifest.xml for an RRO overlay.
#
function write_rro_androidmanifest() {
local TARGET_PACKAGE="$1"
cat << EOF
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="$TARGET_PACKAGE.vendor"
android:versionCode="1"
android:versionName="1.0">
<application android:hasCode="false" />
<overlay
android:targetPackage="$TARGET_PACKAGE"
android:isStatic="true"
android:priority="0"/>
</manifest>
EOF
}
#
# write_rro_blueprint:
#
# $1: package name for the RRO overlay
# $2: target partition for the RRO overlay
#
# Creates an Android.bp for an RRO overlay.
#
function write_rro_blueprint() {
local PKGNAME="$1"
local PARTITION="$2"
printf 'runtime_resource_overlay {\n'
printf '\tname: "%s",\n' "$PKGNAME"
printf '\ttheme: "%s",\n' "$PKGNAME"
printf '\tsdk_version: "%s",\n' "current"
printf '\taaptflags: ["%s"],\n' "--keep-raw-values"
if [ "$PARTITION" = "vendor" ]; then
printf '\tsoc_specific: true,\n'
elif [ "$PARTITION" = "product" ]; then
printf '\tproduct_specific: true,\n'
elif [ "$PARTITION" = "system_ext" ]; then
printf '\tsystem_ext_specific: true,\n'
elif [ "$PARTITION" = "odm" ]; then
printf '\tdevice_specific: true,\n'
fi
printf '}\n'
}
#
# write_blueprint_header:
#
# $1: file which will be written to
#
# writes out the warning message regarding manual file modifications.
# note that this is not an append operation, and should
# be executed first!
#
function write_blueprint_header() {
if [ -f $1 ]; then
rm $1
fi
[ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON"
[ "$COMMON" -eq 1 ] && local VENDOR="${VENDOR_COMMON:-$VENDOR}"
cat << EOF >> $1
// Automatically generated file. DO NOT MODIFY
//
// This file is generated by device/$VENDOR/$DEVICE/setup-makefiles_local.sh
EOF
}
#
# write_makefile_header:
#
# $1: file which will be written to
#
# writes out the warning message regarding manual file modifications.
# note that this is not an append operation, and should
# be executed first!
#
function write_makefile_header() {
if [ -f $1 ]; then
rm $1
fi
[ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON"
[ "$COMMON" -eq 1 ] && local VENDOR="${VENDOR_COMMON:-$VENDOR}"