blob: 8edb0dfa533a0b98cd6ef95d207b431912366534 [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//;/ })
LuK1337508e85f2021-08-23 18:18:57 +0200426 USE_PLATFORM_CERTIFICATE="true"
427 for ARG in "${ARGS[@]}"; do
428 if [ "$ARG" = "PRESIGNED" ]; then
429 USE_PLATFORM_CERTIFICATE="false"
430 printf '\tpresigned: true,\n'
431 elif [[ "$ARG" =~ "OVERRIDES" ]]; then
432 OVERRIDEPKG=${ARG#*=}
433 OVERRIDEPKG=${OVERRIDEPKG//,/ }
434 printf '\toverrides: ["%s"],\n' "$OVERRIDEPKG"
435 elif [ ! -z "$ARG" ]; then
436 USE_PLATFORM_CERTIFICATE="false"
437 printf '\tcertificate: "%s",\n' "$ARG"
438 fi
439 done
440 if [ "$USE_PLATFORM_CERTIFICATE" = "true" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700441 printf '\tcertificate: "platform",\n'
442 fi
443 elif [ "$CLASS" = "JAVA_LIBRARIES" ]; then
444 printf 'dex_import {\n'
445 printf '\tname: "%s",\n' "$PKGNAME"
446 printf '\towner: "%s",\n' "$VENDOR"
447 printf '\tjars: ["%s/framework/%s"],\n' "$SRC" "$FILE"
448 elif [ "$CLASS" = "ETC" ]; then
449 if [ "$EXTENSION" = "xml" ]; then
450 printf 'prebuilt_etc_xml {\n'
451 else
452 printf 'prebuilt_etc {\n'
453 fi
454 printf '\tname: "%s",\n' "$PKGNAME"
455 printf '\towner: "%s",\n' "$VENDOR"
456 printf '\tsrc: "%s/etc/%s",\n' "$SRC" "$FILE"
LuK1337f7f18712020-10-06 19:29:02 +0200457 printf '\tfilename_from_src: true,\n'
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700458 elif [ "$CLASS" = "EXECUTABLES" ]; then
459 if [ "$EXTENSION" = "sh" ]; then
460 printf 'sh_binary {\n'
461 else
462 printf 'cc_prebuilt_binary {\n'
463 fi
464 printf '\tname: "%s",\n' "$PKGNAME"
465 printf '\towner: "%s",\n' "$VENDOR"
466 if [ "$ARGS" = "rootfs" ]; then
467 SRC="$SRC/rootfs"
468 if [ "$EXTRA" = "sbin" ]; then
469 SRC="$SRC/sbin"
470 printf '\tdist {\n'
471 printf '\t\tdest: "%s",\n' "root/sbin"
472 printf '\t},'
473 fi
474 else
475 SRC="$SRC/bin"
476 fi
477 printf '\tsrcs: ["%s/%s"],\n' "$SRC" "$FILE"
Sebastiano Barezzifd4b2b32021-07-14 21:33:10 +0200478 if [ "$EXTENSION" != "sh" ]; then
479 printf '\tcheck_elf_files: false,\n'
480 fi
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700481 unset EXTENSION
482 else
483 printf '\tsrcs: ["%s/%s"],\n' "$SRC" "$FILE"
484 fi
485 if [ "$CLASS" = "APPS" ]; then
486 printf '\tdex_preopt: {\n'
487 printf '\t\tenabled: false,\n'
488 printf '\t},\n'
489 fi
Andreas Schneiderdbcf9db2020-05-25 17:03:17 +0200490 if [ "$CLASS" = "SHARED_LIBRARIES" ] || [ "$CLASS" = "EXECUTABLES" ] ; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700491 if [ "$DIRNAME" != "." ]; then
Andreas Schneider408526a2020-05-23 15:58:43 +0200492 printf '\trelative_install_path: "%s",\n' "$DIRNAME"
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700493 fi
494 fi
Andreas Schneiderdbcf9db2020-05-25 17:03:17 +0200495 if [ "$CLASS" = "ETC" ] ; then
496 if [ "$DIRNAME" != "." ]; then
497 printf '\tsub_dir: "%s",\n' "$DIRNAME"
498 fi
499 fi
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700500 if [ "$CLASS" = "SHARED_LIBRARIES" ] || [ "$CLASS" = "EXECUTABLES" ] ; then
501 printf '\tprefer: true,\n'
502 fi
503 if [ "$EXTRA" = "priv-app" ]; then
504 printf '\tprivileged: true,\n'
505 fi
506 if [ "$PARTITION" = "vendor" ]; then
507 printf '\tsoc_specific: true,\n'
508 elif [ "$PARTITION" = "product" ]; then
509 printf '\tproduct_specific: true,\n'
Luca Stefani776be462020-09-09 15:53:58 +0200510 elif [ "$PARTITION" = "system_ext" ]; then
511 printf '\tsystem_ext_specific: true,\n'
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700512 elif [ "$PARTITION" = "odm" ]; then
513 printf '\tdevice_specific: true,\n'
514 fi
515 printf '}\n\n'
516 done
517}
518
519#
520# write_makefile_packages:
521#
522# $1: The LOCAL_MODULE_CLASS for the given module list
Luca Stefani776be462020-09-09 15:53:58 +0200523# $2: /odm, /product, /system_ext, or /vendor partition
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700524# $3: type-specific extra flags
525# $4: Name of the array holding the target list
526#
527# Internal function which writes out the BUILD_PREBUILT stanzas
528# for all modules in the list. This is called by write_product_packages
529# after the modules are categorized.
530#
531function write_makefile_packages() {
Steve Kondik5bd66602016-07-15 10:39:58 -0700532
533 local CLASS="$1"
razorlovesa0d296b2019-07-29 02:21:34 -0500534 local PARTITION="$2"
Steve Kondik5bd66602016-07-15 10:39:58 -0700535 local EXTRA="$3"
536
537 # Yes, this is a horrible hack - we create a new array using indirection
538 local ARR_NAME="$4[@]"
539 local FILELIST=("${!ARR_NAME}")
540
541 local FILE=
542 local ARGS=
543 local BASENAME=
544 local EXTENSION=
545 local PKGNAME=
546 local SRC=
547
548 for P in "${FILELIST[@]}"; do
Vladimir Olteanc70bc122018-06-24 20:09:55 +0300549 FILE=$(target_file "$P")
Steve Kondik5bd66602016-07-15 10:39:58 -0700550 ARGS=$(target_args "$P")
551
552 BASENAME=$(basename "$FILE")
M1cha3e8c5bf2017-01-04 09:00:11 +0100553 DIRNAME=$(dirname "$FILE")
Steve Kondik5bd66602016-07-15 10:39:58 -0700554 EXTENSION=${BASENAME##*.}
Mohd Farazcb0f4872019-10-08 16:13:50 +0530555 EXTENSION="."$EXTENSION
556 if [ "$EXTENSION" = ".jar" ]; then
557 EXTENSION="\$(COMMON_JAVA_PACKAGE_SUFFIX)"
558 elif [ "$EXTENSION" = ".apk" ]; then
559 EXTENSION="\$(COMMON_ANDROID_PACKAGE_SUFFIX)"
560 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700561 PKGNAME=${BASENAME%.*}
562
563 # Add to final package list
564 PACKAGE_LIST+=("$PKGNAME")
565
566 SRC="proprietary"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400567 if [ "$PARTITION" = "system" ]; then
568 SRC+="/system"
569 elif [ "$PARTITION" = "vendor" ]; then
Steve Kondik5bd66602016-07-15 10:39:58 -0700570 SRC+="/vendor"
razorlovesa0d296b2019-07-29 02:21:34 -0500571 elif [ "$PARTITION" = "product" ]; then
572 SRC+="/product"
Luca Stefani776be462020-09-09 15:53:58 +0200573 elif [ "$PARTITION" = "system_ext" ]; then
574 SRC+="/system_ext"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700575 elif [ "$PARTITION" = "odm" ]; then
576 SRC+="/odm"
Steve Kondik5bd66602016-07-15 10:39:58 -0700577 fi
578
579 printf 'include $(CLEAR_VARS)\n'
580 printf 'LOCAL_MODULE := %s\n' "$PKGNAME"
581 printf 'LOCAL_MODULE_OWNER := %s\n' "$VENDOR"
582 if [ "$CLASS" = "SHARED_LIBRARIES" ]; then
583 if [ "$EXTRA" = "both" ]; then
584 printf 'LOCAL_SRC_FILES_64 := %s/lib64/%s\n' "$SRC" "$FILE"
585 printf 'LOCAL_SRC_FILES_32 := %s/lib/%s\n' "$SRC" "$FILE"
586 #if [ "$VENDOR_PKG" = "true" ]; then
587 # echo "LOCAL_MODULE_PATH_64 := \$(TARGET_OUT_VENDOR_SHARED_LIBRARIES)"
588 # echo "LOCAL_MODULE_PATH_32 := \$(2ND_TARGET_OUT_VENDOR_SHARED_LIBRARIES)"
589 #else
590 # echo "LOCAL_MODULE_PATH_64 := \$(TARGET_OUT_SHARED_LIBRARIES)"
591 # echo "LOCAL_MODULE_PATH_32 := \$(2ND_TARGET_OUT_SHARED_LIBRARIES)"
592 #fi
593 elif [ "$EXTRA" = "64" ]; then
594 printf 'LOCAL_SRC_FILES := %s/lib64/%s\n' "$SRC" "$FILE"
595 else
596 printf 'LOCAL_SRC_FILES := %s/lib/%s\n' "$SRC" "$FILE"
597 fi
598 if [ "$EXTRA" != "none" ]; then
599 printf 'LOCAL_MULTILIB := %s\n' "$EXTRA"
600 fi
601 elif [ "$CLASS" = "APPS" ]; then
Michael Bestas9c6f2eb2018-01-25 21:05:36 +0200602 if [ "$EXTRA" = "priv-app" ]; then
603 SRC="$SRC/priv-app"
604 else
605 SRC="$SRC/app"
Steve Kondik5bd66602016-07-15 10:39:58 -0700606 fi
607 printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE"
608 local CERT=platform
609 if [ ! -z "$ARGS" ]; then
610 CERT="$ARGS"
611 fi
612 printf 'LOCAL_CERTIFICATE := %s\n' "$CERT"
613 elif [ "$CLASS" = "JAVA_LIBRARIES" ]; then
614 printf 'LOCAL_SRC_FILES := %s/framework/%s\n' "$SRC" "$FILE"
Elektroschmockdd792302016-10-04 21:11:43 +0200615 local CERT=platform
616 if [ ! -z "$ARGS" ]; then
617 CERT="$ARGS"
618 fi
619 printf 'LOCAL_CERTIFICATE := %s\n' "$CERT"
Steve Kondik5bd66602016-07-15 10:39:58 -0700620 elif [ "$CLASS" = "ETC" ]; then
621 printf 'LOCAL_SRC_FILES := %s/etc/%s\n' "$SRC" "$FILE"
622 elif [ "$CLASS" = "EXECUTABLES" ]; then
623 if [ "$ARGS" = "rootfs" ]; then
624 SRC="$SRC/rootfs"
625 if [ "$EXTRA" = "sbin" ]; then
626 SRC="$SRC/sbin"
627 printf '%s\n' "LOCAL_MODULE_PATH := \$(TARGET_ROOT_OUT_SBIN)"
628 printf '%s\n' "LOCAL_UNSTRIPPED_PATH := \$(TARGET_ROOT_OUT_SBIN_UNSTRIPPED)"
629 fi
630 else
631 SRC="$SRC/bin"
632 fi
633 printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE"
634 unset EXTENSION
635 else
636 printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE"
637 fi
638 printf 'LOCAL_MODULE_TAGS := optional\n'
639 printf 'LOCAL_MODULE_CLASS := %s\n' "$CLASS"
Hashbang173575f3bb2016-08-28 20:38:45 -0400640 if [ "$CLASS" = "APPS" ]; then
641 printf 'LOCAL_DEX_PREOPT := false\n'
642 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700643 if [ ! -z "$EXTENSION" ]; then
Mohd Farazcb0f4872019-10-08 16:13:50 +0530644 printf 'LOCAL_MODULE_SUFFIX := %s\n' "$EXTENSION"
Steve Kondik5bd66602016-07-15 10:39:58 -0700645 fi
M1cha3e8c5bf2017-01-04 09:00:11 +0100646 if [ "$CLASS" = "SHARED_LIBRARIES" ] || [ "$CLASS" = "EXECUTABLES" ]; then
647 if [ "$DIRNAME" != "." ]; then
648 printf 'LOCAL_MODULE_RELATIVE_PATH := %s\n' "$DIRNAME"
649 fi
650 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700651 if [ "$EXTRA" = "priv-app" ]; then
652 printf 'LOCAL_PRIVILEGED_MODULE := true\n'
653 fi
razorlovesa0d296b2019-07-29 02:21:34 -0500654 if [ "$PARTITION" = "vendor" ]; then
Ethan Chen4f738f52018-02-17 20:03:54 -0800655 printf 'LOCAL_VENDOR_MODULE := true\n'
razorlovesa0d296b2019-07-29 02:21:34 -0500656 elif [ "$PARTITION" = "product" ]; then
657 printf 'LOCAL_PRODUCT_MODULE := true\n'
Luca Stefani776be462020-09-09 15:53:58 +0200658 elif [ "$PARTITION" = "system_ext" ]; then
659 printf 'LOCAL_SYSTEM_EXT_MODULE := true\n'
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700660 elif [ "$PARTITION" = "odm" ]; then
661 printf 'LOCAL_ODM_MODULE := true\n'
Steve Kondik5bd66602016-07-15 10:39:58 -0700662 fi
663 printf 'include $(BUILD_PREBUILT)\n\n'
664 done
665}
666
667#
668# write_product_packages:
669#
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -0700670# This function will create prebuilt entries in the
671# Android.bp and associated PRODUCT_PACKAGES list in the
Steve Kondik5bd66602016-07-15 10:39:58 -0700672# product makefile for all files in the blob list which
673# start with a single dash (-) character.
674#
675function write_product_packages() {
676 PACKAGE_LIST=()
677
678 local COUNT=${#PRODUCT_PACKAGES_LIST[@]}
679
680 if [ "$COUNT" = "0" ]; then
681 return 0
682 fi
683
684 # Figure out what's 32-bit, what's 64-bit, and what's multilib
685 # I really should not be doing this in bash due to shitty array passing :(
686 local T_LIB32=( $(prefix_match "lib/") )
687 local T_LIB64=( $(prefix_match "lib64/") )
688 local MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${T_LIB64[@]}")) )
689 local LIB32=( $(comm -23 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${MULTILIBS[@]}")) )
690 local LIB64=( $(comm -23 <(printf '%s\n' "${T_LIB64[@]}") <(printf '%s\n' "${MULTILIBS[@]}")) )
691
692 if [ "${#MULTILIBS[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700693 write_blueprint_packages "SHARED_LIBRARIES" "" "both" "MULTILIBS" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700694 fi
695 if [ "${#LIB32[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700696 write_blueprint_packages "SHARED_LIBRARIES" "" "32" "LIB32" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700697 fi
698 if [ "${#LIB64[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700699 write_blueprint_packages "SHARED_LIBRARIES" "" "64" "LIB64" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700700 fi
701
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400702 local T_S_LIB32=( $(prefix_match "system/lib/") )
703 local T_S_LIB64=( $(prefix_match "system/lib64/") )
704 local S_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_S_LIB32[@]}") <(printf '%s\n' "${T_S_LIB64[@]}")) )
705 local S_LIB32=( $(comm -23 <(printf '%s\n' "${T_S_LIB32[@]}") <(printf '%s\n' "${S_MULTILIBS[@]}")) )
706 local S_LIB64=( $(comm -23 <(printf '%s\n' "${T_S_LIB64[@]}") <(printf '%s\n' "${S_MULTILIBS[@]}")) )
707
708 if [ "${#S_MULTILIBS[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700709 write_blueprint_packages "SHARED_LIBRARIES" "system" "both" "S_MULTILIBS" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400710 fi
711 if [ "${#S_LIB32[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700712 write_blueprint_packages "SHARED_LIBRARIES" "system" "32" "S_LIB32" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400713 fi
714 if [ "${#S_LIB64[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700715 write_blueprint_packages "SHARED_LIBRARIES" "system" "64" "S_LIB64" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400716 fi
717
Steve Kondik5bd66602016-07-15 10:39:58 -0700718 local T_V_LIB32=( $(prefix_match "vendor/lib/") )
719 local T_V_LIB64=( $(prefix_match "vendor/lib64/") )
720 local V_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${T_V_LIB64[@]}")) )
721 local V_LIB32=( $(comm -23 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${V_MULTILIBS[@]}")) )
722 local V_LIB64=( $(comm -23 <(printf '%s\n' "${T_V_LIB64[@]}") <(printf '%s\n' "${V_MULTILIBS[@]}")) )
723
724 if [ "${#V_MULTILIBS[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700725 write_blueprint_packages "SHARED_LIBRARIES" "vendor" "both" "V_MULTILIBS" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700726 fi
727 if [ "${#V_LIB32[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700728 write_blueprint_packages "SHARED_LIBRARIES" "vendor" "32" "V_LIB32" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700729 fi
730 if [ "${#V_LIB64[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700731 write_blueprint_packages "SHARED_LIBRARIES" "vendor" "64" "V_LIB64" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500732 fi
733
734 local T_P_LIB32=( $(prefix_match "product/lib/") )
735 local T_P_LIB64=( $(prefix_match "product/lib64/") )
736 local P_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_P_LIB32[@]}") <(printf '%s\n' "${T_P_LIB64[@]}")) )
737 local P_LIB32=( $(comm -23 <(printf '%s\n' "${T_P_LIB32[@]}") <(printf '%s\n' "${P_MULTILIBS[@]}")) )
738 local P_LIB64=( $(comm -23 <(printf '%s\n' "${T_P_LIB64[@]}") <(printf '%s\n' "${P_MULTILIBS[@]}")) )
739
740 if [ "${#P_MULTILIBS[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700741 write_blueprint_packages "SHARED_LIBRARIES" "product" "both" "P_MULTILIBS" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500742 fi
743 if [ "${#P_LIB32[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700744 write_blueprint_packages "SHARED_LIBRARIES" "product" "32" "P_LIB32" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500745 fi
746 if [ "${#P_LIB64[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700747 write_blueprint_packages "SHARED_LIBRARIES" "product" "64" "P_LIB64" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700748 fi
749
Luca Stefani776be462020-09-09 15:53:58 +0200750 local T_SE_LIB32=( $(prefix_match "system_ext/lib/") )
751 local T_SE_LIB64=( $(prefix_match "system_ext/lib64/") )
752 local SE_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_SE_LIB32[@]}") <(printf '%s\n' "${T_SE_LIB64[@]}")) )
753 local SE_LIB32=( $(comm -23 <(printf '%s\n' "${T_SE_LIB32[@]}") <(printf '%s\n' "${SE_MULTILIBS[@]}")) )
754 local SE_LIB64=( $(comm -23 <(printf '%s\n' "${T_SE_LIB64[@]}") <(printf '%s\n' "${SE_MULTILIBS[@]}")) )
755
756 if [ "${#SE_MULTILIBS[@]}" -gt "0" ]; then
757 write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "both" "SE_MULTILIBS" >> "$ANDROIDBP"
758 fi
759 if [ "${#SE_LIB32[@]}" -gt "0" ]; then
760 write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "32" "SE_LIB32" >> "$ANDROIDBP"
761 fi
762 if [ "${#SE_LIB64[@]}" -gt "0" ]; then
763 write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "64" "SE_LIB64" >> "$ANDROIDBP"
764 fi
765
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700766 local T_O_LIB32=( $(prefix_match "odm/lib/") )
767 local T_O_LIB64=( $(prefix_match "odm/lib64/") )
768 local O_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_O_LIB32[@]}") <(printf '%s\n' "${T_O_LIB64[@]}")) )
769 local O_LIB32=( $(comm -23 <(printf '%s\n' "${T_O_LIB32[@]}") <(printf '%s\n' "${O_MULTILIBS[@]}")) )
770 local O_LIB64=( $(comm -23 <(printf '%s\n' "${T_O_LIB64[@]}") <(printf '%s\n' "${O_MULTILIBS[@]}")) )
771
772 if [ "${#O_MULTILIBS[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700773 write_blueprint_packages "SHARED_LIBRARIES" "odm" "both" "O_MULTILIBS" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700774 fi
775 if [ "${#O_LIB32[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700776 write_blueprint_packages "SHARED_LIBRARIES" "odm" "32" "O_LIB32" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700777 fi
778 if [ "${#O_LIB64[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700779 write_blueprint_packages "SHARED_LIBRARIES" "odm" "64" "O_LIB64" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700780 fi
781
Steve Kondik5bd66602016-07-15 10:39:58 -0700782 # Apps
783 local APPS=( $(prefix_match "app/") )
784 if [ "${#APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100785 write_blueprint_packages "APPS" "" "" "APPS" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700786 fi
787 local PRIV_APPS=( $(prefix_match "priv-app/") )
788 if [ "${#PRIV_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100789 write_blueprint_packages "APPS" "" "priv-app" "PRIV_APPS" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700790 fi
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400791 local S_APPS=( $(prefix_match "system/app/") )
792 if [ "${#S_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100793 write_blueprint_packages "APPS" "system" "" "S_APPS" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400794 fi
795 local S_PRIV_APPS=( $(prefix_match "system/priv-app/") )
796 if [ "${#S_PRIV_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100797 write_blueprint_packages "APPS" "system" "priv-app" "S_PRIV_APPS" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400798 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700799 local V_APPS=( $(prefix_match "vendor/app/") )
800 if [ "${#V_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100801 write_blueprint_packages "APPS" "vendor" "" "V_APPS" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700802 fi
803 local V_PRIV_APPS=( $(prefix_match "vendor/priv-app/") )
804 if [ "${#V_PRIV_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100805 write_blueprint_packages "APPS" "vendor" "priv-app" "V_PRIV_APPS" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500806 fi
807 local P_APPS=( $(prefix_match "product/app/") )
808 if [ "${#P_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100809 write_blueprint_packages "APPS" "product" "" "P_APPS" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500810 fi
811 local P_PRIV_APPS=( $(prefix_match "product/priv-app/") )
812 if [ "${#P_PRIV_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100813 write_blueprint_packages "APPS" "product" "priv-app" "P_PRIV_APPS" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700814 fi
Luca Stefani776be462020-09-09 15:53:58 +0200815 local SE_APPS=( $(prefix_match "system_ext/app/") )
816 if [ "${#SE_APPS[@]}" -gt "0" ]; then
817 write_blueprint_packages "APPS" "system_ext" "" "SE_APPS" >> "$ANDROIDBP"
818 fi
819 local SE_PRIV_APPS=( $(prefix_match "system_ext/priv-app/") )
820 if [ "${#SE_PRIV_APPS[@]}" -gt "0" ]; then
821 write_blueprint_packages "APPS" "system_ext" "priv-app" "SE_PRIV_APPS" >> "$ANDROIDBP"
822 fi
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700823 local O_APPS=( $(prefix_match "odm/app/") )
824 if [ "${#O_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100825 write_blueprint_packages "APPS" "odm" "" "O_APPS" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700826 fi
827 local O_PRIV_APPS=( $(prefix_match "odm/priv-app/") )
828 if [ "${#O_PRIV_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100829 write_blueprint_packages "APPS" "odm" "priv-app" "O_PRIV_APPS" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700830 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700831
832 # Framework
833 local FRAMEWORK=( $(prefix_match "framework/") )
834 if [ "${#FRAMEWORK[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700835 write_blueprint_packages "JAVA_LIBRARIES" "" "" "FRAMEWORK" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700836 fi
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400837 local S_FRAMEWORK=( $(prefix_match "system/framework/") )
838 if [ "${#S_FRAMEWORK[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700839 write_blueprint_packages "JAVA_LIBRARIES" "system" "" "S_FRAMEWORK" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400840 fi
Christian Oder974b5902017-10-08 23:15:52 +0200841 local V_FRAMEWORK=( $(prefix_match "vendor/framework/") )
Michael Bestas26eb01e2018-02-27 22:31:55 +0200842 if [ "${#V_FRAMEWORK[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700843 write_blueprint_packages "JAVA_LIBRARIES" "vendor" "" "V_FRAMEWORK" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500844 fi
845 local P_FRAMEWORK=( $(prefix_match "product/framework/") )
846 if [ "${#P_FRAMEWORK[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700847 write_blueprint_packages "JAVA_LIBRARIES" "product" "" "P_FRAMEWORK" >> "$ANDROIDBP"
Christian Oder974b5902017-10-08 23:15:52 +0200848 fi
Luca Stefani776be462020-09-09 15:53:58 +0200849 local SE_FRAMEWORK=( $(prefix_match "system_ext/framework/") )
Alexander Koskovich052c77d2020-09-16 17:58:53 -0700850 if [ "${#SE_FRAMEWORK[@]}" -gt "0" ]; then
Luca Stefani776be462020-09-09 15:53:58 +0200851 write_blueprint_packages "JAVA_LIBRARIES" "system_ext" "" "SE_FRAMEWORK" >> "$ANDROIDBP"
852 fi
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700853 local O_FRAMEWORK=( $(prefix_match "odm/framework/") )
854 if [ "${#O_FRAMEWORK[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700855 write_blueprint_packages "JAVA_LIBRARIES" "odm" "" "O_FRAMEWORK" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700856 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700857
858 # Etc
859 local ETC=( $(prefix_match "etc/") )
860 if [ "${#ETC[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700861 write_blueprint_packages "ETC" "" "" "ETC" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700862 fi
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400863 local S_ETC=( $(prefix_match "system/etc/") )
864 if [ "${#ETC[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700865 write_blueprint_packages "ETC" "system" "" "S_ETC" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400866 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700867 local V_ETC=( $(prefix_match "vendor/etc/") )
868 if [ "${#V_ETC[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700869 write_blueprint_packages "ETC" "vendor" "" "V_ETC" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500870 fi
871 local P_ETC=( $(prefix_match "product/etc/") )
872 if [ "${#P_ETC[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700873 write_blueprint_packages "ETC" "product" "" "P_ETC" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700874 fi
Luca Stefani776be462020-09-09 15:53:58 +0200875 local SE_ETC=( $(prefix_match "system_ext/etc/") )
876 if [ "${#SE_ETC[@]}" -gt "0" ]; then
877 write_blueprint_packages "ETC" "system_ext" "" "SE_ETC" >> "$ANDROIDBP"
878 fi
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700879 local O_ETC=( $(prefix_match "odm/etc/") )
880 if [ "${#O_ETC[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700881 write_blueprint_packages "ETC" "odm" "" "O_ETC" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700882 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700883
884 # Executables
885 local BIN=( $(prefix_match "bin/") )
886 if [ "${#BIN[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700887 write_blueprint_packages "EXECUTABLES" "" "" "BIN" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700888 fi
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400889 local S_BIN=( $(prefix_match "system/bin/") )
890 if [ "${#BIN[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700891 write_blueprint_packages "EXECUTABLES" "system" "" "S_BIN" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400892 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700893 local V_BIN=( $(prefix_match "vendor/bin/") )
894 if [ "${#V_BIN[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700895 write_blueprint_packages "EXECUTABLES" "vendor" "" "V_BIN" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500896 fi
897 local P_BIN=( $(prefix_match "product/bin/") )
898 if [ "${#P_BIN[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700899 write_blueprint_packages "EXECUTABLES" "product" "" "P_BIN" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700900 fi
Luca Stefani776be462020-09-09 15:53:58 +0200901 local SE_BIN=( $(prefix_match "system_ext/bin/") )
902 if [ "${#SE_BIN[@]}" -gt "0" ]; then
903 write_blueprint_packages "EXECUTABLES" "system_ext" "" "SE_BIN" >> "$ANDROIDBP"
904 fi
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700905 local O_BIN=( $(prefix_match "odm/bin/") )
906 if [ "${#O_BIN[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700907 write_blueprint_packages "EXECUTABLES" "odm" "" "O_BIN" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700908 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700909 local SBIN=( $(prefix_match "sbin/") )
910 if [ "${#SBIN[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700911 write_makefile_packages "EXECUTABLES" "" "sbin" "SBIN" >> "$ANDROIDMK"
Steve Kondik5bd66602016-07-15 10:39:58 -0700912 fi
913
914
915 # Actually write out the final PRODUCT_PACKAGES list
916 local PACKAGE_COUNT=${#PACKAGE_LIST[@]}
917
918 if [ "$PACKAGE_COUNT" -eq "0" ]; then
919 return 0
920 fi
921
922 printf '\n%s\n' "PRODUCT_PACKAGES += \\" >> "$PRODUCTMK"
923 for (( i=1; i<PACKAGE_COUNT+1; i++ )); do
924 local LINEEND=" \\"
925 if [ "$i" -eq "$PACKAGE_COUNT" ]; then
926 LINEEND=""
927 fi
928 printf ' %s%s\n' "${PACKAGE_LIST[$i-1]}" "$LINEEND" >> "$PRODUCTMK"
929 done
930}
931
932#
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -0700933# write_blueprint_header:
Steve Kondik5bd66602016-07-15 10:39:58 -0700934#
935# $1: file which will be written to
936#
Michael Bestasa2934df2020-12-19 03:50:32 +0200937# writes out the warning message regarding manual file modifications.
Steve Kondik5bd66602016-07-15 10:39:58 -0700938# note that this is not an append operation, and should
939# be executed first!
940#
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -0700941function write_blueprint_header() {
942 if [ -f $1 ]; then
943 rm $1
944 fi
945
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -0700946 [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON"
947
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -0700948 cat << EOF >> $1
Michael Bestasa2934df2020-12-19 03:50:32 +0200949// Automatically generated file. DO NOT MODIFY
950//
951// This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -0700952
953EOF
954}
955
956#
957# write_makefile_header:
958#
959# $1: file which will be written to
960#
Michael Bestasa2934df2020-12-19 03:50:32 +0200961# writes out the warning message regarding manual file modifications.
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -0700962# note that this is not an append operation, and should
963# be executed first!
964#
965function write_makefile_header() {
Jake Whatley9843b322017-01-25 21:49:16 -0500966 if [ -f $1 ]; then
967 rm $1
968 fi
969
Steve Kondik5bd66602016-07-15 10:39:58 -0700970 [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON"
971
Jake Whatley9843b322017-01-25 21:49:16 -0500972 cat << EOF >> $1
Michael Bestasa2934df2020-12-19 03:50:32 +0200973# Automatically generated file. DO NOT MODIFY
Steve Kondik5bd66602016-07-15 10:39:58 -0700974#
Steve Kondik5bd66602016-07-15 10:39:58 -0700975# This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh
976
977EOF
978}
979
980#
981# write_headers:
982#
983# $1: devices falling under common to be added to guard - optional
Jake Whatley9843b322017-01-25 21:49:16 -0500984# $2: custom guard - optional
Steve Kondik5bd66602016-07-15 10:39:58 -0700985#
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -0700986# Calls write_makefile_header for each of the makefiles and
987# write_blueprint_header for Android.bp and creates the initial
988# path declaration and device guard for the Android.mk
Steve Kondik5bd66602016-07-15 10:39:58 -0700989#
990function write_headers() {
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -0700991 write_makefile_header "$ANDROIDMK"
Jake Whatley9843b322017-01-25 21:49:16 -0500992
993 GUARD="$2"
994 if [ -z "$GUARD" ]; then
995 GUARD="TARGET_DEVICE"
996 fi
997
Steve Kondik5bd66602016-07-15 10:39:58 -0700998 cat << EOF >> "$ANDROIDMK"
999LOCAL_PATH := \$(call my-dir)
1000
1001EOF
1002 if [ "$COMMON" -ne 1 ]; then
1003 cat << EOF >> "$ANDROIDMK"
Jake Whatley9843b322017-01-25 21:49:16 -05001004ifeq (\$($GUARD),$DEVICE)
Steve Kondik5bd66602016-07-15 10:39:58 -07001005
1006EOF
1007 else
1008 if [ -z "$1" ]; then
1009 echo "Argument with devices to be added to guard must be set!"
1010 exit 1
1011 fi
1012 cat << EOF >> "$ANDROIDMK"
Jake Whatley9843b322017-01-25 21:49:16 -05001013ifneq (\$(filter $1,\$($GUARD)),)
Steve Kondik5bd66602016-07-15 10:39:58 -07001014
1015EOF
1016 fi
1017
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -07001018 write_makefile_header "$BOARDMK"
1019 write_makefile_header "$PRODUCTMK"
1020 write_blueprint_header "$ANDROIDBP"
1021
1022 cat << EOF >> "$ANDROIDBP"
1023soong_namespace {
1024}
1025
1026EOF
1027
1028 [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON"
1029 cat << EOF >> "$PRODUCTMK"
1030PRODUCT_SOONG_NAMESPACES += \\
1031 vendor/$VENDOR/$DEVICE
1032
1033EOF
Steve Kondik5bd66602016-07-15 10:39:58 -07001034}
1035
1036#
1037# write_footers:
1038#
1039# Closes the inital guard and any other finalization tasks. Must
1040# be called as the final step.
1041#
1042function write_footers() {
1043 cat << EOF >> "$ANDROIDMK"
1044endif
1045EOF
1046}
1047
1048# Return success if adb is up and not in recovery
1049function _adb_connected {
1050 {
Jake Whatley9843b322017-01-25 21:49:16 -05001051 if [[ "$(adb get-state)" == device ]]
Steve Kondik5bd66602016-07-15 10:39:58 -07001052 then
1053 return 0
1054 fi
1055 } 2>/dev/null
1056
1057 return 1
1058};
1059
1060#
1061# parse_file_list:
1062#
1063# $1: input file
Rashed Abdel-Tawabb0d08e82017-04-04 02:48:18 -04001064# $2: blob section in file - optional
Steve Kondik5bd66602016-07-15 10:39:58 -07001065#
1066# Sets PRODUCT_PACKAGES and PRODUCT_COPY_FILES while parsing the input file
1067#
1068function parse_file_list() {
1069 if [ -z "$1" ]; then
1070 echo "An input file is expected!"
1071 exit 1
1072 elif [ ! -f "$1" ]; then
1073 echo "Input file "$1" does not exist!"
1074 exit 1
1075 fi
1076
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001077 if [ -n "$2" ]; then
1078 echo "Using section \"$2\""
Rashed Abdel-Tawabb0d08e82017-04-04 02:48:18 -04001079 LIST=$TMPDIR/files.txt
Vladimir Olteanfa79f212019-01-19 00:44:07 +02001080 # Match all lines starting with first line found to start* with '#'
1081 # comment and contain** $2, and ending with first line to be empty*.
1082 # *whitespaces (tabs, spaces) at the beginning of lines are discarded
1083 # **the $2 match is case-insensitive
1084 cat $1 | sed -n '/^[[:space:]]*#.*'"$2"'/I,/^[[:space:]]*$/ p' > $LIST
Rashed Abdel-Tawabb0d08e82017-04-04 02:48:18 -04001085 else
1086 LIST=$1
1087 fi
1088
1089
Steve Kondik5bd66602016-07-15 10:39:58 -07001090 PRODUCT_PACKAGES_LIST=()
1091 PRODUCT_PACKAGES_HASHES=()
Vladimir Olteande985fe2019-01-17 03:07:34 +02001092 PRODUCT_PACKAGES_FIXUP_HASHES=()
Steve Kondik5bd66602016-07-15 10:39:58 -07001093 PRODUCT_COPY_FILES_LIST=()
1094 PRODUCT_COPY_FILES_HASHES=()
Vladimir Olteande985fe2019-01-17 03:07:34 +02001095 PRODUCT_COPY_FILES_FIXUP_HASHES=()
Steve Kondik5bd66602016-07-15 10:39:58 -07001096
1097 while read -r line; do
1098 if [ -z "$line" ]; then continue; fi
1099
1100 # If the line has a pipe delimiter, a sha1 hash should follow.
1101 # This indicates the file should be pinned and not overwritten
1102 # when extracting files.
1103 local SPLIT=(${line//\|/ })
1104 local COUNT=${#SPLIT[@]}
1105 local SPEC=${SPLIT[0]}
1106 local HASH="x"
Vladimir Olteande985fe2019-01-17 03:07:34 +02001107 local FIXUP_HASH="x"
Steve Kondik5bd66602016-07-15 10:39:58 -07001108 if [ "$COUNT" -gt "1" ]; then
1109 HASH=${SPLIT[1]}
1110 fi
Vladimir Olteande985fe2019-01-17 03:07:34 +02001111 if [ "$COUNT" -gt "2" ]; then
1112 FIXUP_HASH=${SPLIT[2]}
1113 fi
Steve Kondik5bd66602016-07-15 10:39:58 -07001114
1115 # if line starts with a dash, it needs to be packaged
1116 if [[ "$SPEC" =~ ^- ]]; then
1117 PRODUCT_PACKAGES_LIST+=("${SPEC#-}")
1118 PRODUCT_PACKAGES_HASHES+=("$HASH")
Vladimir Olteande985fe2019-01-17 03:07:34 +02001119 PRODUCT_PACKAGES_FIXUP_HASHES+=("$FIXUP_HASH")
Steve Kondik5bd66602016-07-15 10:39:58 -07001120 else
1121 PRODUCT_COPY_FILES_LIST+=("$SPEC")
1122 PRODUCT_COPY_FILES_HASHES+=("$HASH")
Vladimir Olteande985fe2019-01-17 03:07:34 +02001123 PRODUCT_COPY_FILES_FIXUP_HASHES+=("$FIXUP_HASH")
Steve Kondik5bd66602016-07-15 10:39:58 -07001124 fi
1125
Rashed Abdel-Tawabb0d08e82017-04-04 02:48:18 -04001126 done < <(egrep -v '(^#|^[[:space:]]*$)' "$LIST" | LC_ALL=C sort | uniq)
Steve Kondik5bd66602016-07-15 10:39:58 -07001127}
1128
1129#
1130# write_makefiles:
1131#
1132# $1: file containing the list of items to extract
Rashed Abdel-Tawab7fd3ccb2017-10-07 14:18:39 -04001133# $2: make treble compatible makefile - optional
Steve Kondik5bd66602016-07-15 10:39:58 -07001134#
1135# Calls write_product_copy_files and write_product_packages on
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -07001136# the given file and appends to the Android.bp as well as
Steve Kondik5bd66602016-07-15 10:39:58 -07001137# the product makefile.
1138#
1139function write_makefiles() {
1140 parse_file_list "$1"
Rashed Abdel-Tawab7fd3ccb2017-10-07 14:18:39 -04001141 write_product_copy_files "$2"
Steve Kondik5bd66602016-07-15 10:39:58 -07001142 write_product_packages
1143}
1144
1145#
1146# append_firmware_calls_to_makefiles:
1147#
1148# Appends to Android.mk the calls to all images present in radio folder
1149# (filesmap file used by releasetools to map firmware images should be kept in the device tree)
1150#
1151function append_firmware_calls_to_makefiles() {
1152 cat << EOF >> "$ANDROIDMK"
1153ifeq (\$(LOCAL_PATH)/radio, \$(wildcard \$(LOCAL_PATH)/radio))
1154
1155RADIO_FILES := \$(wildcard \$(LOCAL_PATH)/radio/*)
1156\$(foreach f, \$(notdir \$(RADIO_FILES)), \\
1157 \$(call add-radio-file,radio/\$(f)))
1158\$(call add-radio-file,../../../device/$VENDOR/$DEVICE/radio/filesmap)
1159
1160endif
1161
1162EOF
1163}
1164
1165#
1166# get_file:
1167#
1168# $1: input file
1169# $2: target file/folder
1170# $3: source of the file (can be "adb" or a local folder)
1171#
1172# Silently extracts the input file to defined target
1173# Returns success if file can be pulled from the device or found locally
1174#
1175function get_file() {
1176 local SRC="$3"
1177
1178 if [ "$SRC" = "adb" ]; then
1179 # try to pull
1180 adb pull "$1" "$2" >/dev/null 2>&1 && return 0
1181
1182 return 1
1183 else
1184 # try to copy
Vladimir Olteanfe49eae2018-06-25 00:05:56 +03001185 cp -r "$SRC/$1" "$2" 2>/dev/null && return 0
1186 cp -r "$SRC/${1#/system}" "$2" 2>/dev/null && return 0
Vladimir Oltean6780da32019-01-06 19:38:31 +02001187 cp -r "$SRC/system/$1" "$2" 2>/dev/null && return 0
Steve Kondik5bd66602016-07-15 10:39:58 -07001188
1189 return 1
1190 fi
1191};
1192
1193#
1194# oat2dex:
1195#
1196# $1: extracted apk|jar (to check if deodex is required)
1197# $2: odexed apk|jar to deodex
1198# $3: source of the odexed apk|jar
1199#
1200# Convert apk|jar .odex in the corresposing classes.dex
1201#
1202function oat2dex() {
theimpulson9a911af2019-08-14 03:25:12 +00001203 local OMNI_TARGET="$1"
Steve Kondik5bd66602016-07-15 10:39:58 -07001204 local OEM_TARGET="$2"
1205 local SRC="$3"
1206 local TARGET=
Joe Maplesfb3941c2018-01-05 14:51:33 -05001207 local OAT=
Steve Kondik5bd66602016-07-15 10:39:58 -07001208
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001209 if [ -z "$BAKSMALIJAR" ] || [ -z "$SMALIJAR" ]; then
1210 export BAKSMALIJAR="$OMNI_ROOT"/vendor/omni/build/tools/smali/baksmali.jar
1211 export SMALIJAR="$OMNI_ROOT"/vendor/omni/build/tools/smali/smali.jar
Steve Kondik5bd66602016-07-15 10:39:58 -07001212 fi
1213
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001214 if [ -z "$VDEXEXTRACTOR" ]; then
Han Wang7a0b0bd2020-03-10 09:40:47 +02001215 export VDEXEXTRACTOR="$OMNI_ROOT"/vendor/omni/build/tools/${HOST}/vdexExtractor
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001216 fi
Joe Maplesfb3941c2018-01-05 14:51:33 -05001217
codeworkx85eda752018-09-23 12:36:57 +02001218 if [ -z "$CDEXCONVERTER" ]; then
Han Wang7a0b0bd2020-03-10 09:40:47 +02001219 export CDEXCONVERTER="$OMNI_ROOT"/vendor/omni/build/tools/${HOST}/compact_dex_converter
codeworkx85eda752018-09-23 12:36:57 +02001220 fi
1221
Steve Kondik5bd66602016-07-15 10:39:58 -07001222 # Extract existing boot.oats to the temp folder
1223 if [ -z "$ARCHES" ]; then
Jake Whatley9843b322017-01-25 21:49:16 -05001224 echo "Checking if system is odexed and locating boot.oats..."
Steve Kondik5bd66602016-07-15 10:39:58 -07001225 for ARCH in "arm64" "arm" "x86_64" "x86"; do
Jake Whatley9843b322017-01-25 21:49:16 -05001226 mkdir -p "$TMPDIR/system/framework/$ARCH"
Vladimir Olteanfe49eae2018-06-25 00:05:56 +03001227 if get_file "/system/framework/$ARCH" "$TMPDIR/system/framework/" "$SRC"; then
Steve Kondik5bd66602016-07-15 10:39:58 -07001228 ARCHES+="$ARCH "
Jake Whatley9843b322017-01-25 21:49:16 -05001229 else
1230 rmdir "$TMPDIR/system/framework/$ARCH"
Steve Kondik5bd66602016-07-15 10:39:58 -07001231 fi
1232 done
1233 fi
1234
1235 if [ -z "$ARCHES" ]; then
1236 FULLY_DEODEXED=1 && return 0 # system is fully deodexed, return
1237 fi
1238
theimpulson9a911af2019-08-14 03:25:12 +00001239 if [ ! -f "$OMNI_TARGET" ]; then
Steve Kondik5bd66602016-07-15 10:39:58 -07001240 return;
1241 fi
1242
theimpulson9a911af2019-08-14 03:25:12 +00001243 if grep "classes.dex" "$OMNI_TARGET" >/dev/null; then
Steve Kondik5bd66602016-07-15 10:39:58 -07001244 return 0 # target apk|jar is already odexed, return
1245 fi
1246
1247 for ARCH in $ARCHES; do
Jake Whatley9843b322017-01-25 21:49:16 -05001248 BOOTOAT="$TMPDIR/system/framework/$ARCH/boot.oat"
Steve Kondik5bd66602016-07-15 10:39:58 -07001249
Joe Maplesfb3941c2018-01-05 14:51:33 -05001250 local OAT="$(dirname "$OEM_TARGET")/oat/$ARCH/$(basename "$OEM_TARGET" ."${OEM_TARGET##*.}").odex"
1251 local VDEX="$(dirname "$OEM_TARGET")/oat/$ARCH/$(basename "$OEM_TARGET" ."${OEM_TARGET##*.}").vdex"
Steve Kondik5bd66602016-07-15 10:39:58 -07001252
Joe Maplesfb3941c2018-01-05 14:51:33 -05001253 if get_file "$OAT" "$TMPDIR" "$SRC"; then
1254 if get_file "$VDEX" "$TMPDIR" "$SRC"; then
1255 "$VDEXEXTRACTOR" -o "$TMPDIR/" -i "$TMPDIR/$(basename "$VDEX")" > /dev/null
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001256 CLASSES=$(ls "$TMPDIR/$(basename "${OEM_TARGET%.*}")_classes"*)
1257 for CLASS in $CLASSES; do
1258 NEWCLASS=$(echo "$CLASS" | sed 's/.*_//;s/cdex/dex/')
1259 # Check if we have to deal with CompactDex
1260 if [[ "$CLASS" == *.cdex ]]; then
1261 "$CDEXCONVERTER" "$CLASS" &>/dev/null
1262 mv "$CLASS.new" "$TMPDIR/$NEWCLASS"
1263 else
1264 mv "$CLASS" "$TMPDIR/$NEWCLASS"
1265 fi
1266 done
Joe Maplesfb3941c2018-01-05 14:51:33 -05001267 else
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001268 java -jar "$BAKSMALIJAR" deodex -o "$TMPDIR/dexout" -b "$BOOTOAT" -d "$TMPDIR" "$TMPDIR/$(basename "$OAT")"
1269 java -jar "$SMALIJAR" assemble "$TMPDIR/dexout" -o "$TMPDIR/classes.dex"
Joe Maplesfb3941c2018-01-05 14:51:33 -05001270 fi
theimpulson9a911af2019-08-14 03:25:12 +00001271 elif [[ "$OMNI_TARGET" =~ .jar$ ]]; then
Jake Whatley9843b322017-01-25 21:49:16 -05001272 JAROAT="$TMPDIR/system/framework/$ARCH/boot-$(basename ${OEM_TARGET%.*}).oat"
Luca Stefani082f1e82018-10-07 12:44:53 +02001273 JARVDEX="/system/framework/boot-$(basename ${OEM_TARGET%.*}).vdex"
Jake Whatley9843b322017-01-25 21:49:16 -05001274 if [ ! -f "$JAROAT" ]; then
Luca Stefani082f1e82018-10-07 12:44:53 +02001275 JAROAT=$BOOTOAT
Jake Whatley9843b322017-01-25 21:49:16 -05001276 fi
Joe Maplesfb3941c2018-01-05 14:51:33 -05001277 # try to extract classes.dex from boot.vdex for frameworks jars
1278 # fallback to boot.oat if vdex is not available
Luca Stefani082f1e82018-10-07 12:44:53 +02001279 if get_file "$JARVDEX" "$TMPDIR" "$SRC"; then
Luca Stefani6f92e6b2018-10-31 19:16:05 +01001280 "$VDEXEXTRACTOR" -o "$TMPDIR/" -i "$TMPDIR/$(basename "$JARVDEX")" > /dev/null
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001281 CLASSES=$(ls "$TMPDIR/$(basename "${JARVDEX%.*}")_classes"*)
1282 for CLASS in $CLASSES; do
1283 NEWCLASS=$(echo "$CLASS" | sed 's/.*_//;s/cdex/dex/')
1284 # Check if we have to deal with CompactDex
1285 if [[ "$CLASS" == *.cdex ]]; then
1286 "$CDEXCONVERTER" "$CLASS" &>/dev/null
1287 mv "$CLASS.new" "$TMPDIR/$NEWCLASS"
1288 else
1289 mv "$CLASS" "$TMPDIR/$NEWCLASS"
1290 fi
1291 done
Joe Maplesfb3941c2018-01-05 14:51:33 -05001292 else
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001293 java -jar "$BAKSMALIJAR" deodex -o "$TMPDIR/dexout" -b "$BOOTOAT" -d "$TMPDIR" "$JAROAT/$OEM_TARGET"
1294 java -jar "$SMALIJAR" assemble "$TMPDIR/dexout" -o "$TMPDIR/classes.dex"
Joe Maplesfb3941c2018-01-05 14:51:33 -05001295 fi
Steve Kondik5bd66602016-07-15 10:39:58 -07001296 else
1297 continue
1298 fi
1299
Steve Kondik5bd66602016-07-15 10:39:58 -07001300 done
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001301
1302 rm -rf "$TMPDIR/dexout"
Steve Kondik5bd66602016-07-15 10:39:58 -07001303}
1304
1305#
1306# init_adb_connection:
1307#
1308# Starts adb server and waits for the device
1309#
1310function init_adb_connection() {
1311 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
1312 if ! _adb_connected; then
1313 echo "No device is online. Waiting for one..."
1314 echo "Please connect USB and/or enable USB debugging"
1315 until _adb_connected; do
1316 sleep 1
1317 done
1318 echo "Device Found."
1319 fi
1320
1321 # Retrieve IP and PORT info if we're using a TCP connection
1322 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
1323 | head -1 | awk '{print $1}')
1324 adb root &> /dev/null
1325 sleep 0.3
1326 if [ -n "$TCPIPPORT" ]; then
1327 # adb root just killed our connection
1328 # so reconnect...
1329 adb connect "$TCPIPPORT"
1330 fi
1331 adb wait-for-device &> /dev/null
1332 sleep 0.3
1333}
1334
1335#
1336# fix_xml:
1337#
1338# $1: xml file to fix
1339#
1340function fix_xml() {
1341 local XML="$1"
1342 local TEMP_XML="$TMPDIR/`basename "$XML"`.temp"
1343
Dobroslaw Kijowski3af2a8d2017-05-18 12:35:02 +02001344 grep -a '^<?xml version' "$XML" > "$TEMP_XML"
1345 grep -av '^<?xml version' "$XML" >> "$TEMP_XML"
Steve Kondik5bd66602016-07-15 10:39:58 -07001346
1347 mv "$TEMP_XML" "$XML"
1348}
1349
Vladimir Olteande985fe2019-01-17 03:07:34 +02001350function get_hash() {
1351 local FILE="$1"
1352
1353 if [ "$(uname)" == "Darwin" ]; then
1354 shasum "${FILE}" | awk '{print $1}'
1355 else
1356 sha1sum "${FILE}" | awk '{print $1}'
1357 fi
1358}
1359
Vladimir Olteana7d20492019-01-17 03:05:52 +02001360function print_spec() {
1361 local SPEC_PRODUCT_PACKAGE="$1"
1362 local SPEC_SRC_FILE="$2"
1363 local SPEC_DST_FILE="$3"
1364 local SPEC_ARGS="$4"
1365 local SPEC_HASH="$5"
Vladimir Olteande985fe2019-01-17 03:07:34 +02001366 local SPEC_FIXUP_HASH="$6"
Vladimir Olteana7d20492019-01-17 03:05:52 +02001367
1368 local PRODUCT_PACKAGE=""
1369 if [ ${SPEC_PRODUCT_PACKAGE} = true ]; then
1370 PRODUCT_PACKAGE="-"
1371 fi
1372 local SRC=""
1373 if [ ! -z "${SPEC_SRC_FILE}" ] && [ "${SPEC_SRC_FILE}" != "${SPEC_DST_FILE}" ]; then
1374 SRC="${SPEC_SRC_FILE}:"
1375 fi
1376 local DST=""
1377 if [ ! -z "${SPEC_DST_FILE}" ]; then
1378 DST="${SPEC_DST_FILE}"
1379 fi
1380 local ARGS=""
1381 if [ ! -z "${SPEC_ARGS}" ]; then
1382 ARGS=";${SPEC_ARGS}"
1383 fi
1384 local HASH=""
1385 if [ ! -z "${SPEC_HASH}" ] && [ "${SPEC_HASH}" != "x" ]; then
1386 HASH="|${SPEC_HASH}"
1387 fi
Vladimir Olteande985fe2019-01-17 03:07:34 +02001388 local FIXUP_HASH=""
1389 if [ ! -z "${SPEC_FIXUP_HASH}" ] && [ "${SPEC_FIXUP_HASH}" != "x" ] && [ "${SPEC_FIXUP_HASH}" != "${SPEC_HASH}" ]; then
1390 FIXUP_HASH="|${SPEC_FIXUP_HASH}"
1391 fi
1392 printf '%s%s%s%s%s%s\n' "${PRODUCT_PACKAGE}" "${SRC}" "${DST}" "${ARGS}" "${HASH}" "${FIXUP_HASH}"
1393}
1394
1395# To be overridden by device-level extract-files.sh
1396# Parameters:
1397# $1: spec name of a blob. Can be used for filtering.
1398# If the spec is "src:dest", then $1 is "dest".
1399# If the spec is "src", then $1 is "src".
1400# $2: path to blob file. Can be used for fixups.
1401#
1402function blob_fixup() {
1403 :
Vladimir Olteana7d20492019-01-17 03:05:52 +02001404}
1405
Steve Kondik5bd66602016-07-15 10:39:58 -07001406#
1407# extract:
1408#
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001409# Positional parameters:
1410# $1: file containing the list of items to extract (aka proprietary-files.txt)
Dan Pasanen0cc05012017-03-21 09:06:11 -05001411# $2: path to extracted system folder, an ota zip file, or "adb" to extract from device
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001412# $3: section in list file to extract - optional. Setting section via $3 is deprecated.
1413#
1414# Non-positional parameters (coming after $2):
1415# --section: preferred way of selecting the portion to parse and extract from
1416# proprietary-files.txt
Vladimir Olteana7d20492019-01-17 03:05:52 +02001417# --kang: if present, this option will activate the printing of hashes for the
1418# extracted blobs. Useful with --section for subsequent pinning of
1419# blobs taken from other origins.
Steve Kondik5bd66602016-07-15 10:39:58 -07001420#
1421function extract() {
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001422 # Consume positional parameters
1423 local PROPRIETARY_FILES_TXT="$1"; shift
1424 local SRC="$1"; shift
1425 local SECTION=""
Vladimir Olteana7d20492019-01-17 03:05:52 +02001426 local KANG=false
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001427
1428 # Consume optional, non-positional parameters
1429 while [ "$#" -gt 0 ]; do
1430 case "$1" in
1431 -s|--section)
1432 SECTION="$2"; shift
1433 ;;
Vladimir Olteana7d20492019-01-17 03:05:52 +02001434 -k|--kang)
1435 KANG=true
1436 DISABLE_PINNING=1
1437 ;;
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001438 *)
1439 # Backwards-compatibility with the old behavior, where $3, if
1440 # present, denoted an optional positional ${SECTION} argument.
1441 # Users of ${SECTION} are encouraged to migrate from setting it as
1442 # positional $3, to non-positional --section ${SECTION}, the
1443 # reason being that it doesn't scale to have more than 1 optional
1444 # positional argument.
1445 SECTION="$1"
1446 ;;
1447 esac
1448 shift
1449 done
1450
Steve Kondik5bd66602016-07-15 10:39:58 -07001451 if [ -z "$OUTDIR" ]; then
1452 echo "Output dir not set!"
1453 exit 1
1454 fi
1455
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001456 parse_file_list "${PROPRIETARY_FILES_TXT}" "${SECTION}"
Steve Kondik5bd66602016-07-15 10:39:58 -07001457
1458 # Allow failing, so we can try $DEST and/or $FILE
1459 set +e
1460
1461 local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ${PRODUCT_PACKAGES_LIST[@]} )
1462 local HASHLIST=( ${PRODUCT_COPY_FILES_HASHES[@]} ${PRODUCT_PACKAGES_HASHES[@]} )
Vladimir Olteande985fe2019-01-17 03:07:34 +02001463 local FIXUP_HASHLIST=( ${PRODUCT_COPY_FILES_FIXUP_HASHES[@]} ${PRODUCT_PACKAGES_FIXUP_HASHES[@]} )
Vladimir Olteana7d20492019-01-17 03:05:52 +02001464 local PRODUCT_COPY_FILES_COUNT=${#PRODUCT_COPY_FILES_LIST[@]}
Steve Kondik5bd66602016-07-15 10:39:58 -07001465 local COUNT=${#FILELIST[@]}
theimpulson9a911af2019-08-14 03:25:12 +00001466 local OUTPUT_ROOT="$OMNI_ROOT"/"$OUTDIR"/proprietary
Steve Kondik5bd66602016-07-15 10:39:58 -07001467 local OUTPUT_TMP="$TMPDIR"/"$OUTDIR"/proprietary
1468
1469 if [ "$SRC" = "adb" ]; then
1470 init_adb_connection
1471 fi
1472
Dan Pasanen0cc05012017-03-21 09:06:11 -05001473 if [ -f "$SRC" ] && [ "${SRC##*.}" == "zip" ]; then
conbold9baced42017-11-10 16:33:38 +01001474 DUMPDIR="$TMPDIR"/system_dump
Dan Pasanen0cc05012017-03-21 09:06:11 -05001475
1476 # Check if we're working with the same zip that was passed last time.
1477 # If so, let's just use what's already extracted.
1478 MD5=`md5sum "$SRC"| awk '{print $1}'`
1479 OLDMD5=`cat "$DUMPDIR"/zipmd5.txt`
1480
1481 if [ "$MD5" != "$OLDMD5" ]; then
1482 rm -rf "$DUMPDIR"
1483 mkdir "$DUMPDIR"
1484 unzip "$SRC" -d "$DUMPDIR"
1485 echo "$MD5" > "$DUMPDIR"/zipmd5.txt
1486
1487 # Stop if an A/B OTA zip is detected. We cannot extract these.
1488 if [ -a "$DUMPDIR"/payload.bin ]; then
1489 echo "A/B style OTA zip detected. This is not supported at this time. Stopping..."
1490 exit 1
Dan Pasanen0cc05012017-03-21 09:06:11 -05001491 fi
dianlujitao85ddca62020-04-21 23:03:20 +08001492
Luca Stefani776be462020-09-09 15:53:58 +02001493 for PARTITION in "system" "odm" "product" "system_ext" "vendor"
dianlujitao85ddca62020-04-21 23:03:20 +08001494 do
1495 # If OTA is block based, extract it.
dianlujitaoe2cbe262020-04-21 23:01:13 +08001496 if [ -a "$DUMPDIR"/"$PARTITION".new.dat.br ]; then
1497 echo "Converting "$PARTITION".new.dat.br to "$PARTITION".new.dat"
1498 brotli -d "$DUMPDIR"/"$PARTITION".new.dat.br
1499 rm "$DUMPDIR"/"$PARTITION".new.dat.br
1500 fi
dianlujitao85ddca62020-04-21 23:03:20 +08001501 if [ -a "$DUMPDIR"/"$PARTITION".new.dat ]; then
1502 echo "Converting "$PARTITION".new.dat to "$PARTITION".img"
1503 python "$OMNI_ROOT"/vendor/omni/build/tools/sdat2img.py "$DUMPDIR"/"$PARTITION".transfer.list "$DUMPDIR"/"$PARTITION".new.dat "$DUMPDIR"/"$PARTITION".img 2>&1
1504 rm -rf "$DUMPDIR"/"$PARTITION".new.dat "$DUMPDIR"/"$PARTITION"
1505 mkdir "$DUMPDIR"/"$PARTITION" "$DUMPDIR"/tmp
1506 echo "Requesting sudo access to mount the "$PARTITION".img"
1507 sudo mount -o loop "$DUMPDIR"/"$PARTITION".img "$DUMPDIR"/tmp
1508 cp -r "$DUMPDIR"/tmp/* "$DUMPDIR"/"$PARTITION"/
1509 sudo umount "$DUMPDIR"/tmp
1510 rm -rf "$DUMPDIR"/tmp "$DUMPDIR"/"$PARTITION".img
1511 fi
1512 done
Dan Pasanen0cc05012017-03-21 09:06:11 -05001513 fi
1514
1515 SRC="$DUMPDIR"
1516 fi
1517
Steve Kondik5bd66602016-07-15 10:39:58 -07001518 if [ "$VENDOR_STATE" -eq "0" ]; then
1519 echo "Cleaning output directory ($OUTPUT_ROOT).."
1520 rm -rf "${OUTPUT_TMP:?}"
1521 mkdir -p "${OUTPUT_TMP:?}"
Jake Whatley9843b322017-01-25 21:49:16 -05001522 if [ -d "$OUTPUT_ROOT" ]; then
1523 mv "${OUTPUT_ROOT:?}/"* "${OUTPUT_TMP:?}/"
1524 fi
Steve Kondik5bd66602016-07-15 10:39:58 -07001525 VENDOR_STATE=1
1526 fi
1527
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001528 echo "Extracting ${COUNT} files in ${PROPRIETARY_FILES_TXT} from ${SRC}:"
Steve Kondik5bd66602016-07-15 10:39:58 -07001529
1530 for (( i=1; i<COUNT+1; i++ )); do
1531
Vladimir Oltean8e2de652018-06-24 20:41:30 +03001532 local SPEC_SRC_FILE=$(src_file "${FILELIST[$i-1]}")
Vladimir Olteanb06f3aa2018-06-24 20:38:04 +03001533 local SPEC_DST_FILE=$(target_file "${FILELIST[$i-1]}")
Vladimir Olteand6391332018-06-24 20:42:01 +03001534 local SPEC_ARGS=$(target_args "${FILELIST[$i-1]}")
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001535 local OUTPUT_DIR=
1536 local TMP_DIR=
1537 local SRC_FILE=
1538 local DST_FILE=
Vladimir Olteana7d20492019-01-17 03:05:52 +02001539 local IS_PRODUCT_PACKAGE=false
1540
1541 # Note: this relies on the fact that the ${FILELIST[@]} array
1542 # contains first ${PRODUCT_COPY_FILES_LIST[@]}, then ${PRODUCT_PACKAGES_LIST[@]}.
1543 if [ "${i}" -gt "${PRODUCT_COPY_FILES_COUNT}" ]; then
1544 IS_PRODUCT_PACKAGE=true
1545 fi
Steve Kondik5bd66602016-07-15 10:39:58 -07001546
Vladimir Olteand6391332018-06-24 20:42:01 +03001547 if [ "${SPEC_ARGS}" = "rootfs" ]; then
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001548 OUTPUT_DIR="${OUTPUT_ROOT}/rootfs"
1549 TMP_DIR="${OUTPUT_TMP}/rootfs"
1550 SRC_FILE="/${SPEC_SRC_FILE}"
1551 DST_FILE="/${SPEC_DST_FILE}"
Steve Kondik5bd66602016-07-15 10:39:58 -07001552 else
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001553 OUTPUT_DIR="${OUTPUT_ROOT}"
1554 TMP_DIR="${OUTPUT_TMP}"
1555 SRC_FILE="/system/${SPEC_SRC_FILE}"
1556 DST_FILE="/system/${SPEC_DST_FILE}"
Steve Kondik5bd66602016-07-15 10:39:58 -07001557 fi
1558
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001559 # Strip the file path in the vendor repo of "system", if present
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001560 local BLOB_DISPLAY_NAME="${DST_FILE#/system/}"
dianlujitao4ddcfb72020-04-06 12:43:16 +08001561 local VENDOR_REPO_FILE="$OUTPUT_DIR/${BLOB_DISPLAY_NAME}"
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001562 mkdir -p $(dirname "${VENDOR_REPO_FILE}")
Steve Kondik5bd66602016-07-15 10:39:58 -07001563
Gabriele M58270a32017-11-13 23:15:29 +01001564 # Check pinned files
Vladimir Olteane688cf92019-01-17 02:47:02 +02001565 local HASH="$(echo ${HASHLIST[$i-1]} | awk '{ print tolower($0); }')"
Vladimir Olteande985fe2019-01-17 03:07:34 +02001566 local FIXUP_HASH="$(echo ${FIXUP_HASHLIST[$i-1]} | awk '{ print tolower($0); }')"
Gabriele M58270a32017-11-13 23:15:29 +01001567 local KEEP=""
Vladimir Olteande985fe2019-01-17 03:07:34 +02001568 if [ "$DISABLE_PINNING" != "1" ] && [ "$HASH" != "x" ]; then
Vladimir Oltean4daf5592018-06-24 20:46:42 +03001569 if [ -f "${VENDOR_REPO_FILE}" ]; then
1570 local PINNED="${VENDOR_REPO_FILE}"
Gabriele M58270a32017-11-13 23:15:29 +01001571 else
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001572 local PINNED="${TMP_DIR}${DST_FILE#/system}"
Gabriele M58270a32017-11-13 23:15:29 +01001573 fi
1574 if [ -f "$PINNED" ]; then
Vladimir Olteande985fe2019-01-17 03:07:34 +02001575 local TMP_HASH=$(get_hash "${PINNED}")
1576 if [ "${TMP_HASH}" = "${HASH}" ] || [ "${TMP_HASH}" = "${FIXUP_HASH}" ]; then
Gabriele M58270a32017-11-13 23:15:29 +01001577 KEEP="1"
Vladimir Oltean4daf5592018-06-24 20:46:42 +03001578 if [ ! -f "${VENDOR_REPO_FILE}" ]; then
1579 cp -p "$PINNED" "${VENDOR_REPO_FILE}"
Gabriele M58270a32017-11-13 23:15:29 +01001580 fi
1581 fi
1582 fi
1583 fi
1584
Vladimir Olteana7d20492019-01-17 03:05:52 +02001585 if [ "${KANG}" = false ]; then
1586 printf ' - %s\n' "${BLOB_DISPLAY_NAME}"
1587 fi
1588
Gabriele M58270a32017-11-13 23:15:29 +01001589 if [ "$KEEP" = "1" ]; then
Vladimir Olteana7d20492019-01-17 03:05:52 +02001590 printf ' + keeping pinned file with hash %s\n' "${HASH}"
Steve Kondik5bd66602016-07-15 10:39:58 -07001591 else
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001592 FOUND=false
1593 # Try Lineage target first.
1594 # Also try to search for files stripped of
1595 # the "/system" prefix, if we're actually extracting
1596 # from a system image.
Vladimir Olteanfe49eae2018-06-25 00:05:56 +03001597 for CANDIDATE in "${DST_FILE}" "${SRC_FILE}"; do
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001598 get_file ${CANDIDATE} ${VENDOR_REPO_FILE} ${SRC} && {
1599 FOUND=true
1600 break
1601 }
1602 done
1603
1604 if [ "${FOUND}" = false ]; then
Bruno Martins74e00eb2021-04-10 14:36:50 +01001605 colored_echo red " !! ${BLOB_DISPLAY_NAME}: file not found in source"
Vladimir Oltean11329372018-10-18 00:44:02 +03001606 continue
Steve Kondik5bd66602016-07-15 10:39:58 -07001607 fi
1608 fi
1609
Vladimir Olteande985fe2019-01-17 03:07:34 +02001610 # Blob fixup pipeline has 2 parts: one that is fixed and
1611 # one that is user-configurable
1612 local PRE_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE})
1613 # Deodex apk|jar if that's the case
1614 if [[ "$FULLY_DEODEXED" -ne "1" && "${VENDOR_REPO_FILE}" =~ .(apk|jar)$ ]]; then
1615 oat2dex "${VENDOR_REPO_FILE}" "${SRC_FILE}" "$SRC"
1616 if [ -f "$TMPDIR/classes.dex" ]; then
dianlujitaoded7c1e2020-04-06 12:45:36 +08001617 touch -t 200901010000 "$TMPDIR/classes"*
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001618 zip -gjq "${VENDOR_REPO_FILE}" "$TMPDIR/classes"*
1619 rm "$TMPDIR/classes"*
Vladimir Olteande985fe2019-01-17 03:07:34 +02001620 printf ' (updated %s from odex files)\n' "${SRC_FILE}"
Steve Kondik5bd66602016-07-15 10:39:58 -07001621 fi
Vladimir Olteande985fe2019-01-17 03:07:34 +02001622 elif [[ "${VENDOR_REPO_FILE}" =~ .xml$ ]]; then
1623 fix_xml "${VENDOR_REPO_FILE}"
Steve Kondik5bd66602016-07-15 10:39:58 -07001624 fi
Vladimir Olteande985fe2019-01-17 03:07:34 +02001625 # Now run user-supplied fixup function
1626 blob_fixup "${BLOB_DISPLAY_NAME}" "${VENDOR_REPO_FILE}"
1627 local POST_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE})
Steve Kondik5bd66602016-07-15 10:39:58 -07001628
Vladimir Oltean4daf5592018-06-24 20:46:42 +03001629 if [ -f "${VENDOR_REPO_FILE}" ]; then
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001630 local DIR=$(dirname "${VENDOR_REPO_FILE}")
Steve Kondik5bd66602016-07-15 10:39:58 -07001631 local TYPE="${DIR##*/}"
1632 if [ "$TYPE" = "bin" -o "$TYPE" = "sbin" ]; then
Vladimir Oltean4daf5592018-06-24 20:46:42 +03001633 chmod 755 "${VENDOR_REPO_FILE}"
Steve Kondik5bd66602016-07-15 10:39:58 -07001634 else
Vladimir Oltean4daf5592018-06-24 20:46:42 +03001635 chmod 644 "${VENDOR_REPO_FILE}"
Steve Kondik5bd66602016-07-15 10:39:58 -07001636 fi
1637 fi
1638
Vladimir Olteana7d20492019-01-17 03:05:52 +02001639 if [ "${KANG}" = true ]; then
Vladimir Olteande985fe2019-01-17 03:07:34 +02001640 print_spec "${IS_PRODUCT_PACKAGE}" "${SPEC_SRC_FILE}" "${SPEC_DST_FILE}" "${SPEC_ARGS}" "${PRE_FIXUP_HASH}" "${POST_FIXUP_HASH}"
1641 fi
1642
1643 # Check and print whether the fixup pipeline actually did anything.
1644 # This isn't done right after the fixup pipeline because we want this print
1645 # to come after print_spec above, when in kang mode.
1646 if [ "${PRE_FIXUP_HASH}" != "${POST_FIXUP_HASH}" ]; then
1647 printf " + Fixed up %s\n" "${BLOB_DISPLAY_NAME}"
1648 # Now sanity-check the spec for this blob.
1649 if [ "${KANG}" = false ] && [ "${FIXUP_HASH}" = "x" ] && [ "${HASH}" != "x" ]; then
Bruno Martins74e00eb2021-04-10 14:36:50 +01001650 colored_echo yellow "WARNING: The ${BLOB_DISPLAY_NAME} file was fixed up, but it is pinned."
1651 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 +02001652 fi
Vladimir Olteana7d20492019-01-17 03:05:52 +02001653 fi
1654
Steve Kondik5bd66602016-07-15 10:39:58 -07001655 done
1656
1657 # Don't allow failing
1658 set -e
1659}
1660
1661#
Rashed Abdel-Tawab5b97a982019-09-29 01:19:57 -04001662# extract2:
1663#
1664# Positional parameters:
1665# $1: file containing the list of items to extract (aka proprietary-files.txt)
1666#
1667# Non-positional parameters (coming after $2):
1668# --section: selects the portion to parse and extracts from proprietary-files.txt
1669# --kang: if present, this option will activate the printing of hashes for the
1670# extracted blobs. Useful with --section for subsequent pinning of
1671# blobs taken from other origins.
1672#
1673function extract2() {
1674 # Consume positional parameters
1675 local PROPRIETARY_FILES_TXT="$1"; shift
1676 local SECTION=""
1677 local KANG=false
1678
1679 # Consume optional, non-positional parameters
1680 while [ "$#" -gt 0 ]; do
1681 case "$1" in
1682 --adb)
1683 ADB=true
1684 ;;
1685 --system)
1686 SYSTEM_SRC="$2"; shift
1687 ;;
1688 --vendor)
1689 VENDOR_SRC="$2"; shift
1690 ;;
1691 --odm)
1692 ODM_SRC="$2"; shift
1693 ;;
1694 --product)
1695 PRODUCT_SRC="$2"; shift
1696 ;;
1697 -s|--section)
1698 SECTION="$2"; shift
1699 ;;
1700 -k|--kang)
1701 KANG=true
1702 DISABLE_PINNING=1
1703 ;;
1704 esac
1705 shift
1706 done
1707
1708 if [ -z "$ADB" ] || [ -z "$SYSTEM_SRC" && -z "$VENDOR_SRC" && -z "$ODM_SRC" && -z "$PRODUCT_SRC" ]; then
1709 echo "No sources set! You must select --adb or pass paths to partition dumps."
1710 exit 1
1711 fi
1712
1713 if [ -z "$OUTDIR" ]; then
1714 echo "Output dir not set!"
1715 exit 1
1716 fi
1717
1718 parse_file_list "${PROPRIETARY_FILES_TXT}" "${SECTION}"
1719
1720 # Allow failing, so we can try $DEST and/or $FILE
1721 set +e
1722
1723 local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ${PRODUCT_PACKAGES_LIST[@]} )
1724 local HASHLIST=( ${PRODUCT_COPY_FILES_HASHES[@]} ${PRODUCT_PACKAGES_HASHES[@]} )
1725 local FIXUP_HASHLIST=( ${PRODUCT_COPY_FILES_FIXUP_HASHES[@]} ${PRODUCT_PACKAGES_FIXUP_HASHES[@]} )
1726 local PRODUCT_COPY_FILES_COUNT=${#PRODUCT_COPY_FILES_LIST[@]}
1727 local COUNT=${#FILELIST[@]}
1728 local OUTPUT_ROOT="$OMNI_ROOT"/"$OUTDIR"/proprietary
1729 local OUTPUT_TMP="$TMPDIR"/"$OUTDIR"/proprietary
1730
1731 if [ "$ADB" = true ]; then
1732 init_adb_connection
1733 fi
1734
1735 if [ "$VENDOR_STATE" -eq "0" ]; then
1736 echo "Cleaning output directory ($OUTPUT_ROOT).."
1737 rm -rf "${OUTPUT_TMP:?}"
1738 mkdir -p "${OUTPUT_TMP:?}"
1739 if [ -d "$OUTPUT_ROOT" ]; then
1740 mv "${OUTPUT_ROOT:?}/"* "${OUTPUT_TMP:?}/"
1741 fi
1742 VENDOR_STATE=1
1743 fi
1744
1745 echo "Extracting ${COUNT} files in ${PROPRIETARY_FILES_TXT} from ${SRC}:"
1746
1747 for (( i=1; i<COUNT+1; i++ )); do
1748
1749 local SPEC_SRC_FILE=$(src_file "${FILELIST[$i-1]}")
1750 local SPEC_DST_FILE=$(target_file "${FILELIST[$i-1]}")
1751 local SPEC_ARGS=$(target_args "${FILELIST[$i-1]}")
1752 local OUTPUT_DIR=
1753 local TMP_DIR=
1754 local SRC_FILE=
1755 local DST_FILE=
1756 local IS_PRODUCT_PACKAGE=false
1757
1758 # Note: this relies on the fact that the ${FILELIST[@]} array
1759 # contains first ${PRODUCT_COPY_FILES_LIST[@]}, then ${PRODUCT_PACKAGES_LIST[@]}.
1760 if [ "${i}" -gt "${PRODUCT_COPY_FILES_COUNT}" ]; then
1761 IS_PRODUCT_PACKAGE=true
1762 fi
1763
1764 if [ "${SPEC_ARGS}" = "rootfs" ]; then
1765 OUTPUT_DIR="${OUTPUT_ROOT}/rootfs"
1766 TMP_DIR="${OUTPUT_TMP}/rootfs"
1767 else
1768 OUTPUT_DIR="${OUTPUT_ROOT}"
1769 TMP_DIR="${OUTPUT_TMP}"
1770 fi
1771 SRC_FILE="${SPEC_SRC_FILE}"
1772 DST_FILE="${SPEC_DST_FILE}"
1773
1774 local VENDOR_REPO_FILE="$OUTPUT_DIR/${DST_FILE}"
1775 local BLOB_DISPLAY_NAME="${DST_FILE}"
1776 mkdir -p $(dirname "${VENDOR_REPO_FILE}")
1777
1778 # Check pinned files
1779 local HASH="$(echo ${HASHLIST[$i-1]} | awk '{ print tolower($0); }')"
1780 local FIXUP_HASH="$(echo ${FIXUP_HASHLIST[$i-1]} | awk '{ print tolower($0); }')"
1781 local KEEP=""
1782 if [ "$DISABLE_PINNING" != "1" ] && [ "$HASH" != "x" ]; then
1783 if [ -f "${VENDOR_REPO_FILE}" ]; then
1784 local PINNED="${VENDOR_REPO_FILE}"
1785 else
1786 local PINNED="${TMP_DIR}${DST_FILE}"
1787 fi
1788 if [ -f "$PINNED" ]; then
1789 local TMP_HASH=$(get_hash "${PINNED}")
1790 if [ "${TMP_HASH}" = "${HASH}" ] || [ "${TMP_HASH}" = "${FIXUP_HASH}" ]; then
1791 KEEP="1"
1792 if [ ! -f "${VENDOR_REPO_FILE}" ]; then
1793 cp -p "$PINNED" "${VENDOR_REPO_FILE}"
1794 fi
1795 fi
1796 fi
1797 fi
1798
1799 if [ "${KANG}" = false ]; then
1800 printf ' - %s\n' "${BLOB_DISPLAY_NAME}"
1801 fi
1802
1803 if [ "$KEEP" = "1" ]; then
1804 printf ' + keeping pinned file with hash %s\n' "${HASH}"
1805 else
1806 FOUND=false
1807 PARTITION_SOURCE_DIR=
1808 # Try Lineage target first.
1809 for CANDIDATE in "${DST_FILE}" "${SRC_FILE}"; do
1810 PARTITION=$(echo "$CANDIDATE" | cut -d/ -f1)
1811 if [ "$PARTITION" = "system" ]; then
1812 PARTITION_SOURCE_DIR="$SYSTEM_SRC"
1813 elif [ "$PARTITION" = "vendor" ]; then
1814 PARTITION_SOURCE_DIR="$VENDOR_SRC"
1815 elif [ "$PARTITION" = "product" ]; then
1816 PARTITION_SOURCE_DIR="$PRODUCT_SRC"
1817 elif [ "$PARTITION" = "odm" ]; then
1818 PARTITION_SOURCE_DIR="$ODM_SRC"
1819 fi
1820 CANDIDATE_RELATIVE_NAME=$(echo "$CANDIDATE" | cut -d/ -f2-)
1821 get_file ${CANDIDATE_RELATIVE_NAME} ${VENDOR_REPO_FILE} ${PARTITION_SOURCE_DIR} && {
1822 FOUND=true
1823 break
1824 }
1825 # Search with the full system/ prefix if the file was not found on the system partition
1826 # because we may be searching in a mounted system-as-root system.img
1827 if [[ "${FOUND}" = false && "$PARTITION" = "system" ]]; then
1828 get_file ${CANDIDATE} ${VENDOR_REPO_FILE} ${PARTITION_SOURCE_DIR} && {
1829 FOUND=true
1830 break
1831 }
1832 fi
1833 done
1834
1835 if [ -z "${PARTITION_SOURCE_DIR}" ]; then
1836 echo "$CANDIDATE has no preceeding partition path. Prepend system/, vendor/, product/, or odm/ to this entry."
1837 fi
1838
1839 if [ "${FOUND}" = false ]; then
1840 printf ' !! %s: file not found in source\n' "${BLOB_DISPLAY_NAME}"
1841 continue
1842 fi
1843 fi
1844
1845 # Blob fixup pipeline has 2 parts: one that is fixed and
1846 # one that is user-configurable
1847 local PRE_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE})
1848 # Deodex apk|jar if that's the case
1849 if [[ "$FULLY_DEODEXED" -ne "1" && "${VENDOR_REPO_FILE}" =~ .(apk|jar)$ ]]; then
1850 oat2dex "${VENDOR_REPO_FILE}" "${SRC_FILE}" "${SYSTEM_SRC}"
1851 if [ -f "$TMPDIR/classes.dex" ]; then
1852 zip -gjq "${VENDOR_REPO_FILE}" "$TMPDIR/classes"*
1853 rm "$TMPDIR/classes"*
1854 printf ' (updated %s from odex files)\n' "${SRC_FILE}"
1855 fi
1856 elif [[ "${VENDOR_REPO_FILE}" =~ .xml$ ]]; then
1857 fix_xml "${VENDOR_REPO_FILE}"
1858 fi
1859 # Now run user-supplied fixup function
1860 blob_fixup "${BLOB_DISPLAY_NAME}" "${VENDOR_REPO_FILE}"
1861 local POST_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE})
1862
1863 if [ -f "${VENDOR_REPO_FILE}" ]; then
1864 local DIR=$(dirname "${VENDOR_REPO_FILE}")
1865 local TYPE="${DIR##*/}"
1866 if [ "$TYPE" = "bin" -o "$TYPE" = "sbin" ]; then
1867 chmod 755 "${VENDOR_REPO_FILE}"
1868 else
1869 chmod 644 "${VENDOR_REPO_FILE}"
1870 fi
1871 fi
1872
1873 if [ "${KANG}" = true ]; then
1874 print_spec "${IS_PRODUCT_PACKAGE}" "${SPEC_SRC_FILE}" "${SPEC_DST_FILE}" "${SPEC_ARGS}" "${PRE_FIXUP_HASH}" "${POST_FIXUP_HASH}"
1875 fi
1876
1877 # Check and print whether the fixup pipeline actually did anything.
1878 # This isn't done right after the fixup pipeline because we want this print
1879 # to come after print_spec above, when in kang mode.
1880 if [ "${PRE_FIXUP_HASH}" != "${POST_FIXUP_HASH}" ]; then
1881 printf " + Fixed up %s\n" "${BLOB_DISPLAY_NAME}"
1882 # Now sanity-check the spec for this blob.
1883 if [ "${KANG}" = false ] && [ "${FIXUP_HASH}" = "x" ] && [ "${HASH}" != "x" ]; then
1884 printf "WARNING: The %s file was fixed up, but it is pinned.\n" ${BLOB_DISPLAY_NAME}
1885 printf "This is a mistake and you want to either remove the hash completely, or add an extra one.\n"
1886 fi
1887 fi
1888
1889 done
1890
1891 # Don't allow failing
1892 set -e
1893}
1894
1895#
Steve Kondik5bd66602016-07-15 10:39:58 -07001896# extract_firmware:
1897#
1898# $1: file containing the list of items to extract
1899# $2: path to extracted radio folder
1900#
1901function extract_firmware() {
1902 if [ -z "$OUTDIR" ]; then
1903 echo "Output dir not set!"
1904 exit 1
1905 fi
1906
1907 parse_file_list "$1"
1908
1909 # Don't allow failing
1910 set -e
1911
1912 local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} )
1913 local COUNT=${#FILELIST[@]}
1914 local SRC="$2"
theimpulson9a911af2019-08-14 03:25:12 +00001915 local OUTPUT_DIR="$OMNI_ROOT"/"$OUTDIR"/radio
Steve Kondik5bd66602016-07-15 10:39:58 -07001916
1917 if [ "$VENDOR_RADIO_STATE" -eq "0" ]; then
1918 echo "Cleaning firmware output directory ($OUTPUT_DIR).."
1919 rm -rf "${OUTPUT_DIR:?}/"*
1920 VENDOR_RADIO_STATE=1
1921 fi
1922
1923 echo "Extracting $COUNT files in $1 from $SRC:"
1924
1925 for (( i=1; i<COUNT+1; i++ )); do
1926 local FILE="${FILELIST[$i-1]}"
1927 printf ' - %s \n' "/radio/$FILE"
1928
1929 if [ ! -d "$OUTPUT_DIR" ]; then
1930 mkdir -p "$OUTPUT_DIR"
1931 fi
1932 cp "$SRC/$FILE" "$OUTPUT_DIR/$FILE"
1933 chmod 644 "$OUTPUT_DIR/$FILE"
1934 done
1935}
Rashed Abdel-Tawab841c6e82019-03-29 20:07:25 -07001936
1937function extract_img_data() {
1938 local image_file="$1"
1939 local out_dir="$2"
1940 local logFile="$TMPDIR/debugfs.log"
1941
1942 if [ ! -d "$out_dir" ]; then
1943 mkdir -p "$out_dir"
1944 fi
1945
1946 if [[ "$HOST_OS" == "Darwin" ]]; then
1947 debugfs -R "rdump / \"$out_dir\"" "$image_file" &> "$logFile" || {
1948 echo "[-] Failed to extract data from '$image_file'"
1949 abort 1
1950 }
1951 else
1952 debugfs -R 'ls -p' "$image_file" 2>/dev/null | cut -d '/' -f6 | while read -r entry
1953 do
1954 debugfs -R "rdump \"$entry\" \"$out_dir\"" "$image_file" >> "$logFile" 2>&1 || {
1955 echo "[-] Failed to extract data from '$image_file'"
1956 abort 1
1957 }
1958 done
1959 fi
1960
1961 local symlink_err="rdump: Attempt to read block from filesystem resulted in short read while reading symlink"
1962 if grep -Fq "$symlink_err" "$logFile"; then
1963 echo "[-] Symlinks have not been properly processed from $image_file"
1964 echo "[!] If you don't have a compatible debugfs version, modify 'execute-all.sh' to disable 'USE_DEBUGFS' flag"
1965 abort 1
1966 fi
1967}
1968
1969declare -ra VENDOR_SKIP_FILES=(
1970 "bin/toybox_vendor"
1971 "bin/toolbox"
1972 "bin/grep"
1973 "build.prop"
1974 "compatibility_matrix.xml"
1975 "default.prop"
1976 "etc/NOTICE.xml.gz"
1977 "etc/vintf/compatibility_matrix.xml"
1978 "etc/vintf/manifest.xml"
1979 "etc/wifi/wpa_supplicant.conf"
1980 "manifest.xml"
1981 "overlay/DisplayCutoutEmulationCorner/DisplayCutoutEmulationCornerOverlay.apk"
1982 "overlay/DisplayCutoutEmulationDouble/DisplayCutoutEmulationDoubleOverlay.apk"
1983 "overlay/DisplayCutoutEmulationTall/DisplayCutoutEmulationTallOverlay.apk"
1984 "overlay/DisplayCutoutNoCutout/NoCutoutOverlay.apk"
1985 "overlay/framework-res__auto_generated_rro.apk"
1986 "overlay/SysuiDarkTheme/SysuiDarkThemeOverlay.apk"
1987)
1988
1989function array_contains() {
1990 local element
1991 for element in "${@:2}"; do [[ "$element" == "$1" ]] && return 0; done
1992 return 1
1993}
1994
1995function generate_prop_list_from_image() {
1996 local image_file="$1"
1997 local image_dir="$TMPDIR/image-temp"
1998 local output_list="$2"
1999 local output_list_tmp="$TMPDIR/_proprietary-blobs.txt"
2000 local -n skipped_vendor_files="$3"
2001
2002 extract_img_data "$image_file" "$image_dir"
2003
2004 find "$image_dir" -not -type d | sed "s#^$image_dir/##" | while read -r FILE
2005 do
2006 # Skip VENDOR_SKIP_FILES since it will be re-generated at build time
2007 if array_contains "$FILE" "${VENDOR_SKIP_FILES[@]}"; then
2008 continue
2009 fi
2010 # Skip device defined skipped files since they will be re-generated at build time
2011 if array_contains "$FILE" "${skipped_vendor_files[@]}"; then
2012 continue
2013 fi
2014 if suffix_match_file ".apk" "$FILE" ; then
2015 echo "-vendor/$FILE" >> "$output_list_tmp"
2016 else
2017 echo "vendor/$FILE" >> "$output_list_tmp"
2018 fi
2019 done
2020
2021 # Sort merged file with all lists
2022 sort -u "$output_list_tmp" > "$output_list"
2023
2024 # Clean-up
2025 rm -f "$output_list_tmp"
2026}
Bruno Martins0f425f12021-04-10 14:57:32 +01002027
2028function colored_echo() {
2029 IFS=" "
2030 local color=$1;
2031 shift
2032 if ! [[ $color =~ '^[0-9]$' ]] ; then
2033 case $(echo $color | tr '[:upper:]' '[:lower:]') in
2034 black) color=0 ;;
2035 red) color=1 ;;
2036 green) color=2 ;;
2037 yellow) color=3 ;;
2038 blue) color=4 ;;
2039 magenta) color=5 ;;
2040 cyan) color=6 ;;
2041 white|*) color=7 ;; # white or invalid color
2042 esac
2043 fi
Bruno Martins5064db22021-06-21 14:47:40 +01002044 if [ -t 1 ] ; then tput setaf $color; fi
Bruno Martins0f425f12021-04-10 14:57:32 +01002045 printf '%s\n' "$*"
Bruno Martins5064db22021-06-21 14:47:40 +01002046 if [ -t 1 ] ; then tput sgr0; fi
Bruno Martins0f425f12021-04-10 14:57:32 +01002047}