blob: a5e6e68652a8a5e32f20d52782e652beaa6fef10 [file] [log] [blame]
Steve Kondik5bd66602016-07-15 10:39:58 -07001#!/bin/bash
2#
3# Copyright (C) 2016 The CyanogenMod Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18PRODUCT_COPY_FILES_LIST=()
19PRODUCT_COPY_FILES_HASHES=()
Vladimir Olteande985fe2019-01-17 03:07:34 +020020PRODUCT_COPY_FILES_FIXUP_HASHES=()
Steve Kondik5bd66602016-07-15 10:39:58 -070021PRODUCT_PACKAGES_LIST=()
22PRODUCT_PACKAGES_HASHES=()
Vladimir Olteande985fe2019-01-17 03:07:34 +020023PRODUCT_PACKAGES_FIXUP_HASHES=()
Steve Kondik5bd66602016-07-15 10:39:58 -070024PACKAGE_LIST=()
25VENDOR_STATE=-1
26VENDOR_RADIO_STATE=-1
27COMMON=-1
28ARCHES=
29FULLY_DEODEXED=-1
30
Rashed Abdel-Tawabe7d9b5c2017-08-05 23:11:35 -040031TMPDIR=$(mktemp -d)
Volodymyr Zhdanove54a1592020-10-22 01:33:24 +030032HOST="$(uname | tr '[:upper:]' '[:lower:]')"
Steve Kondik5bd66602016-07-15 10:39:58 -070033
34#
35# cleanup
36#
37# kill our tmpfiles with fire on exit
38#
39function cleanup() {
40 rm -rf "${TMPDIR:?}"
41}
42
Gabriele Mb8e54572017-10-11 12:55:51 +020043trap cleanup 0
Steve Kondik5bd66602016-07-15 10:39:58 -070044
45#
46# setup_vendor
47#
48# $1: device name
49# $2: vendor name
theimpulson9a911af2019-08-14 03:25:12 +000050# $3: OMNI root directory
Steve Kondik5bd66602016-07-15 10:39:58 -070051# $4: is common device - optional, default to false
52# $5: cleanup - optional, default to true
Jake Whatley9843b322017-01-25 21:49:16 -050053# $6: custom vendor makefile name - optional, default to false
Steve Kondik5bd66602016-07-15 10:39:58 -070054#
55# Must be called before any other functions can be used. This
56# sets up the internal state for a new vendor configuration.
57#
58function setup_vendor() {
59 local DEVICE="$1"
60 if [ -z "$DEVICE" ]; then
61 echo "\$DEVICE must be set before including this script!"
62 exit 1
63 fi
64
65 export VENDOR="$2"
66 if [ -z "$VENDOR" ]; then
67 echo "\$VENDOR must be set before including this script!"
68 exit 1
69 fi
70
theimpulson9a911af2019-08-14 03:25:12 +000071 export OMNI_ROOT="$3"
72 if [ ! -d "$OMNI_ROOT" ]; then
73 echo "\$OMNI_ROOT must be set and valid before including this script!"
Steve Kondik5bd66602016-07-15 10:39:58 -070074 exit 1
75 fi
76
77 export OUTDIR=vendor/"$VENDOR"/"$DEVICE"
theimpulson9a911af2019-08-14 03:25:12 +000078 if [ ! -d "$OMNI_ROOT/$OUTDIR" ]; then
79 mkdir -p "$OMNI_ROOT/$OUTDIR"
Steve Kondik5bd66602016-07-15 10:39:58 -070080 fi
81
Jake Whatley9843b322017-01-25 21:49:16 -050082 VNDNAME="$6"
83 if [ -z "$VNDNAME" ]; then
84 VNDNAME="$DEVICE"
85 fi
86
theimpulsonbb72ab82019-08-14 06:03:32 +000087 export PRODUCTMK="$OMNI_ROOT"/"$OUTDIR"/"$VNDNAME"-vendor.mk
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -070088 export ANDROIDBP="$OMNI_ROOT"/"$OUTDIR"/Android.bp
theimpulson9a911af2019-08-14 03:25:12 +000089 export ANDROIDMK="$OMNI_ROOT"/"$OUTDIR"/Android.mk
90 export BOARDMK="$OMNI_ROOT"/"$OUTDIR"/BoardConfigVendor.mk
Steve Kondik5bd66602016-07-15 10:39:58 -070091
92 if [ "$4" == "true" ] || [ "$4" == "1" ]; then
93 COMMON=1
94 else
95 COMMON=0
96 fi
97
Gabriele Mc44696d2017-05-01 18:22:04 +020098 if [ "$5" == "false" ] || [ "$5" == "0" ]; then
Steve Kondik5bd66602016-07-15 10:39:58 -070099 VENDOR_STATE=1
100 VENDOR_RADIO_STATE=1
101 else
102 VENDOR_STATE=0
103 VENDOR_RADIO_STATE=0
104 fi
Volodymyr Zhdanove54a1592020-10-22 01:33:24 +0300105
106 if [ -z "$PATCHELF" ]; then
107 export PATCHELF="$OMNI_ROOT"/vendor/omni/build/tools/${HOST}/bin/patchelf
108 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700109}
110
Vladimir Oltean75d8e052018-06-24 20:22:41 +0300111# Helper functions for parsing a spec.
112# notes: an optional "|SHA1" that may appear in the format is stripped
113# early from the spec in the parse_file_list function, and
114# should not be present inside the input parameter passed
115# to these functions.
116
117#
118# input: spec in the form of "src[:dst][;args]"
119# output: "src"
120#
121function src_file() {
122 local SPEC="$1"
123 local SPLIT=(${SPEC//:/ })
124 local ARGS="$(target_args ${SPEC})"
125 # Regardless of there being a ":" delimiter or not in the spec,
126 # the source file is always either the first, or the only entry.
127 local SRC="${SPLIT[0]}"
128 # Remove target_args suffix, if present
129 echo "${SRC%;${ARGS}}"
130}
131
Steve Kondik5bd66602016-07-15 10:39:58 -0700132#
Vladimir Olteanc70bc122018-06-24 20:09:55 +0300133# input: spec in the form of "src[:dst][;args]"
134# output: "dst" if present, "src" otherwise.
Steve Kondik5bd66602016-07-15 10:39:58 -0700135#
136function target_file() {
dianlujitao4918b8a2020-01-02 15:26:44 +0800137 local SPEC="${1%%;*}"
Vladimir Olteanc70bc122018-06-24 20:09:55 +0300138 local SPLIT=(${SPEC//:/ })
139 local ARGS="$(target_args ${SPEC})"
140 local DST=
141 case ${#SPLIT[@]} in
142 1)
143 # The spec doesn't have a : delimiter
144 DST="${SPLIT[0]}"
145 ;;
146 *)
147 # The spec actually has a src:dst format
148 DST="${SPLIT[1]}"
149 ;;
150 esac
151 # Remove target_args suffix, if present
152 echo "${DST%;${ARGS}}"
Steve Kondik5bd66602016-07-15 10:39:58 -0700153}
154
155#
Vladimir Olteanc70bc122018-06-24 20:09:55 +0300156# input: spec in the form of "src[:dst][;args]"
157# output: "args" if present, "" otherwise.
Steve Kondik5bd66602016-07-15 10:39:58 -0700158#
159function target_args() {
Vladimir Olteanc70bc122018-06-24 20:09:55 +0300160 local SPEC="$1"
161 local SPLIT=(${SPEC//;/ })
162 local ARGS=
163 case ${#SPLIT[@]} in
164 1)
165 # No ";" delimiter in the spec.
166 ;;
167 *)
168 # The "args" are whatever comes after the ";" character.
169 # Basically the spec stripped of whatever is to the left of ";".
170 ARGS="${SPEC#${SPLIT[0]};}"
171 ;;
172 esac
173 echo "${ARGS}"
Steve Kondik5bd66602016-07-15 10:39:58 -0700174}
175
176#
177# prefix_match:
178#
Vladimir Oltean011b6b62018-06-12 01:17:35 +0300179# input:
180# - $1: prefix
181# - (global variable) PRODUCT_PACKAGES_LIST: array of [src:]dst[;args] specs.
182# output:
183# - new array consisting of dst[;args] entries where $1 is a prefix of ${dst}.
Steve Kondik5bd66602016-07-15 10:39:58 -0700184#
185function prefix_match() {
186 local PREFIX="$1"
Vladimir Oltean7220f362018-04-02 22:37:09 +0300187 for LINE in "${PRODUCT_PACKAGES_LIST[@]}"; do
188 local FILE=$(target_file "$LINE")
Steve Kondik5bd66602016-07-15 10:39:58 -0700189 if [[ "$FILE" =~ ^"$PREFIX" ]]; then
Vladimir Oltean011b6b62018-06-12 01:17:35 +0300190 local ARGS=$(target_args "$LINE")
191 if [ -z "${ARGS}" ]; then
192 echo "${FILE#$PREFIX}"
193 else
194 echo "${FILE#$PREFIX};${ARGS}"
195 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700196 fi
197 done
198}
199
200#
Rashed Abdel-Tawab7fd3ccb2017-10-07 14:18:39 -0400201# prefix_match_file:
202#
203# $1: the prefix to match on
204# $2: the file to match the prefix for
205#
206# Internal function which returns true if a filename contains the
207# specified prefix.
208#
209function prefix_match_file() {
210 local PREFIX="$1"
211 local FILE="$2"
212 if [[ "$FILE" =~ ^"$PREFIX" ]]; then
213 return 0
214 else
215 return 1
216 fi
217}
218
219#
Rashed Abdel-Tawab841c6e82019-03-29 20:07:25 -0700220# suffix_match_file:
221#
222# $1: the suffix to match on
223# $2: the file to match the suffix for
224#
225# Internal function which returns true if a filename contains the
226# specified suffix.
227#
228function suffix_match_file() {
229 local SUFFIX="$1"
230 local FILE="$2"
231 if [[ "$FILE" = *"$SUFFIX" ]]; then
232 return 0
233 else
234 return 1
235 fi
236}
237
238#
Rashed Abdel-Tawab7fd3ccb2017-10-07 14:18:39 -0400239# truncate_file
240#
241# $1: the filename to truncate
242# $2: the argument to output the truncated filename to
243#
244# Internal function which truncates a filename by removing the first dir
245# in the path. ex. vendor/lib/libsdmextension.so -> lib/libsdmextension.so
246#
247function truncate_file() {
248 local FILE="$1"
249 RETURN_FILE="$2"
250 local FIND="${FILE%%/*}"
251 local LOCATION="${#FIND}+1"
252 echo ${FILE:$LOCATION}
253}
254
255#
Steve Kondik5bd66602016-07-15 10:39:58 -0700256# write_product_copy_files:
257#
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400258# $1: make treble compatible makefile - optional and deprecated, default to true
Rashed Abdel-Tawab7fd3ccb2017-10-07 14:18:39 -0400259#
Steve Kondik5bd66602016-07-15 10:39:58 -0700260# Creates the PRODUCT_COPY_FILES section in the product makefile for all
261# items in the list which do not start with a dash (-).
262#
263function write_product_copy_files() {
264 local COUNT=${#PRODUCT_COPY_FILES_LIST[@]}
265 local TARGET=
266 local FILE=
267 local LINEEND=
Rashed Abdel-Tawab7fd3ccb2017-10-07 14:18:39 -0400268 local TREBLE_COMPAT=$1
Steve Kondik5bd66602016-07-15 10:39:58 -0700269
270 if [ "$COUNT" -eq "0" ]; then
271 return 0
272 fi
273
274 printf '%s\n' "PRODUCT_COPY_FILES += \\" >> "$PRODUCTMK"
275 for (( i=1; i<COUNT+1; i++ )); do
276 FILE="${PRODUCT_COPY_FILES_LIST[$i-1]}"
277 LINEEND=" \\"
278 if [ "$i" -eq "$COUNT" ]; then
279 LINEEND=""
280 fi
281
Vladimir Olteanc70bc122018-06-24 20:09:55 +0300282 TARGET=$(target_file "$FILE")
Rashed Abdel-Tawab06688fc2019-10-05 00:09:41 -0400283 if prefix_match_file "product/" $TARGET ; then
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400284 local OUTTARGET=$(truncate_file $TARGET)
Rashed Abdel-Tawab06688fc2019-10-05 00:09:41 -0400285 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s%s\n' \
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400286 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Rashed Abdel-Tawab06688fc2019-10-05 00:09:41 -0400287 elif prefix_match_file "system/product/" $TARGET ; then
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400288 local OUTTARGET=$(truncate_file $TARGET)
289 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s%s\n' \
290 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Luca Stefani776be462020-09-09 15:53:58 +0200291 elif prefix_match_file "system_ext/" $TARGET ; then
292 local OUTTARGET=$(truncate_file $TARGET)
293 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM_EXT)/%s%s\n' \
294 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
295 elif prefix_match_file "system/system_ext/" $TARGET ; then
296 local OUTTARGET=$(truncate_file $TARGET)
297 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM_EXT)/%s%s\n' \
298 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400299 elif prefix_match_file "odm/" $TARGET ; then
300 local OUTTARGET=$(truncate_file $TARGET)
301 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \
302 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Rashed Abdel-Tawab06688fc2019-10-05 00:09:41 -0400303 elif prefix_match_file "vendor/odm/" $TARGET ; then
304 local OUTTARGET=$(truncate_file $TARGET)
305 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \
306 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
307 elif prefix_match_file "system/vendor/odm/" $TARGET ; then
308 local OUTTARGET=$(truncate_file $TARGET)
309 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \
310 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
311 elif prefix_match_file "vendor/" $TARGET ; then
312 local OUTTARGET=$(truncate_file $TARGET)
313 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR)/%s%s\n' \
314 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
315 elif prefix_match_file "system/vendor/" $TARGET ; then
316 local OUTTARGET=$(truncate_file $TARGET)
317 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR)/%s%s\n' \
318 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400319 elif prefix_match_file "system/" $TARGET ; then
320 local OUTTARGET=$(truncate_file $TARGET)
321 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM)/%s%s\n' \
322 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Rashed Abdel-Tawab7fd3ccb2017-10-07 14:18:39 -0400323 else
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400324 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM)/%s%s\n' \
Rashed Abdel-Tawab7fd3ccb2017-10-07 14:18:39 -0400325 "$OUTDIR" "$TARGET" "$TARGET" "$LINEEND" >> "$PRODUCTMK"
326 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700327 done
328 return 0
329}
330
331#
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700332# write_blueprint_packages:
Steve Kondik5bd66602016-07-15 10:39:58 -0700333#
334# $1: The LOCAL_MODULE_CLASS for the given module list
Luca Stefani776be462020-09-09 15:53:58 +0200335# $2: /system, /odm, /product, /system_ext, or /vendor partition
Steve Kondik5bd66602016-07-15 10:39:58 -0700336# $3: type-specific extra flags
337# $4: Name of the array holding the target list
338#
339# Internal function which writes out the BUILD_PREBUILT stanzas
340# for all modules in the list. This is called by write_product_packages
341# after the modules are categorized.
342#
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700343function write_blueprint_packages() {
344
345 local CLASS="$1"
346 local PARTITION="$2"
347 local EXTRA="$3"
348
349 # Yes, this is a horrible hack - we create a new array using indirection
350 local ARR_NAME="$4[@]"
351 local FILELIST=("${!ARR_NAME}")
352
353 local FILE=
354 local ARGS=
355 local BASENAME=
356 local EXTENSION=
357 local PKGNAME=
358 local SRC=
TheStrix6e24acc2020-04-10 18:20:19 +0530359 local OVERRIDEPKG=
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700360
361 for P in "${FILELIST[@]}"; do
362 FILE=$(target_file "$P")
363 ARGS=$(target_args "$P")
364
365 BASENAME=$(basename "$FILE")
366 DIRNAME=$(dirname "$FILE")
367 EXTENSION=${BASENAME##*.}
368 PKGNAME=${BASENAME%.*}
369
370 # Add to final package list
371 PACKAGE_LIST+=("$PKGNAME")
372
373 SRC="proprietary"
374 if [ "$PARTITION" = "system" ]; then
375 SRC+="/system"
376 elif [ "$PARTITION" = "vendor" ]; then
377 SRC+="/vendor"
378 elif [ "$PARTITION" = "product" ]; then
379 SRC+="/product"
Luca Stefani776be462020-09-09 15:53:58 +0200380 elif [ "$PARTITION" = "system_ext" ]; then
381 SRC+="/system_ext"
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700382 elif [ "$PARTITION" = "odm" ]; then
383 SRC+="/odm"
384 fi
385
386 if [ "$CLASS" = "SHARED_LIBRARIES" ]; then
387 printf 'cc_prebuilt_library_shared {\n'
388 printf '\tname: "%s",\n' "$PKGNAME"
389 printf '\towner: "%s",\n' "$VENDOR"
390 printf '\tstrip: {\n'
391 printf '\t\tnone: true,\n'
392 printf '\t},\n'
393 printf '\ttarget: {\n'
394 if [ "$EXTRA" = "both" ]; then
395 printf '\t\tandroid_arm: {\n'
396 printf '\t\t\tsrcs: ["%s/lib/%s"],\n' "$SRC" "$FILE"
397 printf '\t\t},\n'
398 printf '\t\tandroid_arm64: {\n'
399 printf '\t\t\tsrcs: ["%s/lib64/%s"],\n' "$SRC" "$FILE"
400 printf '\t\t},\n'
401 elif [ "$EXTRA" = "64" ]; then
402 printf '\t\tandroid_arm64: {\n'
403 printf '\t\t\tsrcs: ["%s/lib64/%s"],\n' "$SRC" "$FILE"
404 printf '\t\t},\n'
405 else
406 printf '\t\tandroid_arm: {\n'
407 printf '\t\t\tsrcs: ["%s/lib/%s"],\n' "$SRC" "$FILE"
408 printf '\t\t},\n'
409 fi
410 printf '\t},\n'
411 if [ "$EXTRA" != "none" ]; then
412 printf '\tcompile_multilib: "%s",\n' "$EXTRA"
413 fi
dianlujitao848101c2020-09-12 00:15:13 +0800414 printf '\tcheck_elf_files: false,\n'
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700415 elif [ "$CLASS" = "APPS" ]; then
416 printf 'android_app_import {\n'
417 printf '\tname: "%s",\n' "$PKGNAME"
418 printf '\towner: "%s",\n' "$VENDOR"
419 if [ "$EXTRA" = "priv-app" ]; then
420 SRC="$SRC/priv-app"
421 else
422 SRC="$SRC/app"
423 fi
424 printf '\tapk: "%s/%s",\n' "$SRC" "$FILE"
TheStrix6e24acc2020-04-10 18:20:19 +0530425 ARGS=(${ARGS//;/ })
426 if [ -z "$ARGS" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700427 printf '\tcertificate: "platform",\n'
TheStrix6e24acc2020-04-10 18:20:19 +0530428 else
429 for ARG in "${ARGS[@]}"; do
430 if [ "$ARG" = "PRESIGNED" ]; then
431 printf '\tpresigned: true,\n'
432 elif [[ "$ARG" =~ "OVERRIDES" ]]; then
433 OVERRIDEPKG=${ARG#*=}
434 OVERRIDEPKG=${OVERRIDEPKG//,/ }
435 printf '\toverrides: ["%s"],\n' "$OVERRIDEPKG"
436 elif [ ! -z "$ARG" ]; then
437 printf '\tcertificate: "%s",\n' "$ARG"
438 fi
439 done
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700440 fi
441 elif [ "$CLASS" = "JAVA_LIBRARIES" ]; then
442 printf 'dex_import {\n'
443 printf '\tname: "%s",\n' "$PKGNAME"
444 printf '\towner: "%s",\n' "$VENDOR"
445 printf '\tjars: ["%s/framework/%s"],\n' "$SRC" "$FILE"
446 elif [ "$CLASS" = "ETC" ]; then
447 if [ "$EXTENSION" = "xml" ]; then
448 printf 'prebuilt_etc_xml {\n'
449 else
450 printf 'prebuilt_etc {\n'
451 fi
452 printf '\tname: "%s",\n' "$PKGNAME"
453 printf '\towner: "%s",\n' "$VENDOR"
454 printf '\tsrc: "%s/etc/%s",\n' "$SRC" "$FILE"
LuK1337f7f18712020-10-06 19:29:02 +0200455 printf '\tfilename_from_src: true,\n'
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700456 elif [ "$CLASS" = "EXECUTABLES" ]; then
457 if [ "$EXTENSION" = "sh" ]; then
458 printf 'sh_binary {\n'
459 else
460 printf 'cc_prebuilt_binary {\n'
461 fi
462 printf '\tname: "%s",\n' "$PKGNAME"
463 printf '\towner: "%s",\n' "$VENDOR"
464 if [ "$ARGS" = "rootfs" ]; then
465 SRC="$SRC/rootfs"
466 if [ "$EXTRA" = "sbin" ]; then
467 SRC="$SRC/sbin"
468 printf '\tdist {\n'
469 printf '\t\tdest: "%s",\n' "root/sbin"
470 printf '\t},'
471 fi
472 else
473 SRC="$SRC/bin"
474 fi
475 printf '\tsrcs: ["%s/%s"],\n' "$SRC" "$FILE"
Sebastiano Barezzifd4b2b32021-07-14 21:33:10 +0200476 if [ "$EXTENSION" != "sh" ]; then
477 printf '\tcheck_elf_files: false,\n'
478 fi
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700479 unset EXTENSION
480 else
481 printf '\tsrcs: ["%s/%s"],\n' "$SRC" "$FILE"
482 fi
483 if [ "$CLASS" = "APPS" ]; then
484 printf '\tdex_preopt: {\n'
485 printf '\t\tenabled: false,\n'
486 printf '\t},\n'
487 fi
Andreas Schneiderdbcf9db2020-05-25 17:03:17 +0200488 if [ "$CLASS" = "SHARED_LIBRARIES" ] || [ "$CLASS" = "EXECUTABLES" ] ; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700489 if [ "$DIRNAME" != "." ]; then
Andreas Schneider408526a2020-05-23 15:58:43 +0200490 printf '\trelative_install_path: "%s",\n' "$DIRNAME"
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700491 fi
492 fi
Andreas Schneiderdbcf9db2020-05-25 17:03:17 +0200493 if [ "$CLASS" = "ETC" ] ; then
494 if [ "$DIRNAME" != "." ]; then
495 printf '\tsub_dir: "%s",\n' "$DIRNAME"
496 fi
497 fi
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700498 if [ "$CLASS" = "SHARED_LIBRARIES" ] || [ "$CLASS" = "EXECUTABLES" ] ; then
499 printf '\tprefer: true,\n'
500 fi
501 if [ "$EXTRA" = "priv-app" ]; then
502 printf '\tprivileged: true,\n'
503 fi
504 if [ "$PARTITION" = "vendor" ]; then
505 printf '\tsoc_specific: true,\n'
506 elif [ "$PARTITION" = "product" ]; then
507 printf '\tproduct_specific: true,\n'
Luca Stefani776be462020-09-09 15:53:58 +0200508 elif [ "$PARTITION" = "system_ext" ]; then
509 printf '\tsystem_ext_specific: true,\n'
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700510 elif [ "$PARTITION" = "odm" ]; then
511 printf '\tdevice_specific: true,\n'
512 fi
513 printf '}\n\n'
514 done
515}
516
517#
518# write_makefile_packages:
519#
520# $1: The LOCAL_MODULE_CLASS for the given module list
Luca Stefani776be462020-09-09 15:53:58 +0200521# $2: /odm, /product, /system_ext, or /vendor partition
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700522# $3: type-specific extra flags
523# $4: Name of the array holding the target list
524#
525# Internal function which writes out the BUILD_PREBUILT stanzas
526# for all modules in the list. This is called by write_product_packages
527# after the modules are categorized.
528#
529function write_makefile_packages() {
Steve Kondik5bd66602016-07-15 10:39:58 -0700530
531 local CLASS="$1"
razorlovesa0d296b2019-07-29 02:21:34 -0500532 local PARTITION="$2"
Steve Kondik5bd66602016-07-15 10:39:58 -0700533 local EXTRA="$3"
534
535 # Yes, this is a horrible hack - we create a new array using indirection
536 local ARR_NAME="$4[@]"
537 local FILELIST=("${!ARR_NAME}")
538
539 local FILE=
540 local ARGS=
541 local BASENAME=
542 local EXTENSION=
543 local PKGNAME=
544 local SRC=
545
546 for P in "${FILELIST[@]}"; do
Vladimir Olteanc70bc122018-06-24 20:09:55 +0300547 FILE=$(target_file "$P")
Steve Kondik5bd66602016-07-15 10:39:58 -0700548 ARGS=$(target_args "$P")
549
550 BASENAME=$(basename "$FILE")
M1cha3e8c5bf2017-01-04 09:00:11 +0100551 DIRNAME=$(dirname "$FILE")
Steve Kondik5bd66602016-07-15 10:39:58 -0700552 EXTENSION=${BASENAME##*.}
Mohd Farazcb0f4872019-10-08 16:13:50 +0530553 EXTENSION="."$EXTENSION
554 if [ "$EXTENSION" = ".jar" ]; then
555 EXTENSION="\$(COMMON_JAVA_PACKAGE_SUFFIX)"
556 elif [ "$EXTENSION" = ".apk" ]; then
557 EXTENSION="\$(COMMON_ANDROID_PACKAGE_SUFFIX)"
558 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700559 PKGNAME=${BASENAME%.*}
560
561 # Add to final package list
562 PACKAGE_LIST+=("$PKGNAME")
563
564 SRC="proprietary"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400565 if [ "$PARTITION" = "system" ]; then
566 SRC+="/system"
567 elif [ "$PARTITION" = "vendor" ]; then
Steve Kondik5bd66602016-07-15 10:39:58 -0700568 SRC+="/vendor"
razorlovesa0d296b2019-07-29 02:21:34 -0500569 elif [ "$PARTITION" = "product" ]; then
570 SRC+="/product"
Luca Stefani776be462020-09-09 15:53:58 +0200571 elif [ "$PARTITION" = "system_ext" ]; then
572 SRC+="/system_ext"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700573 elif [ "$PARTITION" = "odm" ]; then
574 SRC+="/odm"
Steve Kondik5bd66602016-07-15 10:39:58 -0700575 fi
576
577 printf 'include $(CLEAR_VARS)\n'
578 printf 'LOCAL_MODULE := %s\n' "$PKGNAME"
579 printf 'LOCAL_MODULE_OWNER := %s\n' "$VENDOR"
580 if [ "$CLASS" = "SHARED_LIBRARIES" ]; then
581 if [ "$EXTRA" = "both" ]; then
582 printf 'LOCAL_SRC_FILES_64 := %s/lib64/%s\n' "$SRC" "$FILE"
583 printf 'LOCAL_SRC_FILES_32 := %s/lib/%s\n' "$SRC" "$FILE"
584 #if [ "$VENDOR_PKG" = "true" ]; then
585 # echo "LOCAL_MODULE_PATH_64 := \$(TARGET_OUT_VENDOR_SHARED_LIBRARIES)"
586 # echo "LOCAL_MODULE_PATH_32 := \$(2ND_TARGET_OUT_VENDOR_SHARED_LIBRARIES)"
587 #else
588 # echo "LOCAL_MODULE_PATH_64 := \$(TARGET_OUT_SHARED_LIBRARIES)"
589 # echo "LOCAL_MODULE_PATH_32 := \$(2ND_TARGET_OUT_SHARED_LIBRARIES)"
590 #fi
591 elif [ "$EXTRA" = "64" ]; then
592 printf 'LOCAL_SRC_FILES := %s/lib64/%s\n' "$SRC" "$FILE"
593 else
594 printf 'LOCAL_SRC_FILES := %s/lib/%s\n' "$SRC" "$FILE"
595 fi
596 if [ "$EXTRA" != "none" ]; then
597 printf 'LOCAL_MULTILIB := %s\n' "$EXTRA"
598 fi
599 elif [ "$CLASS" = "APPS" ]; then
Michael Bestas9c6f2eb2018-01-25 21:05:36 +0200600 if [ "$EXTRA" = "priv-app" ]; then
601 SRC="$SRC/priv-app"
602 else
603 SRC="$SRC/app"
Steve Kondik5bd66602016-07-15 10:39:58 -0700604 fi
605 printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE"
606 local CERT=platform
607 if [ ! -z "$ARGS" ]; then
608 CERT="$ARGS"
609 fi
610 printf 'LOCAL_CERTIFICATE := %s\n' "$CERT"
611 elif [ "$CLASS" = "JAVA_LIBRARIES" ]; then
612 printf 'LOCAL_SRC_FILES := %s/framework/%s\n' "$SRC" "$FILE"
Elektroschmockdd792302016-10-04 21:11:43 +0200613 local CERT=platform
614 if [ ! -z "$ARGS" ]; then
615 CERT="$ARGS"
616 fi
617 printf 'LOCAL_CERTIFICATE := %s\n' "$CERT"
Steve Kondik5bd66602016-07-15 10:39:58 -0700618 elif [ "$CLASS" = "ETC" ]; then
619 printf 'LOCAL_SRC_FILES := %s/etc/%s\n' "$SRC" "$FILE"
620 elif [ "$CLASS" = "EXECUTABLES" ]; then
621 if [ "$ARGS" = "rootfs" ]; then
622 SRC="$SRC/rootfs"
623 if [ "$EXTRA" = "sbin" ]; then
624 SRC="$SRC/sbin"
625 printf '%s\n' "LOCAL_MODULE_PATH := \$(TARGET_ROOT_OUT_SBIN)"
626 printf '%s\n' "LOCAL_UNSTRIPPED_PATH := \$(TARGET_ROOT_OUT_SBIN_UNSTRIPPED)"
627 fi
628 else
629 SRC="$SRC/bin"
630 fi
631 printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE"
632 unset EXTENSION
633 else
634 printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE"
635 fi
636 printf 'LOCAL_MODULE_TAGS := optional\n'
637 printf 'LOCAL_MODULE_CLASS := %s\n' "$CLASS"
Hashbang173575f3bb2016-08-28 20:38:45 -0400638 if [ "$CLASS" = "APPS" ]; then
639 printf 'LOCAL_DEX_PREOPT := false\n'
640 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700641 if [ ! -z "$EXTENSION" ]; then
Mohd Farazcb0f4872019-10-08 16:13:50 +0530642 printf 'LOCAL_MODULE_SUFFIX := %s\n' "$EXTENSION"
Steve Kondik5bd66602016-07-15 10:39:58 -0700643 fi
M1cha3e8c5bf2017-01-04 09:00:11 +0100644 if [ "$CLASS" = "SHARED_LIBRARIES" ] || [ "$CLASS" = "EXECUTABLES" ]; then
645 if [ "$DIRNAME" != "." ]; then
646 printf 'LOCAL_MODULE_RELATIVE_PATH := %s\n' "$DIRNAME"
647 fi
648 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700649 if [ "$EXTRA" = "priv-app" ]; then
650 printf 'LOCAL_PRIVILEGED_MODULE := true\n'
651 fi
razorlovesa0d296b2019-07-29 02:21:34 -0500652 if [ "$PARTITION" = "vendor" ]; then
Ethan Chen4f738f52018-02-17 20:03:54 -0800653 printf 'LOCAL_VENDOR_MODULE := true\n'
razorlovesa0d296b2019-07-29 02:21:34 -0500654 elif [ "$PARTITION" = "product" ]; then
655 printf 'LOCAL_PRODUCT_MODULE := true\n'
Luca Stefani776be462020-09-09 15:53:58 +0200656 elif [ "$PARTITION" = "system_ext" ]; then
657 printf 'LOCAL_SYSTEM_EXT_MODULE := true\n'
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700658 elif [ "$PARTITION" = "odm" ]; then
659 printf 'LOCAL_ODM_MODULE := true\n'
Steve Kondik5bd66602016-07-15 10:39:58 -0700660 fi
661 printf 'include $(BUILD_PREBUILT)\n\n'
662 done
663}
664
665#
666# write_product_packages:
667#
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -0700668# This function will create prebuilt entries in the
669# Android.bp and associated PRODUCT_PACKAGES list in the
Steve Kondik5bd66602016-07-15 10:39:58 -0700670# product makefile for all files in the blob list which
671# start with a single dash (-) character.
672#
673function write_product_packages() {
674 PACKAGE_LIST=()
675
676 local COUNT=${#PRODUCT_PACKAGES_LIST[@]}
677
678 if [ "$COUNT" = "0" ]; then
679 return 0
680 fi
681
682 # Figure out what's 32-bit, what's 64-bit, and what's multilib
683 # I really should not be doing this in bash due to shitty array passing :(
684 local T_LIB32=( $(prefix_match "lib/") )
685 local T_LIB64=( $(prefix_match "lib64/") )
686 local MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${T_LIB64[@]}")) )
687 local LIB32=( $(comm -23 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${MULTILIBS[@]}")) )
688 local LIB64=( $(comm -23 <(printf '%s\n' "${T_LIB64[@]}") <(printf '%s\n' "${MULTILIBS[@]}")) )
689
690 if [ "${#MULTILIBS[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700691 write_blueprint_packages "SHARED_LIBRARIES" "" "both" "MULTILIBS" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700692 fi
693 if [ "${#LIB32[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700694 write_blueprint_packages "SHARED_LIBRARIES" "" "32" "LIB32" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700695 fi
696 if [ "${#LIB64[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700697 write_blueprint_packages "SHARED_LIBRARIES" "" "64" "LIB64" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700698 fi
699
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400700 local T_S_LIB32=( $(prefix_match "system/lib/") )
701 local T_S_LIB64=( $(prefix_match "system/lib64/") )
702 local S_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_S_LIB32[@]}") <(printf '%s\n' "${T_S_LIB64[@]}")) )
703 local S_LIB32=( $(comm -23 <(printf '%s\n' "${T_S_LIB32[@]}") <(printf '%s\n' "${S_MULTILIBS[@]}")) )
704 local S_LIB64=( $(comm -23 <(printf '%s\n' "${T_S_LIB64[@]}") <(printf '%s\n' "${S_MULTILIBS[@]}")) )
705
706 if [ "${#S_MULTILIBS[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700707 write_blueprint_packages "SHARED_LIBRARIES" "system" "both" "S_MULTILIBS" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400708 fi
709 if [ "${#S_LIB32[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700710 write_blueprint_packages "SHARED_LIBRARIES" "system" "32" "S_LIB32" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400711 fi
712 if [ "${#S_LIB64[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700713 write_blueprint_packages "SHARED_LIBRARIES" "system" "64" "S_LIB64" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400714 fi
715
Steve Kondik5bd66602016-07-15 10:39:58 -0700716 local T_V_LIB32=( $(prefix_match "vendor/lib/") )
717 local T_V_LIB64=( $(prefix_match "vendor/lib64/") )
718 local V_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${T_V_LIB64[@]}")) )
719 local V_LIB32=( $(comm -23 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${V_MULTILIBS[@]}")) )
720 local V_LIB64=( $(comm -23 <(printf '%s\n' "${T_V_LIB64[@]}") <(printf '%s\n' "${V_MULTILIBS[@]}")) )
721
722 if [ "${#V_MULTILIBS[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700723 write_blueprint_packages "SHARED_LIBRARIES" "vendor" "both" "V_MULTILIBS" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700724 fi
725 if [ "${#V_LIB32[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700726 write_blueprint_packages "SHARED_LIBRARIES" "vendor" "32" "V_LIB32" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700727 fi
728 if [ "${#V_LIB64[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700729 write_blueprint_packages "SHARED_LIBRARIES" "vendor" "64" "V_LIB64" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500730 fi
731
732 local T_P_LIB32=( $(prefix_match "product/lib/") )
733 local T_P_LIB64=( $(prefix_match "product/lib64/") )
734 local P_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_P_LIB32[@]}") <(printf '%s\n' "${T_P_LIB64[@]}")) )
735 local P_LIB32=( $(comm -23 <(printf '%s\n' "${T_P_LIB32[@]}") <(printf '%s\n' "${P_MULTILIBS[@]}")) )
736 local P_LIB64=( $(comm -23 <(printf '%s\n' "${T_P_LIB64[@]}") <(printf '%s\n' "${P_MULTILIBS[@]}")) )
737
738 if [ "${#P_MULTILIBS[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700739 write_blueprint_packages "SHARED_LIBRARIES" "product" "both" "P_MULTILIBS" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500740 fi
741 if [ "${#P_LIB32[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700742 write_blueprint_packages "SHARED_LIBRARIES" "product" "32" "P_LIB32" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500743 fi
744 if [ "${#P_LIB64[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700745 write_blueprint_packages "SHARED_LIBRARIES" "product" "64" "P_LIB64" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700746 fi
747
Luca Stefani776be462020-09-09 15:53:58 +0200748 local T_SE_LIB32=( $(prefix_match "system_ext/lib/") )
749 local T_SE_LIB64=( $(prefix_match "system_ext/lib64/") )
750 local SE_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_SE_LIB32[@]}") <(printf '%s\n' "${T_SE_LIB64[@]}")) )
751 local SE_LIB32=( $(comm -23 <(printf '%s\n' "${T_SE_LIB32[@]}") <(printf '%s\n' "${SE_MULTILIBS[@]}")) )
752 local SE_LIB64=( $(comm -23 <(printf '%s\n' "${T_SE_LIB64[@]}") <(printf '%s\n' "${SE_MULTILIBS[@]}")) )
753
754 if [ "${#SE_MULTILIBS[@]}" -gt "0" ]; then
755 write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "both" "SE_MULTILIBS" >> "$ANDROIDBP"
756 fi
757 if [ "${#SE_LIB32[@]}" -gt "0" ]; then
758 write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "32" "SE_LIB32" >> "$ANDROIDBP"
759 fi
760 if [ "${#SE_LIB64[@]}" -gt "0" ]; then
761 write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "64" "SE_LIB64" >> "$ANDROIDBP"
762 fi
763
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700764 local T_O_LIB32=( $(prefix_match "odm/lib/") )
765 local T_O_LIB64=( $(prefix_match "odm/lib64/") )
766 local O_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_O_LIB32[@]}") <(printf '%s\n' "${T_O_LIB64[@]}")) )
767 local O_LIB32=( $(comm -23 <(printf '%s\n' "${T_O_LIB32[@]}") <(printf '%s\n' "${O_MULTILIBS[@]}")) )
768 local O_LIB64=( $(comm -23 <(printf '%s\n' "${T_O_LIB64[@]}") <(printf '%s\n' "${O_MULTILIBS[@]}")) )
769
770 if [ "${#O_MULTILIBS[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700771 write_blueprint_packages "SHARED_LIBRARIES" "odm" "both" "O_MULTILIBS" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700772 fi
773 if [ "${#O_LIB32[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700774 write_blueprint_packages "SHARED_LIBRARIES" "odm" "32" "O_LIB32" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700775 fi
776 if [ "${#O_LIB64[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700777 write_blueprint_packages "SHARED_LIBRARIES" "odm" "64" "O_LIB64" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700778 fi
779
Steve Kondik5bd66602016-07-15 10:39:58 -0700780 # Apps
781 local APPS=( $(prefix_match "app/") )
782 if [ "${#APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100783 write_blueprint_packages "APPS" "" "" "APPS" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700784 fi
785 local PRIV_APPS=( $(prefix_match "priv-app/") )
786 if [ "${#PRIV_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100787 write_blueprint_packages "APPS" "" "priv-app" "PRIV_APPS" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700788 fi
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400789 local S_APPS=( $(prefix_match "system/app/") )
790 if [ "${#S_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100791 write_blueprint_packages "APPS" "system" "" "S_APPS" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400792 fi
793 local S_PRIV_APPS=( $(prefix_match "system/priv-app/") )
794 if [ "${#S_PRIV_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100795 write_blueprint_packages "APPS" "system" "priv-app" "S_PRIV_APPS" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400796 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700797 local V_APPS=( $(prefix_match "vendor/app/") )
798 if [ "${#V_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100799 write_blueprint_packages "APPS" "vendor" "" "V_APPS" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700800 fi
801 local V_PRIV_APPS=( $(prefix_match "vendor/priv-app/") )
802 if [ "${#V_PRIV_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100803 write_blueprint_packages "APPS" "vendor" "priv-app" "V_PRIV_APPS" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500804 fi
805 local P_APPS=( $(prefix_match "product/app/") )
806 if [ "${#P_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100807 write_blueprint_packages "APPS" "product" "" "P_APPS" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500808 fi
809 local P_PRIV_APPS=( $(prefix_match "product/priv-app/") )
810 if [ "${#P_PRIV_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100811 write_blueprint_packages "APPS" "product" "priv-app" "P_PRIV_APPS" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700812 fi
Luca Stefani776be462020-09-09 15:53:58 +0200813 local SE_APPS=( $(prefix_match "system_ext/app/") )
814 if [ "${#SE_APPS[@]}" -gt "0" ]; then
815 write_blueprint_packages "APPS" "system_ext" "" "SE_APPS" >> "$ANDROIDBP"
816 fi
817 local SE_PRIV_APPS=( $(prefix_match "system_ext/priv-app/") )
818 if [ "${#SE_PRIV_APPS[@]}" -gt "0" ]; then
819 write_blueprint_packages "APPS" "system_ext" "priv-app" "SE_PRIV_APPS" >> "$ANDROIDBP"
820 fi
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700821 local O_APPS=( $(prefix_match "odm/app/") )
822 if [ "${#O_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100823 write_blueprint_packages "APPS" "odm" "" "O_APPS" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700824 fi
825 local O_PRIV_APPS=( $(prefix_match "odm/priv-app/") )
826 if [ "${#O_PRIV_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100827 write_blueprint_packages "APPS" "odm" "priv-app" "O_PRIV_APPS" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700828 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700829
830 # Framework
831 local FRAMEWORK=( $(prefix_match "framework/") )
832 if [ "${#FRAMEWORK[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700833 write_blueprint_packages "JAVA_LIBRARIES" "" "" "FRAMEWORK" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700834 fi
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400835 local S_FRAMEWORK=( $(prefix_match "system/framework/") )
836 if [ "${#S_FRAMEWORK[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700837 write_blueprint_packages "JAVA_LIBRARIES" "system" "" "S_FRAMEWORK" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400838 fi
Christian Oder974b5902017-10-08 23:15:52 +0200839 local V_FRAMEWORK=( $(prefix_match "vendor/framework/") )
Michael Bestas26eb01e2018-02-27 22:31:55 +0200840 if [ "${#V_FRAMEWORK[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700841 write_blueprint_packages "JAVA_LIBRARIES" "vendor" "" "V_FRAMEWORK" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500842 fi
843 local P_FRAMEWORK=( $(prefix_match "product/framework/") )
844 if [ "${#P_FRAMEWORK[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700845 write_blueprint_packages "JAVA_LIBRARIES" "product" "" "P_FRAMEWORK" >> "$ANDROIDBP"
Christian Oder974b5902017-10-08 23:15:52 +0200846 fi
Luca Stefani776be462020-09-09 15:53:58 +0200847 local SE_FRAMEWORK=( $(prefix_match "system_ext/framework/") )
Alexander Koskovich052c77d2020-09-16 17:58:53 -0700848 if [ "${#SE_FRAMEWORK[@]}" -gt "0" ]; then
Luca Stefani776be462020-09-09 15:53:58 +0200849 write_blueprint_packages "JAVA_LIBRARIES" "system_ext" "" "SE_FRAMEWORK" >> "$ANDROIDBP"
850 fi
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700851 local O_FRAMEWORK=( $(prefix_match "odm/framework/") )
852 if [ "${#O_FRAMEWORK[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700853 write_blueprint_packages "JAVA_LIBRARIES" "odm" "" "O_FRAMEWORK" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700854 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700855
856 # Etc
857 local ETC=( $(prefix_match "etc/") )
858 if [ "${#ETC[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700859 write_blueprint_packages "ETC" "" "" "ETC" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700860 fi
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400861 local S_ETC=( $(prefix_match "system/etc/") )
862 if [ "${#ETC[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700863 write_blueprint_packages "ETC" "system" "" "S_ETC" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400864 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700865 local V_ETC=( $(prefix_match "vendor/etc/") )
866 if [ "${#V_ETC[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700867 write_blueprint_packages "ETC" "vendor" "" "V_ETC" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500868 fi
869 local P_ETC=( $(prefix_match "product/etc/") )
870 if [ "${#P_ETC[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700871 write_blueprint_packages "ETC" "product" "" "P_ETC" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700872 fi
Luca Stefani776be462020-09-09 15:53:58 +0200873 local SE_ETC=( $(prefix_match "system_ext/etc/") )
874 if [ "${#SE_ETC[@]}" -gt "0" ]; then
875 write_blueprint_packages "ETC" "system_ext" "" "SE_ETC" >> "$ANDROIDBP"
876 fi
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700877 local O_ETC=( $(prefix_match "odm/etc/") )
878 if [ "${#O_ETC[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700879 write_blueprint_packages "ETC" "odm" "" "O_ETC" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700880 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700881
882 # Executables
883 local BIN=( $(prefix_match "bin/") )
884 if [ "${#BIN[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700885 write_blueprint_packages "EXECUTABLES" "" "" "BIN" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700886 fi
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400887 local S_BIN=( $(prefix_match "system/bin/") )
888 if [ "${#BIN[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700889 write_blueprint_packages "EXECUTABLES" "system" "" "S_BIN" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400890 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700891 local V_BIN=( $(prefix_match "vendor/bin/") )
892 if [ "${#V_BIN[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700893 write_blueprint_packages "EXECUTABLES" "vendor" "" "V_BIN" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500894 fi
895 local P_BIN=( $(prefix_match "product/bin/") )
896 if [ "${#P_BIN[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700897 write_blueprint_packages "EXECUTABLES" "product" "" "P_BIN" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700898 fi
Luca Stefani776be462020-09-09 15:53:58 +0200899 local SE_BIN=( $(prefix_match "system_ext/bin/") )
900 if [ "${#SE_BIN[@]}" -gt "0" ]; then
901 write_blueprint_packages "EXECUTABLES" "system_ext" "" "SE_BIN" >> "$ANDROIDBP"
902 fi
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700903 local O_BIN=( $(prefix_match "odm/bin/") )
904 if [ "${#O_BIN[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700905 write_blueprint_packages "EXECUTABLES" "odm" "" "O_BIN" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700906 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700907 local SBIN=( $(prefix_match "sbin/") )
908 if [ "${#SBIN[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700909 write_makefile_packages "EXECUTABLES" "" "sbin" "SBIN" >> "$ANDROIDMK"
Steve Kondik5bd66602016-07-15 10:39:58 -0700910 fi
911
912
913 # Actually write out the final PRODUCT_PACKAGES list
914 local PACKAGE_COUNT=${#PACKAGE_LIST[@]}
915
916 if [ "$PACKAGE_COUNT" -eq "0" ]; then
917 return 0
918 fi
919
920 printf '\n%s\n' "PRODUCT_PACKAGES += \\" >> "$PRODUCTMK"
921 for (( i=1; i<PACKAGE_COUNT+1; i++ )); do
922 local LINEEND=" \\"
923 if [ "$i" -eq "$PACKAGE_COUNT" ]; then
924 LINEEND=""
925 fi
926 printf ' %s%s\n' "${PACKAGE_LIST[$i-1]}" "$LINEEND" >> "$PRODUCTMK"
927 done
928}
929
930#
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -0700931# write_blueprint_header:
Steve Kondik5bd66602016-07-15 10:39:58 -0700932#
933# $1: file which will be written to
934#
Michael Bestasa2934df2020-12-19 03:50:32 +0200935# writes out the warning message regarding manual file modifications.
Steve Kondik5bd66602016-07-15 10:39:58 -0700936# note that this is not an append operation, and should
937# be executed first!
938#
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -0700939function write_blueprint_header() {
940 if [ -f $1 ]; then
941 rm $1
942 fi
943
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -0700944 [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON"
945
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -0700946 cat << EOF >> $1
Michael Bestasa2934df2020-12-19 03:50:32 +0200947// Automatically generated file. DO NOT MODIFY
948//
949// This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -0700950
951EOF
952}
953
954#
955# write_makefile_header:
956#
957# $1: file which will be written to
958#
Michael Bestasa2934df2020-12-19 03:50:32 +0200959# writes out the warning message regarding manual file modifications.
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -0700960# note that this is not an append operation, and should
961# be executed first!
962#
963function write_makefile_header() {
Jake Whatley9843b322017-01-25 21:49:16 -0500964 if [ -f $1 ]; then
965 rm $1
966 fi
967
Steve Kondik5bd66602016-07-15 10:39:58 -0700968 [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON"
969
Jake Whatley9843b322017-01-25 21:49:16 -0500970 cat << EOF >> $1
Michael Bestasa2934df2020-12-19 03:50:32 +0200971# Automatically generated file. DO NOT MODIFY
Steve Kondik5bd66602016-07-15 10:39:58 -0700972#
Steve Kondik5bd66602016-07-15 10:39:58 -0700973# This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh
974
975EOF
976}
977
978#
979# write_headers:
980#
981# $1: devices falling under common to be added to guard - optional
Jake Whatley9843b322017-01-25 21:49:16 -0500982# $2: custom guard - optional
Steve Kondik5bd66602016-07-15 10:39:58 -0700983#
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -0700984# Calls write_makefile_header for each of the makefiles and
985# write_blueprint_header for Android.bp and creates the initial
986# path declaration and device guard for the Android.mk
Steve Kondik5bd66602016-07-15 10:39:58 -0700987#
988function write_headers() {
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -0700989 write_makefile_header "$ANDROIDMK"
Jake Whatley9843b322017-01-25 21:49:16 -0500990
991 GUARD="$2"
992 if [ -z "$GUARD" ]; then
993 GUARD="TARGET_DEVICE"
994 fi
995
Steve Kondik5bd66602016-07-15 10:39:58 -0700996 cat << EOF >> "$ANDROIDMK"
997LOCAL_PATH := \$(call my-dir)
998
999EOF
1000 if [ "$COMMON" -ne 1 ]; then
1001 cat << EOF >> "$ANDROIDMK"
Jake Whatley9843b322017-01-25 21:49:16 -05001002ifeq (\$($GUARD),$DEVICE)
Steve Kondik5bd66602016-07-15 10:39:58 -07001003
1004EOF
1005 else
1006 if [ -z "$1" ]; then
1007 echo "Argument with devices to be added to guard must be set!"
1008 exit 1
1009 fi
1010 cat << EOF >> "$ANDROIDMK"
Jake Whatley9843b322017-01-25 21:49:16 -05001011ifneq (\$(filter $1,\$($GUARD)),)
Steve Kondik5bd66602016-07-15 10:39:58 -07001012
1013EOF
1014 fi
1015
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -07001016 write_makefile_header "$BOARDMK"
1017 write_makefile_header "$PRODUCTMK"
1018 write_blueprint_header "$ANDROIDBP"
1019
1020 cat << EOF >> "$ANDROIDBP"
1021soong_namespace {
1022}
1023
1024EOF
1025
1026 [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON"
1027 cat << EOF >> "$PRODUCTMK"
1028PRODUCT_SOONG_NAMESPACES += \\
1029 vendor/$VENDOR/$DEVICE
1030
1031EOF
Steve Kondik5bd66602016-07-15 10:39:58 -07001032}
1033
1034#
1035# write_footers:
1036#
1037# Closes the inital guard and any other finalization tasks. Must
1038# be called as the final step.
1039#
1040function write_footers() {
1041 cat << EOF >> "$ANDROIDMK"
1042endif
1043EOF
1044}
1045
1046# Return success if adb is up and not in recovery
1047function _adb_connected {
1048 {
Jake Whatley9843b322017-01-25 21:49:16 -05001049 if [[ "$(adb get-state)" == device ]]
Steve Kondik5bd66602016-07-15 10:39:58 -07001050 then
1051 return 0
1052 fi
1053 } 2>/dev/null
1054
1055 return 1
1056};
1057
1058#
1059# parse_file_list:
1060#
1061# $1: input file
Rashed Abdel-Tawabb0d08e82017-04-04 02:48:18 -04001062# $2: blob section in file - optional
Steve Kondik5bd66602016-07-15 10:39:58 -07001063#
1064# Sets PRODUCT_PACKAGES and PRODUCT_COPY_FILES while parsing the input file
1065#
1066function parse_file_list() {
1067 if [ -z "$1" ]; then
1068 echo "An input file is expected!"
1069 exit 1
1070 elif [ ! -f "$1" ]; then
1071 echo "Input file "$1" does not exist!"
1072 exit 1
1073 fi
1074
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001075 if [ -n "$2" ]; then
1076 echo "Using section \"$2\""
Rashed Abdel-Tawabb0d08e82017-04-04 02:48:18 -04001077 LIST=$TMPDIR/files.txt
Vladimir Olteanfa79f212019-01-19 00:44:07 +02001078 # Match all lines starting with first line found to start* with '#'
1079 # comment and contain** $2, and ending with first line to be empty*.
1080 # *whitespaces (tabs, spaces) at the beginning of lines are discarded
1081 # **the $2 match is case-insensitive
1082 cat $1 | sed -n '/^[[:space:]]*#.*'"$2"'/I,/^[[:space:]]*$/ p' > $LIST
Rashed Abdel-Tawabb0d08e82017-04-04 02:48:18 -04001083 else
1084 LIST=$1
1085 fi
1086
1087
Steve Kondik5bd66602016-07-15 10:39:58 -07001088 PRODUCT_PACKAGES_LIST=()
1089 PRODUCT_PACKAGES_HASHES=()
Vladimir Olteande985fe2019-01-17 03:07:34 +02001090 PRODUCT_PACKAGES_FIXUP_HASHES=()
Steve Kondik5bd66602016-07-15 10:39:58 -07001091 PRODUCT_COPY_FILES_LIST=()
1092 PRODUCT_COPY_FILES_HASHES=()
Vladimir Olteande985fe2019-01-17 03:07:34 +02001093 PRODUCT_COPY_FILES_FIXUP_HASHES=()
Steve Kondik5bd66602016-07-15 10:39:58 -07001094
1095 while read -r line; do
1096 if [ -z "$line" ]; then continue; fi
1097
1098 # If the line has a pipe delimiter, a sha1 hash should follow.
1099 # This indicates the file should be pinned and not overwritten
1100 # when extracting files.
1101 local SPLIT=(${line//\|/ })
1102 local COUNT=${#SPLIT[@]}
1103 local SPEC=${SPLIT[0]}
1104 local HASH="x"
Vladimir Olteande985fe2019-01-17 03:07:34 +02001105 local FIXUP_HASH="x"
Steve Kondik5bd66602016-07-15 10:39:58 -07001106 if [ "$COUNT" -gt "1" ]; then
1107 HASH=${SPLIT[1]}
1108 fi
Vladimir Olteande985fe2019-01-17 03:07:34 +02001109 if [ "$COUNT" -gt "2" ]; then
1110 FIXUP_HASH=${SPLIT[2]}
1111 fi
Steve Kondik5bd66602016-07-15 10:39:58 -07001112
1113 # if line starts with a dash, it needs to be packaged
1114 if [[ "$SPEC" =~ ^- ]]; then
1115 PRODUCT_PACKAGES_LIST+=("${SPEC#-}")
1116 PRODUCT_PACKAGES_HASHES+=("$HASH")
Vladimir Olteande985fe2019-01-17 03:07:34 +02001117 PRODUCT_PACKAGES_FIXUP_HASHES+=("$FIXUP_HASH")
Steve Kondik5bd66602016-07-15 10:39:58 -07001118 else
1119 PRODUCT_COPY_FILES_LIST+=("$SPEC")
1120 PRODUCT_COPY_FILES_HASHES+=("$HASH")
Vladimir Olteande985fe2019-01-17 03:07:34 +02001121 PRODUCT_COPY_FILES_FIXUP_HASHES+=("$FIXUP_HASH")
Steve Kondik5bd66602016-07-15 10:39:58 -07001122 fi
1123
Rashed Abdel-Tawabb0d08e82017-04-04 02:48:18 -04001124 done < <(egrep -v '(^#|^[[:space:]]*$)' "$LIST" | LC_ALL=C sort | uniq)
Steve Kondik5bd66602016-07-15 10:39:58 -07001125}
1126
1127#
1128# write_makefiles:
1129#
1130# $1: file containing the list of items to extract
Rashed Abdel-Tawab7fd3ccb2017-10-07 14:18:39 -04001131# $2: make treble compatible makefile - optional
Steve Kondik5bd66602016-07-15 10:39:58 -07001132#
1133# Calls write_product_copy_files and write_product_packages on
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -07001134# the given file and appends to the Android.bp as well as
Steve Kondik5bd66602016-07-15 10:39:58 -07001135# the product makefile.
1136#
1137function write_makefiles() {
1138 parse_file_list "$1"
Rashed Abdel-Tawab7fd3ccb2017-10-07 14:18:39 -04001139 write_product_copy_files "$2"
Steve Kondik5bd66602016-07-15 10:39:58 -07001140 write_product_packages
1141}
1142
1143#
1144# append_firmware_calls_to_makefiles:
1145#
1146# Appends to Android.mk the calls to all images present in radio folder
1147# (filesmap file used by releasetools to map firmware images should be kept in the device tree)
1148#
1149function append_firmware_calls_to_makefiles() {
1150 cat << EOF >> "$ANDROIDMK"
1151ifeq (\$(LOCAL_PATH)/radio, \$(wildcard \$(LOCAL_PATH)/radio))
1152
1153RADIO_FILES := \$(wildcard \$(LOCAL_PATH)/radio/*)
1154\$(foreach f, \$(notdir \$(RADIO_FILES)), \\
1155 \$(call add-radio-file,radio/\$(f)))
1156\$(call add-radio-file,../../../device/$VENDOR/$DEVICE/radio/filesmap)
1157
1158endif
1159
1160EOF
1161}
1162
1163#
1164# get_file:
1165#
1166# $1: input file
1167# $2: target file/folder
1168# $3: source of the file (can be "adb" or a local folder)
1169#
1170# Silently extracts the input file to defined target
1171# Returns success if file can be pulled from the device or found locally
1172#
1173function get_file() {
1174 local SRC="$3"
1175
1176 if [ "$SRC" = "adb" ]; then
1177 # try to pull
1178 adb pull "$1" "$2" >/dev/null 2>&1 && return 0
1179
1180 return 1
1181 else
1182 # try to copy
Vladimir Olteanfe49eae2018-06-25 00:05:56 +03001183 cp -r "$SRC/$1" "$2" 2>/dev/null && return 0
1184 cp -r "$SRC/${1#/system}" "$2" 2>/dev/null && return 0
Vladimir Oltean6780da32019-01-06 19:38:31 +02001185 cp -r "$SRC/system/$1" "$2" 2>/dev/null && return 0
Steve Kondik5bd66602016-07-15 10:39:58 -07001186
1187 return 1
1188 fi
1189};
1190
1191#
1192# oat2dex:
1193#
1194# $1: extracted apk|jar (to check if deodex is required)
1195# $2: odexed apk|jar to deodex
1196# $3: source of the odexed apk|jar
1197#
1198# Convert apk|jar .odex in the corresposing classes.dex
1199#
1200function oat2dex() {
theimpulson9a911af2019-08-14 03:25:12 +00001201 local OMNI_TARGET="$1"
Steve Kondik5bd66602016-07-15 10:39:58 -07001202 local OEM_TARGET="$2"
1203 local SRC="$3"
1204 local TARGET=
Joe Maplesfb3941c2018-01-05 14:51:33 -05001205 local OAT=
Steve Kondik5bd66602016-07-15 10:39:58 -07001206
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001207 if [ -z "$BAKSMALIJAR" ] || [ -z "$SMALIJAR" ]; then
1208 export BAKSMALIJAR="$OMNI_ROOT"/vendor/omni/build/tools/smali/baksmali.jar
1209 export SMALIJAR="$OMNI_ROOT"/vendor/omni/build/tools/smali/smali.jar
Steve Kondik5bd66602016-07-15 10:39:58 -07001210 fi
1211
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001212 if [ -z "$VDEXEXTRACTOR" ]; then
Han Wang7a0b0bd2020-03-10 09:40:47 +02001213 export VDEXEXTRACTOR="$OMNI_ROOT"/vendor/omni/build/tools/${HOST}/vdexExtractor
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001214 fi
Joe Maplesfb3941c2018-01-05 14:51:33 -05001215
codeworkx85eda752018-09-23 12:36:57 +02001216 if [ -z "$CDEXCONVERTER" ]; then
Han Wang7a0b0bd2020-03-10 09:40:47 +02001217 export CDEXCONVERTER="$OMNI_ROOT"/vendor/omni/build/tools/${HOST}/compact_dex_converter
codeworkx85eda752018-09-23 12:36:57 +02001218 fi
1219
Steve Kondik5bd66602016-07-15 10:39:58 -07001220 # Extract existing boot.oats to the temp folder
1221 if [ -z "$ARCHES" ]; then
Jake Whatley9843b322017-01-25 21:49:16 -05001222 echo "Checking if system is odexed and locating boot.oats..."
Steve Kondik5bd66602016-07-15 10:39:58 -07001223 for ARCH in "arm64" "arm" "x86_64" "x86"; do
Jake Whatley9843b322017-01-25 21:49:16 -05001224 mkdir -p "$TMPDIR/system/framework/$ARCH"
Vladimir Olteanfe49eae2018-06-25 00:05:56 +03001225 if get_file "/system/framework/$ARCH" "$TMPDIR/system/framework/" "$SRC"; then
Steve Kondik5bd66602016-07-15 10:39:58 -07001226 ARCHES+="$ARCH "
Jake Whatley9843b322017-01-25 21:49:16 -05001227 else
1228 rmdir "$TMPDIR/system/framework/$ARCH"
Steve Kondik5bd66602016-07-15 10:39:58 -07001229 fi
1230 done
1231 fi
1232
1233 if [ -z "$ARCHES" ]; then
1234 FULLY_DEODEXED=1 && return 0 # system is fully deodexed, return
1235 fi
1236
theimpulson9a911af2019-08-14 03:25:12 +00001237 if [ ! -f "$OMNI_TARGET" ]; then
Steve Kondik5bd66602016-07-15 10:39:58 -07001238 return;
1239 fi
1240
theimpulson9a911af2019-08-14 03:25:12 +00001241 if grep "classes.dex" "$OMNI_TARGET" >/dev/null; then
Steve Kondik5bd66602016-07-15 10:39:58 -07001242 return 0 # target apk|jar is already odexed, return
1243 fi
1244
1245 for ARCH in $ARCHES; do
Jake Whatley9843b322017-01-25 21:49:16 -05001246 BOOTOAT="$TMPDIR/system/framework/$ARCH/boot.oat"
Steve Kondik5bd66602016-07-15 10:39:58 -07001247
Joe Maplesfb3941c2018-01-05 14:51:33 -05001248 local OAT="$(dirname "$OEM_TARGET")/oat/$ARCH/$(basename "$OEM_TARGET" ."${OEM_TARGET##*.}").odex"
1249 local VDEX="$(dirname "$OEM_TARGET")/oat/$ARCH/$(basename "$OEM_TARGET" ."${OEM_TARGET##*.}").vdex"
Steve Kondik5bd66602016-07-15 10:39:58 -07001250
Joe Maplesfb3941c2018-01-05 14:51:33 -05001251 if get_file "$OAT" "$TMPDIR" "$SRC"; then
1252 if get_file "$VDEX" "$TMPDIR" "$SRC"; then
1253 "$VDEXEXTRACTOR" -o "$TMPDIR/" -i "$TMPDIR/$(basename "$VDEX")" > /dev/null
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001254 CLASSES=$(ls "$TMPDIR/$(basename "${OEM_TARGET%.*}")_classes"*)
1255 for CLASS in $CLASSES; do
1256 NEWCLASS=$(echo "$CLASS" | sed 's/.*_//;s/cdex/dex/')
1257 # Check if we have to deal with CompactDex
1258 if [[ "$CLASS" == *.cdex ]]; then
1259 "$CDEXCONVERTER" "$CLASS" &>/dev/null
1260 mv "$CLASS.new" "$TMPDIR/$NEWCLASS"
1261 else
1262 mv "$CLASS" "$TMPDIR/$NEWCLASS"
1263 fi
1264 done
Joe Maplesfb3941c2018-01-05 14:51:33 -05001265 else
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001266 java -jar "$BAKSMALIJAR" deodex -o "$TMPDIR/dexout" -b "$BOOTOAT" -d "$TMPDIR" "$TMPDIR/$(basename "$OAT")"
1267 java -jar "$SMALIJAR" assemble "$TMPDIR/dexout" -o "$TMPDIR/classes.dex"
Joe Maplesfb3941c2018-01-05 14:51:33 -05001268 fi
theimpulson9a911af2019-08-14 03:25:12 +00001269 elif [[ "$OMNI_TARGET" =~ .jar$ ]]; then
Jake Whatley9843b322017-01-25 21:49:16 -05001270 JAROAT="$TMPDIR/system/framework/$ARCH/boot-$(basename ${OEM_TARGET%.*}).oat"
Luca Stefani082f1e82018-10-07 12:44:53 +02001271 JARVDEX="/system/framework/boot-$(basename ${OEM_TARGET%.*}).vdex"
Jake Whatley9843b322017-01-25 21:49:16 -05001272 if [ ! -f "$JAROAT" ]; then
Luca Stefani082f1e82018-10-07 12:44:53 +02001273 JAROAT=$BOOTOAT
Jake Whatley9843b322017-01-25 21:49:16 -05001274 fi
Joe Maplesfb3941c2018-01-05 14:51:33 -05001275 # try to extract classes.dex from boot.vdex for frameworks jars
1276 # fallback to boot.oat if vdex is not available
Luca Stefani082f1e82018-10-07 12:44:53 +02001277 if get_file "$JARVDEX" "$TMPDIR" "$SRC"; then
Luca Stefani6f92e6b2018-10-31 19:16:05 +01001278 "$VDEXEXTRACTOR" -o "$TMPDIR/" -i "$TMPDIR/$(basename "$JARVDEX")" > /dev/null
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001279 CLASSES=$(ls "$TMPDIR/$(basename "${JARVDEX%.*}")_classes"*)
1280 for CLASS in $CLASSES; do
1281 NEWCLASS=$(echo "$CLASS" | sed 's/.*_//;s/cdex/dex/')
1282 # Check if we have to deal with CompactDex
1283 if [[ "$CLASS" == *.cdex ]]; then
1284 "$CDEXCONVERTER" "$CLASS" &>/dev/null
1285 mv "$CLASS.new" "$TMPDIR/$NEWCLASS"
1286 else
1287 mv "$CLASS" "$TMPDIR/$NEWCLASS"
1288 fi
1289 done
Joe Maplesfb3941c2018-01-05 14:51:33 -05001290 else
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001291 java -jar "$BAKSMALIJAR" deodex -o "$TMPDIR/dexout" -b "$BOOTOAT" -d "$TMPDIR" "$JAROAT/$OEM_TARGET"
1292 java -jar "$SMALIJAR" assemble "$TMPDIR/dexout" -o "$TMPDIR/classes.dex"
Joe Maplesfb3941c2018-01-05 14:51:33 -05001293 fi
Steve Kondik5bd66602016-07-15 10:39:58 -07001294 else
1295 continue
1296 fi
1297
Steve Kondik5bd66602016-07-15 10:39:58 -07001298 done
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001299
1300 rm -rf "$TMPDIR/dexout"
Steve Kondik5bd66602016-07-15 10:39:58 -07001301}
1302
1303#
1304# init_adb_connection:
1305#
1306# Starts adb server and waits for the device
1307#
1308function init_adb_connection() {
1309 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
1310 if ! _adb_connected; then
1311 echo "No device is online. Waiting for one..."
1312 echo "Please connect USB and/or enable USB debugging"
1313 until _adb_connected; do
1314 sleep 1
1315 done
1316 echo "Device Found."
1317 fi
1318
1319 # Retrieve IP and PORT info if we're using a TCP connection
1320 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
1321 | head -1 | awk '{print $1}')
1322 adb root &> /dev/null
1323 sleep 0.3
1324 if [ -n "$TCPIPPORT" ]; then
1325 # adb root just killed our connection
1326 # so reconnect...
1327 adb connect "$TCPIPPORT"
1328 fi
1329 adb wait-for-device &> /dev/null
1330 sleep 0.3
1331}
1332
1333#
1334# fix_xml:
1335#
1336# $1: xml file to fix
1337#
1338function fix_xml() {
1339 local XML="$1"
1340 local TEMP_XML="$TMPDIR/`basename "$XML"`.temp"
1341
Dobroslaw Kijowski3af2a8d2017-05-18 12:35:02 +02001342 grep -a '^<?xml version' "$XML" > "$TEMP_XML"
1343 grep -av '^<?xml version' "$XML" >> "$TEMP_XML"
Steve Kondik5bd66602016-07-15 10:39:58 -07001344
1345 mv "$TEMP_XML" "$XML"
1346}
1347
Vladimir Olteande985fe2019-01-17 03:07:34 +02001348function get_hash() {
1349 local FILE="$1"
1350
1351 if [ "$(uname)" == "Darwin" ]; then
1352 shasum "${FILE}" | awk '{print $1}'
1353 else
1354 sha1sum "${FILE}" | awk '{print $1}'
1355 fi
1356}
1357
Vladimir Olteana7d20492019-01-17 03:05:52 +02001358function print_spec() {
1359 local SPEC_PRODUCT_PACKAGE="$1"
1360 local SPEC_SRC_FILE="$2"
1361 local SPEC_DST_FILE="$3"
1362 local SPEC_ARGS="$4"
1363 local SPEC_HASH="$5"
Vladimir Olteande985fe2019-01-17 03:07:34 +02001364 local SPEC_FIXUP_HASH="$6"
Vladimir Olteana7d20492019-01-17 03:05:52 +02001365
1366 local PRODUCT_PACKAGE=""
1367 if [ ${SPEC_PRODUCT_PACKAGE} = true ]; then
1368 PRODUCT_PACKAGE="-"
1369 fi
1370 local SRC=""
1371 if [ ! -z "${SPEC_SRC_FILE}" ] && [ "${SPEC_SRC_FILE}" != "${SPEC_DST_FILE}" ]; then
1372 SRC="${SPEC_SRC_FILE}:"
1373 fi
1374 local DST=""
1375 if [ ! -z "${SPEC_DST_FILE}" ]; then
1376 DST="${SPEC_DST_FILE}"
1377 fi
1378 local ARGS=""
1379 if [ ! -z "${SPEC_ARGS}" ]; then
1380 ARGS=";${SPEC_ARGS}"
1381 fi
1382 local HASH=""
1383 if [ ! -z "${SPEC_HASH}" ] && [ "${SPEC_HASH}" != "x" ]; then
1384 HASH="|${SPEC_HASH}"
1385 fi
Vladimir Olteande985fe2019-01-17 03:07:34 +02001386 local FIXUP_HASH=""
1387 if [ ! -z "${SPEC_FIXUP_HASH}" ] && [ "${SPEC_FIXUP_HASH}" != "x" ] && [ "${SPEC_FIXUP_HASH}" != "${SPEC_HASH}" ]; then
1388 FIXUP_HASH="|${SPEC_FIXUP_HASH}"
1389 fi
1390 printf '%s%s%s%s%s%s\n' "${PRODUCT_PACKAGE}" "${SRC}" "${DST}" "${ARGS}" "${HASH}" "${FIXUP_HASH}"
1391}
1392
1393# To be overridden by device-level extract-files.sh
1394# Parameters:
1395# $1: spec name of a blob. Can be used for filtering.
1396# If the spec is "src:dest", then $1 is "dest".
1397# If the spec is "src", then $1 is "src".
1398# $2: path to blob file. Can be used for fixups.
1399#
1400function blob_fixup() {
1401 :
Vladimir Olteana7d20492019-01-17 03:05:52 +02001402}
1403
Steve Kondik5bd66602016-07-15 10:39:58 -07001404#
1405# extract:
1406#
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001407# Positional parameters:
1408# $1: file containing the list of items to extract (aka proprietary-files.txt)
Dan Pasanen0cc05012017-03-21 09:06:11 -05001409# $2: path to extracted system folder, an ota zip file, or "adb" to extract from device
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001410# $3: section in list file to extract - optional. Setting section via $3 is deprecated.
1411#
1412# Non-positional parameters (coming after $2):
1413# --section: preferred way of selecting the portion to parse and extract from
1414# proprietary-files.txt
Vladimir Olteana7d20492019-01-17 03:05:52 +02001415# --kang: if present, this option will activate the printing of hashes for the
1416# extracted blobs. Useful with --section for subsequent pinning of
1417# blobs taken from other origins.
Steve Kondik5bd66602016-07-15 10:39:58 -07001418#
1419function extract() {
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001420 # Consume positional parameters
1421 local PROPRIETARY_FILES_TXT="$1"; shift
1422 local SRC="$1"; shift
1423 local SECTION=""
Vladimir Olteana7d20492019-01-17 03:05:52 +02001424 local KANG=false
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001425
1426 # Consume optional, non-positional parameters
1427 while [ "$#" -gt 0 ]; do
1428 case "$1" in
1429 -s|--section)
1430 SECTION="$2"; shift
1431 ;;
Vladimir Olteana7d20492019-01-17 03:05:52 +02001432 -k|--kang)
1433 KANG=true
1434 DISABLE_PINNING=1
1435 ;;
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001436 *)
1437 # Backwards-compatibility with the old behavior, where $3, if
1438 # present, denoted an optional positional ${SECTION} argument.
1439 # Users of ${SECTION} are encouraged to migrate from setting it as
1440 # positional $3, to non-positional --section ${SECTION}, the
1441 # reason being that it doesn't scale to have more than 1 optional
1442 # positional argument.
1443 SECTION="$1"
1444 ;;
1445 esac
1446 shift
1447 done
1448
Steve Kondik5bd66602016-07-15 10:39:58 -07001449 if [ -z "$OUTDIR" ]; then
1450 echo "Output dir not set!"
1451 exit 1
1452 fi
1453
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001454 parse_file_list "${PROPRIETARY_FILES_TXT}" "${SECTION}"
Steve Kondik5bd66602016-07-15 10:39:58 -07001455
1456 # Allow failing, so we can try $DEST and/or $FILE
1457 set +e
1458
1459 local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ${PRODUCT_PACKAGES_LIST[@]} )
1460 local HASHLIST=( ${PRODUCT_COPY_FILES_HASHES[@]} ${PRODUCT_PACKAGES_HASHES[@]} )
Vladimir Olteande985fe2019-01-17 03:07:34 +02001461 local FIXUP_HASHLIST=( ${PRODUCT_COPY_FILES_FIXUP_HASHES[@]} ${PRODUCT_PACKAGES_FIXUP_HASHES[@]} )
Vladimir Olteana7d20492019-01-17 03:05:52 +02001462 local PRODUCT_COPY_FILES_COUNT=${#PRODUCT_COPY_FILES_LIST[@]}
Steve Kondik5bd66602016-07-15 10:39:58 -07001463 local COUNT=${#FILELIST[@]}
theimpulson9a911af2019-08-14 03:25:12 +00001464 local OUTPUT_ROOT="$OMNI_ROOT"/"$OUTDIR"/proprietary
Steve Kondik5bd66602016-07-15 10:39:58 -07001465 local OUTPUT_TMP="$TMPDIR"/"$OUTDIR"/proprietary
1466
1467 if [ "$SRC" = "adb" ]; then
1468 init_adb_connection
1469 fi
1470
Dan Pasanen0cc05012017-03-21 09:06:11 -05001471 if [ -f "$SRC" ] && [ "${SRC##*.}" == "zip" ]; then
conbold9baced42017-11-10 16:33:38 +01001472 DUMPDIR="$TMPDIR"/system_dump
Dan Pasanen0cc05012017-03-21 09:06:11 -05001473
1474 # Check if we're working with the same zip that was passed last time.
1475 # If so, let's just use what's already extracted.
1476 MD5=`md5sum "$SRC"| awk '{print $1}'`
1477 OLDMD5=`cat "$DUMPDIR"/zipmd5.txt`
1478
1479 if [ "$MD5" != "$OLDMD5" ]; then
1480 rm -rf "$DUMPDIR"
1481 mkdir "$DUMPDIR"
1482 unzip "$SRC" -d "$DUMPDIR"
1483 echo "$MD5" > "$DUMPDIR"/zipmd5.txt
1484
1485 # Stop if an A/B OTA zip is detected. We cannot extract these.
1486 if [ -a "$DUMPDIR"/payload.bin ]; then
1487 echo "A/B style OTA zip detected. This is not supported at this time. Stopping..."
1488 exit 1
Dan Pasanen0cc05012017-03-21 09:06:11 -05001489 fi
dianlujitao85ddca62020-04-21 23:03:20 +08001490
Luca Stefani776be462020-09-09 15:53:58 +02001491 for PARTITION in "system" "odm" "product" "system_ext" "vendor"
dianlujitao85ddca62020-04-21 23:03:20 +08001492 do
1493 # If OTA is block based, extract it.
dianlujitaoe2cbe262020-04-21 23:01:13 +08001494 if [ -a "$DUMPDIR"/"$PARTITION".new.dat.br ]; then
1495 echo "Converting "$PARTITION".new.dat.br to "$PARTITION".new.dat"
1496 brotli -d "$DUMPDIR"/"$PARTITION".new.dat.br
1497 rm "$DUMPDIR"/"$PARTITION".new.dat.br
1498 fi
dianlujitao85ddca62020-04-21 23:03:20 +08001499 if [ -a "$DUMPDIR"/"$PARTITION".new.dat ]; then
1500 echo "Converting "$PARTITION".new.dat to "$PARTITION".img"
1501 python "$OMNI_ROOT"/vendor/omni/build/tools/sdat2img.py "$DUMPDIR"/"$PARTITION".transfer.list "$DUMPDIR"/"$PARTITION".new.dat "$DUMPDIR"/"$PARTITION".img 2>&1
1502 rm -rf "$DUMPDIR"/"$PARTITION".new.dat "$DUMPDIR"/"$PARTITION"
1503 mkdir "$DUMPDIR"/"$PARTITION" "$DUMPDIR"/tmp
1504 echo "Requesting sudo access to mount the "$PARTITION".img"
1505 sudo mount -o loop "$DUMPDIR"/"$PARTITION".img "$DUMPDIR"/tmp
1506 cp -r "$DUMPDIR"/tmp/* "$DUMPDIR"/"$PARTITION"/
1507 sudo umount "$DUMPDIR"/tmp
1508 rm -rf "$DUMPDIR"/tmp "$DUMPDIR"/"$PARTITION".img
1509 fi
1510 done
Dan Pasanen0cc05012017-03-21 09:06:11 -05001511 fi
1512
1513 SRC="$DUMPDIR"
1514 fi
1515
Steve Kondik5bd66602016-07-15 10:39:58 -07001516 if [ "$VENDOR_STATE" -eq "0" ]; then
1517 echo "Cleaning output directory ($OUTPUT_ROOT).."
1518 rm -rf "${OUTPUT_TMP:?}"
1519 mkdir -p "${OUTPUT_TMP:?}"
Jake Whatley9843b322017-01-25 21:49:16 -05001520 if [ -d "$OUTPUT_ROOT" ]; then
1521 mv "${OUTPUT_ROOT:?}/"* "${OUTPUT_TMP:?}/"
1522 fi
Steve Kondik5bd66602016-07-15 10:39:58 -07001523 VENDOR_STATE=1
1524 fi
1525
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001526 echo "Extracting ${COUNT} files in ${PROPRIETARY_FILES_TXT} from ${SRC}:"
Steve Kondik5bd66602016-07-15 10:39:58 -07001527
1528 for (( i=1; i<COUNT+1; i++ )); do
1529
Vladimir Oltean8e2de652018-06-24 20:41:30 +03001530 local SPEC_SRC_FILE=$(src_file "${FILELIST[$i-1]}")
Vladimir Olteanb06f3aa2018-06-24 20:38:04 +03001531 local SPEC_DST_FILE=$(target_file "${FILELIST[$i-1]}")
Vladimir Olteand6391332018-06-24 20:42:01 +03001532 local SPEC_ARGS=$(target_args "${FILELIST[$i-1]}")
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001533 local OUTPUT_DIR=
1534 local TMP_DIR=
1535 local SRC_FILE=
1536 local DST_FILE=
Vladimir Olteana7d20492019-01-17 03:05:52 +02001537 local IS_PRODUCT_PACKAGE=false
1538
1539 # Note: this relies on the fact that the ${FILELIST[@]} array
1540 # contains first ${PRODUCT_COPY_FILES_LIST[@]}, then ${PRODUCT_PACKAGES_LIST[@]}.
1541 if [ "${i}" -gt "${PRODUCT_COPY_FILES_COUNT}" ]; then
1542 IS_PRODUCT_PACKAGE=true
1543 fi
Steve Kondik5bd66602016-07-15 10:39:58 -07001544
Vladimir Olteand6391332018-06-24 20:42:01 +03001545 if [ "${SPEC_ARGS}" = "rootfs" ]; then
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001546 OUTPUT_DIR="${OUTPUT_ROOT}/rootfs"
1547 TMP_DIR="${OUTPUT_TMP}/rootfs"
1548 SRC_FILE="/${SPEC_SRC_FILE}"
1549 DST_FILE="/${SPEC_DST_FILE}"
Steve Kondik5bd66602016-07-15 10:39:58 -07001550 else
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001551 OUTPUT_DIR="${OUTPUT_ROOT}"
1552 TMP_DIR="${OUTPUT_TMP}"
1553 SRC_FILE="/system/${SPEC_SRC_FILE}"
1554 DST_FILE="/system/${SPEC_DST_FILE}"
Steve Kondik5bd66602016-07-15 10:39:58 -07001555 fi
1556
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001557 # Strip the file path in the vendor repo of "system", if present
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001558 local BLOB_DISPLAY_NAME="${DST_FILE#/system/}"
dianlujitao4ddcfb72020-04-06 12:43:16 +08001559 local VENDOR_REPO_FILE="$OUTPUT_DIR/${BLOB_DISPLAY_NAME}"
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001560 mkdir -p $(dirname "${VENDOR_REPO_FILE}")
Steve Kondik5bd66602016-07-15 10:39:58 -07001561
Gabriele M58270a32017-11-13 23:15:29 +01001562 # Check pinned files
Vladimir Olteane688cf92019-01-17 02:47:02 +02001563 local HASH="$(echo ${HASHLIST[$i-1]} | awk '{ print tolower($0); }')"
Vladimir Olteande985fe2019-01-17 03:07:34 +02001564 local FIXUP_HASH="$(echo ${FIXUP_HASHLIST[$i-1]} | awk '{ print tolower($0); }')"
Gabriele M58270a32017-11-13 23:15:29 +01001565 local KEEP=""
Vladimir Olteande985fe2019-01-17 03:07:34 +02001566 if [ "$DISABLE_PINNING" != "1" ] && [ "$HASH" != "x" ]; then
Vladimir Oltean4daf5592018-06-24 20:46:42 +03001567 if [ -f "${VENDOR_REPO_FILE}" ]; then
1568 local PINNED="${VENDOR_REPO_FILE}"
Gabriele M58270a32017-11-13 23:15:29 +01001569 else
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001570 local PINNED="${TMP_DIR}${DST_FILE#/system}"
Gabriele M58270a32017-11-13 23:15:29 +01001571 fi
1572 if [ -f "$PINNED" ]; then
Vladimir Olteande985fe2019-01-17 03:07:34 +02001573 local TMP_HASH=$(get_hash "${PINNED}")
1574 if [ "${TMP_HASH}" = "${HASH}" ] || [ "${TMP_HASH}" = "${FIXUP_HASH}" ]; then
Gabriele M58270a32017-11-13 23:15:29 +01001575 KEEP="1"
Vladimir Oltean4daf5592018-06-24 20:46:42 +03001576 if [ ! -f "${VENDOR_REPO_FILE}" ]; then
1577 cp -p "$PINNED" "${VENDOR_REPO_FILE}"
Gabriele M58270a32017-11-13 23:15:29 +01001578 fi
1579 fi
1580 fi
1581 fi
1582
Vladimir Olteana7d20492019-01-17 03:05:52 +02001583 if [ "${KANG}" = false ]; then
1584 printf ' - %s\n' "${BLOB_DISPLAY_NAME}"
1585 fi
1586
Gabriele M58270a32017-11-13 23:15:29 +01001587 if [ "$KEEP" = "1" ]; then
Vladimir Olteana7d20492019-01-17 03:05:52 +02001588 printf ' + keeping pinned file with hash %s\n' "${HASH}"
Steve Kondik5bd66602016-07-15 10:39:58 -07001589 else
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001590 FOUND=false
1591 # Try Lineage target first.
1592 # Also try to search for files stripped of
1593 # the "/system" prefix, if we're actually extracting
1594 # from a system image.
Vladimir Olteanfe49eae2018-06-25 00:05:56 +03001595 for CANDIDATE in "${DST_FILE}" "${SRC_FILE}"; do
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001596 get_file ${CANDIDATE} ${VENDOR_REPO_FILE} ${SRC} && {
1597 FOUND=true
1598 break
1599 }
1600 done
1601
1602 if [ "${FOUND}" = false ]; then
Bruno Martins74e00eb2021-04-10 14:36:50 +01001603 colored_echo red " !! ${BLOB_DISPLAY_NAME}: file not found in source"
Vladimir Oltean11329372018-10-18 00:44:02 +03001604 continue
Steve Kondik5bd66602016-07-15 10:39:58 -07001605 fi
1606 fi
1607
Vladimir Olteande985fe2019-01-17 03:07:34 +02001608 # Blob fixup pipeline has 2 parts: one that is fixed and
1609 # one that is user-configurable
1610 local PRE_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE})
1611 # Deodex apk|jar if that's the case
1612 if [[ "$FULLY_DEODEXED" -ne "1" && "${VENDOR_REPO_FILE}" =~ .(apk|jar)$ ]]; then
1613 oat2dex "${VENDOR_REPO_FILE}" "${SRC_FILE}" "$SRC"
1614 if [ -f "$TMPDIR/classes.dex" ]; then
dianlujitaoded7c1e2020-04-06 12:45:36 +08001615 touch -t 200901010000 "$TMPDIR/classes"*
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001616 zip -gjq "${VENDOR_REPO_FILE}" "$TMPDIR/classes"*
1617 rm "$TMPDIR/classes"*
Vladimir Olteande985fe2019-01-17 03:07:34 +02001618 printf ' (updated %s from odex files)\n' "${SRC_FILE}"
Steve Kondik5bd66602016-07-15 10:39:58 -07001619 fi
Vladimir Olteande985fe2019-01-17 03:07:34 +02001620 elif [[ "${VENDOR_REPO_FILE}" =~ .xml$ ]]; then
1621 fix_xml "${VENDOR_REPO_FILE}"
Steve Kondik5bd66602016-07-15 10:39:58 -07001622 fi
Vladimir Olteande985fe2019-01-17 03:07:34 +02001623 # Now run user-supplied fixup function
1624 blob_fixup "${BLOB_DISPLAY_NAME}" "${VENDOR_REPO_FILE}"
1625 local POST_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE})
Steve Kondik5bd66602016-07-15 10:39:58 -07001626
Vladimir Oltean4daf5592018-06-24 20:46:42 +03001627 if [ -f "${VENDOR_REPO_FILE}" ]; then
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001628 local DIR=$(dirname "${VENDOR_REPO_FILE}")
Steve Kondik5bd66602016-07-15 10:39:58 -07001629 local TYPE="${DIR##*/}"
1630 if [ "$TYPE" = "bin" -o "$TYPE" = "sbin" ]; then
Vladimir Oltean4daf5592018-06-24 20:46:42 +03001631 chmod 755 "${VENDOR_REPO_FILE}"
Steve Kondik5bd66602016-07-15 10:39:58 -07001632 else
Vladimir Oltean4daf5592018-06-24 20:46:42 +03001633 chmod 644 "${VENDOR_REPO_FILE}"
Steve Kondik5bd66602016-07-15 10:39:58 -07001634 fi
1635 fi
1636
Vladimir Olteana7d20492019-01-17 03:05:52 +02001637 if [ "${KANG}" = true ]; then
Vladimir Olteande985fe2019-01-17 03:07:34 +02001638 print_spec "${IS_PRODUCT_PACKAGE}" "${SPEC_SRC_FILE}" "${SPEC_DST_FILE}" "${SPEC_ARGS}" "${PRE_FIXUP_HASH}" "${POST_FIXUP_HASH}"
1639 fi
1640
1641 # Check and print whether the fixup pipeline actually did anything.
1642 # This isn't done right after the fixup pipeline because we want this print
1643 # to come after print_spec above, when in kang mode.
1644 if [ "${PRE_FIXUP_HASH}" != "${POST_FIXUP_HASH}" ]; then
1645 printf " + Fixed up %s\n" "${BLOB_DISPLAY_NAME}"
1646 # Now sanity-check the spec for this blob.
1647 if [ "${KANG}" = false ] && [ "${FIXUP_HASH}" = "x" ] && [ "${HASH}" != "x" ]; then
Bruno Martins74e00eb2021-04-10 14:36:50 +01001648 colored_echo yellow "WARNING: The ${BLOB_DISPLAY_NAME} file was fixed up, but it is pinned."
1649 colored_echo yellow "This is a mistake and you want to either remove the hash completely, or add an extra one."
Vladimir Olteande985fe2019-01-17 03:07:34 +02001650 fi
Vladimir Olteana7d20492019-01-17 03:05:52 +02001651 fi
1652
Steve Kondik5bd66602016-07-15 10:39:58 -07001653 done
1654
1655 # Don't allow failing
1656 set -e
1657}
1658
1659#
Rashed Abdel-Tawab5b97a982019-09-29 01:19:57 -04001660# extract2:
1661#
1662# Positional parameters:
1663# $1: file containing the list of items to extract (aka proprietary-files.txt)
1664#
1665# Non-positional parameters (coming after $2):
1666# --section: selects the portion to parse and extracts from proprietary-files.txt
1667# --kang: if present, this option will activate the printing of hashes for the
1668# extracted blobs. Useful with --section for subsequent pinning of
1669# blobs taken from other origins.
1670#
1671function extract2() {
1672 # Consume positional parameters
1673 local PROPRIETARY_FILES_TXT="$1"; shift
1674 local SECTION=""
1675 local KANG=false
1676
1677 # Consume optional, non-positional parameters
1678 while [ "$#" -gt 0 ]; do
1679 case "$1" in
1680 --adb)
1681 ADB=true
1682 ;;
1683 --system)
1684 SYSTEM_SRC="$2"; shift
1685 ;;
1686 --vendor)
1687 VENDOR_SRC="$2"; shift
1688 ;;
1689 --odm)
1690 ODM_SRC="$2"; shift
1691 ;;
1692 --product)
1693 PRODUCT_SRC="$2"; shift
1694 ;;
1695 -s|--section)
1696 SECTION="$2"; shift
1697 ;;
1698 -k|--kang)
1699 KANG=true
1700 DISABLE_PINNING=1
1701 ;;
1702 esac
1703 shift
1704 done
1705
1706 if [ -z "$ADB" ] || [ -z "$SYSTEM_SRC" && -z "$VENDOR_SRC" && -z "$ODM_SRC" && -z "$PRODUCT_SRC" ]; then
1707 echo "No sources set! You must select --adb or pass paths to partition dumps."
1708 exit 1
1709 fi
1710
1711 if [ -z "$OUTDIR" ]; then
1712 echo "Output dir not set!"
1713 exit 1
1714 fi
1715
1716 parse_file_list "${PROPRIETARY_FILES_TXT}" "${SECTION}"
1717
1718 # Allow failing, so we can try $DEST and/or $FILE
1719 set +e
1720
1721 local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ${PRODUCT_PACKAGES_LIST[@]} )
1722 local HASHLIST=( ${PRODUCT_COPY_FILES_HASHES[@]} ${PRODUCT_PACKAGES_HASHES[@]} )
1723 local FIXUP_HASHLIST=( ${PRODUCT_COPY_FILES_FIXUP_HASHES[@]} ${PRODUCT_PACKAGES_FIXUP_HASHES[@]} )
1724 local PRODUCT_COPY_FILES_COUNT=${#PRODUCT_COPY_FILES_LIST[@]}
1725 local COUNT=${#FILELIST[@]}
1726 local OUTPUT_ROOT="$OMNI_ROOT"/"$OUTDIR"/proprietary
1727 local OUTPUT_TMP="$TMPDIR"/"$OUTDIR"/proprietary
1728
1729 if [ "$ADB" = true ]; then
1730 init_adb_connection
1731 fi
1732
1733 if [ "$VENDOR_STATE" -eq "0" ]; then
1734 echo "Cleaning output directory ($OUTPUT_ROOT).."
1735 rm -rf "${OUTPUT_TMP:?}"
1736 mkdir -p "${OUTPUT_TMP:?}"
1737 if [ -d "$OUTPUT_ROOT" ]; then
1738 mv "${OUTPUT_ROOT:?}/"* "${OUTPUT_TMP:?}/"
1739 fi
1740 VENDOR_STATE=1
1741 fi
1742
1743 echo "Extracting ${COUNT} files in ${PROPRIETARY_FILES_TXT} from ${SRC}:"
1744
1745 for (( i=1; i<COUNT+1; i++ )); do
1746
1747 local SPEC_SRC_FILE=$(src_file "${FILELIST[$i-1]}")
1748 local SPEC_DST_FILE=$(target_file "${FILELIST[$i-1]}")
1749 local SPEC_ARGS=$(target_args "${FILELIST[$i-1]}")
1750 local OUTPUT_DIR=
1751 local TMP_DIR=
1752 local SRC_FILE=
1753 local DST_FILE=
1754 local IS_PRODUCT_PACKAGE=false
1755
1756 # Note: this relies on the fact that the ${FILELIST[@]} array
1757 # contains first ${PRODUCT_COPY_FILES_LIST[@]}, then ${PRODUCT_PACKAGES_LIST[@]}.
1758 if [ "${i}" -gt "${PRODUCT_COPY_FILES_COUNT}" ]; then
1759 IS_PRODUCT_PACKAGE=true
1760 fi
1761
1762 if [ "${SPEC_ARGS}" = "rootfs" ]; then
1763 OUTPUT_DIR="${OUTPUT_ROOT}/rootfs"
1764 TMP_DIR="${OUTPUT_TMP}/rootfs"
1765 else
1766 OUTPUT_DIR="${OUTPUT_ROOT}"
1767 TMP_DIR="${OUTPUT_TMP}"
1768 fi
1769 SRC_FILE="${SPEC_SRC_FILE}"
1770 DST_FILE="${SPEC_DST_FILE}"
1771
1772 local VENDOR_REPO_FILE="$OUTPUT_DIR/${DST_FILE}"
1773 local BLOB_DISPLAY_NAME="${DST_FILE}"
1774 mkdir -p $(dirname "${VENDOR_REPO_FILE}")
1775
1776 # Check pinned files
1777 local HASH="$(echo ${HASHLIST[$i-1]} | awk '{ print tolower($0); }')"
1778 local FIXUP_HASH="$(echo ${FIXUP_HASHLIST[$i-1]} | awk '{ print tolower($0); }')"
1779 local KEEP=""
1780 if [ "$DISABLE_PINNING" != "1" ] && [ "$HASH" != "x" ]; then
1781 if [ -f "${VENDOR_REPO_FILE}" ]; then
1782 local PINNED="${VENDOR_REPO_FILE}"
1783 else
1784 local PINNED="${TMP_DIR}${DST_FILE}"
1785 fi
1786 if [ -f "$PINNED" ]; then
1787 local TMP_HASH=$(get_hash "${PINNED}")
1788 if [ "${TMP_HASH}" = "${HASH}" ] || [ "${TMP_HASH}" = "${FIXUP_HASH}" ]; then
1789 KEEP="1"
1790 if [ ! -f "${VENDOR_REPO_FILE}" ]; then
1791 cp -p "$PINNED" "${VENDOR_REPO_FILE}"
1792 fi
1793 fi
1794 fi
1795 fi
1796
1797 if [ "${KANG}" = false ]; then
1798 printf ' - %s\n' "${BLOB_DISPLAY_NAME}"
1799 fi
1800
1801 if [ "$KEEP" = "1" ]; then
1802 printf ' + keeping pinned file with hash %s\n' "${HASH}"
1803 else
1804 FOUND=false
1805 PARTITION_SOURCE_DIR=
1806 # Try Lineage target first.
1807 for CANDIDATE in "${DST_FILE}" "${SRC_FILE}"; do
1808 PARTITION=$(echo "$CANDIDATE" | cut -d/ -f1)
1809 if [ "$PARTITION" = "system" ]; then
1810 PARTITION_SOURCE_DIR="$SYSTEM_SRC"
1811 elif [ "$PARTITION" = "vendor" ]; then
1812 PARTITION_SOURCE_DIR="$VENDOR_SRC"
1813 elif [ "$PARTITION" = "product" ]; then
1814 PARTITION_SOURCE_DIR="$PRODUCT_SRC"
1815 elif [ "$PARTITION" = "odm" ]; then
1816 PARTITION_SOURCE_DIR="$ODM_SRC"
1817 fi
1818 CANDIDATE_RELATIVE_NAME=$(echo "$CANDIDATE" | cut -d/ -f2-)
1819 get_file ${CANDIDATE_RELATIVE_NAME} ${VENDOR_REPO_FILE} ${PARTITION_SOURCE_DIR} && {
1820 FOUND=true
1821 break
1822 }
1823 # Search with the full system/ prefix if the file was not found on the system partition
1824 # because we may be searching in a mounted system-as-root system.img
1825 if [[ "${FOUND}" = false && "$PARTITION" = "system" ]]; then
1826 get_file ${CANDIDATE} ${VENDOR_REPO_FILE} ${PARTITION_SOURCE_DIR} && {
1827 FOUND=true
1828 break
1829 }
1830 fi
1831 done
1832
1833 if [ -z "${PARTITION_SOURCE_DIR}" ]; then
1834 echo "$CANDIDATE has no preceeding partition path. Prepend system/, vendor/, product/, or odm/ to this entry."
1835 fi
1836
1837 if [ "${FOUND}" = false ]; then
1838 printf ' !! %s: file not found in source\n' "${BLOB_DISPLAY_NAME}"
1839 continue
1840 fi
1841 fi
1842
1843 # Blob fixup pipeline has 2 parts: one that is fixed and
1844 # one that is user-configurable
1845 local PRE_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE})
1846 # Deodex apk|jar if that's the case
1847 if [[ "$FULLY_DEODEXED" -ne "1" && "${VENDOR_REPO_FILE}" =~ .(apk|jar)$ ]]; then
1848 oat2dex "${VENDOR_REPO_FILE}" "${SRC_FILE}" "${SYSTEM_SRC}"
1849 if [ -f "$TMPDIR/classes.dex" ]; then
1850 zip -gjq "${VENDOR_REPO_FILE}" "$TMPDIR/classes"*
1851 rm "$TMPDIR/classes"*
1852 printf ' (updated %s from odex files)\n' "${SRC_FILE}"
1853 fi
1854 elif [[ "${VENDOR_REPO_FILE}" =~ .xml$ ]]; then
1855 fix_xml "${VENDOR_REPO_FILE}"
1856 fi
1857 # Now run user-supplied fixup function
1858 blob_fixup "${BLOB_DISPLAY_NAME}" "${VENDOR_REPO_FILE}"
1859 local POST_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE})
1860
1861 if [ -f "${VENDOR_REPO_FILE}" ]; then
1862 local DIR=$(dirname "${VENDOR_REPO_FILE}")
1863 local TYPE="${DIR##*/}"
1864 if [ "$TYPE" = "bin" -o "$TYPE" = "sbin" ]; then
1865 chmod 755 "${VENDOR_REPO_FILE}"
1866 else
1867 chmod 644 "${VENDOR_REPO_FILE}"
1868 fi
1869 fi
1870
1871 if [ "${KANG}" = true ]; then
1872 print_spec "${IS_PRODUCT_PACKAGE}" "${SPEC_SRC_FILE}" "${SPEC_DST_FILE}" "${SPEC_ARGS}" "${PRE_FIXUP_HASH}" "${POST_FIXUP_HASH}"
1873 fi
1874
1875 # Check and print whether the fixup pipeline actually did anything.
1876 # This isn't done right after the fixup pipeline because we want this print
1877 # to come after print_spec above, when in kang mode.
1878 if [ "${PRE_FIXUP_HASH}" != "${POST_FIXUP_HASH}" ]; then
1879 printf " + Fixed up %s\n" "${BLOB_DISPLAY_NAME}"
1880 # Now sanity-check the spec for this blob.
1881 if [ "${KANG}" = false ] && [ "${FIXUP_HASH}" = "x" ] && [ "${HASH}" != "x" ]; then
1882 printf "WARNING: The %s file was fixed up, but it is pinned.\n" ${BLOB_DISPLAY_NAME}
1883 printf "This is a mistake and you want to either remove the hash completely, or add an extra one.\n"
1884 fi
1885 fi
1886
1887 done
1888
1889 # Don't allow failing
1890 set -e
1891}
1892
1893#
Steve Kondik5bd66602016-07-15 10:39:58 -07001894# extract_firmware:
1895#
1896# $1: file containing the list of items to extract
1897# $2: path to extracted radio folder
1898#
1899function extract_firmware() {
1900 if [ -z "$OUTDIR" ]; then
1901 echo "Output dir not set!"
1902 exit 1
1903 fi
1904
1905 parse_file_list "$1"
1906
1907 # Don't allow failing
1908 set -e
1909
1910 local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} )
1911 local COUNT=${#FILELIST[@]}
1912 local SRC="$2"
theimpulson9a911af2019-08-14 03:25:12 +00001913 local OUTPUT_DIR="$OMNI_ROOT"/"$OUTDIR"/radio
Steve Kondik5bd66602016-07-15 10:39:58 -07001914
1915 if [ "$VENDOR_RADIO_STATE" -eq "0" ]; then
1916 echo "Cleaning firmware output directory ($OUTPUT_DIR).."
1917 rm -rf "${OUTPUT_DIR:?}/"*
1918 VENDOR_RADIO_STATE=1
1919 fi
1920
1921 echo "Extracting $COUNT files in $1 from $SRC:"
1922
1923 for (( i=1; i<COUNT+1; i++ )); do
1924 local FILE="${FILELIST[$i-1]}"
1925 printf ' - %s \n' "/radio/$FILE"
1926
1927 if [ ! -d "$OUTPUT_DIR" ]; then
1928 mkdir -p "$OUTPUT_DIR"
1929 fi
1930 cp "$SRC/$FILE" "$OUTPUT_DIR/$FILE"
1931 chmod 644 "$OUTPUT_DIR/$FILE"
1932 done
1933}
Rashed Abdel-Tawab841c6e82019-03-29 20:07:25 -07001934
1935function extract_img_data() {
1936 local image_file="$1"
1937 local out_dir="$2"
1938 local logFile="$TMPDIR/debugfs.log"
1939
1940 if [ ! -d "$out_dir" ]; then
1941 mkdir -p "$out_dir"
1942 fi
1943
1944 if [[ "$HOST_OS" == "Darwin" ]]; then
1945 debugfs -R "rdump / \"$out_dir\"" "$image_file" &> "$logFile" || {
1946 echo "[-] Failed to extract data from '$image_file'"
1947 abort 1
1948 }
1949 else
1950 debugfs -R 'ls -p' "$image_file" 2>/dev/null | cut -d '/' -f6 | while read -r entry
1951 do
1952 debugfs -R "rdump \"$entry\" \"$out_dir\"" "$image_file" >> "$logFile" 2>&1 || {
1953 echo "[-] Failed to extract data from '$image_file'"
1954 abort 1
1955 }
1956 done
1957 fi
1958
1959 local symlink_err="rdump: Attempt to read block from filesystem resulted in short read while reading symlink"
1960 if grep -Fq "$symlink_err" "$logFile"; then
1961 echo "[-] Symlinks have not been properly processed from $image_file"
1962 echo "[!] If you don't have a compatible debugfs version, modify 'execute-all.sh' to disable 'USE_DEBUGFS' flag"
1963 abort 1
1964 fi
1965}
1966
1967declare -ra VENDOR_SKIP_FILES=(
1968 "bin/toybox_vendor"
1969 "bin/toolbox"
1970 "bin/grep"
1971 "build.prop"
1972 "compatibility_matrix.xml"
1973 "default.prop"
1974 "etc/NOTICE.xml.gz"
1975 "etc/vintf/compatibility_matrix.xml"
1976 "etc/vintf/manifest.xml"
1977 "etc/wifi/wpa_supplicant.conf"
1978 "manifest.xml"
1979 "overlay/DisplayCutoutEmulationCorner/DisplayCutoutEmulationCornerOverlay.apk"
1980 "overlay/DisplayCutoutEmulationDouble/DisplayCutoutEmulationDoubleOverlay.apk"
1981 "overlay/DisplayCutoutEmulationTall/DisplayCutoutEmulationTallOverlay.apk"
1982 "overlay/DisplayCutoutNoCutout/NoCutoutOverlay.apk"
1983 "overlay/framework-res__auto_generated_rro.apk"
1984 "overlay/SysuiDarkTheme/SysuiDarkThemeOverlay.apk"
1985)
1986
1987function array_contains() {
1988 local element
1989 for element in "${@:2}"; do [[ "$element" == "$1" ]] && return 0; done
1990 return 1
1991}
1992
1993function generate_prop_list_from_image() {
1994 local image_file="$1"
1995 local image_dir="$TMPDIR/image-temp"
1996 local output_list="$2"
1997 local output_list_tmp="$TMPDIR/_proprietary-blobs.txt"
1998 local -n skipped_vendor_files="$3"
1999
2000 extract_img_data "$image_file" "$image_dir"
2001
2002 find "$image_dir" -not -type d | sed "s#^$image_dir/##" | while read -r FILE
2003 do
2004 # Skip VENDOR_SKIP_FILES since it will be re-generated at build time
2005 if array_contains "$FILE" "${VENDOR_SKIP_FILES[@]}"; then
2006 continue
2007 fi
2008 # Skip device defined skipped files since they will be re-generated at build time
2009 if array_contains "$FILE" "${skipped_vendor_files[@]}"; then
2010 continue
2011 fi
2012 if suffix_match_file ".apk" "$FILE" ; then
2013 echo "-vendor/$FILE" >> "$output_list_tmp"
2014 else
2015 echo "vendor/$FILE" >> "$output_list_tmp"
2016 fi
2017 done
2018
2019 # Sort merged file with all lists
2020 sort -u "$output_list_tmp" > "$output_list"
2021
2022 # Clean-up
2023 rm -f "$output_list_tmp"
2024}
Bruno Martins0f425f12021-04-10 14:57:32 +01002025
2026function colored_echo() {
2027 IFS=" "
2028 local color=$1;
2029 shift
2030 if ! [[ $color =~ '^[0-9]$' ]] ; then
2031 case $(echo $color | tr '[:upper:]' '[:lower:]') in
2032 black) color=0 ;;
2033 red) color=1 ;;
2034 green) color=2 ;;
2035 yellow) color=3 ;;
2036 blue) color=4 ;;
2037 magenta) color=5 ;;
2038 cyan) color=6 ;;
2039 white|*) color=7 ;; # white or invalid color
2040 esac
2041 fi
Bruno Martins5064db22021-06-21 14:47:40 +01002042 if [ -t 1 ] ; then tput setaf $color; fi
Bruno Martins0f425f12021-04-10 14:57:32 +01002043 printf '%s\n' "$*"
Bruno Martins5064db22021-06-21 14:47:40 +01002044 if [ -t 1 ] ; then tput sgr0; fi
Bruno Martins0f425f12021-04-10 14:57:32 +01002045}