blob: 42d00378b2a622d88287895e134081bae564626c [file] [log] [blame]
Steve Kondik4e2aaab2016-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=()
Steve Kondik48f8df82016-08-14 03:55:08 -070019PRODUCT_COPY_FILES_HASHES=()
Vladimir Oltean4818c232019-01-17 03:07:34 +020020PRODUCT_COPY_FILES_FIXUP_HASHES=()
Steve Kondik4e2aaab2016-07-15 10:39:58 -070021PRODUCT_PACKAGES_LIST=()
Steve Kondik48f8df82016-08-14 03:55:08 -070022PRODUCT_PACKAGES_HASHES=()
Vladimir Oltean4818c232019-01-17 03:07:34 +020023PRODUCT_PACKAGES_FIXUP_HASHES=()
Steve Kondik4e2aaab2016-07-15 10:39:58 -070024PACKAGE_LIST=()
25VENDOR_STATE=-1
Louis Popia516c2f2016-07-25 15:51:13 +020026VENDOR_RADIO_STATE=-1
Steve Kondik4e2aaab2016-07-15 10:39:58 -070027COMMON=-1
Luca Stefani7f9fff22016-07-18 13:47:55 +020028ARCHES=
29FULLY_DEODEXED=-1
30
Rashed Abdel-Tawab11186d62017-08-05 23:11:35 -040031TMPDIR=$(mktemp -d)
Steve Kondik4e2aaab2016-07-15 10:39:58 -070032
33#
Steve Kondik48f8df82016-08-14 03:55:08 -070034# cleanup
35#
36# kill our tmpfiles with fire on exit
37#
38function cleanup() {
39 rm -rf "${TMPDIR:?}"
40}
41
Gabriele M6c3c2c02017-10-11 12:55:51 +020042trap cleanup 0
Steve Kondik48f8df82016-08-14 03:55:08 -070043
44#
Steve Kondik4e2aaab2016-07-15 10:39:58 -070045# setup_vendor
46#
47# $1: device name
48# $2: vendor name
Luca Stefani5c60e4f2017-08-17 19:28:48 +020049# $3: Lineage root directory
Steve Kondik4e2aaab2016-07-15 10:39:58 -070050# $4: is common device - optional, default to false
51# $5: cleanup - optional, default to true
Rashed Abdel-Tawab5f173152016-10-01 20:33:00 -040052# $6: custom vendor makefile name - optional, default to false
Steve Kondik4e2aaab2016-07-15 10:39:58 -070053#
54# Must be called before any other functions can be used. This
55# sets up the internal state for a new vendor configuration.
56#
57function setup_vendor() {
58 local DEVICE="$1"
59 if [ -z "$DEVICE" ]; then
60 echo "\$DEVICE must be set before including this script!"
61 exit 1
62 fi
63
64 export VENDOR="$2"
65 if [ -z "$VENDOR" ]; then
66 echo "\$VENDOR must be set before including this script!"
67 exit 1
68 fi
69
Jackeaglecf6f4de2019-09-24 04:07:22 -040070 export BLISS_ROOT="$3"
71 if [ ! -d "$BLISS_ROOT" ]; then
72 echo "\$BLISS_ROOT must be set and valid before including this script!"
Steve Kondik4e2aaab2016-07-15 10:39:58 -070073 exit 1
74 fi
75
76 export OUTDIR=vendor/"$VENDOR"/"$DEVICE"
Jackeaglecf6f4de2019-09-24 04:07:22 -040077 if [ ! -d "$BLISS_ROOT/$OUTDIR" ]; then
78 mkdir -p "$BLISS_ROOT/$OUTDIR"
Steve Kondik4e2aaab2016-07-15 10:39:58 -070079 fi
80
Rashed Abdel-Tawab5f173152016-10-01 20:33:00 -040081 VNDNAME="$6"
82 if [ -z "$VNDNAME" ]; then
83 VNDNAME="$DEVICE"
84 fi
85
Jackeaglecf6f4de2019-09-24 04:07:22 -040086 export PRODUCTMK="$BLISS_ROOT"/"$OUTDIR"/"$VNDNAME"-vendor.mk
Rashed Abdel-Tawab05784b42019-09-20 07:06:09 -070087 export ANDROIDBP="$BLISS_ROOT"/"$OUTDIR"/Android.bp
Jackeaglecf6f4de2019-09-24 04:07:22 -040088 export ANDROIDMK="$BLISS_ROOT"/"$OUTDIR"/Android.mk
89 export BOARDMK="$BLISS_ROOT"/"$OUTDIR"/BoardConfigVendor.mk
Steve Kondik4e2aaab2016-07-15 10:39:58 -070090
91 if [ "$4" == "true" ] || [ "$4" == "1" ]; then
92 COMMON=1
93 else
94 COMMON=0
95 fi
96
Gabriele Mb6effb32017-05-01 18:22:04 +020097 if [ "$5" == "false" ] || [ "$5" == "0" ]; then
Steve Kondik4e2aaab2016-07-15 10:39:58 -070098 VENDOR_STATE=1
Louis Popia516c2f2016-07-25 15:51:13 +020099 VENDOR_RADIO_STATE=1
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700100 else
101 VENDOR_STATE=0
Louis Popia516c2f2016-07-25 15:51:13 +0200102 VENDOR_RADIO_STATE=0
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700103 fi
104}
105
Vladimir Oltean95643282018-06-24 20:22:41 +0300106# Helper functions for parsing a spec.
107# notes: an optional "|SHA1" that may appear in the format is stripped
108# early from the spec in the parse_file_list function, and
109# should not be present inside the input parameter passed
110# to these functions.
111
112#
113# input: spec in the form of "src[:dst][;args]"
114# output: "src"
115#
116function src_file() {
117 local SPEC="$1"
118 local SPLIT=(${SPEC//:/ })
119 local ARGS="$(target_args ${SPEC})"
120 # Regardless of there being a ":" delimiter or not in the spec,
121 # the source file is always either the first, or the only entry.
122 local SRC="${SPLIT[0]}"
123 # Remove target_args suffix, if present
124 echo "${SRC%;${ARGS}}"
125}
126
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700127#
Vladimir Oltean6a7946b2018-06-24 20:09:55 +0300128# input: spec in the form of "src[:dst][;args]"
129# output: "dst" if present, "src" otherwise.
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700130#
131function target_file() {
Vladimir Oltean6a7946b2018-06-24 20:09:55 +0300132 local SPEC="$1"
133 local SPLIT=(${SPEC//:/ })
134 local ARGS="$(target_args ${SPEC})"
135 local DST=
136 case ${#SPLIT[@]} in
137 1)
138 # The spec doesn't have a : delimiter
139 DST="${SPLIT[0]}"
140 ;;
141 *)
142 # The spec actually has a src:dst format
143 DST="${SPLIT[1]}"
144 ;;
145 esac
146 # Remove target_args suffix, if present
147 echo "${DST%;${ARGS}}"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700148}
149
150#
Vladimir Oltean6a7946b2018-06-24 20:09:55 +0300151# input: spec in the form of "src[:dst][;args]"
152# output: "args" if present, "" otherwise.
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700153#
154function target_args() {
Vladimir Oltean6a7946b2018-06-24 20:09:55 +0300155 local SPEC="$1"
156 local SPLIT=(${SPEC//;/ })
157 local ARGS=
158 case ${#SPLIT[@]} in
159 1)
160 # No ";" delimiter in the spec.
161 ;;
162 *)
163 # The "args" are whatever comes after the ";" character.
164 # Basically the spec stripped of whatever is to the left of ";".
165 ARGS="${SPEC#${SPLIT[0]};}"
166 ;;
167 esac
168 echo "${ARGS}"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700169}
170
171#
172# prefix_match:
173#
Vladimir Oltean2654eaa2018-06-12 01:17:35 +0300174# input:
175# - $1: prefix
176# - (global variable) PRODUCT_PACKAGES_LIST: array of [src:]dst[;args] specs.
177# output:
178# - new array consisting of dst[;args] entries where $1 is a prefix of ${dst}.
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700179#
180function prefix_match() {
181 local PREFIX="$1"
Vladimir Olteana48b9fe2018-04-02 22:37:09 +0300182 for LINE in "${PRODUCT_PACKAGES_LIST[@]}"; do
183 local FILE=$(target_file "$LINE")
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700184 if [[ "$FILE" =~ ^"$PREFIX" ]]; then
Vladimir Oltean2654eaa2018-06-12 01:17:35 +0300185 local ARGS=$(target_args "$LINE")
186 if [ -z "${ARGS}" ]; then
187 echo "${FILE#$PREFIX}"
188 else
189 echo "${FILE#$PREFIX};${ARGS}"
190 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700191 fi
192 done
193}
194
195#
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400196# prefix_match_file:
197#
198# $1: the prefix to match on
199# $2: the file to match the prefix for
200#
201# Internal function which returns true if a filename contains the
202# specified prefix.
203#
204function prefix_match_file() {
205 local PREFIX="$1"
206 local FILE="$2"
207 if [[ "$FILE" =~ ^"$PREFIX" ]]; then
208 return 0
209 else
210 return 1
211 fi
212}
213
214#
Rashed Abdel-Tawab1c29c372019-03-29 20:07:25 -0700215# suffix_match_file:
216#
217# $1: the suffix to match on
218# $2: the file to match the suffix for
219#
220# Internal function which returns true if a filename contains the
221# specified suffix.
222#
223function suffix_match_file() {
224 local SUFFIX="$1"
225 local FILE="$2"
226 if [[ "$FILE" = *"$SUFFIX" ]]; then
227 return 0
228 else
229 return 1
230 fi
231}
232
233#
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400234# truncate_file
235#
236# $1: the filename to truncate
237# $2: the argument to output the truncated filename to
238#
239# Internal function which truncates a filename by removing the first dir
240# in the path. ex. vendor/lib/libsdmextension.so -> lib/libsdmextension.so
241#
242function truncate_file() {
243 local FILE="$1"
244 RETURN_FILE="$2"
245 local FIND="${FILE%%/*}"
246 local LOCATION="${#FIND}+1"
247 echo ${FILE:$LOCATION}
248}
249
250#
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700251# write_product_copy_files:
252#
Rashed Abdel-Tawab1370f192019-09-28 23:37:36 -0400253# $1: make treble compatible makefile - optional and deprecated, default to true
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400254#
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700255# Creates the PRODUCT_COPY_FILES section in the product makefile for all
256# items in the list which do not start with a dash (-).
257#
258function write_product_copy_files() {
259 local COUNT=${#PRODUCT_COPY_FILES_LIST[@]}
260 local TARGET=
261 local FILE=
262 local LINEEND=
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400263 local TREBLE_COMPAT=$1
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700264
265 if [ "$COUNT" -eq "0" ]; then
266 return 0
267 fi
268
269 printf '%s\n' "PRODUCT_COPY_FILES += \\" >> "$PRODUCTMK"
270 for (( i=1; i<COUNT+1; i++ )); do
271 FILE="${PRODUCT_COPY_FILES_LIST[$i-1]}"
272 LINEEND=" \\"
273 if [ "$i" -eq "$COUNT" ]; then
274 LINEEND=""
275 fi
276
Vladimir Oltean6a7946b2018-06-24 20:09:55 +0300277 TARGET=$(target_file "$FILE")
Rashed Abdel-Tawabb2f042d2019-10-05 00:09:41 -0400278 if prefix_match_file "product/" $TARGET ; then
Rashed Abdel-Tawab1370f192019-09-28 23:37:36 -0400279 local OUTTARGET=$(truncate_file $TARGET)
Rashed Abdel-Tawabb2f042d2019-10-05 00:09:41 -0400280 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s%s\n' \
Rashed Abdel-Tawab1370f192019-09-28 23:37:36 -0400281 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Rashed Abdel-Tawabb2f042d2019-10-05 00:09:41 -0400282 elif prefix_match_file "system/product/" $TARGET ; then
Rashed Abdel-Tawab1370f192019-09-28 23:37:36 -0400283 local OUTTARGET=$(truncate_file $TARGET)
284 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s%s\n' \
285 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
286 elif prefix_match_file "odm/" $TARGET ; then
287 local OUTTARGET=$(truncate_file $TARGET)
288 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \
289 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Rashed Abdel-Tawabb2f042d2019-10-05 00:09:41 -0400290 elif prefix_match_file "vendor/odm/" $TARGET ; then
291 local OUTTARGET=$(truncate_file $TARGET)
292 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \
293 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
294 elif prefix_match_file "system/vendor/odm/" $TARGET ; then
295 local OUTTARGET=$(truncate_file $TARGET)
296 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \
297 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
298 elif prefix_match_file "vendor/" $TARGET ; then
299 local OUTTARGET=$(truncate_file $TARGET)
300 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR)/%s%s\n' \
301 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
302 elif prefix_match_file "system/vendor/" $TARGET ; then
303 local OUTTARGET=$(truncate_file $TARGET)
304 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR)/%s%s\n' \
305 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Rashed Abdel-Tawab1370f192019-09-28 23:37:36 -0400306 elif prefix_match_file "system/" $TARGET ; then
307 local OUTTARGET=$(truncate_file $TARGET)
308 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM)/%s%s\n' \
309 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400310 else
Rashed Abdel-Tawab1370f192019-09-28 23:37:36 -0400311 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM)/%s%s\n' \
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400312 "$OUTDIR" "$TARGET" "$TARGET" "$LINEEND" >> "$PRODUCTMK"
313 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700314 done
315 return 0
316}
317
318#
319# write_packages:
320#
321# $1: The LOCAL_MODULE_CLASS for the given module list
Rashed Abdel-Tawab1370f192019-09-28 23:37:36 -0400322# $2: /system, /odm, /product, or /vendor partition
Steve Kondika991cf12016-07-28 12:13:12 -0700323# $3: type-specific extra flags
324# $4: Name of the array holding the target list
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700325#
326# Internal function which writes out the BUILD_PREBUILT stanzas
327# for all modules in the list. This is called by write_product_packages
328# after the modules are categorized.
329#
330function write_packages() {
331
332 local CLASS="$1"
razorlovesb5c2c962019-07-29 02:21:34 -0500333 local PARTITION="$2"
Steve Kondika991cf12016-07-28 12:13:12 -0700334 local EXTRA="$3"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700335
336 # Yes, this is a horrible hack - we create a new array using indirection
Steve Kondika991cf12016-07-28 12:13:12 -0700337 local ARR_NAME="$4[@]"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700338 local FILELIST=("${!ARR_NAME}")
339
340 local FILE=
341 local ARGS=
342 local BASENAME=
343 local EXTENSION=
344 local PKGNAME=
345 local SRC=
346
347 for P in "${FILELIST[@]}"; do
Vladimir Oltean6a7946b2018-06-24 20:09:55 +0300348 FILE=$(target_file "$P")
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700349 ARGS=$(target_args "$P")
350
351 BASENAME=$(basename "$FILE")
M1cha15f226c2017-01-04 09:00:11 +0100352 DIRNAME=$(dirname "$FILE")
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700353 EXTENSION=${BASENAME##*.}
354 PKGNAME=${BASENAME%.*}
355
356 # Add to final package list
357 PACKAGE_LIST+=("$PKGNAME")
358
359 SRC="proprietary"
Rashed Abdel-Tawab1370f192019-09-28 23:37:36 -0400360 if [ "$PARTITION" = "system" ]; then
361 SRC+="/system"
362 elif [ "$PARTITION" = "vendor" ]; then
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700363 SRC+="/vendor"
razorlovesb5c2c962019-07-29 02:21:34 -0500364 elif [ "$PARTITION" = "product" ]; then
365 SRC+="/product"
Rashed Abdel-Tawab8c3c95f2019-09-20 07:32:39 -0700366 elif [ "$PARTITION" = "odm" ]; then
367 SRC+="/odm"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700368 fi
369
370 printf 'include $(CLEAR_VARS)\n'
371 printf 'LOCAL_MODULE := %s\n' "$PKGNAME"
372 printf 'LOCAL_MODULE_OWNER := %s\n' "$VENDOR"
373 if [ "$CLASS" = "SHARED_LIBRARIES" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -0700374 if [ "$EXTRA" = "both" ]; then
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700375 printf 'LOCAL_SRC_FILES_64 := %s/lib64/%s\n' "$SRC" "$FILE"
376 printf 'LOCAL_SRC_FILES_32 := %s/lib/%s\n' "$SRC" "$FILE"
377 #if [ "$VENDOR_PKG" = "true" ]; then
378 # echo "LOCAL_MODULE_PATH_64 := \$(TARGET_OUT_VENDOR_SHARED_LIBRARIES)"
379 # echo "LOCAL_MODULE_PATH_32 := \$(2ND_TARGET_OUT_VENDOR_SHARED_LIBRARIES)"
380 #else
381 # echo "LOCAL_MODULE_PATH_64 := \$(TARGET_OUT_SHARED_LIBRARIES)"
382 # echo "LOCAL_MODULE_PATH_32 := \$(2ND_TARGET_OUT_SHARED_LIBRARIES)"
383 #fi
Steve Kondika991cf12016-07-28 12:13:12 -0700384 elif [ "$EXTRA" = "64" ]; then
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700385 printf 'LOCAL_SRC_FILES := %s/lib64/%s\n' "$SRC" "$FILE"
386 else
387 printf 'LOCAL_SRC_FILES := %s/lib/%s\n' "$SRC" "$FILE"
388 fi
Steve Kondik03ce4002016-07-29 00:00:16 -0700389 if [ "$EXTRA" != "none" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -0700390 printf 'LOCAL_MULTILIB := %s\n' "$EXTRA"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700391 fi
392 elif [ "$CLASS" = "APPS" ]; then
Michael Bestas3f9b94c2018-01-25 21:05:36 +0200393 if [ "$EXTRA" = "priv-app" ]; then
394 SRC="$SRC/priv-app"
395 else
396 SRC="$SRC/app"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700397 fi
398 printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE"
399 local CERT=platform
400 if [ ! -z "$ARGS" ]; then
401 CERT="$ARGS"
402 fi
403 printf 'LOCAL_CERTIFICATE := %s\n' "$CERT"
404 elif [ "$CLASS" = "JAVA_LIBRARIES" ]; then
405 printf 'LOCAL_SRC_FILES := %s/framework/%s\n' "$SRC" "$FILE"
Elektroschmock082e0ec2016-10-04 21:11:43 +0200406 local CERT=platform
407 if [ ! -z "$ARGS" ]; then
408 CERT="$ARGS"
409 fi
410 printf 'LOCAL_CERTIFICATE := %s\n' "$CERT"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700411 elif [ "$CLASS" = "ETC" ]; then
412 printf 'LOCAL_SRC_FILES := %s/etc/%s\n' "$SRC" "$FILE"
413 elif [ "$CLASS" = "EXECUTABLES" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -0700414 if [ "$ARGS" = "rootfs" ]; then
415 SRC="$SRC/rootfs"
416 if [ "$EXTRA" = "sbin" ]; then
417 SRC="$SRC/sbin"
418 printf '%s\n' "LOCAL_MODULE_PATH := \$(TARGET_ROOT_OUT_SBIN)"
419 printf '%s\n' "LOCAL_UNSTRIPPED_PATH := \$(TARGET_ROOT_OUT_SBIN_UNSTRIPPED)"
420 fi
421 else
422 SRC="$SRC/bin"
423 fi
424 printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE"
425 unset EXTENSION
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700426 else
Steve Kondika991cf12016-07-28 12:13:12 -0700427 printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700428 fi
429 printf 'LOCAL_MODULE_TAGS := optional\n'
430 printf 'LOCAL_MODULE_CLASS := %s\n' "$CLASS"
Hashbang1733b3a0e12016-08-28 20:38:45 -0400431 if [ "$CLASS" = "APPS" ]; then
432 printf 'LOCAL_DEX_PREOPT := false\n'
433 fi
Steve Kondika991cf12016-07-28 12:13:12 -0700434 if [ ! -z "$EXTENSION" ]; then
435 printf 'LOCAL_MODULE_SUFFIX := .%s\n' "$EXTENSION"
436 fi
M1cha15f226c2017-01-04 09:00:11 +0100437 if [ "$CLASS" = "SHARED_LIBRARIES" ] || [ "$CLASS" = "EXECUTABLES" ]; then
438 if [ "$DIRNAME" != "." ]; then
439 printf 'LOCAL_MODULE_RELATIVE_PATH := %s\n' "$DIRNAME"
440 fi
441 fi
Steve Kondika991cf12016-07-28 12:13:12 -0700442 if [ "$EXTRA" = "priv-app" ]; then
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700443 printf 'LOCAL_PRIVILEGED_MODULE := true\n'
444 fi
razorlovesb5c2c962019-07-29 02:21:34 -0500445 if [ "$PARTITION" = "vendor" ]; then
Ethan Chen5bc3c842018-02-17 20:03:54 -0800446 printf 'LOCAL_VENDOR_MODULE := true\n'
razorlovesb5c2c962019-07-29 02:21:34 -0500447 elif [ "$PARTITION" = "product" ]; then
448 printf 'LOCAL_PRODUCT_MODULE := true\n'
Rashed Abdel-Tawab8c3c95f2019-09-20 07:32:39 -0700449 elif [ "$PARTITION" = "odm" ]; then
450 printf 'LOCAL_ODM_MODULE := true\n'
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700451 fi
452 printf 'include $(BUILD_PREBUILT)\n\n'
453 done
454}
455
456#
457# write_product_packages:
458#
Rashed Abdel-Tawab05784b42019-09-20 07:06:09 -0700459# This function will create prebuilt entries in the
460# Android.bp and associated PRODUCT_PACKAGES list in the
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700461# product makefile for all files in the blob list which
462# start with a single dash (-) character.
463#
464function write_product_packages() {
465 PACKAGE_LIST=()
466
467 local COUNT=${#PRODUCT_PACKAGES_LIST[@]}
468
469 if [ "$COUNT" = "0" ]; then
470 return 0
471 fi
472
473 # Figure out what's 32-bit, what's 64-bit, and what's multilib
474 # I really should not be doing this in bash due to shitty array passing :(
475 local T_LIB32=( $(prefix_match "lib/") )
476 local T_LIB64=( $(prefix_match "lib64/") )
477 local MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${T_LIB64[@]}")) )
478 local LIB32=( $(comm -23 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${MULTILIBS[@]}")) )
Steve Kondik60ef86d2016-07-20 20:03:40 -0700479 local LIB64=( $(comm -23 <(printf '%s\n' "${T_LIB64[@]}") <(printf '%s\n' "${MULTILIBS[@]}")) )
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700480
Steve Kondik03ce4002016-07-29 00:00:16 -0700481 if [ "${#MULTILIBS[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500482 write_packages "SHARED_LIBRARIES" "" "both" "MULTILIBS" >> "$ANDROIDMK"
Steve Kondik03ce4002016-07-29 00:00:16 -0700483 fi
484 if [ "${#LIB32[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500485 write_packages "SHARED_LIBRARIES" "" "32" "LIB32" >> "$ANDROIDMK"
Steve Kondik03ce4002016-07-29 00:00:16 -0700486 fi
487 if [ "${#LIB64[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500488 write_packages "SHARED_LIBRARIES" "" "64" "LIB64" >> "$ANDROIDMK"
Steve Kondik03ce4002016-07-29 00:00:16 -0700489 fi
490
Rashed Abdel-Tawab1370f192019-09-28 23:37:36 -0400491 local T_S_LIB32=( $(prefix_match "system/lib/") )
492 local T_S_LIB64=( $(prefix_match "system/lib64/") )
493 local S_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_S_LIB32[@]}") <(printf '%s\n' "${T_S_LIB64[@]}")) )
494 local S_LIB32=( $(comm -23 <(printf '%s\n' "${T_S_LIB32[@]}") <(printf '%s\n' "${S_MULTILIBS[@]}")) )
495 local S_LIB64=( $(comm -23 <(printf '%s\n' "${T_S_LIB64[@]}") <(printf '%s\n' "${S_MULTILIBS[@]}")) )
496
497 if [ "${#S_MULTILIBS[@]}" -gt "0" ]; then
498 write_packages "SHARED_LIBRARIES" "system" "both" "S_MULTILIBS" >> "$ANDROIDMK"
499 fi
500 if [ "${#S_LIB32[@]}" -gt "0" ]; then
501 write_packages "SHARED_LIBRARIES" "system" "32" "S_LIB32" >> "$ANDROIDMK"
502 fi
503 if [ "${#S_LIB64[@]}" -gt "0" ]; then
504 write_packages "SHARED_LIBRARIES" "system" "64" "S_LIB64" >> "$ANDROIDMK"
505 fi
506
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700507 local T_V_LIB32=( $(prefix_match "vendor/lib/") )
508 local T_V_LIB64=( $(prefix_match "vendor/lib64/") )
509 local V_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${T_V_LIB64[@]}")) )
510 local V_LIB32=( $(comm -23 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${V_MULTILIBS[@]}")) )
Steve Kondik60ef86d2016-07-20 20:03:40 -0700511 local V_LIB64=( $(comm -23 <(printf '%s\n' "${T_V_LIB64[@]}") <(printf '%s\n' "${V_MULTILIBS[@]}")) )
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700512
513 if [ "${#V_MULTILIBS[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500514 write_packages "SHARED_LIBRARIES" "vendor" "both" "V_MULTILIBS" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700515 fi
516 if [ "${#V_LIB32[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500517 write_packages "SHARED_LIBRARIES" "vendor" "32" "V_LIB32" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700518 fi
519 if [ "${#V_LIB64[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500520 write_packages "SHARED_LIBRARIES" "vendor" "64" "V_LIB64" >> "$ANDROIDMK"
521 fi
522
523 local T_P_LIB32=( $(prefix_match "product/lib/") )
524 local T_P_LIB64=( $(prefix_match "product/lib64/") )
525 local P_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_P_LIB32[@]}") <(printf '%s\n' "${T_P_LIB64[@]}")) )
526 local P_LIB32=( $(comm -23 <(printf '%s\n' "${T_P_LIB32[@]}") <(printf '%s\n' "${P_MULTILIBS[@]}")) )
527 local P_LIB64=( $(comm -23 <(printf '%s\n' "${T_P_LIB64[@]}") <(printf '%s\n' "${P_MULTILIBS[@]}")) )
528
529 if [ "${#P_MULTILIBS[@]}" -gt "0" ]; then
530 write_packages "SHARED_LIBRARIES" "product" "both" "P_MULTILIBS" >> "$ANDROIDMK"
531 fi
532 if [ "${#P_LIB32[@]}" -gt "0" ]; then
533 write_packages "SHARED_LIBRARIES" "product" "32" "P_LIB32" >> "$ANDROIDMK"
534 fi
535 if [ "${#P_LIB64[@]}" -gt "0" ]; then
536 write_packages "SHARED_LIBRARIES" "product" "64" "P_LIB64" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700537 fi
538
Rashed Abdel-Tawab8c3c95f2019-09-20 07:32:39 -0700539 local T_O_LIB32=( $(prefix_match "odm/lib/") )
540 local T_O_LIB64=( $(prefix_match "odm/lib64/") )
541 local O_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_O_LIB32[@]}") <(printf '%s\n' "${T_O_LIB64[@]}")) )
542 local O_LIB32=( $(comm -23 <(printf '%s\n' "${T_O_LIB32[@]}") <(printf '%s\n' "${O_MULTILIBS[@]}")) )
543 local O_LIB64=( $(comm -23 <(printf '%s\n' "${T_O_LIB64[@]}") <(printf '%s\n' "${O_MULTILIBS[@]}")) )
544
545 if [ "${#O_MULTILIBS[@]}" -gt "0" ]; then
546 write_packages "SHARED_LIBRARIES" "odm" "both" "O_MULTILIBS" >> "$ANDROIDMK"
547 fi
548 if [ "${#O_LIB32[@]}" -gt "0" ]; then
549 write_packages "SHARED_LIBRARIES" "odm" "32" "O_LIB32" >> "$ANDROIDMK"
550 fi
551 if [ "${#O_LIB64[@]}" -gt "0" ]; then
552 write_packages "SHARED_LIBRARIES" "odm" "64" "O_LIB64" >> "$ANDROIDMK"
553 fi
554
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700555 # Apps
556 local APPS=( $(prefix_match "app/") )
557 if [ "${#APPS[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500558 write_packages "APPS" "" "" "APPS" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700559 fi
560 local PRIV_APPS=( $(prefix_match "priv-app/") )
561 if [ "${#PRIV_APPS[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500562 write_packages "APPS" "" "priv-app" "PRIV_APPS" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700563 fi
Rashed Abdel-Tawab1370f192019-09-28 23:37:36 -0400564 local S_APPS=( $(prefix_match "system/app/") )
565 if [ "${#S_APPS[@]}" -gt "0" ]; then
566 write_packages "APPS" "system" "" "S_APPS" >> "$ANDROIDMK"
567 fi
568 local S_PRIV_APPS=( $(prefix_match "system/priv-app/") )
569 if [ "${#S_PRIV_APPS[@]}" -gt "0" ]; then
570 write_packages "APPS" "system" "priv-app" "S_PRIV_APPS" >> "$ANDROIDMK"
571 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700572 local V_APPS=( $(prefix_match "vendor/app/") )
573 if [ "${#V_APPS[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500574 write_packages "APPS" "vendor" "" "V_APPS" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700575 fi
576 local V_PRIV_APPS=( $(prefix_match "vendor/priv-app/") )
577 if [ "${#V_PRIV_APPS[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500578 write_packages "APPS" "vendor" "priv-app" "V_PRIV_APPS" >> "$ANDROIDMK"
579 fi
580 local P_APPS=( $(prefix_match "product/app/") )
581 if [ "${#P_APPS[@]}" -gt "0" ]; then
582 write_packages "APPS" "product" "" "P_APPS" >> "$ANDROIDMK"
583 fi
584 local P_PRIV_APPS=( $(prefix_match "product/priv-app/") )
585 if [ "${#P_PRIV_APPS[@]}" -gt "0" ]; then
586 write_packages "APPS" "product" "priv-app" "P_PRIV_APPS" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700587 fi
Rashed Abdel-Tawab8c3c95f2019-09-20 07:32:39 -0700588 local O_APPS=( $(prefix_match "odm/app/") )
589 if [ "${#O_APPS[@]}" -gt "0" ]; then
590 write_packages "APPS" "odm" "" "O_APPS" >> "$ANDROIDMK"
591 fi
592 local O_PRIV_APPS=( $(prefix_match "odm/priv-app/") )
593 if [ "${#O_PRIV_APPS[@]}" -gt "0" ]; then
594 write_packages "APPS" "odm" "priv-app" "O_PRIV_APPS" >> "$ANDROIDMK"
595 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700596
597 # Framework
598 local FRAMEWORK=( $(prefix_match "framework/") )
599 if [ "${#FRAMEWORK[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500600 write_packages "JAVA_LIBRARIES" "" "" "FRAMEWORK" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700601 fi
Rashed Abdel-Tawab1370f192019-09-28 23:37:36 -0400602 local S_FRAMEWORK=( $(prefix_match "system/framework/") )
603 if [ "${#S_FRAMEWORK[@]}" -gt "0" ]; then
604 write_packages "JAVA_LIBRARIES" "system" "" "S_FRAMEWORK" >> "$ANDROIDMK"
605 fi
Christian Oderc16f3272017-10-08 23:15:52 +0200606 local V_FRAMEWORK=( $(prefix_match "vendor/framework/") )
Michael Bestasa3f97c72018-02-27 22:31:55 +0200607 if [ "${#V_FRAMEWORK[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500608 write_packages "JAVA_LIBRARIES" "vendor" "" "V_FRAMEWORK" >> "$ANDROIDMK"
609 fi
610 local P_FRAMEWORK=( $(prefix_match "product/framework/") )
611 if [ "${#P_FRAMEWORK[@]}" -gt "0" ]; then
612 write_packages "JAVA_LIBRARIES" "product" "" "P_FRAMEWORK" >> "$ANDROIDMK"
Christian Oderc16f3272017-10-08 23:15:52 +0200613 fi
Rashed Abdel-Tawab8c3c95f2019-09-20 07:32:39 -0700614 local O_FRAMEWORK=( $(prefix_match "odm/framework/") )
615 if [ "${#O_FRAMEWORK[@]}" -gt "0" ]; then
616 write_packages "JAVA_LIBRARIES" "odm" "" "O_FRAMEWORK" >> "$ANDROIDMK"
617 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700618
619 # Etc
620 local ETC=( $(prefix_match "etc/") )
621 if [ "${#ETC[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500622 write_packages "ETC" "" "" "ETC" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700623 fi
Rashed Abdel-Tawab1370f192019-09-28 23:37:36 -0400624 local S_ETC=( $(prefix_match "system/etc/") )
625 if [ "${#ETC[@]}" -gt "0" ]; then
626 write_packages "ETC" "system" "" "S_ETC" >> "$ANDROIDMK"
627 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700628 local V_ETC=( $(prefix_match "vendor/etc/") )
629 if [ "${#V_ETC[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500630 write_packages "ETC" "vendor" "" "V_ETC" >> "$ANDROIDMK"
631 fi
632 local P_ETC=( $(prefix_match "product/etc/") )
633 if [ "${#P_ETC[@]}" -gt "0" ]; then
634 write_packages "ETC" "product" "" "P_ETC" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700635 fi
Rashed Abdel-Tawab8c3c95f2019-09-20 07:32:39 -0700636 local O_ETC=( $(prefix_match "odm/etc/") )
637 if [ "${#O_ETC[@]}" -gt "0" ]; then
638 write_packages "ETC" "odm" "" "O_ETC" >> "$ANDROIDMK"
639 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700640
641 # Executables
642 local BIN=( $(prefix_match "bin/") )
643 if [ "${#BIN[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500644 write_packages "EXECUTABLES" "" "" "BIN" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700645 fi
Rashed Abdel-Tawab1370f192019-09-28 23:37:36 -0400646 local S_BIN=( $(prefix_match "system/bin/") )
647 if [ "${#BIN[@]}" -gt "0" ]; then
648 write_packages "EXECUTABLES" "system" "" "S_BIN" >> "$ANDROIDMK"
649 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700650 local V_BIN=( $(prefix_match "vendor/bin/") )
651 if [ "${#V_BIN[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500652 write_packages "EXECUTABLES" "vendor" "" "V_BIN" >> "$ANDROIDMK"
653 fi
654 local P_BIN=( $(prefix_match "product/bin/") )
655 if [ "${#P_BIN[@]}" -gt "0" ]; then
656 write_packages "EXECUTABLES" "product" "" "P_BIN" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700657 fi
Rashed Abdel-Tawab8c3c95f2019-09-20 07:32:39 -0700658 local O_BIN=( $(prefix_match "odm/bin/") )
659 if [ "${#O_BIN[@]}" -gt "0" ]; then
660 write_packages "EXECUTABLES" "odm" "" "O_BIN" >> "$ANDROIDMK"
661 fi
Steve Kondika991cf12016-07-28 12:13:12 -0700662 local SBIN=( $(prefix_match "sbin/") )
663 if [ "${#SBIN[@]}" -gt "0" ]; then
razorlovesb5c2c962019-07-29 02:21:34 -0500664 write_packages "EXECUTABLES" "" "sbin" "SBIN" >> "$ANDROIDMK"
Steve Kondika991cf12016-07-28 12:13:12 -0700665 fi
666
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700667
668 # Actually write out the final PRODUCT_PACKAGES list
669 local PACKAGE_COUNT=${#PACKAGE_LIST[@]}
670
671 if [ "$PACKAGE_COUNT" -eq "0" ]; then
672 return 0
673 fi
674
675 printf '\n%s\n' "PRODUCT_PACKAGES += \\" >> "$PRODUCTMK"
676 for (( i=1; i<PACKAGE_COUNT+1; i++ )); do
677 local LINEEND=" \\"
678 if [ "$i" -eq "$PACKAGE_COUNT" ]; then
679 LINEEND=""
680 fi
681 printf ' %s%s\n' "${PACKAGE_LIST[$i-1]}" "$LINEEND" >> "$PRODUCTMK"
682 done
683}
684
685#
Rashed Abdel-Tawab05784b42019-09-20 07:06:09 -0700686# write_blueprint_header:
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700687#
688# $1: file which will be written to
689#
690# writes out the copyright header with the current year.
691# note that this is not an append operation, and should
692# be executed first!
693#
Rashed Abdel-Tawab05784b42019-09-20 07:06:09 -0700694function write_blueprint_header() {
695 if [ -f $1 ]; then
696 rm $1
697 fi
698
699 YEAR=$(date +"%Y")
700
701 [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON"
702
703 printf "/**\n" > $1
704 NUM_REGEX='^[0-9]+$'
705 if [[ ! $INITIAL_COPYRIGHT_YEAR =~ $NUM_REGEX ]] || [ $INITIAL_COPYRIGHT_YEAR -lt 2019 ]; then
706 BLUEPRINT_INITIAL_COPYRIGHT_YEAR=2019
707 else
708 BLUEPRINT_INITIAL_COPYRIGHT_YEAR=$INITIAL_COPYRIGHT_YEAR
709 fi
710
711 if [ $BLUEPRINT_INITIAL_COPYRIGHT_YEAR -eq $YEAR ]; then
712 printf " * Copyright (C) $YEAR The LineageOS Project\n" >> $1
713 elif [ $BLUEPRINT_INITIAL_COPYRIGHT_YEAR -le 2019 ]; then
714 printf " * Copyright (C) 2019-$YEAR The LineageOS Project\n" >> $1
715 else
716 printf " * Copyright (C) $BLUEPRINT_INITIAL_COPYRIGHT_YEAR-$YEAR The LineageOS Project\n" >> $1
717 fi
718
719 cat << EOF >> $1
720 *
721 * Licensed under the Apache License, Version 2.0 (the "License");
722 * you may not use this file except in compliance with the License.
723 * You may obtain a copy of the License at
724 *
725 * http://www.apache.org/licenses/LICENSE-2.0
726 *
727 * Unless required by applicable law or agreed to in writing, software
728 * distributed under the License is distributed on an "AS IS" BASIS,
729 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
730 * See the License for the specific language governing permissions and
731 * limitations under the License.
732 *
733 * This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh
734 */
735
736EOF
737}
738
739#
740# write_makefile_header:
741#
742# $1: file which will be written to
743#
744# writes out the copyright header with the current year.
745# note that this is not an append operation, and should
746# be executed first!
747#
748function write_makefile_header() {
Matt Mower8945f5e2017-01-07 14:08:17 -0600749 if [ -f $1 ]; then
750 rm $1
751 fi
752
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700753 YEAR=$(date +"%Y")
754
755 [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON"
756
Matt Mower8945f5e2017-01-07 14:08:17 -0600757 NUM_REGEX='^[0-9]+$'
758 if [[ $INITIAL_COPYRIGHT_YEAR =~ $NUM_REGEX ]] && [ $INITIAL_COPYRIGHT_YEAR -le $YEAR ]; then
759 if [ $INITIAL_COPYRIGHT_YEAR -lt 2016 ]; then
760 printf "# Copyright (C) $INITIAL_COPYRIGHT_YEAR-2016 The CyanogenMod Project\n" > $1
761 elif [ $INITIAL_COPYRIGHT_YEAR -eq 2016 ]; then
762 printf "# Copyright (C) 2016 The CyanogenMod Project\n" > $1
763 fi
764 if [ $YEAR -eq 2017 ]; then
765 printf "# Copyright (C) 2017 The LineageOS Project\n" >> $1
766 elif [ $INITIAL_COPYRIGHT_YEAR -eq $YEAR ]; then
767 printf "# Copyright (C) $YEAR The LineageOS Project\n" >> $1
768 elif [ $INITIAL_COPYRIGHT_YEAR -le 2017 ]; then
769 printf "# Copyright (C) 2017-$YEAR The LineageOS Project\n" >> $1
770 else
771 printf "# Copyright (C) $INITIAL_COPYRIGHT_YEAR-$YEAR The LineageOS Project\n" >> $1
772 fi
773 else
774 printf "# Copyright (C) $YEAR The LineageOS Project\n" > $1
775 fi
776
777 cat << EOF >> $1
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700778#
779# Licensed under the Apache License, Version 2.0 (the "License");
780# you may not use this file except in compliance with the License.
781# You may obtain a copy of the License at
782#
783# http://www.apache.org/licenses/LICENSE-2.0
784#
785# Unless required by applicable law or agreed to in writing, software
786# distributed under the License is distributed on an "AS IS" BASIS,
787# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
788# See the License for the specific language governing permissions and
789# limitations under the License.
790
791# This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh
792
793EOF
794}
795
796#
797# write_headers:
798#
799# $1: devices falling under common to be added to guard - optional
Rashed Abdel-Tawabd53bff12016-10-02 01:00:54 -0400800# $2: custom guard - optional
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700801#
Rashed Abdel-Tawab05784b42019-09-20 07:06:09 -0700802# Calls write_makefile_header for each of the makefiles and
803# write_blueprint_header for Android.bp and creates the initial
804# path declaration and device guard for the Android.mk
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700805#
806function write_headers() {
Rashed Abdel-Tawab05784b42019-09-20 07:06:09 -0700807 write_makefile_header "$ANDROIDMK"
Rashed Abdel-Tawabd53bff12016-10-02 01:00:54 -0400808
809 GUARD="$2"
810 if [ -z "$GUARD" ]; then
811 GUARD="TARGET_DEVICE"
812 fi
813
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700814 cat << EOF >> "$ANDROIDMK"
815LOCAL_PATH := \$(call my-dir)
816
817EOF
818 if [ "$COMMON" -ne 1 ]; then
819 cat << EOF >> "$ANDROIDMK"
Rashed Abdel-Tawabd53bff12016-10-02 01:00:54 -0400820ifeq (\$($GUARD),$DEVICE)
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700821
822EOF
823 else
824 if [ -z "$1" ]; then
825 echo "Argument with devices to be added to guard must be set!"
826 exit 1
827 fi
828 cat << EOF >> "$ANDROIDMK"
Rashed Abdel-Tawabd53bff12016-10-02 01:00:54 -0400829ifneq (\$(filter $1,\$($GUARD)),)
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700830
831EOF
832 fi
833
Rashed Abdel-Tawab05784b42019-09-20 07:06:09 -0700834 write_makefile_header "$BOARDMK"
835 write_makefile_header "$PRODUCTMK"
836 write_blueprint_header "$ANDROIDBP"
837
838 cat << EOF >> "$ANDROIDBP"
839soong_namespace {
840}
841
842EOF
843
844 [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON"
845 cat << EOF >> "$PRODUCTMK"
846PRODUCT_SOONG_NAMESPACES += \\
847 vendor/$VENDOR/$DEVICE
848
849EOF
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700850}
851
852#
853# write_footers:
854#
855# Closes the inital guard and any other finalization tasks. Must
856# be called as the final step.
857#
858function write_footers() {
859 cat << EOF >> "$ANDROIDMK"
860endif
861EOF
862}
863
864# Return success if adb is up and not in recovery
865function _adb_connected {
866 {
Steve Kondik7561d192016-09-01 21:40:27 -0700867 if [[ "$(adb get-state)" == device ]]
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700868 then
869 return 0
870 fi
871 } 2>/dev/null
872
873 return 1
874};
875
876#
Bruno Martins3b96ba52016-07-27 15:00:05 +0100877# parse_file_list:
878#
879# $1: input file
Rashed Abdel-Tawab855fbdd2017-04-04 02:48:18 -0400880# $2: blob section in file - optional
Bruno Martins3b96ba52016-07-27 15:00:05 +0100881#
882# Sets PRODUCT_PACKAGES and PRODUCT_COPY_FILES while parsing the input file
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700883#
884function parse_file_list() {
Bruno Martins3b96ba52016-07-27 15:00:05 +0100885 if [ -z "$1" ]; then
886 echo "An input file is expected!"
887 exit 1
888 elif [ ! -f "$1" ]; then
889 echo "Input file "$1" does not exist!"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700890 exit 1
891 fi
892
Vladimir Olteanc5034462019-01-17 03:04:16 +0200893 if [ -n "$2" ]; then
894 echo "Using section \"$2\""
Rashed Abdel-Tawab855fbdd2017-04-04 02:48:18 -0400895 LIST=$TMPDIR/files.txt
Vladimir Oltean5238ba82019-01-19 00:44:07 +0200896 # Match all lines starting with first line found to start* with '#'
897 # comment and contain** $2, and ending with first line to be empty*.
898 # *whitespaces (tabs, spaces) at the beginning of lines are discarded
899 # **the $2 match is case-insensitive
900 cat $1 | sed -n '/^[[:space:]]*#.*'"$2"'/I,/^[[:space:]]*$/ p' > $LIST
Rashed Abdel-Tawab855fbdd2017-04-04 02:48:18 -0400901 else
902 LIST=$1
903 fi
904
905
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700906 PRODUCT_PACKAGES_LIST=()
Steve Kondik48f8df82016-08-14 03:55:08 -0700907 PRODUCT_PACKAGES_HASHES=()
Vladimir Oltean4818c232019-01-17 03:07:34 +0200908 PRODUCT_PACKAGES_FIXUP_HASHES=()
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700909 PRODUCT_COPY_FILES_LIST=()
Steve Kondik48f8df82016-08-14 03:55:08 -0700910 PRODUCT_COPY_FILES_HASHES=()
Vladimir Oltean4818c232019-01-17 03:07:34 +0200911 PRODUCT_COPY_FILES_FIXUP_HASHES=()
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700912
913 while read -r line; do
914 if [ -z "$line" ]; then continue; fi
915
Steve Kondik48f8df82016-08-14 03:55:08 -0700916 # If the line has a pipe delimiter, a sha1 hash should follow.
917 # This indicates the file should be pinned and not overwritten
918 # when extracting files.
919 local SPLIT=(${line//\|/ })
920 local COUNT=${#SPLIT[@]}
921 local SPEC=${SPLIT[0]}
922 local HASH="x"
Vladimir Oltean4818c232019-01-17 03:07:34 +0200923 local FIXUP_HASH="x"
Steve Kondik48f8df82016-08-14 03:55:08 -0700924 if [ "$COUNT" -gt "1" ]; then
925 HASH=${SPLIT[1]}
926 fi
Vladimir Oltean4818c232019-01-17 03:07:34 +0200927 if [ "$COUNT" -gt "2" ]; then
928 FIXUP_HASH=${SPLIT[2]}
929 fi
Steve Kondik48f8df82016-08-14 03:55:08 -0700930
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700931 # if line starts with a dash, it needs to be packaged
Steve Kondik48f8df82016-08-14 03:55:08 -0700932 if [[ "$SPEC" =~ ^- ]]; then
933 PRODUCT_PACKAGES_LIST+=("${SPEC#-}")
934 PRODUCT_PACKAGES_HASHES+=("$HASH")
Vladimir Oltean4818c232019-01-17 03:07:34 +0200935 PRODUCT_PACKAGES_FIXUP_HASHES+=("$FIXUP_HASH")
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700936 else
Steve Kondik48f8df82016-08-14 03:55:08 -0700937 PRODUCT_COPY_FILES_LIST+=("$SPEC")
938 PRODUCT_COPY_FILES_HASHES+=("$HASH")
Vladimir Oltean4818c232019-01-17 03:07:34 +0200939 PRODUCT_COPY_FILES_FIXUP_HASHES+=("$FIXUP_HASH")
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700940 fi
941
Rashed Abdel-Tawab855fbdd2017-04-04 02:48:18 -0400942 done < <(egrep -v '(^#|^[[:space:]]*$)' "$LIST" | LC_ALL=C sort | uniq)
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700943}
944
945#
946# write_makefiles:
947#
948# $1: file containing the list of items to extract
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400949# $2: make treble compatible makefile - optional
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700950#
951# Calls write_product_copy_files and write_product_packages on
Rashed Abdel-Tawab05784b42019-09-20 07:06:09 -0700952# the given file and appends to the Android.bp as well as
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700953# the product makefile.
954#
955function write_makefiles() {
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700956 parse_file_list "$1"
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400957 write_product_copy_files "$2"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700958 write_product_packages
959}
960
961#
Louis Popia516c2f2016-07-25 15:51:13 +0200962# append_firmware_calls_to_makefiles:
963#
964# Appends to Android.mk the calls to all images present in radio folder
965# (filesmap file used by releasetools to map firmware images should be kept in the device tree)
966#
967function append_firmware_calls_to_makefiles() {
968 cat << EOF >> "$ANDROIDMK"
969ifeq (\$(LOCAL_PATH)/radio, \$(wildcard \$(LOCAL_PATH)/radio))
970
971RADIO_FILES := \$(wildcard \$(LOCAL_PATH)/radio/*)
972\$(foreach f, \$(notdir \$(RADIO_FILES)), \\
973 \$(call add-radio-file,radio/\$(f)))
974\$(call add-radio-file,../../../device/$VENDOR/$DEVICE/radio/filesmap)
975
976endif
977
978EOF
979}
980
981#
Luca Stefani7f9fff22016-07-18 13:47:55 +0200982# get_file:
983#
984# $1: input file
985# $2: target file/folder
986# $3: source of the file (can be "adb" or a local folder)
987#
988# Silently extracts the input file to defined target
989# Returns success if file can be pulled from the device or found locally
990#
991function get_file() {
992 local SRC="$3"
993
994 if [ "$SRC" = "adb" ]; then
995 # try to pull
996 adb pull "$1" "$2" >/dev/null 2>&1 && return 0
997
998 return 1
999 else
1000 # try to copy
Vladimir Olteand5773252018-06-25 00:05:56 +03001001 cp -r "$SRC/$1" "$2" 2>/dev/null && return 0
1002 cp -r "$SRC/${1#/system}" "$2" 2>/dev/null && return 0
Vladimir Oltean78d690d2019-01-06 19:38:31 +02001003 cp -r "$SRC/system/$1" "$2" 2>/dev/null && return 0
Luca Stefani7f9fff22016-07-18 13:47:55 +02001004
1005 return 1
1006 fi
1007};
1008
1009#
1010# oat2dex:
1011#
1012# $1: extracted apk|jar (to check if deodex is required)
1013# $2: odexed apk|jar to deodex
1014# $3: source of the odexed apk|jar
1015#
1016# Convert apk|jar .odex in the corresposing classes.dex
1017#
1018function oat2dex() {
Luca Stefani5c60e4f2017-08-17 19:28:48 +02001019 local LINEAGE_TARGET="$1"
Luca Stefani7f9fff22016-07-18 13:47:55 +02001020 local OEM_TARGET="$2"
1021 local SRC="$3"
1022 local TARGET=
1023 local OAT=
Joe Maples9be579f2018-01-05 14:51:33 -05001024 local HOST="$(uname)"
Luca Stefani7f9fff22016-07-18 13:47:55 +02001025
1026 if [ -z "$BAKSMALIJAR" ] || [ -z "$SMALIJAR" ]; then
Bruno Martins98599b62019-10-02 15:56:25 -06001027 export BAKSMALIJAR="$BLISS_ROOT"/prebuilts/tools-bliss/common/smali/baksmali.jar
1028 export SMALIJAR="$BLISS_ROOT"/prebuilts/tools-bliss/common/smali/smali.jar
Luca Stefani7f9fff22016-07-18 13:47:55 +02001029 fi
1030
Joe Maples9be579f2018-01-05 14:51:33 -05001031 if [ -z "$VDEXEXTRACTOR" ]; then
Bruno Martins98599b62019-10-02 15:56:25 -06001032 export VDEXEXTRACTOR="$BLISS_ROOT"/prebuilts/tools-bliss/"${HOST,,}"-x86/bin/vdexExtractor
Joe Maples9be579f2018-01-05 14:51:33 -05001033 fi
1034
codeworkx1c29bf62018-09-23 12:36:57 +02001035 if [ -z "$CDEXCONVERTER" ]; then
Bruno Martins98599b62019-10-02 15:56:25 -06001036 export CDEXCONVERTER="$BLISS_ROOT"/prebuilts/tools-bliss/"${HOST,,}"-x86/bin/compact_dex_converter
codeworkx1c29bf62018-09-23 12:36:57 +02001037 fi
1038
Luca Stefani7f9fff22016-07-18 13:47:55 +02001039 # Extract existing boot.oats to the temp folder
1040 if [ -z "$ARCHES" ]; then
Sam Mortimer2e994ce2016-10-05 09:50:49 -07001041 echo "Checking if system is odexed and locating boot.oats..."
Luca Stefani7f9fff22016-07-18 13:47:55 +02001042 for ARCH in "arm64" "arm" "x86_64" "x86"; do
Sam Mortimer2e994ce2016-10-05 09:50:49 -07001043 mkdir -p "$TMPDIR/system/framework/$ARCH"
Vladimir Olteand5773252018-06-25 00:05:56 +03001044 if get_file "/system/framework/$ARCH" "$TMPDIR/system/framework/" "$SRC"; then
Luca Stefani7f9fff22016-07-18 13:47:55 +02001045 ARCHES+="$ARCH "
Sam Mortimer2e994ce2016-10-05 09:50:49 -07001046 else
1047 rmdir "$TMPDIR/system/framework/$ARCH"
Luca Stefani7f9fff22016-07-18 13:47:55 +02001048 fi
1049 done
1050 fi
1051
1052 if [ -z "$ARCHES" ]; then
1053 FULLY_DEODEXED=1 && return 0 # system is fully deodexed, return
1054 fi
1055
Luca Stefani5c60e4f2017-08-17 19:28:48 +02001056 if [ ! -f "$LINEAGE_TARGET" ]; then
Steve Kondik48f8df82016-08-14 03:55:08 -07001057 return;
1058 fi
1059
Luca Stefani5c60e4f2017-08-17 19:28:48 +02001060 if grep "classes.dex" "$LINEAGE_TARGET" >/dev/null; then
Luca Stefani7f9fff22016-07-18 13:47:55 +02001061 return 0 # target apk|jar is already odexed, return
1062 fi
1063
1064 for ARCH in $ARCHES; do
Sam Mortimer2e994ce2016-10-05 09:50:49 -07001065 BOOTOAT="$TMPDIR/system/framework/$ARCH/boot.oat"
Luca Stefani7f9fff22016-07-18 13:47:55 +02001066
1067 local OAT="$(dirname "$OEM_TARGET")/oat/$ARCH/$(basename "$OEM_TARGET" ."${OEM_TARGET##*.}").odex"
Rashed Abdel-Tawab54b5d5e2017-08-23 15:13:17 -04001068 local VDEX="$(dirname "$OEM_TARGET")/oat/$ARCH/$(basename "$OEM_TARGET" ."${OEM_TARGET##*.}").vdex"
Luca Stefani7f9fff22016-07-18 13:47:55 +02001069
1070 if get_file "$OAT" "$TMPDIR" "$SRC"; then
Rashed Abdel-Tawab54b5d5e2017-08-23 15:13:17 -04001071 if get_file "$VDEX" "$TMPDIR" "$SRC"; then
Joe Maples9be579f2018-01-05 14:51:33 -05001072 "$VDEXEXTRACTOR" -o "$TMPDIR/" -i "$TMPDIR/$(basename "$VDEX")" > /dev/null
Rashed Abdel-Tawab19c36cd2018-03-15 12:55:22 -07001073 CLASSES=$(ls "$TMPDIR/$(basename "${OEM_TARGET%.*}")_classes"*)
1074 for CLASS in $CLASSES; do
1075 NEWCLASS=$(echo "$CLASS" | sed 's/.*_//;s/cdex/dex/')
1076 # Check if we have to deal with CompactDex
1077 if [[ "$CLASS" == *.cdex ]]; then
1078 "$CDEXCONVERTER" "$CLASS" &>/dev/null
1079 mv "$CLASS.new" "$TMPDIR/$NEWCLASS"
1080 else
1081 mv "$CLASS" "$TMPDIR/$NEWCLASS"
1082 fi
1083 done
Joe Maples9be579f2018-01-05 14:51:33 -05001084 else
1085 java -jar "$BAKSMALIJAR" deodex -o "$TMPDIR/dexout" -b "$BOOTOAT" -d "$TMPDIR" "$TMPDIR/$(basename "$OAT")"
1086 java -jar "$SMALIJAR" assemble "$TMPDIR/dexout" -o "$TMPDIR/classes.dex"
Rashed Abdel-Tawab54b5d5e2017-08-23 15:13:17 -04001087 fi
Luca Stefani5c60e4f2017-08-17 19:28:48 +02001088 elif [[ "$LINEAGE_TARGET" =~ .jar$ ]]; then
Gabriele M4cf635a2017-01-05 22:10:00 +01001089 JAROAT="$TMPDIR/system/framework/$ARCH/boot-$(basename ${OEM_TARGET%.*}).oat"
Luca Stefanif6096e92018-10-07 12:44:53 +02001090 JARVDEX="/system/framework/boot-$(basename ${OEM_TARGET%.*}).vdex"
Gabriele M4cf635a2017-01-05 22:10:00 +01001091 if [ ! -f "$JAROAT" ]; then
Luca Stefanif6096e92018-10-07 12:44:53 +02001092 JAROAT=$BOOTOAT
Gabriele M4cf635a2017-01-05 22:10:00 +01001093 fi
Joe Maples9be579f2018-01-05 14:51:33 -05001094 # try to extract classes.dex from boot.vdex for frameworks jars
1095 # fallback to boot.oat if vdex is not available
Luca Stefanif6096e92018-10-07 12:44:53 +02001096 if get_file "$JARVDEX" "$TMPDIR" "$SRC"; then
Luca Stefani99a66bf2018-10-31 19:16:05 +01001097 "$VDEXEXTRACTOR" -o "$TMPDIR/" -i "$TMPDIR/$(basename "$JARVDEX")" > /dev/null
Rashed Abdel-Tawab19c36cd2018-03-15 12:55:22 -07001098 CLASSES=$(ls "$TMPDIR/$(basename "${JARVDEX%.*}")_classes"*)
1099 for CLASS in $CLASSES; do
1100 NEWCLASS=$(echo "$CLASS" | sed 's/.*_//;s/cdex/dex/')
1101 # Check if we have to deal with CompactDex
1102 if [[ "$CLASS" == *.cdex ]]; then
1103 "$CDEXCONVERTER" "$CLASS" &>/dev/null
1104 mv "$CLASS.new" "$TMPDIR/$NEWCLASS"
1105 else
1106 mv "$CLASS" "$TMPDIR/$NEWCLASS"
1107 fi
1108 done
Joe Maples9be579f2018-01-05 14:51:33 -05001109 else
1110 java -jar "$BAKSMALIJAR" deodex -o "$TMPDIR/dexout" -b "$BOOTOAT" -d "$TMPDIR" "$JAROAT/$OEM_TARGET"
1111 java -jar "$SMALIJAR" assemble "$TMPDIR/dexout" -o "$TMPDIR/classes.dex"
1112 fi
Luca Stefani7f9fff22016-07-18 13:47:55 +02001113 else
1114 continue
1115 fi
1116
Luca Stefani7f9fff22016-07-18 13:47:55 +02001117 done
1118
1119 rm -rf "$TMPDIR/dexout"
1120}
1121
1122#
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001123# init_adb_connection:
1124#
1125# Starts adb server and waits for the device
1126#
1127function init_adb_connection() {
1128 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
1129 if ! _adb_connected; then
1130 echo "No device is online. Waiting for one..."
1131 echo "Please connect USB and/or enable USB debugging"
1132 until _adb_connected; do
1133 sleep 1
1134 done
1135 echo "Device Found."
1136 fi
1137
1138 # Retrieve IP and PORT info if we're using a TCP connection
1139 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
1140 | head -1 | awk '{print $1}')
1141 adb root &> /dev/null
1142 sleep 0.3
1143 if [ -n "$TCPIPPORT" ]; then
1144 # adb root just killed our connection
1145 # so reconnect...
1146 adb connect "$TCPIPPORT"
1147 fi
1148 adb wait-for-device &> /dev/null
1149 sleep 0.3
1150}
1151
1152#
Luca Stefani3a030122016-07-30 12:08:25 +02001153# fix_xml:
1154#
1155# $1: xml file to fix
1156#
1157function fix_xml() {
1158 local XML="$1"
1159 local TEMP_XML="$TMPDIR/`basename "$XML"`.temp"
1160
Dobroslaw Kijowski65f03f12017-05-18 12:35:02 +02001161 grep -a '^<?xml version' "$XML" > "$TEMP_XML"
1162 grep -av '^<?xml version' "$XML" >> "$TEMP_XML"
Luca Stefani3a030122016-07-30 12:08:25 +02001163
1164 mv "$TEMP_XML" "$XML"
1165}
1166
Vladimir Oltean4818c232019-01-17 03:07:34 +02001167function get_hash() {
1168 local FILE="$1"
1169
1170 if [ "$(uname)" == "Darwin" ]; then
1171 shasum "${FILE}" | awk '{print $1}'
1172 else
1173 sha1sum "${FILE}" | awk '{print $1}'
1174 fi
1175}
1176
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001177function print_spec() {
1178 local SPEC_PRODUCT_PACKAGE="$1"
1179 local SPEC_SRC_FILE="$2"
1180 local SPEC_DST_FILE="$3"
1181 local SPEC_ARGS="$4"
1182 local SPEC_HASH="$5"
Vladimir Oltean4818c232019-01-17 03:07:34 +02001183 local SPEC_FIXUP_HASH="$6"
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001184
1185 local PRODUCT_PACKAGE=""
1186 if [ ${SPEC_PRODUCT_PACKAGE} = true ]; then
1187 PRODUCT_PACKAGE="-"
1188 fi
1189 local SRC=""
1190 if [ ! -z "${SPEC_SRC_FILE}" ] && [ "${SPEC_SRC_FILE}" != "${SPEC_DST_FILE}" ]; then
1191 SRC="${SPEC_SRC_FILE}:"
1192 fi
1193 local DST=""
1194 if [ ! -z "${SPEC_DST_FILE}" ]; then
1195 DST="${SPEC_DST_FILE}"
1196 fi
1197 local ARGS=""
1198 if [ ! -z "${SPEC_ARGS}" ]; then
1199 ARGS=";${SPEC_ARGS}"
1200 fi
1201 local HASH=""
1202 if [ ! -z "${SPEC_HASH}" ] && [ "${SPEC_HASH}" != "x" ]; then
1203 HASH="|${SPEC_HASH}"
1204 fi
Vladimir Oltean4818c232019-01-17 03:07:34 +02001205 local FIXUP_HASH=""
1206 if [ ! -z "${SPEC_FIXUP_HASH}" ] && [ "${SPEC_FIXUP_HASH}" != "x" ] && [ "${SPEC_FIXUP_HASH}" != "${SPEC_HASH}" ]; then
1207 FIXUP_HASH="|${SPEC_FIXUP_HASH}"
1208 fi
1209 printf '%s%s%s%s%s%s\n' "${PRODUCT_PACKAGE}" "${SRC}" "${DST}" "${ARGS}" "${HASH}" "${FIXUP_HASH}"
1210}
1211
1212# To be overridden by device-level extract-files.sh
1213# Parameters:
1214# $1: spec name of a blob. Can be used for filtering.
1215# If the spec is "src:dest", then $1 is "dest".
1216# If the spec is "src", then $1 is "src".
1217# $2: path to blob file. Can be used for fixups.
1218#
1219function blob_fixup() {
1220 :
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001221}
1222
Luca Stefani3a030122016-07-30 12:08:25 +02001223#
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001224# extract:
1225#
Vladimir Olteanc5034462019-01-17 03:04:16 +02001226# Positional parameters:
1227# $1: file containing the list of items to extract (aka proprietary-files.txt)
Dan Pasanen7dc287f2017-03-21 09:06:11 -05001228# $2: path to extracted system folder, an ota zip file, or "adb" to extract from device
Vladimir Olteanc5034462019-01-17 03:04:16 +02001229# $3: section in list file to extract - optional. Setting section via $3 is deprecated.
1230#
1231# Non-positional parameters (coming after $2):
1232# --section: preferred way of selecting the portion to parse and extract from
1233# proprietary-files.txt
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001234# --kang: if present, this option will activate the printing of hashes for the
1235# extracted blobs. Useful with --section for subsequent pinning of
1236# blobs taken from other origins.
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001237#
1238function extract() {
Vladimir Olteanc5034462019-01-17 03:04:16 +02001239 # Consume positional parameters
1240 local PROPRIETARY_FILES_TXT="$1"; shift
1241 local SRC="$1"; shift
1242 local SECTION=""
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001243 local KANG=false
Vladimir Olteanc5034462019-01-17 03:04:16 +02001244
1245 # Consume optional, non-positional parameters
1246 while [ "$#" -gt 0 ]; do
1247 case "$1" in
1248 -s|--section)
1249 SECTION="$2"; shift
1250 ;;
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001251 -k|--kang)
1252 KANG=true
1253 DISABLE_PINNING=1
1254 ;;
Vladimir Olteanc5034462019-01-17 03:04:16 +02001255 *)
1256 # Backwards-compatibility with the old behavior, where $3, if
1257 # present, denoted an optional positional ${SECTION} argument.
1258 # Users of ${SECTION} are encouraged to migrate from setting it as
1259 # positional $3, to non-positional --section ${SECTION}, the
1260 # reason being that it doesn't scale to have more than 1 optional
1261 # positional argument.
1262 SECTION="$1"
1263 ;;
1264 esac
1265 shift
1266 done
1267
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001268 if [ -z "$OUTDIR" ]; then
1269 echo "Output dir not set!"
1270 exit 1
1271 fi
1272
Vladimir Olteanc5034462019-01-17 03:04:16 +02001273 parse_file_list "${PROPRIETARY_FILES_TXT}" "${SECTION}"
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001274
1275 # Allow failing, so we can try $DEST and/or $FILE
1276 set +e
1277
1278 local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ${PRODUCT_PACKAGES_LIST[@]} )
Steve Kondik48f8df82016-08-14 03:55:08 -07001279 local HASHLIST=( ${PRODUCT_COPY_FILES_HASHES[@]} ${PRODUCT_PACKAGES_HASHES[@]} )
Vladimir Oltean4818c232019-01-17 03:07:34 +02001280 local FIXUP_HASHLIST=( ${PRODUCT_COPY_FILES_FIXUP_HASHES[@]} ${PRODUCT_PACKAGES_FIXUP_HASHES[@]} )
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001281 local PRODUCT_COPY_FILES_COUNT=${#PRODUCT_COPY_FILES_LIST[@]}
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001282 local COUNT=${#FILELIST[@]}
Jackeaglecf6f4de2019-09-24 04:07:22 -04001283 local OUTPUT_ROOT="$BLISS_ROOT"/"$OUTDIR"/proprietary
Steve Kondik48f8df82016-08-14 03:55:08 -07001284 local OUTPUT_TMP="$TMPDIR"/"$OUTDIR"/proprietary
1285
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001286 if [ "$SRC" = "adb" ]; then
1287 init_adb_connection
1288 fi
1289
Dan Pasanen7dc287f2017-03-21 09:06:11 -05001290 if [ -f "$SRC" ] && [ "${SRC##*.}" == "zip" ]; then
conbold575c6352017-11-10 16:33:38 +01001291 DUMPDIR="$TMPDIR"/system_dump
Dan Pasanen7dc287f2017-03-21 09:06:11 -05001292
1293 # Check if we're working with the same zip that was passed last time.
1294 # If so, let's just use what's already extracted.
1295 MD5=`md5sum "$SRC"| awk '{print $1}'`
1296 OLDMD5=`cat "$DUMPDIR"/zipmd5.txt`
1297
1298 if [ "$MD5" != "$OLDMD5" ]; then
1299 rm -rf "$DUMPDIR"
1300 mkdir "$DUMPDIR"
1301 unzip "$SRC" -d "$DUMPDIR"
1302 echo "$MD5" > "$DUMPDIR"/zipmd5.txt
1303
1304 # Stop if an A/B OTA zip is detected. We cannot extract these.
1305 if [ -a "$DUMPDIR"/payload.bin ]; then
1306 echo "A/B style OTA zip detected. This is not supported at this time. Stopping..."
1307 exit 1
1308 # If OTA is block based, extract it.
1309 elif [ -a "$DUMPDIR"/system.new.dat ]; then
1310 echo "Converting system.new.dat to system.img"
Jackeaglecf6f4de2019-09-24 04:07:22 -04001311 python "$BLISS_ROOT"/vendor/bliss/build/tools/sdat2img.py "$DUMPDIR"/system.transfer.list "$DUMPDIR"/system.new.dat "$DUMPDIR"/system.img 2>&1
Dan Pasanen7dc287f2017-03-21 09:06:11 -05001312 rm -rf "$DUMPDIR"/system.new.dat "$DUMPDIR"/system
1313 mkdir "$DUMPDIR"/system "$DUMPDIR"/tmp
1314 echo "Requesting sudo access to mount the system.img"
1315 sudo mount -o loop "$DUMPDIR"/system.img "$DUMPDIR"/tmp
1316 cp -r "$DUMPDIR"/tmp/* "$DUMPDIR"/system/
1317 sudo umount "$DUMPDIR"/tmp
1318 rm -rf "$DUMPDIR"/tmp "$DUMPDIR"/system.img
1319 fi
1320 fi
1321
1322 SRC="$DUMPDIR"
1323 fi
1324
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001325 if [ "$VENDOR_STATE" -eq "0" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -07001326 echo "Cleaning output directory ($OUTPUT_ROOT).."
Steve Kondik48f8df82016-08-14 03:55:08 -07001327 rm -rf "${OUTPUT_TMP:?}"
1328 mkdir -p "${OUTPUT_TMP:?}"
Adrian DC3c6bdac2017-01-15 14:03:26 +01001329 if [ -d "$OUTPUT_ROOT" ]; then
1330 mv "${OUTPUT_ROOT:?}/"* "${OUTPUT_TMP:?}/"
1331 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001332 VENDOR_STATE=1
1333 fi
1334
Vladimir Olteanc5034462019-01-17 03:04:16 +02001335 echo "Extracting ${COUNT} files in ${PROPRIETARY_FILES_TXT} from ${SRC}:"
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001336
1337 for (( i=1; i<COUNT+1; i++ )); do
Steve Kondika991cf12016-07-28 12:13:12 -07001338
Vladimir Olteanda3b6442018-06-24 20:41:30 +03001339 local SPEC_SRC_FILE=$(src_file "${FILELIST[$i-1]}")
Vladimir Oltean411e0692018-06-24 20:38:04 +03001340 local SPEC_DST_FILE=$(target_file "${FILELIST[$i-1]}")
Vladimir Olteand652a062018-06-24 20:42:01 +03001341 local SPEC_ARGS=$(target_args "${FILELIST[$i-1]}")
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001342 local OUTPUT_DIR=
1343 local TMP_DIR=
1344 local SRC_FILE=
1345 local DST_FILE=
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001346 local IS_PRODUCT_PACKAGE=false
1347
1348 # Note: this relies on the fact that the ${FILELIST[@]} array
1349 # contains first ${PRODUCT_COPY_FILES_LIST[@]}, then ${PRODUCT_PACKAGES_LIST[@]}.
1350 if [ "${i}" -gt "${PRODUCT_COPY_FILES_COUNT}" ]; then
1351 IS_PRODUCT_PACKAGE=true
1352 fi
Steve Kondika991cf12016-07-28 12:13:12 -07001353
Vladimir Olteand652a062018-06-24 20:42:01 +03001354 if [ "${SPEC_ARGS}" = "rootfs" ]; then
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001355 OUTPUT_DIR="${OUTPUT_ROOT}/rootfs"
1356 TMP_DIR="${OUTPUT_TMP}/rootfs"
1357 SRC_FILE="/${SPEC_SRC_FILE}"
1358 DST_FILE="/${SPEC_DST_FILE}"
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001359 else
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001360 OUTPUT_DIR="${OUTPUT_ROOT}"
1361 TMP_DIR="${OUTPUT_TMP}"
1362 SRC_FILE="/system/${SPEC_SRC_FILE}"
1363 DST_FILE="/system/${SPEC_DST_FILE}"
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001364 fi
Steve Kondika991cf12016-07-28 12:13:12 -07001365
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001366 # Strip the file path in the vendor repo of "system", if present
1367 local VENDOR_REPO_FILE="$OUTPUT_DIR/${DST_FILE#/system}"
Vladimir Olteanc5034462019-01-17 03:04:16 +02001368 local BLOB_DISPLAY_NAME="${DST_FILE#/system/}"
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001369 mkdir -p $(dirname "${VENDOR_REPO_FILE}")
Steve Kondika991cf12016-07-28 12:13:12 -07001370
Gabriele Me6df25b2017-10-11 00:58:59 +02001371 # Check pinned files
Vladimir Olteanb2c38212019-01-17 02:47:02 +02001372 local HASH="$(echo ${HASHLIST[$i-1]} | awk '{ print tolower($0); }')"
Vladimir Oltean4818c232019-01-17 03:07:34 +02001373 local FIXUP_HASH="$(echo ${FIXUP_HASHLIST[$i-1]} | awk '{ print tolower($0); }')"
Gabriele Me6df25b2017-10-11 00:58:59 +02001374 local KEEP=""
Vladimir Oltean4818c232019-01-17 03:07:34 +02001375 if [ "$DISABLE_PINNING" != "1" ] && [ "$HASH" != "x" ]; then
Vladimir Olteand6747712018-06-24 20:46:42 +03001376 if [ -f "${VENDOR_REPO_FILE}" ]; then
1377 local PINNED="${VENDOR_REPO_FILE}"
Gabriele Me6df25b2017-10-11 00:58:59 +02001378 else
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001379 local PINNED="${TMP_DIR}${DST_FILE#/system}"
Gabriele Me6df25b2017-10-11 00:58:59 +02001380 fi
1381 if [ -f "$PINNED" ]; then
Vladimir Oltean4818c232019-01-17 03:07:34 +02001382 local TMP_HASH=$(get_hash "${PINNED}")
1383 if [ "${TMP_HASH}" = "${HASH}" ] || [ "${TMP_HASH}" = "${FIXUP_HASH}" ]; then
Gabriele Me6df25b2017-10-11 00:58:59 +02001384 KEEP="1"
Vladimir Olteand6747712018-06-24 20:46:42 +03001385 if [ ! -f "${VENDOR_REPO_FILE}" ]; then
1386 cp -p "$PINNED" "${VENDOR_REPO_FILE}"
Gabriele Me6df25b2017-10-11 00:58:59 +02001387 fi
1388 fi
1389 fi
1390 fi
1391
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001392 if [ "${KANG}" = false ]; then
1393 printf ' - %s\n' "${BLOB_DISPLAY_NAME}"
1394 fi
1395
Gabriele Me6df25b2017-10-11 00:58:59 +02001396 if [ "$KEEP" = "1" ]; then
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001397 printf ' + keeping pinned file with hash %s\n' "${HASH}"
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001398 else
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001399 FOUND=false
1400 # Try Lineage target first.
1401 # Also try to search for files stripped of
1402 # the "/system" prefix, if we're actually extracting
1403 # from a system image.
Vladimir Olteand5773252018-06-25 00:05:56 +03001404 for CANDIDATE in "${DST_FILE}" "${SRC_FILE}"; do
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001405 get_file ${CANDIDATE} ${VENDOR_REPO_FILE} ${SRC} && {
1406 FOUND=true
1407 break
1408 }
1409 done
1410
1411 if [ "${FOUND}" = false ]; then
Vladimir Olteanc5034462019-01-17 03:04:16 +02001412 printf ' !! %s: file not found in source\n' "${BLOB_DISPLAY_NAME}"
Vladimir Olteanb8084ec2018-10-18 00:44:02 +03001413 continue
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001414 fi
1415 fi
Steve Kondika991cf12016-07-28 12:13:12 -07001416
Vladimir Oltean4818c232019-01-17 03:07:34 +02001417 # Blob fixup pipeline has 2 parts: one that is fixed and
1418 # one that is user-configurable
1419 local PRE_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE})
1420 # Deodex apk|jar if that's the case
1421 if [[ "$FULLY_DEODEXED" -ne "1" && "${VENDOR_REPO_FILE}" =~ .(apk|jar)$ ]]; then
1422 oat2dex "${VENDOR_REPO_FILE}" "${SRC_FILE}" "$SRC"
1423 if [ -f "$TMPDIR/classes.dex" ]; then
Rashed Abdel-Tawab19c36cd2018-03-15 12:55:22 -07001424 zip -gjq "${VENDOR_REPO_FILE}" "$TMPDIR/classes"*
1425 rm "$TMPDIR/classes"*
Vladimir Oltean4818c232019-01-17 03:07:34 +02001426 printf ' (updated %s from odex files)\n' "${SRC_FILE}"
Luca Stefani7f9fff22016-07-18 13:47:55 +02001427 fi
Vladimir Oltean4818c232019-01-17 03:07:34 +02001428 elif [[ "${VENDOR_REPO_FILE}" =~ .xml$ ]]; then
1429 fix_xml "${VENDOR_REPO_FILE}"
Luca Stefani7f9fff22016-07-18 13:47:55 +02001430 fi
Vladimir Oltean4818c232019-01-17 03:07:34 +02001431 # Now run user-supplied fixup function
1432 blob_fixup "${BLOB_DISPLAY_NAME}" "${VENDOR_REPO_FILE}"
1433 local POST_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE})
Luca Stefani7f9fff22016-07-18 13:47:55 +02001434
Vladimir Olteand6747712018-06-24 20:46:42 +03001435 if [ -f "${VENDOR_REPO_FILE}" ]; then
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001436 local DIR=$(dirname "${VENDOR_REPO_FILE}")
Steve Kondik48f8df82016-08-14 03:55:08 -07001437 local TYPE="${DIR##*/}"
1438 if [ "$TYPE" = "bin" -o "$TYPE" = "sbin" ]; then
Vladimir Olteand6747712018-06-24 20:46:42 +03001439 chmod 755 "${VENDOR_REPO_FILE}"
Steve Kondik48f8df82016-08-14 03:55:08 -07001440 else
Vladimir Olteand6747712018-06-24 20:46:42 +03001441 chmod 644 "${VENDOR_REPO_FILE}"
Steve Kondik48f8df82016-08-14 03:55:08 -07001442 fi
1443 fi
1444
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001445 if [ "${KANG}" = true ]; then
Vladimir Oltean4818c232019-01-17 03:07:34 +02001446 print_spec "${IS_PRODUCT_PACKAGE}" "${SPEC_SRC_FILE}" "${SPEC_DST_FILE}" "${SPEC_ARGS}" "${PRE_FIXUP_HASH}" "${POST_FIXUP_HASH}"
1447 fi
1448
1449 # Check and print whether the fixup pipeline actually did anything.
1450 # This isn't done right after the fixup pipeline because we want this print
1451 # to come after print_spec above, when in kang mode.
1452 if [ "${PRE_FIXUP_HASH}" != "${POST_FIXUP_HASH}" ]; then
1453 printf " + Fixed up %s\n" "${BLOB_DISPLAY_NAME}"
1454 # Now sanity-check the spec for this blob.
1455 if [ "${KANG}" = false ] && [ "${FIXUP_HASH}" = "x" ] && [ "${HASH}" != "x" ]; then
1456 printf "WARNING: The %s file was fixed up, but it is pinned.\n" ${BLOB_DISPLAY_NAME}
1457 printf "This is a mistake and you want to either remove the hash completely, or add an extra one.\n"
1458 fi
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001459 fi
1460
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001461 done
1462
1463 # Don't allow failing
1464 set -e
1465}
Louis Popia516c2f2016-07-25 15:51:13 +02001466
1467#
1468# extract_firmware:
1469#
1470# $1: file containing the list of items to extract
1471# $2: path to extracted radio folder
1472#
1473function extract_firmware() {
1474 if [ -z "$OUTDIR" ]; then
1475 echo "Output dir not set!"
1476 exit 1
1477 fi
1478
1479 parse_file_list "$1"
1480
1481 # Don't allow failing
1482 set -e
1483
1484 local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} )
1485 local COUNT=${#FILELIST[@]}
1486 local SRC="$2"
Jackeaglecf6f4de2019-09-24 04:07:22 -04001487 local OUTPUT_DIR="$BLISS_ROOT"/"$OUTDIR"/radio
Louis Popia516c2f2016-07-25 15:51:13 +02001488
1489 if [ "$VENDOR_RADIO_STATE" -eq "0" ]; then
1490 echo "Cleaning firmware output directory ($OUTPUT_DIR).."
1491 rm -rf "${OUTPUT_DIR:?}/"*
1492 VENDOR_RADIO_STATE=1
1493 fi
1494
1495 echo "Extracting $COUNT files in $1 from $SRC:"
1496
1497 for (( i=1; i<COUNT+1; i++ )); do
1498 local FILE="${FILELIST[$i-1]}"
1499 printf ' - %s \n' "/radio/$FILE"
1500
1501 if [ ! -d "$OUTPUT_DIR" ]; then
1502 mkdir -p "$OUTPUT_DIR"
1503 fi
1504 cp "$SRC/$FILE" "$OUTPUT_DIR/$FILE"
1505 chmod 644 "$OUTPUT_DIR/$FILE"
1506 done
1507}
Rashed Abdel-Tawab1c29c372019-03-29 20:07:25 -07001508
1509function extract_img_data() {
1510 local image_file="$1"
1511 local out_dir="$2"
1512 local logFile="$TMPDIR/debugfs.log"
1513
1514 if [ ! -d "$out_dir" ]; then
1515 mkdir -p "$out_dir"
1516 fi
1517
1518 if [[ "$HOST_OS" == "Darwin" ]]; then
1519 debugfs -R "rdump / \"$out_dir\"" "$image_file" &> "$logFile" || {
1520 echo "[-] Failed to extract data from '$image_file'"
1521 abort 1
1522 }
1523 else
1524 debugfs -R 'ls -p' "$image_file" 2>/dev/null | cut -d '/' -f6 | while read -r entry
1525 do
1526 debugfs -R "rdump \"$entry\" \"$out_dir\"" "$image_file" >> "$logFile" 2>&1 || {
1527 echo "[-] Failed to extract data from '$image_file'"
1528 abort 1
1529 }
1530 done
1531 fi
1532
1533 local symlink_err="rdump: Attempt to read block from filesystem resulted in short read while reading symlink"
1534 if grep -Fq "$symlink_err" "$logFile"; then
1535 echo "[-] Symlinks have not been properly processed from $image_file"
1536 echo "[!] If you don't have a compatible debugfs version, modify 'execute-all.sh' to disable 'USE_DEBUGFS' flag"
1537 abort 1
1538 fi
1539}
1540
1541declare -ra VENDOR_SKIP_FILES=(
1542 "bin/toybox_vendor"
1543 "bin/toolbox"
1544 "bin/grep"
1545 "build.prop"
1546 "compatibility_matrix.xml"
1547 "default.prop"
1548 "etc/NOTICE.xml.gz"
1549 "etc/vintf/compatibility_matrix.xml"
1550 "etc/vintf/manifest.xml"
1551 "etc/wifi/wpa_supplicant.conf"
1552 "manifest.xml"
1553 "overlay/DisplayCutoutEmulationCorner/DisplayCutoutEmulationCornerOverlay.apk"
1554 "overlay/DisplayCutoutEmulationDouble/DisplayCutoutEmulationDoubleOverlay.apk"
1555 "overlay/DisplayCutoutEmulationTall/DisplayCutoutEmulationTallOverlay.apk"
1556 "overlay/DisplayCutoutNoCutout/NoCutoutOverlay.apk"
1557 "overlay/framework-res__auto_generated_rro.apk"
1558 "overlay/SysuiDarkTheme/SysuiDarkThemeOverlay.apk"
1559)
1560
1561function array_contains() {
1562 local element
1563 for element in "${@:2}"; do [[ "$element" == "$1" ]] && return 0; done
1564 return 1
1565}
1566
1567function generate_prop_list_from_image() {
1568 local image_file="$1"
1569 local image_dir="$TMPDIR/image-temp"
1570 local output_list="$2"
1571 local output_list_tmp="$TMPDIR/_proprietary-blobs.txt"
1572 local -n skipped_vendor_files="$3"
1573
1574 extract_img_data "$image_file" "$image_dir"
1575
1576 find "$image_dir" -not -type d | sed "s#^$image_dir/##" | while read -r FILE
1577 do
1578 # Skip VENDOR_SKIP_FILES since it will be re-generated at build time
1579 if array_contains "$FILE" "${VENDOR_SKIP_FILES[@]}"; then
1580 continue
1581 fi
1582 # Skip device defined skipped files since they will be re-generated at build time
1583 if array_contains "$FILE" "${skipped_vendor_files[@]}"; then
1584 continue
1585 fi
1586 if suffix_match_file ".apk" "$FILE" ; then
1587 echo "-vendor/$FILE" >> "$output_list_tmp"
1588 else
1589 echo "vendor/$FILE" >> "$output_list_tmp"
1590 fi
1591 done
1592
1593 # Sort merged file with all lists
1594 sort -u "$output_list_tmp" > "$output_list"
1595
1596 # Clean-up
1597 rm -f "$output_list_tmp"
1598}