blob: 51e63617e59a87024ebd5f335a4b26f8ce3bff12 [file] [log] [blame]
PIPIPIG23366617d7dcb2019-09-29 12:47:28 -04001#!/bin/bash
Steve Kondik4e2aaab2016-07-15 10:39:58 -07002#
3# Copyright (C) 2016 The CyanogenMod Project
Bruno Martins8194b8e2019-09-23 11:51:33 +01004# Copyright (C) 2017-2019 The LineageOS Project
Steve Kondik4e2aaab2016-07-15 10:39:58 -07005#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19PRODUCT_COPY_FILES_LIST=()
Steve Kondik48f8df82016-08-14 03:55:08 -070020PRODUCT_COPY_FILES_HASHES=()
Vladimir Oltean4818c232019-01-17 03:07:34 +020021PRODUCT_COPY_FILES_FIXUP_HASHES=()
Steve Kondik4e2aaab2016-07-15 10:39:58 -070022PRODUCT_PACKAGES_LIST=()
Steve Kondik48f8df82016-08-14 03:55:08 -070023PRODUCT_PACKAGES_HASHES=()
Vladimir Oltean4818c232019-01-17 03:07:34 +020024PRODUCT_PACKAGES_FIXUP_HASHES=()
Steve Kondik4e2aaab2016-07-15 10:39:58 -070025PACKAGE_LIST=()
26VENDOR_STATE=-1
Louis Popia516c2f2016-07-25 15:51:13 +020027VENDOR_RADIO_STATE=-1
Steve Kondik4e2aaab2016-07-15 10:39:58 -070028COMMON=-1
Luca Stefani7f9fff22016-07-18 13:47:55 +020029ARCHES=
30FULLY_DEODEXED=-1
31
Rashed Abdel-Tawab11186d62017-08-05 23:11:35 -040032TMPDIR=$(mktemp -d)
Steve Kondik4e2aaab2016-07-15 10:39:58 -070033
34#
Steve Kondik48f8df82016-08-14 03:55:08 -070035# cleanup
36#
37# kill our tmpfiles with fire on exit
38#
39function cleanup() {
40 rm -rf "${TMPDIR:?}"
41}
42
Gabriele M6c3c2c02017-10-11 12:55:51 +020043trap cleanup 0
Steve Kondik48f8df82016-08-14 03:55:08 -070044
45#
Steve Kondik4e2aaab2016-07-15 10:39:58 -070046# setup_vendor
47#
48# $1: device name
49# $2: vendor name
Luca Stefani5c60e4f2017-08-17 19:28:48 +020050# $3: Lineage root directory
Steve Kondik4e2aaab2016-07-15 10:39:58 -070051# $4: is common device - optional, default to false
52# $5: cleanup - optional, default to true
Rashed Abdel-Tawab5f173152016-10-01 20:33:00 -040053# $6: custom vendor makefile name - optional, default to false
Steve Kondik4e2aaab2016-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
Luca Stefani5c60e4f2017-08-17 19:28:48 +020071 export LINEAGE_ROOT="$3"
72 if [ ! -d "$LINEAGE_ROOT" ]; then
73 echo "\$LINEAGE_ROOT must be set and valid before including this script!"
Steve Kondik4e2aaab2016-07-15 10:39:58 -070074 exit 1
75 fi
76
77 export OUTDIR=vendor/"$VENDOR"/"$DEVICE"
Luca Stefani5c60e4f2017-08-17 19:28:48 +020078 if [ ! -d "$LINEAGE_ROOT/$OUTDIR" ]; then
79 mkdir -p "$LINEAGE_ROOT/$OUTDIR"
Steve Kondik4e2aaab2016-07-15 10:39:58 -070080 fi
81
Rashed Abdel-Tawab5f173152016-10-01 20:33:00 -040082 VNDNAME="$6"
83 if [ -z "$VNDNAME" ]; then
84 VNDNAME="$DEVICE"
85 fi
86
Luca Stefani5c60e4f2017-08-17 19:28:48 +020087 export PRODUCTMK="$LINEAGE_ROOT"/"$OUTDIR"/"$VNDNAME"-vendor.mk
Rashed Abdel-Tawab42752d42019-09-20 07:06:09 -070088 export ANDROIDBP="$LINEAGE_ROOT"/"$OUTDIR"/Android.bp
Luca Stefani5c60e4f2017-08-17 19:28:48 +020089 export ANDROIDMK="$LINEAGE_ROOT"/"$OUTDIR"/Android.mk
90 export BOARDMK="$LINEAGE_ROOT"/"$OUTDIR"/BoardConfigVendor.mk
Steve Kondik4e2aaab2016-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 Mb6effb32017-05-01 18:22:04 +020098 if [ "$5" == "false" ] || [ "$5" == "0" ]; then
Steve Kondik4e2aaab2016-07-15 10:39:58 -070099 VENDOR_STATE=1
Louis Popia516c2f2016-07-25 15:51:13 +0200100 VENDOR_RADIO_STATE=1
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700101 else
102 VENDOR_STATE=0
Louis Popia516c2f2016-07-25 15:51:13 +0200103 VENDOR_RADIO_STATE=0
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700104 fi
105}
106
Vladimir Oltean95643282018-06-24 20:22:41 +0300107# Helper functions for parsing a spec.
108# notes: an optional "|SHA1" that may appear in the format is stripped
109# early from the spec in the parse_file_list function, and
110# should not be present inside the input parameter passed
111# to these functions.
112
113#
114# input: spec in the form of "src[:dst][;args]"
115# output: "src"
116#
117function src_file() {
118 local SPEC="$1"
119 local SPLIT=(${SPEC//:/ })
120 local ARGS="$(target_args ${SPEC})"
121 # Regardless of there being a ":" delimiter or not in the spec,
122 # the source file is always either the first, or the only entry.
123 local SRC="${SPLIT[0]}"
124 # Remove target_args suffix, if present
125 echo "${SRC%;${ARGS}}"
126}
127
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700128#
Vladimir Oltean6a7946b2018-06-24 20:09:55 +0300129# input: spec in the form of "src[:dst][;args]"
130# output: "dst" if present, "src" otherwise.
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700131#
132function target_file() {
Vladimir Oltean6a7946b2018-06-24 20:09:55 +0300133 local SPEC="$1"
134 local SPLIT=(${SPEC//:/ })
135 local ARGS="$(target_args ${SPEC})"
136 local DST=
137 case ${#SPLIT[@]} in
138 1)
139 # The spec doesn't have a : delimiter
140 DST="${SPLIT[0]}"
141 ;;
142 *)
143 # The spec actually has a src:dst format
144 DST="${SPLIT[1]}"
145 ;;
146 esac
147 # Remove target_args suffix, if present
148 echo "${DST%;${ARGS}}"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700149}
150
151#
Vladimir Oltean6a7946b2018-06-24 20:09:55 +0300152# input: spec in the form of "src[:dst][;args]"
153# output: "args" if present, "" otherwise.
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700154#
155function target_args() {
Vladimir Oltean6a7946b2018-06-24 20:09:55 +0300156 local SPEC="$1"
157 local SPLIT=(${SPEC//;/ })
158 local ARGS=
159 case ${#SPLIT[@]} in
160 1)
161 # No ";" delimiter in the spec.
162 ;;
163 *)
164 # The "args" are whatever comes after the ";" character.
165 # Basically the spec stripped of whatever is to the left of ";".
166 ARGS="${SPEC#${SPLIT[0]};}"
167 ;;
168 esac
169 echo "${ARGS}"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700170}
171
172#
173# prefix_match:
174#
Vladimir Oltean2654eaa2018-06-12 01:17:35 +0300175# input:
176# - $1: prefix
177# - (global variable) PRODUCT_PACKAGES_LIST: array of [src:]dst[;args] specs.
178# output:
179# - new array consisting of dst[;args] entries where $1 is a prefix of ${dst}.
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700180#
181function prefix_match() {
182 local PREFIX="$1"
Vladimir Olteana48b9fe2018-04-02 22:37:09 +0300183 for LINE in "${PRODUCT_PACKAGES_LIST[@]}"; do
184 local FILE=$(target_file "$LINE")
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700185 if [[ "$FILE" =~ ^"$PREFIX" ]]; then
Vladimir Oltean2654eaa2018-06-12 01:17:35 +0300186 local ARGS=$(target_args "$LINE")
187 if [ -z "${ARGS}" ]; then
188 echo "${FILE#$PREFIX}"
189 else
190 echo "${FILE#$PREFIX};${ARGS}"
191 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700192 fi
193 done
194}
195
196#
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400197# prefix_match_file:
198#
199# $1: the prefix to match on
200# $2: the file to match the prefix for
201#
202# Internal function which returns true if a filename contains the
203# specified prefix.
204#
205function prefix_match_file() {
206 local PREFIX="$1"
207 local FILE="$2"
208 if [[ "$FILE" =~ ^"$PREFIX" ]]; then
209 return 0
210 else
211 return 1
212 fi
213}
214
215#
Rashed Abdel-Tawab1c29c372019-03-29 20:07:25 -0700216# suffix_match_file:
217#
218# $1: the suffix to match on
219# $2: the file to match the suffix for
220#
221# Internal function which returns true if a filename contains the
222# specified suffix.
223#
224function suffix_match_file() {
225 local SUFFIX="$1"
226 local FILE="$2"
227 if [[ "$FILE" = *"$SUFFIX" ]]; then
228 return 0
229 else
230 return 1
231 fi
232}
233
234#
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400235# truncate_file
236#
237# $1: the filename to truncate
238# $2: the argument to output the truncated filename to
239#
240# Internal function which truncates a filename by removing the first dir
241# in the path. ex. vendor/lib/libsdmextension.so -> lib/libsdmextension.so
242#
243function truncate_file() {
244 local FILE="$1"
245 RETURN_FILE="$2"
246 local FIND="${FILE%%/*}"
247 local LOCATION="${#FIND}+1"
248 echo ${FILE:$LOCATION}
249}
250
251#
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700252# write_product_copy_files:
253#
Rashed Abdel-Tawab8de76b22019-09-28 23:37:36 -0400254# $1: make treble compatible makefile - optional and deprecated, default to true
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400255#
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700256# Creates the PRODUCT_COPY_FILES section in the product makefile for all
257# items in the list which do not start with a dash (-).
258#
259function write_product_copy_files() {
260 local COUNT=${#PRODUCT_COPY_FILES_LIST[@]}
261 local TARGET=
262 local FILE=
263 local LINEEND=
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400264 local TREBLE_COMPAT=$1
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700265
266 if [ "$COUNT" -eq "0" ]; then
267 return 0
268 fi
269
270 printf '%s\n' "PRODUCT_COPY_FILES += \\" >> "$PRODUCTMK"
271 for (( i=1; i<COUNT+1; i++ )); do
272 FILE="${PRODUCT_COPY_FILES_LIST[$i-1]}"
273 LINEEND=" \\"
274 if [ "$i" -eq "$COUNT" ]; then
275 LINEEND=""
276 fi
277
Vladimir Oltean6a7946b2018-06-24 20:09:55 +0300278 TARGET=$(target_file "$FILE")
Rashed Abdel-Tawab8aae50d2019-10-05 00:09:41 -0400279 if prefix_match_file "product/" $TARGET ; then
Rashed Abdel-Tawab8de76b22019-09-28 23:37:36 -0400280 local OUTTARGET=$(truncate_file $TARGET)
Rashed Abdel-Tawab8aae50d2019-10-05 00:09:41 -0400281 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s%s\n' \
Rashed Abdel-Tawab8de76b22019-09-28 23:37:36 -0400282 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Rashed Abdel-Tawab8aae50d2019-10-05 00:09:41 -0400283 elif prefix_match_file "system/product/" $TARGET ; then
Rashed Abdel-Tawab8de76b22019-09-28 23:37:36 -0400284 local OUTTARGET=$(truncate_file $TARGET)
285 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s%s\n' \
286 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
287 elif prefix_match_file "odm/" $TARGET ; then
288 local OUTTARGET=$(truncate_file $TARGET)
289 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \
290 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Rashed Abdel-Tawab8aae50d2019-10-05 00:09:41 -0400291 elif prefix_match_file "vendor/odm/" $TARGET ; then
292 local OUTTARGET=$(truncate_file $TARGET)
293 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \
294 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
295 elif prefix_match_file "system/vendor/odm/" $TARGET ; then
296 local OUTTARGET=$(truncate_file $TARGET)
297 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \
298 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
299 elif prefix_match_file "vendor/" $TARGET ; then
300 local OUTTARGET=$(truncate_file $TARGET)
301 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR)/%s%s\n' \
302 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
303 elif prefix_match_file "system/vendor/" $TARGET ; then
304 local OUTTARGET=$(truncate_file $TARGET)
305 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR)/%s%s\n' \
306 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Rashed Abdel-Tawab8de76b22019-09-28 23:37:36 -0400307 elif prefix_match_file "system/" $TARGET ; then
308 local OUTTARGET=$(truncate_file $TARGET)
309 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM)/%s%s\n' \
310 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400311 else
Rashed Abdel-Tawab8de76b22019-09-28 23:37:36 -0400312 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM)/%s%s\n' \
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400313 "$OUTDIR" "$TARGET" "$TARGET" "$LINEEND" >> "$PRODUCTMK"
314 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700315 done
316 return 0
317}
318
319#
320# write_packages:
321#
322# $1: The LOCAL_MODULE_CLASS for the given module list
Rashed Abdel-Tawab8de76b22019-09-28 23:37:36 -0400323# $2: /system, /odm, /product, or /vendor partition
Steve Kondika991cf12016-07-28 12:13:12 -0700324# $3: type-specific extra flags
325# $4: Name of the array holding the target list
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700326#
327# Internal function which writes out the BUILD_PREBUILT stanzas
328# for all modules in the list. This is called by write_product_packages
329# after the modules are categorized.
330#
331function write_packages() {
332
333 local CLASS="$1"
razorlovesb5c2c962019-07-29 02:21:34 -0500334 local PARTITION="$2"
Steve Kondika991cf12016-07-28 12:13:12 -0700335 local EXTRA="$3"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700336
337 # Yes, this is a horrible hack - we create a new array using indirection
Steve Kondika991cf12016-07-28 12:13:12 -0700338 local ARR_NAME="$4[@]"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700339 local FILELIST=("${!ARR_NAME}")
340
341 local FILE=
342 local ARGS=
343 local BASENAME=
344 local EXTENSION=
345 local PKGNAME=
346 local SRC=
347
348 for P in "${FILELIST[@]}"; do
Vladimir Oltean6a7946b2018-06-24 20:09:55 +0300349 FILE=$(target_file "$P")
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700350 ARGS=$(target_args "$P")
351
352 BASENAME=$(basename "$FILE")
M1cha15f226c2017-01-04 09:00:11 +0100353 DIRNAME=$(dirname "$FILE")
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700354 EXTENSION=${BASENAME##*.}
355 PKGNAME=${BASENAME%.*}
356
357 # Add to final package list
358 PACKAGE_LIST+=("$PKGNAME")
359
360 SRC="proprietary"
Rashed Abdel-Tawab8de76b22019-09-28 23:37:36 -0400361 if [ "$PARTITION" = "system" ]; then
362 SRC+="/system"
363 elif [ "$PARTITION" = "vendor" ]; then
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700364 SRC+="/vendor"
razorlovesb5c2c962019-07-29 02:21:34 -0500365 elif [ "$PARTITION" = "product" ]; then
366 SRC+="/product"
Rashed Abdel-Tawab08e3a272019-09-20 07:32:39 -0700367 elif [ "$PARTITION" = "odm" ]; then
368 SRC+="/odm"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700369 fi
370
371 printf 'include $(CLEAR_VARS)\n'
372 printf 'LOCAL_MODULE := %s\n' "$PKGNAME"
373 printf 'LOCAL_MODULE_OWNER := %s\n' "$VENDOR"
374 if [ "$CLASS" = "SHARED_LIBRARIES" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -0700375 if [ "$EXTRA" = "both" ]; then
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700376 printf 'LOCAL_SRC_FILES_64 := %s/lib64/%s\n' "$SRC" "$FILE"
377 printf 'LOCAL_SRC_FILES_32 := %s/lib/%s\n' "$SRC" "$FILE"
378 #if [ "$VENDOR_PKG" = "true" ]; then
379 # echo "LOCAL_MODULE_PATH_64 := \$(TARGET_OUT_VENDOR_SHARED_LIBRARIES)"
380 # echo "LOCAL_MODULE_PATH_32 := \$(2ND_TARGET_OUT_VENDOR_SHARED_LIBRARIES)"
381 #else
382 # echo "LOCAL_MODULE_PATH_64 := \$(TARGET_OUT_SHARED_LIBRARIES)"
383 # echo "LOCAL_MODULE_PATH_32 := \$(2ND_TARGET_OUT_SHARED_LIBRARIES)"
384 #fi
Steve Kondika991cf12016-07-28 12:13:12 -0700385 elif [ "$EXTRA" = "64" ]; then
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700386 printf 'LOCAL_SRC_FILES := %s/lib64/%s\n' "$SRC" "$FILE"
387 else
388 printf 'LOCAL_SRC_FILES := %s/lib/%s\n' "$SRC" "$FILE"
389 fi
Steve Kondik03ce4002016-07-29 00:00:16 -0700390 if [ "$EXTRA" != "none" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -0700391 printf 'LOCAL_MULTILIB := %s\n' "$EXTRA"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700392 fi
393 elif [ "$CLASS" = "APPS" ]; then
Michael Bestas3f9b94c2018-01-25 21:05:36 +0200394 if [ "$EXTRA" = "priv-app" ]; then
395 SRC="$SRC/priv-app"
396 else
397 SRC="$SRC/app"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700398 fi
399 printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE"
400 local CERT=platform
401 if [ ! -z "$ARGS" ]; then
402 CERT="$ARGS"
403 fi
404 printf 'LOCAL_CERTIFICATE := %s\n' "$CERT"
405 elif [ "$CLASS" = "JAVA_LIBRARIES" ]; then
406 printf 'LOCAL_SRC_FILES := %s/framework/%s\n' "$SRC" "$FILE"
Elektroschmock082e0ec2016-10-04 21:11:43 +0200407 local CERT=platform
408 if [ ! -z "$ARGS" ]; then
409 CERT="$ARGS"
410 fi
411 printf 'LOCAL_CERTIFICATE := %s\n' "$CERT"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700412 elif [ "$CLASS" = "ETC" ]; then
413 printf 'LOCAL_SRC_FILES := %s/etc/%s\n' "$SRC" "$FILE"
414 elif [ "$CLASS" = "EXECUTABLES" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -0700415 if [ "$ARGS" = "rootfs" ]; then
416 SRC="$SRC/rootfs"
417 if [ "$EXTRA" = "sbin" ]; then
418 SRC="$SRC/sbin"
419 printf '%s\n' "LOCAL_MODULE_PATH := \$(TARGET_ROOT_OUT_SBIN)"
420 printf '%s\n' "LOCAL_UNSTRIPPED_PATH := \$(TARGET_ROOT_OUT_SBIN_UNSTRIPPED)"
421 fi
422 else
423 SRC="$SRC/bin"
424 fi
425 printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE"
426 unset EXTENSION
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700427 else
Steve Kondika991cf12016-07-28 12:13:12 -0700428 printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700429 fi
430 printf 'LOCAL_MODULE_TAGS := optional\n'
431 printf 'LOCAL_MODULE_CLASS := %s\n' "$CLASS"
Hashbang1733b3a0e12016-08-28 20:38:45 -0400432 if [ "$CLASS" = "APPS" ]; then
433 printf 'LOCAL_DEX_PREOPT := false\n'
434 fi
Steve Kondika991cf12016-07-28 12:13:12 -0700435 if [ ! -z "$EXTENSION" ]; then
436 printf 'LOCAL_MODULE_SUFFIX := .%s\n' "$EXTENSION"
437 fi
M1cha15f226c2017-01-04 09:00:11 +0100438 if [ "$CLASS" = "SHARED_LIBRARIES" ] || [ "$CLASS" = "EXECUTABLES" ]; then
439 if [ "$DIRNAME" != "." ]; then
440 printf 'LOCAL_MODULE_RELATIVE_PATH := %s\n' "$DIRNAME"
441 fi
442 fi
Steve Kondika991cf12016-07-28 12:13:12 -0700443 if [ "$EXTRA" = "priv-app" ]; then
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700444 printf 'LOCAL_PRIVILEGED_MODULE := true\n'
445 fi
razorlovesb5c2c962019-07-29 02:21:34 -0500446 if [ "$PARTITION" = "vendor" ]; then
Ethan Chen5bc3c842018-02-17 20:03:54 -0800447 printf 'LOCAL_VENDOR_MODULE := true\n'
razorlovesb5c2c962019-07-29 02:21:34 -0500448 elif [ "$PARTITION" = "product" ]; then
449 printf 'LOCAL_PRODUCT_MODULE := true\n'
Rashed Abdel-Tawab08e3a272019-09-20 07:32:39 -0700450 elif [ "$PARTITION" = "odm" ]; then
451 printf 'LOCAL_ODM_MODULE := true\n'
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700452 fi
453 printf 'include $(BUILD_PREBUILT)\n\n'
454 done
455}
456
457#
458# write_product_packages:
459#
Rashed Abdel-Tawab42752d42019-09-20 07:06:09 -0700460# This function will create prebuilt entries in the
461# Android.bp and associated PRODUCT_PACKAGES list in the
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700462# product makefile for all files in the blob list which
463# start with a single dash (-) character.
464#
465function write_product_packages() {
466 PACKAGE_LIST=()
467
468 local COUNT=${#PRODUCT_PACKAGES_LIST[@]}
469
470 if [ "$COUNT" = "0" ]; then
471 return 0
472 fi
473
474 # Figure out what's 32-bit, what's 64-bit, and what's multilib
475 # I really should not be doing this in bash due to shitty array passing :(
476 local T_LIB32=( $(prefix_match "lib/") )
477 local T_LIB64=( $(prefix_match "lib64/") )
478 local MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${T_LIB64[@]}")) )
479 local LIB32=( $(comm -23 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${MULTILIBS[@]}")) )
Steve Kondik60ef86d2016-07-20 20:03:40 -0700480 local LIB64=( $(comm -23 <(printf '%s\n' "${T_LIB64[@]}") <(printf '%s\n' "${MULTILIBS[@]}")) )
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700481
Steve Kondik03ce4002016-07-29 00:00:16 -0700482 if [ "${#MULTILIBS[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500483 write_packages "SHARED_LIBRARIES" "" "both" "MULTILIBS" >> "$ANDROIDMK"
Steve Kondik03ce4002016-07-29 00:00:16 -0700484 fi
485 if [ "${#LIB32[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500486 write_packages "SHARED_LIBRARIES" "" "32" "LIB32" >> "$ANDROIDMK"
Steve Kondik03ce4002016-07-29 00:00:16 -0700487 fi
488 if [ "${#LIB64[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500489 write_packages "SHARED_LIBRARIES" "" "64" "LIB64" >> "$ANDROIDMK"
Steve Kondik03ce4002016-07-29 00:00:16 -0700490 fi
491
Rashed Abdel-Tawab8de76b22019-09-28 23:37:36 -0400492 local T_S_LIB32=( $(prefix_match "system/lib/") )
493 local T_S_LIB64=( $(prefix_match "system/lib64/") )
494 local S_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_S_LIB32[@]}") <(printf '%s\n' "${T_S_LIB64[@]}")) )
495 local S_LIB32=( $(comm -23 <(printf '%s\n' "${T_S_LIB32[@]}") <(printf '%s\n' "${S_MULTILIBS[@]}")) )
496 local S_LIB64=( $(comm -23 <(printf '%s\n' "${T_S_LIB64[@]}") <(printf '%s\n' "${S_MULTILIBS[@]}")) )
497
498 if [ "${#S_MULTILIBS[@]}" -gt "0" ]; then
499 write_packages "SHARED_LIBRARIES" "system" "both" "S_MULTILIBS" >> "$ANDROIDMK"
500 fi
501 if [ "${#S_LIB32[@]}" -gt "0" ]; then
502 write_packages "SHARED_LIBRARIES" "system" "32" "S_LIB32" >> "$ANDROIDMK"
503 fi
504 if [ "${#S_LIB64[@]}" -gt "0" ]; then
505 write_packages "SHARED_LIBRARIES" "system" "64" "S_LIB64" >> "$ANDROIDMK"
506 fi
507
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700508 local T_V_LIB32=( $(prefix_match "vendor/lib/") )
509 local T_V_LIB64=( $(prefix_match "vendor/lib64/") )
510 local V_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${T_V_LIB64[@]}")) )
511 local V_LIB32=( $(comm -23 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${V_MULTILIBS[@]}")) )
Steve Kondik60ef86d2016-07-20 20:03:40 -0700512 local V_LIB64=( $(comm -23 <(printf '%s\n' "${T_V_LIB64[@]}") <(printf '%s\n' "${V_MULTILIBS[@]}")) )
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700513
514 if [ "${#V_MULTILIBS[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500515 write_packages "SHARED_LIBRARIES" "vendor" "both" "V_MULTILIBS" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700516 fi
517 if [ "${#V_LIB32[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500518 write_packages "SHARED_LIBRARIES" "vendor" "32" "V_LIB32" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700519 fi
520 if [ "${#V_LIB64[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500521 write_packages "SHARED_LIBRARIES" "vendor" "64" "V_LIB64" >> "$ANDROIDMK"
522 fi
523
524 local T_P_LIB32=( $(prefix_match "product/lib/") )
525 local T_P_LIB64=( $(prefix_match "product/lib64/") )
526 local P_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_P_LIB32[@]}") <(printf '%s\n' "${T_P_LIB64[@]}")) )
527 local P_LIB32=( $(comm -23 <(printf '%s\n' "${T_P_LIB32[@]}") <(printf '%s\n' "${P_MULTILIBS[@]}")) )
528 local P_LIB64=( $(comm -23 <(printf '%s\n' "${T_P_LIB64[@]}") <(printf '%s\n' "${P_MULTILIBS[@]}")) )
529
530 if [ "${#P_MULTILIBS[@]}" -gt "0" ]; then
531 write_packages "SHARED_LIBRARIES" "product" "both" "P_MULTILIBS" >> "$ANDROIDMK"
532 fi
533 if [ "${#P_LIB32[@]}" -gt "0" ]; then
534 write_packages "SHARED_LIBRARIES" "product" "32" "P_LIB32" >> "$ANDROIDMK"
535 fi
536 if [ "${#P_LIB64[@]}" -gt "0" ]; then
537 write_packages "SHARED_LIBRARIES" "product" "64" "P_LIB64" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700538 fi
539
Rashed Abdel-Tawab08e3a272019-09-20 07:32:39 -0700540 local T_O_LIB32=( $(prefix_match "odm/lib/") )
541 local T_O_LIB64=( $(prefix_match "odm/lib64/") )
542 local O_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_O_LIB32[@]}") <(printf '%s\n' "${T_O_LIB64[@]}")) )
543 local O_LIB32=( $(comm -23 <(printf '%s\n' "${T_O_LIB32[@]}") <(printf '%s\n' "${O_MULTILIBS[@]}")) )
544 local O_LIB64=( $(comm -23 <(printf '%s\n' "${T_O_LIB64[@]}") <(printf '%s\n' "${O_MULTILIBS[@]}")) )
545
546 if [ "${#O_MULTILIBS[@]}" -gt "0" ]; then
547 write_packages "SHARED_LIBRARIES" "odm" "both" "O_MULTILIBS" >> "$ANDROIDMK"
548 fi
549 if [ "${#O_LIB32[@]}" -gt "0" ]; then
550 write_packages "SHARED_LIBRARIES" "odm" "32" "O_LIB32" >> "$ANDROIDMK"
551 fi
552 if [ "${#O_LIB64[@]}" -gt "0" ]; then
553 write_packages "SHARED_LIBRARIES" "odm" "64" "O_LIB64" >> "$ANDROIDMK"
554 fi
555
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700556 # Apps
557 local APPS=( $(prefix_match "app/") )
558 if [ "${#APPS[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500559 write_packages "APPS" "" "" "APPS" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700560 fi
561 local PRIV_APPS=( $(prefix_match "priv-app/") )
562 if [ "${#PRIV_APPS[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500563 write_packages "APPS" "" "priv-app" "PRIV_APPS" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700564 fi
Rashed Abdel-Tawab8de76b22019-09-28 23:37:36 -0400565 local S_APPS=( $(prefix_match "system/app/") )
566 if [ "${#S_APPS[@]}" -gt "0" ]; then
567 write_packages "APPS" "system" "" "S_APPS" >> "$ANDROIDMK"
568 fi
569 local S_PRIV_APPS=( $(prefix_match "system/priv-app/") )
570 if [ "${#S_PRIV_APPS[@]}" -gt "0" ]; then
571 write_packages "APPS" "system" "priv-app" "S_PRIV_APPS" >> "$ANDROIDMK"
572 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700573 local V_APPS=( $(prefix_match "vendor/app/") )
574 if [ "${#V_APPS[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500575 write_packages "APPS" "vendor" "" "V_APPS" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700576 fi
577 local V_PRIV_APPS=( $(prefix_match "vendor/priv-app/") )
578 if [ "${#V_PRIV_APPS[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500579 write_packages "APPS" "vendor" "priv-app" "V_PRIV_APPS" >> "$ANDROIDMK"
580 fi
581 local P_APPS=( $(prefix_match "product/app/") )
582 if [ "${#P_APPS[@]}" -gt "0" ]; then
583 write_packages "APPS" "product" "" "P_APPS" >> "$ANDROIDMK"
584 fi
585 local P_PRIV_APPS=( $(prefix_match "product/priv-app/") )
586 if [ "${#P_PRIV_APPS[@]}" -gt "0" ]; then
587 write_packages "APPS" "product" "priv-app" "P_PRIV_APPS" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700588 fi
Rashed Abdel-Tawab08e3a272019-09-20 07:32:39 -0700589 local O_APPS=( $(prefix_match "odm/app/") )
590 if [ "${#O_APPS[@]}" -gt "0" ]; then
591 write_packages "APPS" "odm" "" "O_APPS" >> "$ANDROIDMK"
592 fi
593 local O_PRIV_APPS=( $(prefix_match "odm/priv-app/") )
594 if [ "${#O_PRIV_APPS[@]}" -gt "0" ]; then
595 write_packages "APPS" "odm" "priv-app" "O_PRIV_APPS" >> "$ANDROIDMK"
596 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700597
598 # Framework
599 local FRAMEWORK=( $(prefix_match "framework/") )
600 if [ "${#FRAMEWORK[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500601 write_packages "JAVA_LIBRARIES" "" "" "FRAMEWORK" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700602 fi
Rashed Abdel-Tawab8de76b22019-09-28 23:37:36 -0400603 local S_FRAMEWORK=( $(prefix_match "system/framework/") )
604 if [ "${#S_FRAMEWORK[@]}" -gt "0" ]; then
605 write_packages "JAVA_LIBRARIES" "system" "" "S_FRAMEWORK" >> "$ANDROIDMK"
606 fi
Christian Oderc16f3272017-10-08 23:15:52 +0200607 local V_FRAMEWORK=( $(prefix_match "vendor/framework/") )
Michael Bestasa3f97c72018-02-27 22:31:55 +0200608 if [ "${#V_FRAMEWORK[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500609 write_packages "JAVA_LIBRARIES" "vendor" "" "V_FRAMEWORK" >> "$ANDROIDMK"
610 fi
611 local P_FRAMEWORK=( $(prefix_match "product/framework/") )
612 if [ "${#P_FRAMEWORK[@]}" -gt "0" ]; then
613 write_packages "JAVA_LIBRARIES" "product" "" "P_FRAMEWORK" >> "$ANDROIDMK"
Christian Oderc16f3272017-10-08 23:15:52 +0200614 fi
Rashed Abdel-Tawab08e3a272019-09-20 07:32:39 -0700615 local O_FRAMEWORK=( $(prefix_match "odm/framework/") )
616 if [ "${#O_FRAMEWORK[@]}" -gt "0" ]; then
617 write_packages "JAVA_LIBRARIES" "odm" "" "O_FRAMEWORK" >> "$ANDROIDMK"
618 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700619
620 # Etc
621 local ETC=( $(prefix_match "etc/") )
622 if [ "${#ETC[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500623 write_packages "ETC" "" "" "ETC" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700624 fi
Rashed Abdel-Tawab8de76b22019-09-28 23:37:36 -0400625 local S_ETC=( $(prefix_match "system/etc/") )
626 if [ "${#ETC[@]}" -gt "0" ]; then
627 write_packages "ETC" "system" "" "S_ETC" >> "$ANDROIDMK"
628 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700629 local V_ETC=( $(prefix_match "vendor/etc/") )
630 if [ "${#V_ETC[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500631 write_packages "ETC" "vendor" "" "V_ETC" >> "$ANDROIDMK"
632 fi
633 local P_ETC=( $(prefix_match "product/etc/") )
634 if [ "${#P_ETC[@]}" -gt "0" ]; then
635 write_packages "ETC" "product" "" "P_ETC" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700636 fi
Rashed Abdel-Tawab08e3a272019-09-20 07:32:39 -0700637 local O_ETC=( $(prefix_match "odm/etc/") )
638 if [ "${#O_ETC[@]}" -gt "0" ]; then
639 write_packages "ETC" "odm" "" "O_ETC" >> "$ANDROIDMK"
640 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700641
642 # Executables
643 local BIN=( $(prefix_match "bin/") )
644 if [ "${#BIN[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500645 write_packages "EXECUTABLES" "" "" "BIN" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700646 fi
Rashed Abdel-Tawab8de76b22019-09-28 23:37:36 -0400647 local S_BIN=( $(prefix_match "system/bin/") )
648 if [ "${#BIN[@]}" -gt "0" ]; then
649 write_packages "EXECUTABLES" "system" "" "S_BIN" >> "$ANDROIDMK"
650 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700651 local V_BIN=( $(prefix_match "vendor/bin/") )
652 if [ "${#V_BIN[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500653 write_packages "EXECUTABLES" "vendor" "" "V_BIN" >> "$ANDROIDMK"
654 fi
655 local P_BIN=( $(prefix_match "product/bin/") )
656 if [ "${#P_BIN[@]}" -gt "0" ]; then
657 write_packages "EXECUTABLES" "product" "" "P_BIN" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700658 fi
Rashed Abdel-Tawab08e3a272019-09-20 07:32:39 -0700659 local O_BIN=( $(prefix_match "odm/bin/") )
660 if [ "${#O_BIN[@]}" -gt "0" ]; then
661 write_packages "EXECUTABLES" "odm" "" "O_BIN" >> "$ANDROIDMK"
662 fi
Steve Kondika991cf12016-07-28 12:13:12 -0700663 local SBIN=( $(prefix_match "sbin/") )
664 if [ "${#SBIN[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500665 write_packages "EXECUTABLES" "" "sbin" "SBIN" >> "$ANDROIDMK"
Steve Kondika991cf12016-07-28 12:13:12 -0700666 fi
667
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700668
669 # Actually write out the final PRODUCT_PACKAGES list
670 local PACKAGE_COUNT=${#PACKAGE_LIST[@]}
671
672 if [ "$PACKAGE_COUNT" -eq "0" ]; then
673 return 0
674 fi
675
676 printf '\n%s\n' "PRODUCT_PACKAGES += \\" >> "$PRODUCTMK"
677 for (( i=1; i<PACKAGE_COUNT+1; i++ )); do
678 local LINEEND=" \\"
679 if [ "$i" -eq "$PACKAGE_COUNT" ]; then
680 LINEEND=""
681 fi
682 printf ' %s%s\n' "${PACKAGE_LIST[$i-1]}" "$LINEEND" >> "$PRODUCTMK"
683 done
684}
685
686#
Rashed Abdel-Tawab42752d42019-09-20 07:06:09 -0700687# write_blueprint_header:
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700688#
689# $1: file which will be written to
690#
691# writes out the copyright header with the current year.
692# note that this is not an append operation, and should
693# be executed first!
694#
Rashed Abdel-Tawab42752d42019-09-20 07:06:09 -0700695function write_blueprint_header() {
696 if [ -f $1 ]; then
697 rm $1
698 fi
699
700 YEAR=$(date +"%Y")
701
702 [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON"
703
704 printf "/**\n" > $1
705 NUM_REGEX='^[0-9]+$'
706 if [[ ! $INITIAL_COPYRIGHT_YEAR =~ $NUM_REGEX ]] || [ $INITIAL_COPYRIGHT_YEAR -lt 2019 ]; then
707 BLUEPRINT_INITIAL_COPYRIGHT_YEAR=2019
708 else
709 BLUEPRINT_INITIAL_COPYRIGHT_YEAR=$INITIAL_COPYRIGHT_YEAR
710 fi
711
712 if [ $BLUEPRINT_INITIAL_COPYRIGHT_YEAR -eq $YEAR ]; then
713 printf " * Copyright (C) $YEAR The LineageOS Project\n" >> $1
714 elif [ $BLUEPRINT_INITIAL_COPYRIGHT_YEAR -le 2019 ]; then
715 printf " * Copyright (C) 2019-$YEAR The LineageOS Project\n" >> $1
716 else
717 printf " * Copyright (C) $BLUEPRINT_INITIAL_COPYRIGHT_YEAR-$YEAR The LineageOS Project\n" >> $1
718 fi
719
720 cat << EOF >> $1
721 *
722 * Licensed under the Apache License, Version 2.0 (the "License");
723 * you may not use this file except in compliance with the License.
724 * You may obtain a copy of the License at
725 *
726 * http://www.apache.org/licenses/LICENSE-2.0
727 *
728 * Unless required by applicable law or agreed to in writing, software
729 * distributed under the License is distributed on an "AS IS" BASIS,
730 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
731 * See the License for the specific language governing permissions and
732 * limitations under the License.
733 *
734 * This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh
735 */
736
737EOF
738}
739
740#
741# write_makefile_header:
742#
743# $1: file which will be written to
744#
745# writes out the copyright header with the current year.
746# note that this is not an append operation, and should
747# be executed first!
748#
749function write_makefile_header() {
Matt Mower8945f5e2017-01-07 14:08:17 -0600750 if [ -f $1 ]; then
751 rm $1
752 fi
753
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700754 YEAR=$(date +"%Y")
755
756 [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON"
757
Matt Mower8945f5e2017-01-07 14:08:17 -0600758 NUM_REGEX='^[0-9]+$'
759 if [[ $INITIAL_COPYRIGHT_YEAR =~ $NUM_REGEX ]] && [ $INITIAL_COPYRIGHT_YEAR -le $YEAR ]; then
760 if [ $INITIAL_COPYRIGHT_YEAR -lt 2016 ]; then
761 printf "# Copyright (C) $INITIAL_COPYRIGHT_YEAR-2016 The CyanogenMod Project\n" > $1
762 elif [ $INITIAL_COPYRIGHT_YEAR -eq 2016 ]; then
763 printf "# Copyright (C) 2016 The CyanogenMod Project\n" > $1
764 fi
765 if [ $YEAR -eq 2017 ]; then
766 printf "# Copyright (C) 2017 The LineageOS Project\n" >> $1
767 elif [ $INITIAL_COPYRIGHT_YEAR -eq $YEAR ]; then
768 printf "# Copyright (C) $YEAR The LineageOS Project\n" >> $1
769 elif [ $INITIAL_COPYRIGHT_YEAR -le 2017 ]; then
770 printf "# Copyright (C) 2017-$YEAR The LineageOS Project\n" >> $1
771 else
772 printf "# Copyright (C) $INITIAL_COPYRIGHT_YEAR-$YEAR The LineageOS Project\n" >> $1
773 fi
774 else
775 printf "# Copyright (C) $YEAR The LineageOS Project\n" > $1
776 fi
777
778 cat << EOF >> $1
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700779#
780# Licensed under the Apache License, Version 2.0 (the "License");
781# you may not use this file except in compliance with the License.
782# You may obtain a copy of the License at
783#
784# http://www.apache.org/licenses/LICENSE-2.0
785#
786# Unless required by applicable law or agreed to in writing, software
787# distributed under the License is distributed on an "AS IS" BASIS,
788# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
789# See the License for the specific language governing permissions and
790# limitations under the License.
791
792# This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh
793
794EOF
795}
796
797#
798# write_headers:
799#
800# $1: devices falling under common to be added to guard - optional
Rashed Abdel-Tawabd53bff12016-10-02 01:00:54 -0400801# $2: custom guard - optional
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700802#
Rashed Abdel-Tawab42752d42019-09-20 07:06:09 -0700803# Calls write_makefile_header for each of the makefiles and
804# write_blueprint_header for Android.bp and creates the initial
805# path declaration and device guard for the Android.mk
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700806#
807function write_headers() {
Rashed Abdel-Tawab42752d42019-09-20 07:06:09 -0700808 write_makefile_header "$ANDROIDMK"
Rashed Abdel-Tawabd53bff12016-10-02 01:00:54 -0400809
810 GUARD="$2"
811 if [ -z "$GUARD" ]; then
812 GUARD="TARGET_DEVICE"
813 fi
814
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700815 cat << EOF >> "$ANDROIDMK"
816LOCAL_PATH := \$(call my-dir)
817
818EOF
819 if [ "$COMMON" -ne 1 ]; then
820 cat << EOF >> "$ANDROIDMK"
Rashed Abdel-Tawabd53bff12016-10-02 01:00:54 -0400821ifeq (\$($GUARD),$DEVICE)
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700822
823EOF
824 else
825 if [ -z "$1" ]; then
826 echo "Argument with devices to be added to guard must be set!"
827 exit 1
828 fi
829 cat << EOF >> "$ANDROIDMK"
Rashed Abdel-Tawabd53bff12016-10-02 01:00:54 -0400830ifneq (\$(filter $1,\$($GUARD)),)
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700831
832EOF
833 fi
834
Rashed Abdel-Tawab42752d42019-09-20 07:06:09 -0700835 write_makefile_header "$BOARDMK"
836 write_makefile_header "$PRODUCTMK"
837 write_blueprint_header "$ANDROIDBP"
838
839 cat << EOF >> "$ANDROIDBP"
840soong_namespace {
841}
842
843EOF
844
845 [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON"
846 cat << EOF >> "$PRODUCTMK"
847PRODUCT_SOONG_NAMESPACES += \\
848 vendor/$VENDOR/$DEVICE
849
850EOF
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700851}
852
853#
854# write_footers:
855#
856# Closes the inital guard and any other finalization tasks. Must
857# be called as the final step.
858#
859function write_footers() {
860 cat << EOF >> "$ANDROIDMK"
861endif
862EOF
863}
864
865# Return success if adb is up and not in recovery
866function _adb_connected {
867 {
Steve Kondik7561d192016-09-01 21:40:27 -0700868 if [[ "$(adb get-state)" == device ]]
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700869 then
870 return 0
871 fi
872 } 2>/dev/null
873
874 return 1
875};
876
877#
Bruno Martins3b96ba52016-07-27 15:00:05 +0100878# parse_file_list:
879#
880# $1: input file
Rashed Abdel-Tawab855fbdd2017-04-04 02:48:18 -0400881# $2: blob section in file - optional
Bruno Martins3b96ba52016-07-27 15:00:05 +0100882#
883# Sets PRODUCT_PACKAGES and PRODUCT_COPY_FILES while parsing the input file
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700884#
885function parse_file_list() {
Bruno Martins3b96ba52016-07-27 15:00:05 +0100886 if [ -z "$1" ]; then
887 echo "An input file is expected!"
888 exit 1
889 elif [ ! -f "$1" ]; then
890 echo "Input file "$1" does not exist!"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700891 exit 1
892 fi
893
Vladimir Olteanc5034462019-01-17 03:04:16 +0200894 if [ -n "$2" ]; then
895 echo "Using section \"$2\""
Rashed Abdel-Tawab855fbdd2017-04-04 02:48:18 -0400896 LIST=$TMPDIR/files.txt
Vladimir Oltean5238ba82019-01-19 00:44:07 +0200897 # Match all lines starting with first line found to start* with '#'
898 # comment and contain** $2, and ending with first line to be empty*.
899 # *whitespaces (tabs, spaces) at the beginning of lines are discarded
900 # **the $2 match is case-insensitive
901 cat $1 | sed -n '/^[[:space:]]*#.*'"$2"'/I,/^[[:space:]]*$/ p' > $LIST
Rashed Abdel-Tawab855fbdd2017-04-04 02:48:18 -0400902 else
903 LIST=$1
904 fi
905
906
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700907 PRODUCT_PACKAGES_LIST=()
Steve Kondik48f8df82016-08-14 03:55:08 -0700908 PRODUCT_PACKAGES_HASHES=()
Vladimir Oltean4818c232019-01-17 03:07:34 +0200909 PRODUCT_PACKAGES_FIXUP_HASHES=()
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700910 PRODUCT_COPY_FILES_LIST=()
Steve Kondik48f8df82016-08-14 03:55:08 -0700911 PRODUCT_COPY_FILES_HASHES=()
Vladimir Oltean4818c232019-01-17 03:07:34 +0200912 PRODUCT_COPY_FILES_FIXUP_HASHES=()
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700913
914 while read -r line; do
915 if [ -z "$line" ]; then continue; fi
916
Steve Kondik48f8df82016-08-14 03:55:08 -0700917 # If the line has a pipe delimiter, a sha1 hash should follow.
918 # This indicates the file should be pinned and not overwritten
919 # when extracting files.
920 local SPLIT=(${line//\|/ })
921 local COUNT=${#SPLIT[@]}
922 local SPEC=${SPLIT[0]}
923 local HASH="x"
Vladimir Oltean4818c232019-01-17 03:07:34 +0200924 local FIXUP_HASH="x"
Steve Kondik48f8df82016-08-14 03:55:08 -0700925 if [ "$COUNT" -gt "1" ]; then
926 HASH=${SPLIT[1]}
927 fi
Vladimir Oltean4818c232019-01-17 03:07:34 +0200928 if [ "$COUNT" -gt "2" ]; then
929 FIXUP_HASH=${SPLIT[2]}
930 fi
Steve Kondik48f8df82016-08-14 03:55:08 -0700931
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700932 # if line starts with a dash, it needs to be packaged
Steve Kondik48f8df82016-08-14 03:55:08 -0700933 if [[ "$SPEC" =~ ^- ]]; then
934 PRODUCT_PACKAGES_LIST+=("${SPEC#-}")
935 PRODUCT_PACKAGES_HASHES+=("$HASH")
Vladimir Oltean4818c232019-01-17 03:07:34 +0200936 PRODUCT_PACKAGES_FIXUP_HASHES+=("$FIXUP_HASH")
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700937 else
Steve Kondik48f8df82016-08-14 03:55:08 -0700938 PRODUCT_COPY_FILES_LIST+=("$SPEC")
939 PRODUCT_COPY_FILES_HASHES+=("$HASH")
Vladimir Oltean4818c232019-01-17 03:07:34 +0200940 PRODUCT_COPY_FILES_FIXUP_HASHES+=("$FIXUP_HASH")
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700941 fi
942
Rashed Abdel-Tawab855fbdd2017-04-04 02:48:18 -0400943 done < <(egrep -v '(^#|^[[:space:]]*$)' "$LIST" | LC_ALL=C sort | uniq)
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700944}
945
946#
947# write_makefiles:
948#
949# $1: file containing the list of items to extract
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400950# $2: make treble compatible makefile - optional
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700951#
952# Calls write_product_copy_files and write_product_packages on
Rashed Abdel-Tawab42752d42019-09-20 07:06:09 -0700953# the given file and appends to the Android.bp as well as
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700954# the product makefile.
955#
956function write_makefiles() {
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700957 parse_file_list "$1"
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400958 write_product_copy_files "$2"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700959 write_product_packages
960}
961
962#
Louis Popia516c2f2016-07-25 15:51:13 +0200963# append_firmware_calls_to_makefiles:
964#
965# Appends to Android.mk the calls to all images present in radio folder
966# (filesmap file used by releasetools to map firmware images should be kept in the device tree)
967#
968function append_firmware_calls_to_makefiles() {
969 cat << EOF >> "$ANDROIDMK"
970ifeq (\$(LOCAL_PATH)/radio, \$(wildcard \$(LOCAL_PATH)/radio))
971
972RADIO_FILES := \$(wildcard \$(LOCAL_PATH)/radio/*)
973\$(foreach f, \$(notdir \$(RADIO_FILES)), \\
974 \$(call add-radio-file,radio/\$(f)))
975\$(call add-radio-file,../../../device/$VENDOR/$DEVICE/radio/filesmap)
976
977endif
978
979EOF
980}
981
982#
Luca Stefani7f9fff22016-07-18 13:47:55 +0200983# get_file:
984#
985# $1: input file
986# $2: target file/folder
987# $3: source of the file (can be "adb" or a local folder)
988#
989# Silently extracts the input file to defined target
990# Returns success if file can be pulled from the device or found locally
991#
992function get_file() {
993 local SRC="$3"
994
995 if [ "$SRC" = "adb" ]; then
996 # try to pull
997 adb pull "$1" "$2" >/dev/null 2>&1 && return 0
998
999 return 1
1000 else
1001 # try to copy
Vladimir Olteand5773252018-06-25 00:05:56 +03001002 cp -r "$SRC/$1" "$2" 2>/dev/null && return 0
1003 cp -r "$SRC/${1#/system}" "$2" 2>/dev/null && return 0
Vladimir Oltean78d690d2019-01-06 19:38:31 +02001004 cp -r "$SRC/system/$1" "$2" 2>/dev/null && return 0
Luca Stefani7f9fff22016-07-18 13:47:55 +02001005
1006 return 1
1007 fi
1008};
1009
1010#
1011# oat2dex:
1012#
1013# $1: extracted apk|jar (to check if deodex is required)
1014# $2: odexed apk|jar to deodex
1015# $3: source of the odexed apk|jar
1016#
1017# Convert apk|jar .odex in the corresposing classes.dex
1018#
1019function oat2dex() {
Luca Stefani5c60e4f2017-08-17 19:28:48 +02001020 local LINEAGE_TARGET="$1"
Luca Stefani7f9fff22016-07-18 13:47:55 +02001021 local OEM_TARGET="$2"
1022 local SRC="$3"
1023 local TARGET=
1024 local OAT=
Joe Maples9be579f2018-01-05 14:51:33 -05001025 local HOST="$(uname)"
Luca Stefani7f9fff22016-07-18 13:47:55 +02001026
1027 if [ -z "$BAKSMALIJAR" ] || [ -z "$SMALIJAR" ]; then
Bruno Martins8194b8e2019-09-23 11:51:33 +01001028 export BAKSMALIJAR="$LINEAGE_ROOT"/prebuilts/tools-lineage/common/smali/baksmali.jar
1029 export SMALIJAR="$LINEAGE_ROOT"/prebuilts/tools-lineage/common/smali/smali.jar
Luca Stefani7f9fff22016-07-18 13:47:55 +02001030 fi
1031
Joe Maples9be579f2018-01-05 14:51:33 -05001032 if [ -z "$VDEXEXTRACTOR" ]; then
Bruno Martins8194b8e2019-09-23 11:51:33 +01001033 export VDEXEXTRACTOR="$LINEAGE_ROOT"/prebuilts/tools-lineage/"${HOST,,}"-x86/bin/vdexExtractor
Joe Maples9be579f2018-01-05 14:51:33 -05001034 fi
1035
codeworkx1c29bf62018-09-23 12:36:57 +02001036 if [ -z "$CDEXCONVERTER" ]; then
Bruno Martins8194b8e2019-09-23 11:51:33 +01001037 export CDEXCONVERTER="$LINEAGE_ROOT"/prebuilts/tools-lineage/"${HOST,,}"-x86/bin/compact_dex_converter
codeworkx1c29bf62018-09-23 12:36:57 +02001038 fi
1039
Luca Stefani7f9fff22016-07-18 13:47:55 +02001040 # Extract existing boot.oats to the temp folder
1041 if [ -z "$ARCHES" ]; then
Sam Mortimer2e994ce2016-10-05 09:50:49 -07001042 echo "Checking if system is odexed and locating boot.oats..."
Luca Stefani7f9fff22016-07-18 13:47:55 +02001043 for ARCH in "arm64" "arm" "x86_64" "x86"; do
Sam Mortimer2e994ce2016-10-05 09:50:49 -07001044 mkdir -p "$TMPDIR/system/framework/$ARCH"
Vladimir Olteand5773252018-06-25 00:05:56 +03001045 if get_file "/system/framework/$ARCH" "$TMPDIR/system/framework/" "$SRC"; then
Luca Stefani7f9fff22016-07-18 13:47:55 +02001046 ARCHES+="$ARCH "
Sam Mortimer2e994ce2016-10-05 09:50:49 -07001047 else
1048 rmdir "$TMPDIR/system/framework/$ARCH"
Luca Stefani7f9fff22016-07-18 13:47:55 +02001049 fi
1050 done
1051 fi
1052
1053 if [ -z "$ARCHES" ]; then
1054 FULLY_DEODEXED=1 && return 0 # system is fully deodexed, return
1055 fi
1056
Luca Stefani5c60e4f2017-08-17 19:28:48 +02001057 if [ ! -f "$LINEAGE_TARGET" ]; then
Steve Kondik48f8df82016-08-14 03:55:08 -07001058 return;
1059 fi
1060
Luca Stefani5c60e4f2017-08-17 19:28:48 +02001061 if grep "classes.dex" "$LINEAGE_TARGET" >/dev/null; then
Luca Stefani7f9fff22016-07-18 13:47:55 +02001062 return 0 # target apk|jar is already odexed, return
1063 fi
1064
1065 for ARCH in $ARCHES; do
Sam Mortimer2e994ce2016-10-05 09:50:49 -07001066 BOOTOAT="$TMPDIR/system/framework/$ARCH/boot.oat"
Luca Stefani7f9fff22016-07-18 13:47:55 +02001067
1068 local OAT="$(dirname "$OEM_TARGET")/oat/$ARCH/$(basename "$OEM_TARGET" ."${OEM_TARGET##*.}").odex"
Rashed Abdel-Tawab54b5d5e2017-08-23 15:13:17 -04001069 local VDEX="$(dirname "$OEM_TARGET")/oat/$ARCH/$(basename "$OEM_TARGET" ."${OEM_TARGET##*.}").vdex"
Luca Stefani7f9fff22016-07-18 13:47:55 +02001070
1071 if get_file "$OAT" "$TMPDIR" "$SRC"; then
Rashed Abdel-Tawab54b5d5e2017-08-23 15:13:17 -04001072 if get_file "$VDEX" "$TMPDIR" "$SRC"; then
Joe Maples9be579f2018-01-05 14:51:33 -05001073 "$VDEXEXTRACTOR" -o "$TMPDIR/" -i "$TMPDIR/$(basename "$VDEX")" > /dev/null
Rashed Abdel-Tawab19c36cd2018-03-15 12:55:22 -07001074 CLASSES=$(ls "$TMPDIR/$(basename "${OEM_TARGET%.*}")_classes"*)
1075 for CLASS in $CLASSES; do
1076 NEWCLASS=$(echo "$CLASS" | sed 's/.*_//;s/cdex/dex/')
1077 # Check if we have to deal with CompactDex
1078 if [[ "$CLASS" == *.cdex ]]; then
1079 "$CDEXCONVERTER" "$CLASS" &>/dev/null
1080 mv "$CLASS.new" "$TMPDIR/$NEWCLASS"
1081 else
1082 mv "$CLASS" "$TMPDIR/$NEWCLASS"
1083 fi
1084 done
Joe Maples9be579f2018-01-05 14:51:33 -05001085 else
1086 java -jar "$BAKSMALIJAR" deodex -o "$TMPDIR/dexout" -b "$BOOTOAT" -d "$TMPDIR" "$TMPDIR/$(basename "$OAT")"
1087 java -jar "$SMALIJAR" assemble "$TMPDIR/dexout" -o "$TMPDIR/classes.dex"
Rashed Abdel-Tawab54b5d5e2017-08-23 15:13:17 -04001088 fi
Luca Stefani5c60e4f2017-08-17 19:28:48 +02001089 elif [[ "$LINEAGE_TARGET" =~ .jar$ ]]; then
Gabriele M4cf635a2017-01-05 22:10:00 +01001090 JAROAT="$TMPDIR/system/framework/$ARCH/boot-$(basename ${OEM_TARGET%.*}).oat"
Luca Stefanif6096e92018-10-07 12:44:53 +02001091 JARVDEX="/system/framework/boot-$(basename ${OEM_TARGET%.*}).vdex"
Gabriele M4cf635a2017-01-05 22:10:00 +01001092 if [ ! -f "$JAROAT" ]; then
Luca Stefanif6096e92018-10-07 12:44:53 +02001093 JAROAT=$BOOTOAT
Gabriele M4cf635a2017-01-05 22:10:00 +01001094 fi
Joe Maples9be579f2018-01-05 14:51:33 -05001095 # try to extract classes.dex from boot.vdex for frameworks jars
1096 # fallback to boot.oat if vdex is not available
Luca Stefanif6096e92018-10-07 12:44:53 +02001097 if get_file "$JARVDEX" "$TMPDIR" "$SRC"; then
Luca Stefani99a66bf2018-10-31 19:16:05 +01001098 "$VDEXEXTRACTOR" -o "$TMPDIR/" -i "$TMPDIR/$(basename "$JARVDEX")" > /dev/null
Rashed Abdel-Tawab19c36cd2018-03-15 12:55:22 -07001099 CLASSES=$(ls "$TMPDIR/$(basename "${JARVDEX%.*}")_classes"*)
1100 for CLASS in $CLASSES; do
1101 NEWCLASS=$(echo "$CLASS" | sed 's/.*_//;s/cdex/dex/')
1102 # Check if we have to deal with CompactDex
1103 if [[ "$CLASS" == *.cdex ]]; then
1104 "$CDEXCONVERTER" "$CLASS" &>/dev/null
1105 mv "$CLASS.new" "$TMPDIR/$NEWCLASS"
1106 else
1107 mv "$CLASS" "$TMPDIR/$NEWCLASS"
1108 fi
1109 done
Joe Maples9be579f2018-01-05 14:51:33 -05001110 else
1111 java -jar "$BAKSMALIJAR" deodex -o "$TMPDIR/dexout" -b "$BOOTOAT" -d "$TMPDIR" "$JAROAT/$OEM_TARGET"
1112 java -jar "$SMALIJAR" assemble "$TMPDIR/dexout" -o "$TMPDIR/classes.dex"
1113 fi
Luca Stefani7f9fff22016-07-18 13:47:55 +02001114 else
1115 continue
1116 fi
1117
Luca Stefani7f9fff22016-07-18 13:47:55 +02001118 done
1119
1120 rm -rf "$TMPDIR/dexout"
1121}
1122
1123#
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001124# init_adb_connection:
1125#
1126# Starts adb server and waits for the device
1127#
1128function init_adb_connection() {
1129 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
1130 if ! _adb_connected; then
1131 echo "No device is online. Waiting for one..."
1132 echo "Please connect USB and/or enable USB debugging"
1133 until _adb_connected; do
1134 sleep 1
1135 done
1136 echo "Device Found."
1137 fi
1138
1139 # Retrieve IP and PORT info if we're using a TCP connection
1140 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
1141 | head -1 | awk '{print $1}')
1142 adb root &> /dev/null
1143 sleep 0.3
1144 if [ -n "$TCPIPPORT" ]; then
1145 # adb root just killed our connection
1146 # so reconnect...
1147 adb connect "$TCPIPPORT"
1148 fi
1149 adb wait-for-device &> /dev/null
1150 sleep 0.3
1151}
1152
1153#
Luca Stefani3a030122016-07-30 12:08:25 +02001154# fix_xml:
1155#
1156# $1: xml file to fix
1157#
1158function fix_xml() {
1159 local XML="$1"
1160 local TEMP_XML="$TMPDIR/`basename "$XML"`.temp"
1161
Dobroslaw Kijowski65f03f12017-05-18 12:35:02 +02001162 grep -a '^<?xml version' "$XML" > "$TEMP_XML"
1163 grep -av '^<?xml version' "$XML" >> "$TEMP_XML"
Luca Stefani3a030122016-07-30 12:08:25 +02001164
1165 mv "$TEMP_XML" "$XML"
1166}
1167
Vladimir Oltean4818c232019-01-17 03:07:34 +02001168function get_hash() {
1169 local FILE="$1"
1170
1171 if [ "$(uname)" == "Darwin" ]; then
1172 shasum "${FILE}" | awk '{print $1}'
1173 else
1174 sha1sum "${FILE}" | awk '{print $1}'
1175 fi
1176}
1177
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001178function print_spec() {
1179 local SPEC_PRODUCT_PACKAGE="$1"
1180 local SPEC_SRC_FILE="$2"
1181 local SPEC_DST_FILE="$3"
1182 local SPEC_ARGS="$4"
1183 local SPEC_HASH="$5"
Vladimir Oltean4818c232019-01-17 03:07:34 +02001184 local SPEC_FIXUP_HASH="$6"
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001185
1186 local PRODUCT_PACKAGE=""
1187 if [ ${SPEC_PRODUCT_PACKAGE} = true ]; then
1188 PRODUCT_PACKAGE="-"
1189 fi
1190 local SRC=""
1191 if [ ! -z "${SPEC_SRC_FILE}" ] && [ "${SPEC_SRC_FILE}" != "${SPEC_DST_FILE}" ]; then
1192 SRC="${SPEC_SRC_FILE}:"
1193 fi
1194 local DST=""
1195 if [ ! -z "${SPEC_DST_FILE}" ]; then
1196 DST="${SPEC_DST_FILE}"
1197 fi
1198 local ARGS=""
1199 if [ ! -z "${SPEC_ARGS}" ]; then
1200 ARGS=";${SPEC_ARGS}"
1201 fi
1202 local HASH=""
1203 if [ ! -z "${SPEC_HASH}" ] && [ "${SPEC_HASH}" != "x" ]; then
1204 HASH="|${SPEC_HASH}"
1205 fi
Vladimir Oltean4818c232019-01-17 03:07:34 +02001206 local FIXUP_HASH=""
1207 if [ ! -z "${SPEC_FIXUP_HASH}" ] && [ "${SPEC_FIXUP_HASH}" != "x" ] && [ "${SPEC_FIXUP_HASH}" != "${SPEC_HASH}" ]; then
1208 FIXUP_HASH="|${SPEC_FIXUP_HASH}"
1209 fi
1210 printf '%s%s%s%s%s%s\n' "${PRODUCT_PACKAGE}" "${SRC}" "${DST}" "${ARGS}" "${HASH}" "${FIXUP_HASH}"
1211}
1212
1213# To be overridden by device-level extract-files.sh
1214# Parameters:
1215# $1: spec name of a blob. Can be used for filtering.
1216# If the spec is "src:dest", then $1 is "dest".
1217# If the spec is "src", then $1 is "src".
1218# $2: path to blob file. Can be used for fixups.
1219#
1220function blob_fixup() {
1221 :
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001222}
1223
Luca Stefani3a030122016-07-30 12:08:25 +02001224#
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001225# extract:
1226#
Vladimir Olteanc5034462019-01-17 03:04:16 +02001227# Positional parameters:
1228# $1: file containing the list of items to extract (aka proprietary-files.txt)
Dan Pasanen7dc287f2017-03-21 09:06:11 -05001229# $2: path to extracted system folder, an ota zip file, or "adb" to extract from device
Vladimir Olteanc5034462019-01-17 03:04:16 +02001230# $3: section in list file to extract - optional. Setting section via $3 is deprecated.
1231#
1232# Non-positional parameters (coming after $2):
1233# --section: preferred way of selecting the portion to parse and extract from
1234# proprietary-files.txt
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001235# --kang: if present, this option will activate the printing of hashes for the
1236# extracted blobs. Useful with --section for subsequent pinning of
1237# blobs taken from other origins.
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001238#
1239function extract() {
Vladimir Olteanc5034462019-01-17 03:04:16 +02001240 # Consume positional parameters
1241 local PROPRIETARY_FILES_TXT="$1"; shift
1242 local SRC="$1"; shift
1243 local SECTION=""
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001244 local KANG=false
Vladimir Olteanc5034462019-01-17 03:04:16 +02001245
1246 # Consume optional, non-positional parameters
1247 while [ "$#" -gt 0 ]; do
1248 case "$1" in
1249 -s|--section)
1250 SECTION="$2"; shift
1251 ;;
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001252 -k|--kang)
1253 KANG=true
1254 DISABLE_PINNING=1
1255 ;;
Vladimir Olteanc5034462019-01-17 03:04:16 +02001256 *)
1257 # Backwards-compatibility with the old behavior, where $3, if
1258 # present, denoted an optional positional ${SECTION} argument.
1259 # Users of ${SECTION} are encouraged to migrate from setting it as
1260 # positional $3, to non-positional --section ${SECTION}, the
1261 # reason being that it doesn't scale to have more than 1 optional
1262 # positional argument.
1263 SECTION="$1"
1264 ;;
1265 esac
1266 shift
1267 done
1268
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001269 if [ -z "$OUTDIR" ]; then
1270 echo "Output dir not set!"
1271 exit 1
1272 fi
1273
Vladimir Olteanc5034462019-01-17 03:04:16 +02001274 parse_file_list "${PROPRIETARY_FILES_TXT}" "${SECTION}"
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001275
1276 # Allow failing, so we can try $DEST and/or $FILE
1277 set +e
1278
1279 local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ${PRODUCT_PACKAGES_LIST[@]} )
Steve Kondik48f8df82016-08-14 03:55:08 -07001280 local HASHLIST=( ${PRODUCT_COPY_FILES_HASHES[@]} ${PRODUCT_PACKAGES_HASHES[@]} )
Vladimir Oltean4818c232019-01-17 03:07:34 +02001281 local FIXUP_HASHLIST=( ${PRODUCT_COPY_FILES_FIXUP_HASHES[@]} ${PRODUCT_PACKAGES_FIXUP_HASHES[@]} )
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001282 local PRODUCT_COPY_FILES_COUNT=${#PRODUCT_COPY_FILES_LIST[@]}
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001283 local COUNT=${#FILELIST[@]}
Luca Stefani5c60e4f2017-08-17 19:28:48 +02001284 local OUTPUT_ROOT="$LINEAGE_ROOT"/"$OUTDIR"/proprietary
Steve Kondik48f8df82016-08-14 03:55:08 -07001285 local OUTPUT_TMP="$TMPDIR"/"$OUTDIR"/proprietary
1286
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001287 if [ "$SRC" = "adb" ]; then
1288 init_adb_connection
1289 fi
1290
Dan Pasanen7dc287f2017-03-21 09:06:11 -05001291 if [ -f "$SRC" ] && [ "${SRC##*.}" == "zip" ]; then
conbold575c6352017-11-10 16:33:38 +01001292 DUMPDIR="$TMPDIR"/system_dump
Dan Pasanen7dc287f2017-03-21 09:06:11 -05001293
1294 # Check if we're working with the same zip that was passed last time.
1295 # If so, let's just use what's already extracted.
1296 MD5=`md5sum "$SRC"| awk '{print $1}'`
1297 OLDMD5=`cat "$DUMPDIR"/zipmd5.txt`
1298
1299 if [ "$MD5" != "$OLDMD5" ]; then
1300 rm -rf "$DUMPDIR"
1301 mkdir "$DUMPDIR"
1302 unzip "$SRC" -d "$DUMPDIR"
1303 echo "$MD5" > "$DUMPDIR"/zipmd5.txt
1304
1305 # Stop if an A/B OTA zip is detected. We cannot extract these.
1306 if [ -a "$DUMPDIR"/payload.bin ]; then
1307 echo "A/B style OTA zip detected. This is not supported at this time. Stopping..."
1308 exit 1
1309 # If OTA is block based, extract it.
1310 elif [ -a "$DUMPDIR"/system.new.dat ]; then
1311 echo "Converting system.new.dat to system.img"
Luca Stefani5c60e4f2017-08-17 19:28:48 +02001312 python "$LINEAGE_ROOT"/vendor/lineage/build/tools/sdat2img.py "$DUMPDIR"/system.transfer.list "$DUMPDIR"/system.new.dat "$DUMPDIR"/system.img 2>&1
Dan Pasanen7dc287f2017-03-21 09:06:11 -05001313 rm -rf "$DUMPDIR"/system.new.dat "$DUMPDIR"/system
1314 mkdir "$DUMPDIR"/system "$DUMPDIR"/tmp
1315 echo "Requesting sudo access to mount the system.img"
1316 sudo mount -o loop "$DUMPDIR"/system.img "$DUMPDIR"/tmp
1317 cp -r "$DUMPDIR"/tmp/* "$DUMPDIR"/system/
1318 sudo umount "$DUMPDIR"/tmp
1319 rm -rf "$DUMPDIR"/tmp "$DUMPDIR"/system.img
1320 fi
1321 fi
1322
1323 SRC="$DUMPDIR"
1324 fi
1325
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001326 if [ "$VENDOR_STATE" -eq "0" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -07001327 echo "Cleaning output directory ($OUTPUT_ROOT).."
Steve Kondik48f8df82016-08-14 03:55:08 -07001328 rm -rf "${OUTPUT_TMP:?}"
1329 mkdir -p "${OUTPUT_TMP:?}"
Adrian DC3c6bdac2017-01-15 14:03:26 +01001330 if [ -d "$OUTPUT_ROOT" ]; then
1331 mv "${OUTPUT_ROOT:?}/"* "${OUTPUT_TMP:?}/"
1332 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001333 VENDOR_STATE=1
1334 fi
1335
Vladimir Olteanc5034462019-01-17 03:04:16 +02001336 echo "Extracting ${COUNT} files in ${PROPRIETARY_FILES_TXT} from ${SRC}:"
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001337
1338 for (( i=1; i<COUNT+1; i++ )); do
Steve Kondika991cf12016-07-28 12:13:12 -07001339
Vladimir Olteanda3b6442018-06-24 20:41:30 +03001340 local SPEC_SRC_FILE=$(src_file "${FILELIST[$i-1]}")
Vladimir Oltean411e0692018-06-24 20:38:04 +03001341 local SPEC_DST_FILE=$(target_file "${FILELIST[$i-1]}")
Vladimir Olteand652a062018-06-24 20:42:01 +03001342 local SPEC_ARGS=$(target_args "${FILELIST[$i-1]}")
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001343 local OUTPUT_DIR=
1344 local TMP_DIR=
1345 local SRC_FILE=
1346 local DST_FILE=
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001347 local IS_PRODUCT_PACKAGE=false
1348
1349 # Note: this relies on the fact that the ${FILELIST[@]} array
1350 # contains first ${PRODUCT_COPY_FILES_LIST[@]}, then ${PRODUCT_PACKAGES_LIST[@]}.
1351 if [ "${i}" -gt "${PRODUCT_COPY_FILES_COUNT}" ]; then
1352 IS_PRODUCT_PACKAGE=true
1353 fi
Steve Kondika991cf12016-07-28 12:13:12 -07001354
Vladimir Olteand652a062018-06-24 20:42:01 +03001355 if [ "${SPEC_ARGS}" = "rootfs" ]; then
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001356 OUTPUT_DIR="${OUTPUT_ROOT}/rootfs"
1357 TMP_DIR="${OUTPUT_TMP}/rootfs"
1358 SRC_FILE="/${SPEC_SRC_FILE}"
1359 DST_FILE="/${SPEC_DST_FILE}"
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001360 else
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001361 OUTPUT_DIR="${OUTPUT_ROOT}"
1362 TMP_DIR="${OUTPUT_TMP}"
1363 SRC_FILE="/system/${SPEC_SRC_FILE}"
1364 DST_FILE="/system/${SPEC_DST_FILE}"
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001365 fi
Steve Kondika991cf12016-07-28 12:13:12 -07001366
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001367 # Strip the file path in the vendor repo of "system", if present
1368 local VENDOR_REPO_FILE="$OUTPUT_DIR/${DST_FILE#/system}"
Vladimir Olteanc5034462019-01-17 03:04:16 +02001369 local BLOB_DISPLAY_NAME="${DST_FILE#/system/}"
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001370 mkdir -p $(dirname "${VENDOR_REPO_FILE}")
Steve Kondika991cf12016-07-28 12:13:12 -07001371
Gabriele Me6df25b2017-10-11 00:58:59 +02001372 # Check pinned files
Vladimir Olteanb2c38212019-01-17 02:47:02 +02001373 local HASH="$(echo ${HASHLIST[$i-1]} | awk '{ print tolower($0); }')"
Vladimir Oltean4818c232019-01-17 03:07:34 +02001374 local FIXUP_HASH="$(echo ${FIXUP_HASHLIST[$i-1]} | awk '{ print tolower($0); }')"
Gabriele Me6df25b2017-10-11 00:58:59 +02001375 local KEEP=""
Vladimir Oltean4818c232019-01-17 03:07:34 +02001376 if [ "$DISABLE_PINNING" != "1" ] && [ "$HASH" != "x" ]; then
Vladimir Olteand6747712018-06-24 20:46:42 +03001377 if [ -f "${VENDOR_REPO_FILE}" ]; then
1378 local PINNED="${VENDOR_REPO_FILE}"
Gabriele Me6df25b2017-10-11 00:58:59 +02001379 else
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001380 local PINNED="${TMP_DIR}${DST_FILE#/system}"
Gabriele Me6df25b2017-10-11 00:58:59 +02001381 fi
1382 if [ -f "$PINNED" ]; then
Vladimir Oltean4818c232019-01-17 03:07:34 +02001383 local TMP_HASH=$(get_hash "${PINNED}")
1384 if [ "${TMP_HASH}" = "${HASH}" ] || [ "${TMP_HASH}" = "${FIXUP_HASH}" ]; then
Gabriele Me6df25b2017-10-11 00:58:59 +02001385 KEEP="1"
Vladimir Olteand6747712018-06-24 20:46:42 +03001386 if [ ! -f "${VENDOR_REPO_FILE}" ]; then
1387 cp -p "$PINNED" "${VENDOR_REPO_FILE}"
Gabriele Me6df25b2017-10-11 00:58:59 +02001388 fi
1389 fi
1390 fi
1391 fi
1392
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001393 if [ "${KANG}" = false ]; then
1394 printf ' - %s\n' "${BLOB_DISPLAY_NAME}"
1395 fi
1396
Gabriele Me6df25b2017-10-11 00:58:59 +02001397 if [ "$KEEP" = "1" ]; then
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001398 printf ' + keeping pinned file with hash %s\n' "${HASH}"
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001399 else
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001400 FOUND=false
1401 # Try Lineage target first.
1402 # Also try to search for files stripped of
1403 # the "/system" prefix, if we're actually extracting
1404 # from a system image.
Vladimir Olteand5773252018-06-25 00:05:56 +03001405 for CANDIDATE in "${DST_FILE}" "${SRC_FILE}"; do
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001406 get_file ${CANDIDATE} ${VENDOR_REPO_FILE} ${SRC} && {
1407 FOUND=true
1408 break
1409 }
1410 done
1411
1412 if [ "${FOUND}" = false ]; then
Vladimir Olteanc5034462019-01-17 03:04:16 +02001413 printf ' !! %s: file not found in source\n' "${BLOB_DISPLAY_NAME}"
Vladimir Olteanb8084ec2018-10-18 00:44:02 +03001414 continue
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001415 fi
1416 fi
Steve Kondika991cf12016-07-28 12:13:12 -07001417
Vladimir Oltean4818c232019-01-17 03:07:34 +02001418 # Blob fixup pipeline has 2 parts: one that is fixed and
1419 # one that is user-configurable
1420 local PRE_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE})
1421 # Deodex apk|jar if that's the case
1422 if [[ "$FULLY_DEODEXED" -ne "1" && "${VENDOR_REPO_FILE}" =~ .(apk|jar)$ ]]; then
1423 oat2dex "${VENDOR_REPO_FILE}" "${SRC_FILE}" "$SRC"
1424 if [ -f "$TMPDIR/classes.dex" ]; then
Rashed Abdel-Tawab19c36cd2018-03-15 12:55:22 -07001425 zip -gjq "${VENDOR_REPO_FILE}" "$TMPDIR/classes"*
1426 rm "$TMPDIR/classes"*
Vladimir Oltean4818c232019-01-17 03:07:34 +02001427 printf ' (updated %s from odex files)\n' "${SRC_FILE}"
Luca Stefani7f9fff22016-07-18 13:47:55 +02001428 fi
Vladimir Oltean4818c232019-01-17 03:07:34 +02001429 elif [[ "${VENDOR_REPO_FILE}" =~ .xml$ ]]; then
1430 fix_xml "${VENDOR_REPO_FILE}"
Luca Stefani7f9fff22016-07-18 13:47:55 +02001431 fi
Vladimir Oltean4818c232019-01-17 03:07:34 +02001432 # Now run user-supplied fixup function
1433 blob_fixup "${BLOB_DISPLAY_NAME}" "${VENDOR_REPO_FILE}"
1434 local POST_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE})
Luca Stefani7f9fff22016-07-18 13:47:55 +02001435
Vladimir Olteand6747712018-06-24 20:46:42 +03001436 if [ -f "${VENDOR_REPO_FILE}" ]; then
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001437 local DIR=$(dirname "${VENDOR_REPO_FILE}")
Steve Kondik48f8df82016-08-14 03:55:08 -07001438 local TYPE="${DIR##*/}"
1439 if [ "$TYPE" = "bin" -o "$TYPE" = "sbin" ]; then
Vladimir Olteand6747712018-06-24 20:46:42 +03001440 chmod 755 "${VENDOR_REPO_FILE}"
Steve Kondik48f8df82016-08-14 03:55:08 -07001441 else
Vladimir Olteand6747712018-06-24 20:46:42 +03001442 chmod 644 "${VENDOR_REPO_FILE}"
Steve Kondik48f8df82016-08-14 03:55:08 -07001443 fi
1444 fi
1445
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001446 if [ "${KANG}" = true ]; then
Vladimir Oltean4818c232019-01-17 03:07:34 +02001447 print_spec "${IS_PRODUCT_PACKAGE}" "${SPEC_SRC_FILE}" "${SPEC_DST_FILE}" "${SPEC_ARGS}" "${PRE_FIXUP_HASH}" "${POST_FIXUP_HASH}"
1448 fi
1449
1450 # Check and print whether the fixup pipeline actually did anything.
1451 # This isn't done right after the fixup pipeline because we want this print
1452 # to come after print_spec above, when in kang mode.
1453 if [ "${PRE_FIXUP_HASH}" != "${POST_FIXUP_HASH}" ]; then
1454 printf " + Fixed up %s\n" "${BLOB_DISPLAY_NAME}"
1455 # Now sanity-check the spec for this blob.
1456 if [ "${KANG}" = false ] && [ "${FIXUP_HASH}" = "x" ] && [ "${HASH}" != "x" ]; then
1457 printf "WARNING: The %s file was fixed up, but it is pinned.\n" ${BLOB_DISPLAY_NAME}
1458 printf "This is a mistake and you want to either remove the hash completely, or add an extra one.\n"
1459 fi
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001460 fi
1461
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001462 done
1463
1464 # Don't allow failing
1465 set -e
1466}
Louis Popia516c2f2016-07-25 15:51:13 +02001467
1468#
1469# extract_firmware:
1470#
1471# $1: file containing the list of items to extract
1472# $2: path to extracted radio folder
1473#
1474function extract_firmware() {
1475 if [ -z "$OUTDIR" ]; then
1476 echo "Output dir not set!"
1477 exit 1
1478 fi
1479
1480 parse_file_list "$1"
1481
1482 # Don't allow failing
1483 set -e
1484
1485 local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} )
1486 local COUNT=${#FILELIST[@]}
1487 local SRC="$2"
Luca Stefani5c60e4f2017-08-17 19:28:48 +02001488 local OUTPUT_DIR="$LINEAGE_ROOT"/"$OUTDIR"/radio
Louis Popia516c2f2016-07-25 15:51:13 +02001489
1490 if [ "$VENDOR_RADIO_STATE" -eq "0" ]; then
1491 echo "Cleaning firmware output directory ($OUTPUT_DIR).."
1492 rm -rf "${OUTPUT_DIR:?}/"*
1493 VENDOR_RADIO_STATE=1
1494 fi
1495
1496 echo "Extracting $COUNT files in $1 from $SRC:"
1497
1498 for (( i=1; i<COUNT+1; i++ )); do
1499 local FILE="${FILELIST[$i-1]}"
1500 printf ' - %s \n' "/radio/$FILE"
1501
1502 if [ ! -d "$OUTPUT_DIR" ]; then
1503 mkdir -p "$OUTPUT_DIR"
1504 fi
1505 cp "$SRC/$FILE" "$OUTPUT_DIR/$FILE"
1506 chmod 644 "$OUTPUT_DIR/$FILE"
1507 done
1508}
Rashed Abdel-Tawab1c29c372019-03-29 20:07:25 -07001509
1510function extract_img_data() {
1511 local image_file="$1"
1512 local out_dir="$2"
1513 local logFile="$TMPDIR/debugfs.log"
1514
1515 if [ ! -d "$out_dir" ]; then
1516 mkdir -p "$out_dir"
1517 fi
1518
1519 if [[ "$HOST_OS" == "Darwin" ]]; then
1520 debugfs -R "rdump / \"$out_dir\"" "$image_file" &> "$logFile" || {
1521 echo "[-] Failed to extract data from '$image_file'"
1522 abort 1
1523 }
1524 else
1525 debugfs -R 'ls -p' "$image_file" 2>/dev/null | cut -d '/' -f6 | while read -r entry
1526 do
1527 debugfs -R "rdump \"$entry\" \"$out_dir\"" "$image_file" >> "$logFile" 2>&1 || {
1528 echo "[-] Failed to extract data from '$image_file'"
1529 abort 1
1530 }
1531 done
1532 fi
1533
1534 local symlink_err="rdump: Attempt to read block from filesystem resulted in short read while reading symlink"
1535 if grep -Fq "$symlink_err" "$logFile"; then
1536 echo "[-] Symlinks have not been properly processed from $image_file"
1537 echo "[!] If you don't have a compatible debugfs version, modify 'execute-all.sh' to disable 'USE_DEBUGFS' flag"
1538 abort 1
1539 fi
1540}
1541
1542declare -ra VENDOR_SKIP_FILES=(
1543 "bin/toybox_vendor"
1544 "bin/toolbox"
1545 "bin/grep"
1546 "build.prop"
1547 "compatibility_matrix.xml"
1548 "default.prop"
1549 "etc/NOTICE.xml.gz"
1550 "etc/vintf/compatibility_matrix.xml"
1551 "etc/vintf/manifest.xml"
1552 "etc/wifi/wpa_supplicant.conf"
1553 "manifest.xml"
1554 "overlay/DisplayCutoutEmulationCorner/DisplayCutoutEmulationCornerOverlay.apk"
1555 "overlay/DisplayCutoutEmulationDouble/DisplayCutoutEmulationDoubleOverlay.apk"
1556 "overlay/DisplayCutoutEmulationTall/DisplayCutoutEmulationTallOverlay.apk"
1557 "overlay/DisplayCutoutNoCutout/NoCutoutOverlay.apk"
1558 "overlay/framework-res__auto_generated_rro.apk"
1559 "overlay/SysuiDarkTheme/SysuiDarkThemeOverlay.apk"
1560)
1561
1562function array_contains() {
1563 local element
1564 for element in "${@:2}"; do [[ "$element" == "$1" ]] && return 0; done
1565 return 1
1566}
1567
1568function generate_prop_list_from_image() {
1569 local image_file="$1"
1570 local image_dir="$TMPDIR/image-temp"
1571 local output_list="$2"
1572 local output_list_tmp="$TMPDIR/_proprietary-blobs.txt"
1573 local -n skipped_vendor_files="$3"
1574
1575 extract_img_data "$image_file" "$image_dir"
1576
1577 find "$image_dir" -not -type d | sed "s#^$image_dir/##" | while read -r FILE
1578 do
1579 # Skip VENDOR_SKIP_FILES since it will be re-generated at build time
1580 if array_contains "$FILE" "${VENDOR_SKIP_FILES[@]}"; then
1581 continue
1582 fi
1583 # Skip device defined skipped files since they will be re-generated at build time
1584 if array_contains "$FILE" "${skipped_vendor_files[@]}"; then
1585 continue
1586 fi
1587 if suffix_match_file ".apk" "$FILE" ; then
1588 echo "-vendor/$FILE" >> "$output_list_tmp"
1589 else
1590 echo "vendor/$FILE" >> "$output_list_tmp"
1591 fi
1592 done
1593
1594 # Sort merged file with all lists
1595 sort -u "$output_list_tmp" > "$output_list"
1596
1597 # Clean-up
1598 rm -f "$output_list_tmp"
1599}