blob: fb39fa915525842e0e39277d7bffefdb84376c17 [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
Luca Stefani5c60e4f2017-08-17 19:28:48 +020070 export LINEAGE_ROOT="$3"
71 if [ ! -d "$LINEAGE_ROOT" ]; then
72 echo "\$LINEAGE_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"
Luca Stefani5c60e4f2017-08-17 19:28:48 +020077 if [ ! -d "$LINEAGE_ROOT/$OUTDIR" ]; then
78 mkdir -p "$LINEAGE_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
Luca Stefani5c60e4f2017-08-17 19:28:48 +020086 export PRODUCTMK="$LINEAGE_ROOT"/"$OUTDIR"/"$VNDNAME"-vendor.mk
87 export ANDROIDMK="$LINEAGE_ROOT"/"$OUTDIR"/Android.mk
88 export BOARDMK="$LINEAGE_ROOT"/"$OUTDIR"/BoardConfigVendor.mk
Steve Kondik4e2aaab2016-07-15 10:39:58 -070089
90 if [ "$4" == "true" ] || [ "$4" == "1" ]; then
91 COMMON=1
92 else
93 COMMON=0
94 fi
95
Gabriele Mb6effb32017-05-01 18:22:04 +020096 if [ "$5" == "false" ] || [ "$5" == "0" ]; then
Steve Kondik4e2aaab2016-07-15 10:39:58 -070097 VENDOR_STATE=1
Louis Popia516c2f2016-07-25 15:51:13 +020098 VENDOR_RADIO_STATE=1
Steve Kondik4e2aaab2016-07-15 10:39:58 -070099 else
100 VENDOR_STATE=0
Louis Popia516c2f2016-07-25 15:51:13 +0200101 VENDOR_RADIO_STATE=0
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700102 fi
103}
104
Vladimir Oltean95643282018-06-24 20:22:41 +0300105# Helper functions for parsing a spec.
106# notes: an optional "|SHA1" that may appear in the format is stripped
107# early from the spec in the parse_file_list function, and
108# should not be present inside the input parameter passed
109# to these functions.
110
111#
112# input: spec in the form of "src[:dst][;args]"
113# output: "src"
114#
115function src_file() {
116 local SPEC="$1"
117 local SPLIT=(${SPEC//:/ })
118 local ARGS="$(target_args ${SPEC})"
119 # Regardless of there being a ":" delimiter or not in the spec,
120 # the source file is always either the first, or the only entry.
121 local SRC="${SPLIT[0]}"
122 # Remove target_args suffix, if present
123 echo "${SRC%;${ARGS}}"
124}
125
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700126#
Vladimir Oltean6a7946b2018-06-24 20:09:55 +0300127# input: spec in the form of "src[:dst][;args]"
128# output: "dst" if present, "src" otherwise.
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700129#
130function target_file() {
Vladimir Oltean6a7946b2018-06-24 20:09:55 +0300131 local SPEC="$1"
132 local SPLIT=(${SPEC//:/ })
133 local ARGS="$(target_args ${SPEC})"
134 local DST=
135 case ${#SPLIT[@]} in
136 1)
137 # The spec doesn't have a : delimiter
138 DST="${SPLIT[0]}"
139 ;;
140 *)
141 # The spec actually has a src:dst format
142 DST="${SPLIT[1]}"
143 ;;
144 esac
145 # Remove target_args suffix, if present
146 echo "${DST%;${ARGS}}"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700147}
148
149#
Vladimir Oltean6a7946b2018-06-24 20:09:55 +0300150# input: spec in the form of "src[:dst][;args]"
151# output: "args" if present, "" otherwise.
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700152#
153function target_args() {
Vladimir Oltean6a7946b2018-06-24 20:09:55 +0300154 local SPEC="$1"
155 local SPLIT=(${SPEC//;/ })
156 local ARGS=
157 case ${#SPLIT[@]} in
158 1)
159 # No ";" delimiter in the spec.
160 ;;
161 *)
162 # The "args" are whatever comes after the ";" character.
163 # Basically the spec stripped of whatever is to the left of ";".
164 ARGS="${SPEC#${SPLIT[0]};}"
165 ;;
166 esac
167 echo "${ARGS}"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700168}
169
170#
171# prefix_match:
172#
Vladimir Oltean2654eaa2018-06-12 01:17:35 +0300173# input:
174# - $1: prefix
175# - (global variable) PRODUCT_PACKAGES_LIST: array of [src:]dst[;args] specs.
176# output:
177# - new array consisting of dst[;args] entries where $1 is a prefix of ${dst}.
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700178#
179function prefix_match() {
180 local PREFIX="$1"
Vladimir Olteana48b9fe2018-04-02 22:37:09 +0300181 for LINE in "${PRODUCT_PACKAGES_LIST[@]}"; do
182 local FILE=$(target_file "$LINE")
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700183 if [[ "$FILE" =~ ^"$PREFIX" ]]; then
Vladimir Oltean2654eaa2018-06-12 01:17:35 +0300184 local ARGS=$(target_args "$LINE")
185 if [ -z "${ARGS}" ]; then
186 echo "${FILE#$PREFIX}"
187 else
188 echo "${FILE#$PREFIX};${ARGS}"
189 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700190 fi
191 done
192}
193
194#
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400195# prefix_match_file:
196#
197# $1: the prefix to match on
198# $2: the file to match the prefix for
199#
200# Internal function which returns true if a filename contains the
201# specified prefix.
202#
203function prefix_match_file() {
204 local PREFIX="$1"
205 local FILE="$2"
206 if [[ "$FILE" =~ ^"$PREFIX" ]]; then
207 return 0
208 else
209 return 1
210 fi
211}
212
213#
214# truncate_file
215#
216# $1: the filename to truncate
217# $2: the argument to output the truncated filename to
218#
219# Internal function which truncates a filename by removing the first dir
220# in the path. ex. vendor/lib/libsdmextension.so -> lib/libsdmextension.so
221#
222function truncate_file() {
223 local FILE="$1"
224 RETURN_FILE="$2"
225 local FIND="${FILE%%/*}"
226 local LOCATION="${#FIND}+1"
227 echo ${FILE:$LOCATION}
228}
229
230#
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700231# write_product_copy_files:
232#
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400233# $1: make treble compatible makefile - optional, default to false
234#
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700235# Creates the PRODUCT_COPY_FILES section in the product makefile for all
236# items in the list which do not start with a dash (-).
237#
238function write_product_copy_files() {
239 local COUNT=${#PRODUCT_COPY_FILES_LIST[@]}
240 local TARGET=
241 local FILE=
242 local LINEEND=
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400243 local TREBLE_COMPAT=$1
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700244
245 if [ "$COUNT" -eq "0" ]; then
246 return 0
247 fi
248
249 printf '%s\n' "PRODUCT_COPY_FILES += \\" >> "$PRODUCTMK"
250 for (( i=1; i<COUNT+1; i++ )); do
251 FILE="${PRODUCT_COPY_FILES_LIST[$i-1]}"
252 LINEEND=" \\"
253 if [ "$i" -eq "$COUNT" ]; then
254 LINEEND=""
255 fi
256
Vladimir Oltean6a7946b2018-06-24 20:09:55 +0300257 TARGET=$(target_file "$FILE")
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400258 if [ "$TREBLE_COMPAT" == "true" ] || [ "$TREBLE_COMPAT" == "1" ]; then
259 if prefix_match_file "vendor/" $TARGET ; then
260 local OUTTARGET=$(truncate_file $TARGET)
261 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR)/%s%s\n' \
262 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
263 else
264 printf ' %s/proprietary/%s:system/%s%s\n' \
265 "$OUTDIR" "$TARGET" "$TARGET" "$LINEEND" >> "$PRODUCTMK"
266 fi
267 else
268 printf ' %s/proprietary/%s:system/%s%s\n' \
269 "$OUTDIR" "$TARGET" "$TARGET" "$LINEEND" >> "$PRODUCTMK"
270 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700271 done
272 return 0
273}
274
275#
276# write_packages:
277#
278# $1: The LOCAL_MODULE_CLASS for the given module list
279# $2: "true" if this package is part of the vendor/ path
Steve Kondika991cf12016-07-28 12:13:12 -0700280# $3: type-specific extra flags
281# $4: Name of the array holding the target list
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700282#
283# Internal function which writes out the BUILD_PREBUILT stanzas
284# for all modules in the list. This is called by write_product_packages
285# after the modules are categorized.
286#
287function write_packages() {
288
289 local CLASS="$1"
290 local VENDOR_PKG="$2"
Steve Kondika991cf12016-07-28 12:13:12 -0700291 local EXTRA="$3"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700292
293 # Yes, this is a horrible hack - we create a new array using indirection
Steve Kondika991cf12016-07-28 12:13:12 -0700294 local ARR_NAME="$4[@]"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700295 local FILELIST=("${!ARR_NAME}")
296
297 local FILE=
298 local ARGS=
299 local BASENAME=
300 local EXTENSION=
301 local PKGNAME=
302 local SRC=
303
304 for P in "${FILELIST[@]}"; do
Vladimir Oltean6a7946b2018-06-24 20:09:55 +0300305 FILE=$(target_file "$P")
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700306 ARGS=$(target_args "$P")
307
308 BASENAME=$(basename "$FILE")
M1cha15f226c2017-01-04 09:00:11 +0100309 DIRNAME=$(dirname "$FILE")
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700310 EXTENSION=${BASENAME##*.}
311 PKGNAME=${BASENAME%.*}
312
313 # Add to final package list
314 PACKAGE_LIST+=("$PKGNAME")
315
316 SRC="proprietary"
317 if [ "$VENDOR_PKG" = "true" ]; then
318 SRC+="/vendor"
319 fi
320
321 printf 'include $(CLEAR_VARS)\n'
322 printf 'LOCAL_MODULE := %s\n' "$PKGNAME"
323 printf 'LOCAL_MODULE_OWNER := %s\n' "$VENDOR"
324 if [ "$CLASS" = "SHARED_LIBRARIES" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -0700325 if [ "$EXTRA" = "both" ]; then
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700326 printf 'LOCAL_SRC_FILES_64 := %s/lib64/%s\n' "$SRC" "$FILE"
327 printf 'LOCAL_SRC_FILES_32 := %s/lib/%s\n' "$SRC" "$FILE"
328 #if [ "$VENDOR_PKG" = "true" ]; then
329 # echo "LOCAL_MODULE_PATH_64 := \$(TARGET_OUT_VENDOR_SHARED_LIBRARIES)"
330 # echo "LOCAL_MODULE_PATH_32 := \$(2ND_TARGET_OUT_VENDOR_SHARED_LIBRARIES)"
331 #else
332 # echo "LOCAL_MODULE_PATH_64 := \$(TARGET_OUT_SHARED_LIBRARIES)"
333 # echo "LOCAL_MODULE_PATH_32 := \$(2ND_TARGET_OUT_SHARED_LIBRARIES)"
334 #fi
Steve Kondika991cf12016-07-28 12:13:12 -0700335 elif [ "$EXTRA" = "64" ]; then
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700336 printf 'LOCAL_SRC_FILES := %s/lib64/%s\n' "$SRC" "$FILE"
337 else
338 printf 'LOCAL_SRC_FILES := %s/lib/%s\n' "$SRC" "$FILE"
339 fi
Steve Kondik03ce4002016-07-29 00:00:16 -0700340 if [ "$EXTRA" != "none" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -0700341 printf 'LOCAL_MULTILIB := %s\n' "$EXTRA"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700342 fi
343 elif [ "$CLASS" = "APPS" ]; then
Michael Bestas3f9b94c2018-01-25 21:05:36 +0200344 if [ "$EXTRA" = "priv-app" ]; then
345 SRC="$SRC/priv-app"
346 else
347 SRC="$SRC/app"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700348 fi
349 printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE"
350 local CERT=platform
351 if [ ! -z "$ARGS" ]; then
352 CERT="$ARGS"
353 fi
354 printf 'LOCAL_CERTIFICATE := %s\n' "$CERT"
355 elif [ "$CLASS" = "JAVA_LIBRARIES" ]; then
356 printf 'LOCAL_SRC_FILES := %s/framework/%s\n' "$SRC" "$FILE"
Elektroschmock082e0ec2016-10-04 21:11:43 +0200357 local CERT=platform
358 if [ ! -z "$ARGS" ]; then
359 CERT="$ARGS"
360 fi
361 printf 'LOCAL_CERTIFICATE := %s\n' "$CERT"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700362 elif [ "$CLASS" = "ETC" ]; then
363 printf 'LOCAL_SRC_FILES := %s/etc/%s\n' "$SRC" "$FILE"
364 elif [ "$CLASS" = "EXECUTABLES" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -0700365 if [ "$ARGS" = "rootfs" ]; then
366 SRC="$SRC/rootfs"
367 if [ "$EXTRA" = "sbin" ]; then
368 SRC="$SRC/sbin"
369 printf '%s\n' "LOCAL_MODULE_PATH := \$(TARGET_ROOT_OUT_SBIN)"
370 printf '%s\n' "LOCAL_UNSTRIPPED_PATH := \$(TARGET_ROOT_OUT_SBIN_UNSTRIPPED)"
371 fi
372 else
373 SRC="$SRC/bin"
374 fi
375 printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE"
376 unset EXTENSION
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700377 else
Steve Kondika991cf12016-07-28 12:13:12 -0700378 printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700379 fi
380 printf 'LOCAL_MODULE_TAGS := optional\n'
381 printf 'LOCAL_MODULE_CLASS := %s\n' "$CLASS"
Hashbang1733b3a0e12016-08-28 20:38:45 -0400382 if [ "$CLASS" = "APPS" ]; then
383 printf 'LOCAL_DEX_PREOPT := false\n'
384 fi
Steve Kondika991cf12016-07-28 12:13:12 -0700385 if [ ! -z "$EXTENSION" ]; then
386 printf 'LOCAL_MODULE_SUFFIX := .%s\n' "$EXTENSION"
387 fi
M1cha15f226c2017-01-04 09:00:11 +0100388 if [ "$CLASS" = "SHARED_LIBRARIES" ] || [ "$CLASS" = "EXECUTABLES" ]; then
389 if [ "$DIRNAME" != "." ]; then
390 printf 'LOCAL_MODULE_RELATIVE_PATH := %s\n' "$DIRNAME"
391 fi
392 fi
Steve Kondika991cf12016-07-28 12:13:12 -0700393 if [ "$EXTRA" = "priv-app" ]; then
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700394 printf 'LOCAL_PRIVILEGED_MODULE := true\n'
395 fi
396 if [ "$VENDOR_PKG" = "true" ]; then
Ethan Chen5bc3c842018-02-17 20:03:54 -0800397 printf 'LOCAL_VENDOR_MODULE := true\n'
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700398 fi
399 printf 'include $(BUILD_PREBUILT)\n\n'
400 done
401}
402
403#
404# write_product_packages:
405#
406# This function will create BUILD_PREBUILT entries in the
407# Android.mk and associated PRODUCT_PACKAGES list in the
408# product makefile for all files in the blob list which
409# start with a single dash (-) character.
410#
411function write_product_packages() {
412 PACKAGE_LIST=()
413
414 local COUNT=${#PRODUCT_PACKAGES_LIST[@]}
415
416 if [ "$COUNT" = "0" ]; then
417 return 0
418 fi
419
420 # Figure out what's 32-bit, what's 64-bit, and what's multilib
421 # I really should not be doing this in bash due to shitty array passing :(
422 local T_LIB32=( $(prefix_match "lib/") )
423 local T_LIB64=( $(prefix_match "lib64/") )
424 local MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${T_LIB64[@]}")) )
425 local LIB32=( $(comm -23 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${MULTILIBS[@]}")) )
Steve Kondik60ef86d2016-07-20 20:03:40 -0700426 local LIB64=( $(comm -23 <(printf '%s\n' "${T_LIB64[@]}") <(printf '%s\n' "${MULTILIBS[@]}")) )
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700427
Steve Kondik03ce4002016-07-29 00:00:16 -0700428 if [ "${#MULTILIBS[@]}" -gt "0" ]; then
429 write_packages "SHARED_LIBRARIES" "false" "both" "MULTILIBS" >> "$ANDROIDMK"
430 fi
431 if [ "${#LIB32[@]}" -gt "0" ]; then
432 write_packages "SHARED_LIBRARIES" "false" "32" "LIB32" >> "$ANDROIDMK"
433 fi
434 if [ "${#LIB64[@]}" -gt "0" ]; then
435 write_packages "SHARED_LIBRARIES" "false" "64" "LIB64" >> "$ANDROIDMK"
436 fi
437
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700438 local T_V_LIB32=( $(prefix_match "vendor/lib/") )
439 local T_V_LIB64=( $(prefix_match "vendor/lib64/") )
440 local V_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${T_V_LIB64[@]}")) )
441 local V_LIB32=( $(comm -23 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${V_MULTILIBS[@]}")) )
Steve Kondik60ef86d2016-07-20 20:03:40 -0700442 local V_LIB64=( $(comm -23 <(printf '%s\n' "${T_V_LIB64[@]}") <(printf '%s\n' "${V_MULTILIBS[@]}")) )
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700443
444 if [ "${#V_MULTILIBS[@]}" -gt "0" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -0700445 write_packages "SHARED_LIBRARIES" "true" "both" "V_MULTILIBS" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700446 fi
447 if [ "${#V_LIB32[@]}" -gt "0" ]; then
Steve Kondik03ce4002016-07-29 00:00:16 -0700448 write_packages "SHARED_LIBRARIES" "true" "32" "V_LIB32" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700449 fi
450 if [ "${#V_LIB64[@]}" -gt "0" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -0700451 write_packages "SHARED_LIBRARIES" "true" "64" "V_LIB64" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700452 fi
453
454 # Apps
455 local APPS=( $(prefix_match "app/") )
456 if [ "${#APPS[@]}" -gt "0" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -0700457 write_packages "APPS" "false" "" "APPS" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700458 fi
459 local PRIV_APPS=( $(prefix_match "priv-app/") )
460 if [ "${#PRIV_APPS[@]}" -gt "0" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -0700461 write_packages "APPS" "false" "priv-app" "PRIV_APPS" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700462 fi
463 local V_APPS=( $(prefix_match "vendor/app/") )
464 if [ "${#V_APPS[@]}" -gt "0" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -0700465 write_packages "APPS" "true" "" "V_APPS" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700466 fi
467 local V_PRIV_APPS=( $(prefix_match "vendor/priv-app/") )
468 if [ "${#V_PRIV_APPS[@]}" -gt "0" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -0700469 write_packages "APPS" "true" "priv-app" "V_PRIV_APPS" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700470 fi
471
472 # Framework
473 local FRAMEWORK=( $(prefix_match "framework/") )
474 if [ "${#FRAMEWORK[@]}" -gt "0" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -0700475 write_packages "JAVA_LIBRARIES" "false" "" "FRAMEWORK" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700476 fi
Christian Oderc16f3272017-10-08 23:15:52 +0200477 local V_FRAMEWORK=( $(prefix_match "vendor/framework/") )
Michael Bestasa3f97c72018-02-27 22:31:55 +0200478 if [ "${#V_FRAMEWORK[@]}" -gt "0" ]; then
Christian Oderc16f3272017-10-08 23:15:52 +0200479 write_packages "JAVA_LIBRARIES" "true" "" "V_FRAMEWORK" >> "$ANDROIDMK"
480 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700481
482 # Etc
483 local ETC=( $(prefix_match "etc/") )
484 if [ "${#ETC[@]}" -gt "0" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -0700485 write_packages "ETC" "false" "" "ETC" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700486 fi
487 local V_ETC=( $(prefix_match "vendor/etc/") )
488 if [ "${#V_ETC[@]}" -gt "0" ]; then
Rashed Abdel-Tawab00c07662017-10-08 17:33:42 -0400489 write_packages "ETC" "true" "" "V_ETC" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700490 fi
491
492 # Executables
493 local BIN=( $(prefix_match "bin/") )
494 if [ "${#BIN[@]}" -gt "0" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -0700495 write_packages "EXECUTABLES" "false" "" "BIN" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700496 fi
497 local V_BIN=( $(prefix_match "vendor/bin/") )
498 if [ "${#V_BIN[@]}" -gt "0" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -0700499 write_packages "EXECUTABLES" "true" "" "V_BIN" >> "$ANDROIDMK"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700500 fi
Steve Kondika991cf12016-07-28 12:13:12 -0700501 local SBIN=( $(prefix_match "sbin/") )
502 if [ "${#SBIN[@]}" -gt "0" ]; then
503 write_packages "EXECUTABLES" "false" "sbin" "SBIN" >> "$ANDROIDMK"
504 fi
505
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700506
507 # Actually write out the final PRODUCT_PACKAGES list
508 local PACKAGE_COUNT=${#PACKAGE_LIST[@]}
509
510 if [ "$PACKAGE_COUNT" -eq "0" ]; then
511 return 0
512 fi
513
514 printf '\n%s\n' "PRODUCT_PACKAGES += \\" >> "$PRODUCTMK"
515 for (( i=1; i<PACKAGE_COUNT+1; i++ )); do
516 local LINEEND=" \\"
517 if [ "$i" -eq "$PACKAGE_COUNT" ]; then
518 LINEEND=""
519 fi
520 printf ' %s%s\n' "${PACKAGE_LIST[$i-1]}" "$LINEEND" >> "$PRODUCTMK"
521 done
522}
523
524#
525# write_header:
526#
527# $1: file which will be written to
528#
529# writes out the copyright header with the current year.
530# note that this is not an append operation, and should
531# be executed first!
532#
533function write_header() {
Matt Mower8945f5e2017-01-07 14:08:17 -0600534 if [ -f $1 ]; then
535 rm $1
536 fi
537
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700538 YEAR=$(date +"%Y")
539
540 [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON"
541
Matt Mower8945f5e2017-01-07 14:08:17 -0600542 NUM_REGEX='^[0-9]+$'
543 if [[ $INITIAL_COPYRIGHT_YEAR =~ $NUM_REGEX ]] && [ $INITIAL_COPYRIGHT_YEAR -le $YEAR ]; then
544 if [ $INITIAL_COPYRIGHT_YEAR -lt 2016 ]; then
545 printf "# Copyright (C) $INITIAL_COPYRIGHT_YEAR-2016 The CyanogenMod Project\n" > $1
546 elif [ $INITIAL_COPYRIGHT_YEAR -eq 2016 ]; then
547 printf "# Copyright (C) 2016 The CyanogenMod Project\n" > $1
548 fi
549 if [ $YEAR -eq 2017 ]; then
550 printf "# Copyright (C) 2017 The LineageOS Project\n" >> $1
551 elif [ $INITIAL_COPYRIGHT_YEAR -eq $YEAR ]; then
552 printf "# Copyright (C) $YEAR The LineageOS Project\n" >> $1
553 elif [ $INITIAL_COPYRIGHT_YEAR -le 2017 ]; then
554 printf "# Copyright (C) 2017-$YEAR The LineageOS Project\n" >> $1
555 else
556 printf "# Copyright (C) $INITIAL_COPYRIGHT_YEAR-$YEAR The LineageOS Project\n" >> $1
557 fi
558 else
559 printf "# Copyright (C) $YEAR The LineageOS Project\n" > $1
560 fi
561
562 cat << EOF >> $1
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700563#
564# Licensed under the Apache License, Version 2.0 (the "License");
565# you may not use this file except in compliance with the License.
566# You may obtain a copy of the License at
567#
568# http://www.apache.org/licenses/LICENSE-2.0
569#
570# Unless required by applicable law or agreed to in writing, software
571# distributed under the License is distributed on an "AS IS" BASIS,
572# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
573# See the License for the specific language governing permissions and
574# limitations under the License.
575
576# This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh
577
578EOF
579}
580
581#
582# write_headers:
583#
584# $1: devices falling under common to be added to guard - optional
Rashed Abdel-Tawabd53bff12016-10-02 01:00:54 -0400585# $2: custom guard - optional
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700586#
587# Calls write_header for each of the makefiles and creates
588# the initial path declaration and device guard for the
589# Android.mk
590#
591function write_headers() {
592 write_header "$ANDROIDMK"
Rashed Abdel-Tawabd53bff12016-10-02 01:00:54 -0400593
594 GUARD="$2"
595 if [ -z "$GUARD" ]; then
596 GUARD="TARGET_DEVICE"
597 fi
598
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700599 cat << EOF >> "$ANDROIDMK"
600LOCAL_PATH := \$(call my-dir)
601
602EOF
603 if [ "$COMMON" -ne 1 ]; then
604 cat << EOF >> "$ANDROIDMK"
Rashed Abdel-Tawabd53bff12016-10-02 01:00:54 -0400605ifeq (\$($GUARD),$DEVICE)
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700606
607EOF
608 else
609 if [ -z "$1" ]; then
610 echo "Argument with devices to be added to guard must be set!"
611 exit 1
612 fi
613 cat << EOF >> "$ANDROIDMK"
Rashed Abdel-Tawabd53bff12016-10-02 01:00:54 -0400614ifneq (\$(filter $1,\$($GUARD)),)
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700615
616EOF
617 fi
618
619 write_header "$BOARDMK"
620 write_header "$PRODUCTMK"
621}
622
623#
624# write_footers:
625#
626# Closes the inital guard and any other finalization tasks. Must
627# be called as the final step.
628#
629function write_footers() {
630 cat << EOF >> "$ANDROIDMK"
631endif
632EOF
633}
634
635# Return success if adb is up and not in recovery
636function _adb_connected {
637 {
Steve Kondik7561d192016-09-01 21:40:27 -0700638 if [[ "$(adb get-state)" == device ]]
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700639 then
640 return 0
641 fi
642 } 2>/dev/null
643
644 return 1
645};
646
647#
Bruno Martins3b96ba52016-07-27 15:00:05 +0100648# parse_file_list:
649#
650# $1: input file
Rashed Abdel-Tawab855fbdd2017-04-04 02:48:18 -0400651# $2: blob section in file - optional
Bruno Martins3b96ba52016-07-27 15:00:05 +0100652#
653# Sets PRODUCT_PACKAGES and PRODUCT_COPY_FILES while parsing the input file
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700654#
655function parse_file_list() {
Bruno Martins3b96ba52016-07-27 15:00:05 +0100656 if [ -z "$1" ]; then
657 echo "An input file is expected!"
658 exit 1
659 elif [ ! -f "$1" ]; then
660 echo "Input file "$1" does not exist!"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700661 exit 1
662 fi
663
Vladimir Olteanc5034462019-01-17 03:04:16 +0200664 if [ -n "$2" ]; then
665 echo "Using section \"$2\""
Rashed Abdel-Tawab855fbdd2017-04-04 02:48:18 -0400666 LIST=$TMPDIR/files.txt
Vladimir Oltean5238ba82019-01-19 00:44:07 +0200667 # Match all lines starting with first line found to start* with '#'
668 # comment and contain** $2, and ending with first line to be empty*.
669 # *whitespaces (tabs, spaces) at the beginning of lines are discarded
670 # **the $2 match is case-insensitive
671 cat $1 | sed -n '/^[[:space:]]*#.*'"$2"'/I,/^[[:space:]]*$/ p' > $LIST
Rashed Abdel-Tawab855fbdd2017-04-04 02:48:18 -0400672 else
673 LIST=$1
674 fi
675
676
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700677 PRODUCT_PACKAGES_LIST=()
Steve Kondik48f8df82016-08-14 03:55:08 -0700678 PRODUCT_PACKAGES_HASHES=()
Vladimir Oltean4818c232019-01-17 03:07:34 +0200679 PRODUCT_PACKAGES_FIXUP_HASHES=()
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700680 PRODUCT_COPY_FILES_LIST=()
Steve Kondik48f8df82016-08-14 03:55:08 -0700681 PRODUCT_COPY_FILES_HASHES=()
Vladimir Oltean4818c232019-01-17 03:07:34 +0200682 PRODUCT_COPY_FILES_FIXUP_HASHES=()
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700683
684 while read -r line; do
685 if [ -z "$line" ]; then continue; fi
686
Steve Kondik48f8df82016-08-14 03:55:08 -0700687 # If the line has a pipe delimiter, a sha1 hash should follow.
688 # This indicates the file should be pinned and not overwritten
689 # when extracting files.
690 local SPLIT=(${line//\|/ })
691 local COUNT=${#SPLIT[@]}
692 local SPEC=${SPLIT[0]}
693 local HASH="x"
Vladimir Oltean4818c232019-01-17 03:07:34 +0200694 local FIXUP_HASH="x"
Steve Kondik48f8df82016-08-14 03:55:08 -0700695 if [ "$COUNT" -gt "1" ]; then
696 HASH=${SPLIT[1]}
697 fi
Vladimir Oltean4818c232019-01-17 03:07:34 +0200698 if [ "$COUNT" -gt "2" ]; then
699 FIXUP_HASH=${SPLIT[2]}
700 fi
Steve Kondik48f8df82016-08-14 03:55:08 -0700701
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700702 # if line starts with a dash, it needs to be packaged
Steve Kondik48f8df82016-08-14 03:55:08 -0700703 if [[ "$SPEC" =~ ^- ]]; then
704 PRODUCT_PACKAGES_LIST+=("${SPEC#-}")
705 PRODUCT_PACKAGES_HASHES+=("$HASH")
Vladimir Oltean4818c232019-01-17 03:07:34 +0200706 PRODUCT_PACKAGES_FIXUP_HASHES+=("$FIXUP_HASH")
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700707 else
Steve Kondik48f8df82016-08-14 03:55:08 -0700708 PRODUCT_COPY_FILES_LIST+=("$SPEC")
709 PRODUCT_COPY_FILES_HASHES+=("$HASH")
Vladimir Oltean4818c232019-01-17 03:07:34 +0200710 PRODUCT_COPY_FILES_FIXUP_HASHES+=("$FIXUP_HASH")
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700711 fi
712
Rashed Abdel-Tawab855fbdd2017-04-04 02:48:18 -0400713 done < <(egrep -v '(^#|^[[:space:]]*$)' "$LIST" | LC_ALL=C sort | uniq)
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700714}
715
716#
717# write_makefiles:
718#
719# $1: file containing the list of items to extract
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400720# $2: make treble compatible makefile - optional
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700721#
722# Calls write_product_copy_files and write_product_packages on
723# the given file and appends to the Android.mk as well as
724# the product makefile.
725#
726function write_makefiles() {
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700727 parse_file_list "$1"
Rashed Abdel-Tawab0ca76432017-10-07 14:18:39 -0400728 write_product_copy_files "$2"
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700729 write_product_packages
730}
731
732#
Louis Popia516c2f2016-07-25 15:51:13 +0200733# append_firmware_calls_to_makefiles:
734#
735# Appends to Android.mk the calls to all images present in radio folder
736# (filesmap file used by releasetools to map firmware images should be kept in the device tree)
737#
738function append_firmware_calls_to_makefiles() {
739 cat << EOF >> "$ANDROIDMK"
740ifeq (\$(LOCAL_PATH)/radio, \$(wildcard \$(LOCAL_PATH)/radio))
741
742RADIO_FILES := \$(wildcard \$(LOCAL_PATH)/radio/*)
743\$(foreach f, \$(notdir \$(RADIO_FILES)), \\
744 \$(call add-radio-file,radio/\$(f)))
745\$(call add-radio-file,../../../device/$VENDOR/$DEVICE/radio/filesmap)
746
747endif
748
749EOF
750}
751
752#
Luca Stefani7f9fff22016-07-18 13:47:55 +0200753# get_file:
754#
755# $1: input file
756# $2: target file/folder
757# $3: source of the file (can be "adb" or a local folder)
758#
759# Silently extracts the input file to defined target
760# Returns success if file can be pulled from the device or found locally
761#
762function get_file() {
763 local SRC="$3"
764
765 if [ "$SRC" = "adb" ]; then
766 # try to pull
767 adb pull "$1" "$2" >/dev/null 2>&1 && return 0
768
769 return 1
770 else
771 # try to copy
Vladimir Olteand5773252018-06-25 00:05:56 +0300772 cp -r "$SRC/$1" "$2" 2>/dev/null && return 0
773 cp -r "$SRC/${1#/system}" "$2" 2>/dev/null && return 0
Vladimir Oltean78d690d2019-01-06 19:38:31 +0200774 cp -r "$SRC/system/$1" "$2" 2>/dev/null && return 0
Luca Stefani7f9fff22016-07-18 13:47:55 +0200775
776 return 1
777 fi
778};
779
780#
781# oat2dex:
782#
783# $1: extracted apk|jar (to check if deodex is required)
784# $2: odexed apk|jar to deodex
785# $3: source of the odexed apk|jar
786#
787# Convert apk|jar .odex in the corresposing classes.dex
788#
789function oat2dex() {
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200790 local LINEAGE_TARGET="$1"
Luca Stefani7f9fff22016-07-18 13:47:55 +0200791 local OEM_TARGET="$2"
792 local SRC="$3"
793 local TARGET=
794 local OAT=
Joe Maples9be579f2018-01-05 14:51:33 -0500795 local HOST="$(uname)"
Luca Stefani7f9fff22016-07-18 13:47:55 +0200796
797 if [ -z "$BAKSMALIJAR" ] || [ -z "$SMALIJAR" ]; then
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200798 export BAKSMALIJAR="$LINEAGE_ROOT"/vendor/lineage/build/tools/smali/baksmali.jar
799 export SMALIJAR="$LINEAGE_ROOT"/vendor/lineage/build/tools/smali/smali.jar
Luca Stefani7f9fff22016-07-18 13:47:55 +0200800 fi
801
Joe Maples9be579f2018-01-05 14:51:33 -0500802 if [ -z "$VDEXEXTRACTOR" ]; then
803 export VDEXEXTRACTOR="$LINEAGE_ROOT"/vendor/lineage/build/tools/"$HOST"/vdexExtractor
804 fi
805
codeworkx1c29bf62018-09-23 12:36:57 +0200806 if [ -z "$CDEXCONVERTER" ]; then
807 export CDEXCONVERTER="$LINEAGE_ROOT"/vendor/lineage/build/tools/"$HOST"/compact_dex_converter
808 fi
809
Luca Stefani7f9fff22016-07-18 13:47:55 +0200810 # Extract existing boot.oats to the temp folder
811 if [ -z "$ARCHES" ]; then
Sam Mortimer2e994ce2016-10-05 09:50:49 -0700812 echo "Checking if system is odexed and locating boot.oats..."
Luca Stefani7f9fff22016-07-18 13:47:55 +0200813 for ARCH in "arm64" "arm" "x86_64" "x86"; do
Sam Mortimer2e994ce2016-10-05 09:50:49 -0700814 mkdir -p "$TMPDIR/system/framework/$ARCH"
Vladimir Olteand5773252018-06-25 00:05:56 +0300815 if get_file "/system/framework/$ARCH" "$TMPDIR/system/framework/" "$SRC"; then
Luca Stefani7f9fff22016-07-18 13:47:55 +0200816 ARCHES+="$ARCH "
Sam Mortimer2e994ce2016-10-05 09:50:49 -0700817 else
818 rmdir "$TMPDIR/system/framework/$ARCH"
Luca Stefani7f9fff22016-07-18 13:47:55 +0200819 fi
820 done
821 fi
822
823 if [ -z "$ARCHES" ]; then
824 FULLY_DEODEXED=1 && return 0 # system is fully deodexed, return
825 fi
826
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200827 if [ ! -f "$LINEAGE_TARGET" ]; then
Steve Kondik48f8df82016-08-14 03:55:08 -0700828 return;
829 fi
830
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200831 if grep "classes.dex" "$LINEAGE_TARGET" >/dev/null; then
Luca Stefani7f9fff22016-07-18 13:47:55 +0200832 return 0 # target apk|jar is already odexed, return
833 fi
834
835 for ARCH in $ARCHES; do
Sam Mortimer2e994ce2016-10-05 09:50:49 -0700836 BOOTOAT="$TMPDIR/system/framework/$ARCH/boot.oat"
Luca Stefani7f9fff22016-07-18 13:47:55 +0200837
838 local OAT="$(dirname "$OEM_TARGET")/oat/$ARCH/$(basename "$OEM_TARGET" ."${OEM_TARGET##*.}").odex"
Rashed Abdel-Tawab54b5d5e2017-08-23 15:13:17 -0400839 local VDEX="$(dirname "$OEM_TARGET")/oat/$ARCH/$(basename "$OEM_TARGET" ."${OEM_TARGET##*.}").vdex"
Luca Stefani7f9fff22016-07-18 13:47:55 +0200840
841 if get_file "$OAT" "$TMPDIR" "$SRC"; then
Rashed Abdel-Tawab54b5d5e2017-08-23 15:13:17 -0400842 if get_file "$VDEX" "$TMPDIR" "$SRC"; then
Joe Maples9be579f2018-01-05 14:51:33 -0500843 "$VDEXEXTRACTOR" -o "$TMPDIR/" -i "$TMPDIR/$(basename "$VDEX")" > /dev/null
codeworkx1c29bf62018-09-23 12:36:57 +0200844 # Check if we have to deal with CompactDex
845 if [ -f "$TMPDIR/$(basename "${OEM_TARGET%.*}")_classes.cdex" ]; then
846 "$CDEXCONVERTER" "$TMPDIR/$(basename "${OEM_TARGET%.*}")_classes.cdex" &> /dev/null
847 mv "$TMPDIR/$(basename "${OEM_TARGET%.*}")_classes.cdex.new" "$TMPDIR/classes.dex"
848 else
TheStrix5aad0742018-10-03 19:06:49 +0530849 mv "$TMPDIR/$(basename "${OEM_TARGET%.*}")_classes.dex" "$TMPDIR/classes.dex"
codeworkx1c29bf62018-09-23 12:36:57 +0200850 fi
Joe Maples9be579f2018-01-05 14:51:33 -0500851 else
852 java -jar "$BAKSMALIJAR" deodex -o "$TMPDIR/dexout" -b "$BOOTOAT" -d "$TMPDIR" "$TMPDIR/$(basename "$OAT")"
853 java -jar "$SMALIJAR" assemble "$TMPDIR/dexout" -o "$TMPDIR/classes.dex"
Rashed Abdel-Tawab54b5d5e2017-08-23 15:13:17 -0400854 fi
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200855 elif [[ "$LINEAGE_TARGET" =~ .jar$ ]]; then
Gabriele M4cf635a2017-01-05 22:10:00 +0100856 JAROAT="$TMPDIR/system/framework/$ARCH/boot-$(basename ${OEM_TARGET%.*}).oat"
Luca Stefanif6096e92018-10-07 12:44:53 +0200857 JARVDEX="/system/framework/boot-$(basename ${OEM_TARGET%.*}).vdex"
Gabriele M4cf635a2017-01-05 22:10:00 +0100858 if [ ! -f "$JAROAT" ]; then
Luca Stefanif6096e92018-10-07 12:44:53 +0200859 JAROAT=$BOOTOAT
Gabriele M4cf635a2017-01-05 22:10:00 +0100860 fi
Joe Maples9be579f2018-01-05 14:51:33 -0500861 # try to extract classes.dex from boot.vdex for frameworks jars
862 # fallback to boot.oat if vdex is not available
Luca Stefanif6096e92018-10-07 12:44:53 +0200863 if get_file "$JARVDEX" "$TMPDIR" "$SRC"; then
Luca Stefani99a66bf2018-10-31 19:16:05 +0100864 "$VDEXEXTRACTOR" -o "$TMPDIR/" -i "$TMPDIR/$(basename "$JARVDEX")" > /dev/null
Luca Stefanif6096e92018-10-07 12:44:53 +0200865 # Check if we have to deal with CompactDex
866 if [ -f "$TMPDIR/$(basename "${JARVDEX%.*}")_classes.cdex" ]; then
867 "$CDEXCONVERTER" "$TMPDIR/$(basename "${JARVDEX%.*}")_classes.cdex" &> /dev/null
868 mv "$TMPDIR/$(basename "${JARVDEX%.*}")_classes.cdex.new" "$TMPDIR/classes.dex"
869 else
870 mv "$TMPDIR/$(basename "${JARVDEX%.*}")_classes.dex" "$TMPDIR/classes.dex"
871 fi
Joe Maples9be579f2018-01-05 14:51:33 -0500872 else
873 java -jar "$BAKSMALIJAR" deodex -o "$TMPDIR/dexout" -b "$BOOTOAT" -d "$TMPDIR" "$JAROAT/$OEM_TARGET"
874 java -jar "$SMALIJAR" assemble "$TMPDIR/dexout" -o "$TMPDIR/classes.dex"
875 fi
Luca Stefani7f9fff22016-07-18 13:47:55 +0200876 else
877 continue
878 fi
879
Luca Stefani7f9fff22016-07-18 13:47:55 +0200880 done
881
882 rm -rf "$TMPDIR/dexout"
883}
884
885#
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700886# init_adb_connection:
887#
888# Starts adb server and waits for the device
889#
890function init_adb_connection() {
891 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
892 if ! _adb_connected; then
893 echo "No device is online. Waiting for one..."
894 echo "Please connect USB and/or enable USB debugging"
895 until _adb_connected; do
896 sleep 1
897 done
898 echo "Device Found."
899 fi
900
901 # Retrieve IP and PORT info if we're using a TCP connection
902 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
903 | head -1 | awk '{print $1}')
904 adb root &> /dev/null
905 sleep 0.3
906 if [ -n "$TCPIPPORT" ]; then
907 # adb root just killed our connection
908 # so reconnect...
909 adb connect "$TCPIPPORT"
910 fi
911 adb wait-for-device &> /dev/null
912 sleep 0.3
913}
914
915#
Luca Stefani3a030122016-07-30 12:08:25 +0200916# fix_xml:
917#
918# $1: xml file to fix
919#
920function fix_xml() {
921 local XML="$1"
922 local TEMP_XML="$TMPDIR/`basename "$XML"`.temp"
923
Dobroslaw Kijowski65f03f12017-05-18 12:35:02 +0200924 grep -a '^<?xml version' "$XML" > "$TEMP_XML"
925 grep -av '^<?xml version' "$XML" >> "$TEMP_XML"
Luca Stefani3a030122016-07-30 12:08:25 +0200926
927 mv "$TEMP_XML" "$XML"
928}
929
Vladimir Oltean4818c232019-01-17 03:07:34 +0200930function get_hash() {
931 local FILE="$1"
932
933 if [ "$(uname)" == "Darwin" ]; then
934 shasum "${FILE}" | awk '{print $1}'
935 else
936 sha1sum "${FILE}" | awk '{print $1}'
937 fi
938}
939
Vladimir Olteanbec92eb2019-01-17 03:05:52 +0200940function print_spec() {
941 local SPEC_PRODUCT_PACKAGE="$1"
942 local SPEC_SRC_FILE="$2"
943 local SPEC_DST_FILE="$3"
944 local SPEC_ARGS="$4"
945 local SPEC_HASH="$5"
Vladimir Oltean4818c232019-01-17 03:07:34 +0200946 local SPEC_FIXUP_HASH="$6"
Vladimir Olteanbec92eb2019-01-17 03:05:52 +0200947
948 local PRODUCT_PACKAGE=""
949 if [ ${SPEC_PRODUCT_PACKAGE} = true ]; then
950 PRODUCT_PACKAGE="-"
951 fi
952 local SRC=""
953 if [ ! -z "${SPEC_SRC_FILE}" ] && [ "${SPEC_SRC_FILE}" != "${SPEC_DST_FILE}" ]; then
954 SRC="${SPEC_SRC_FILE}:"
955 fi
956 local DST=""
957 if [ ! -z "${SPEC_DST_FILE}" ]; then
958 DST="${SPEC_DST_FILE}"
959 fi
960 local ARGS=""
961 if [ ! -z "${SPEC_ARGS}" ]; then
962 ARGS=";${SPEC_ARGS}"
963 fi
964 local HASH=""
965 if [ ! -z "${SPEC_HASH}" ] && [ "${SPEC_HASH}" != "x" ]; then
966 HASH="|${SPEC_HASH}"
967 fi
Vladimir Oltean4818c232019-01-17 03:07:34 +0200968 local FIXUP_HASH=""
969 if [ ! -z "${SPEC_FIXUP_HASH}" ] && [ "${SPEC_FIXUP_HASH}" != "x" ] && [ "${SPEC_FIXUP_HASH}" != "${SPEC_HASH}" ]; then
970 FIXUP_HASH="|${SPEC_FIXUP_HASH}"
971 fi
972 printf '%s%s%s%s%s%s\n' "${PRODUCT_PACKAGE}" "${SRC}" "${DST}" "${ARGS}" "${HASH}" "${FIXUP_HASH}"
973}
974
975# To be overridden by device-level extract-files.sh
976# Parameters:
977# $1: spec name of a blob. Can be used for filtering.
978# If the spec is "src:dest", then $1 is "dest".
979# If the spec is "src", then $1 is "src".
980# $2: path to blob file. Can be used for fixups.
981#
982function blob_fixup() {
983 :
Vladimir Olteanbec92eb2019-01-17 03:05:52 +0200984}
985
Luca Stefani3a030122016-07-30 12:08:25 +0200986#
Steve Kondik4e2aaab2016-07-15 10:39:58 -0700987# extract:
988#
Vladimir Olteanc5034462019-01-17 03:04:16 +0200989# Positional parameters:
990# $1: file containing the list of items to extract (aka proprietary-files.txt)
Dan Pasanen7dc287f2017-03-21 09:06:11 -0500991# $2: path to extracted system folder, an ota zip file, or "adb" to extract from device
Vladimir Olteanc5034462019-01-17 03:04:16 +0200992# $3: section in list file to extract - optional. Setting section via $3 is deprecated.
993#
994# Non-positional parameters (coming after $2):
995# --section: preferred way of selecting the portion to parse and extract from
996# proprietary-files.txt
Vladimir Olteanbec92eb2019-01-17 03:05:52 +0200997# --kang: if present, this option will activate the printing of hashes for the
998# extracted blobs. Useful with --section for subsequent pinning of
999# blobs taken from other origins.
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001000#
1001function extract() {
Vladimir Olteanc5034462019-01-17 03:04:16 +02001002 # Consume positional parameters
1003 local PROPRIETARY_FILES_TXT="$1"; shift
1004 local SRC="$1"; shift
1005 local SECTION=""
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001006 local KANG=false
Vladimir Olteanc5034462019-01-17 03:04:16 +02001007
1008 # Consume optional, non-positional parameters
1009 while [ "$#" -gt 0 ]; do
1010 case "$1" in
1011 -s|--section)
1012 SECTION="$2"; shift
1013 ;;
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001014 -k|--kang)
1015 KANG=true
1016 DISABLE_PINNING=1
1017 ;;
Vladimir Olteanc5034462019-01-17 03:04:16 +02001018 *)
1019 # Backwards-compatibility with the old behavior, where $3, if
1020 # present, denoted an optional positional ${SECTION} argument.
1021 # Users of ${SECTION} are encouraged to migrate from setting it as
1022 # positional $3, to non-positional --section ${SECTION}, the
1023 # reason being that it doesn't scale to have more than 1 optional
1024 # positional argument.
1025 SECTION="$1"
1026 ;;
1027 esac
1028 shift
1029 done
1030
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001031 if [ -z "$OUTDIR" ]; then
1032 echo "Output dir not set!"
1033 exit 1
1034 fi
1035
Vladimir Olteanc5034462019-01-17 03:04:16 +02001036 parse_file_list "${PROPRIETARY_FILES_TXT}" "${SECTION}"
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001037
1038 # Allow failing, so we can try $DEST and/or $FILE
1039 set +e
1040
1041 local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ${PRODUCT_PACKAGES_LIST[@]} )
Steve Kondik48f8df82016-08-14 03:55:08 -07001042 local HASHLIST=( ${PRODUCT_COPY_FILES_HASHES[@]} ${PRODUCT_PACKAGES_HASHES[@]} )
Vladimir Oltean4818c232019-01-17 03:07:34 +02001043 local FIXUP_HASHLIST=( ${PRODUCT_COPY_FILES_FIXUP_HASHES[@]} ${PRODUCT_PACKAGES_FIXUP_HASHES[@]} )
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001044 local PRODUCT_COPY_FILES_COUNT=${#PRODUCT_COPY_FILES_LIST[@]}
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001045 local COUNT=${#FILELIST[@]}
Luca Stefani5c60e4f2017-08-17 19:28:48 +02001046 local OUTPUT_ROOT="$LINEAGE_ROOT"/"$OUTDIR"/proprietary
Steve Kondik48f8df82016-08-14 03:55:08 -07001047 local OUTPUT_TMP="$TMPDIR"/"$OUTDIR"/proprietary
1048
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001049 if [ "$SRC" = "adb" ]; then
1050 init_adb_connection
1051 fi
1052
Dan Pasanen7dc287f2017-03-21 09:06:11 -05001053 if [ -f "$SRC" ] && [ "${SRC##*.}" == "zip" ]; then
conbold575c6352017-11-10 16:33:38 +01001054 DUMPDIR="$TMPDIR"/system_dump
Dan Pasanen7dc287f2017-03-21 09:06:11 -05001055
1056 # Check if we're working with the same zip that was passed last time.
1057 # If so, let's just use what's already extracted.
1058 MD5=`md5sum "$SRC"| awk '{print $1}'`
1059 OLDMD5=`cat "$DUMPDIR"/zipmd5.txt`
1060
1061 if [ "$MD5" != "$OLDMD5" ]; then
1062 rm -rf "$DUMPDIR"
1063 mkdir "$DUMPDIR"
1064 unzip "$SRC" -d "$DUMPDIR"
1065 echo "$MD5" > "$DUMPDIR"/zipmd5.txt
1066
1067 # Stop if an A/B OTA zip is detected. We cannot extract these.
1068 if [ -a "$DUMPDIR"/payload.bin ]; then
1069 echo "A/B style OTA zip detected. This is not supported at this time. Stopping..."
1070 exit 1
1071 # If OTA is block based, extract it.
1072 elif [ -a "$DUMPDIR"/system.new.dat ]; then
1073 echo "Converting system.new.dat to system.img"
Luca Stefani5c60e4f2017-08-17 19:28:48 +02001074 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 -05001075 rm -rf "$DUMPDIR"/system.new.dat "$DUMPDIR"/system
1076 mkdir "$DUMPDIR"/system "$DUMPDIR"/tmp
1077 echo "Requesting sudo access to mount the system.img"
1078 sudo mount -o loop "$DUMPDIR"/system.img "$DUMPDIR"/tmp
1079 cp -r "$DUMPDIR"/tmp/* "$DUMPDIR"/system/
1080 sudo umount "$DUMPDIR"/tmp
1081 rm -rf "$DUMPDIR"/tmp "$DUMPDIR"/system.img
1082 fi
1083 fi
1084
1085 SRC="$DUMPDIR"
1086 fi
1087
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001088 if [ "$VENDOR_STATE" -eq "0" ]; then
Steve Kondika991cf12016-07-28 12:13:12 -07001089 echo "Cleaning output directory ($OUTPUT_ROOT).."
Steve Kondik48f8df82016-08-14 03:55:08 -07001090 rm -rf "${OUTPUT_TMP:?}"
1091 mkdir -p "${OUTPUT_TMP:?}"
Adrian DC3c6bdac2017-01-15 14:03:26 +01001092 if [ -d "$OUTPUT_ROOT" ]; then
1093 mv "${OUTPUT_ROOT:?}/"* "${OUTPUT_TMP:?}/"
1094 fi
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001095 VENDOR_STATE=1
1096 fi
1097
Vladimir Olteanc5034462019-01-17 03:04:16 +02001098 echo "Extracting ${COUNT} files in ${PROPRIETARY_FILES_TXT} from ${SRC}:"
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001099
1100 for (( i=1; i<COUNT+1; i++ )); do
Steve Kondika991cf12016-07-28 12:13:12 -07001101
Vladimir Olteanda3b6442018-06-24 20:41:30 +03001102 local SPEC_SRC_FILE=$(src_file "${FILELIST[$i-1]}")
Vladimir Oltean411e0692018-06-24 20:38:04 +03001103 local SPEC_DST_FILE=$(target_file "${FILELIST[$i-1]}")
Vladimir Olteand652a062018-06-24 20:42:01 +03001104 local SPEC_ARGS=$(target_args "${FILELIST[$i-1]}")
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001105 local OUTPUT_DIR=
1106 local TMP_DIR=
1107 local SRC_FILE=
1108 local DST_FILE=
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001109 local IS_PRODUCT_PACKAGE=false
1110
1111 # Note: this relies on the fact that the ${FILELIST[@]} array
1112 # contains first ${PRODUCT_COPY_FILES_LIST[@]}, then ${PRODUCT_PACKAGES_LIST[@]}.
1113 if [ "${i}" -gt "${PRODUCT_COPY_FILES_COUNT}" ]; then
1114 IS_PRODUCT_PACKAGE=true
1115 fi
Steve Kondika991cf12016-07-28 12:13:12 -07001116
Vladimir Olteand652a062018-06-24 20:42:01 +03001117 if [ "${SPEC_ARGS}" = "rootfs" ]; then
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001118 OUTPUT_DIR="${OUTPUT_ROOT}/rootfs"
1119 TMP_DIR="${OUTPUT_TMP}/rootfs"
1120 SRC_FILE="/${SPEC_SRC_FILE}"
1121 DST_FILE="/${SPEC_DST_FILE}"
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001122 else
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001123 OUTPUT_DIR="${OUTPUT_ROOT}"
1124 TMP_DIR="${OUTPUT_TMP}"
1125 SRC_FILE="/system/${SPEC_SRC_FILE}"
1126 DST_FILE="/system/${SPEC_DST_FILE}"
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001127 fi
Steve Kondika991cf12016-07-28 12:13:12 -07001128
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001129 # Strip the file path in the vendor repo of "system", if present
1130 local VENDOR_REPO_FILE="$OUTPUT_DIR/${DST_FILE#/system}"
Vladimir Olteanc5034462019-01-17 03:04:16 +02001131 local BLOB_DISPLAY_NAME="${DST_FILE#/system/}"
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001132 mkdir -p $(dirname "${VENDOR_REPO_FILE}")
Steve Kondika991cf12016-07-28 12:13:12 -07001133
Gabriele Me6df25b2017-10-11 00:58:59 +02001134 # Check pinned files
Vladimir Olteanb2c38212019-01-17 02:47:02 +02001135 local HASH="$(echo ${HASHLIST[$i-1]} | awk '{ print tolower($0); }')"
Vladimir Oltean4818c232019-01-17 03:07:34 +02001136 local FIXUP_HASH="$(echo ${FIXUP_HASHLIST[$i-1]} | awk '{ print tolower($0); }')"
Gabriele Me6df25b2017-10-11 00:58:59 +02001137 local KEEP=""
Vladimir Oltean4818c232019-01-17 03:07:34 +02001138 if [ "$DISABLE_PINNING" != "1" ] && [ "$HASH" != "x" ]; then
Vladimir Olteand6747712018-06-24 20:46:42 +03001139 if [ -f "${VENDOR_REPO_FILE}" ]; then
1140 local PINNED="${VENDOR_REPO_FILE}"
Gabriele Me6df25b2017-10-11 00:58:59 +02001141 else
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001142 local PINNED="${TMP_DIR}${DST_FILE#/system}"
Gabriele Me6df25b2017-10-11 00:58:59 +02001143 fi
1144 if [ -f "$PINNED" ]; then
Vladimir Oltean4818c232019-01-17 03:07:34 +02001145 local TMP_HASH=$(get_hash "${PINNED}")
1146 if [ "${TMP_HASH}" = "${HASH}" ] || [ "${TMP_HASH}" = "${FIXUP_HASH}" ]; then
Gabriele Me6df25b2017-10-11 00:58:59 +02001147 KEEP="1"
Vladimir Olteand6747712018-06-24 20:46:42 +03001148 if [ ! -f "${VENDOR_REPO_FILE}" ]; then
1149 cp -p "$PINNED" "${VENDOR_REPO_FILE}"
Gabriele Me6df25b2017-10-11 00:58:59 +02001150 fi
1151 fi
1152 fi
1153 fi
1154
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001155 if [ "${KANG}" = false ]; then
1156 printf ' - %s\n' "${BLOB_DISPLAY_NAME}"
1157 fi
1158
Gabriele Me6df25b2017-10-11 00:58:59 +02001159 if [ "$KEEP" = "1" ]; then
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001160 printf ' + keeping pinned file with hash %s\n' "${HASH}"
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001161 else
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001162 FOUND=false
1163 # Try Lineage target first.
1164 # Also try to search for files stripped of
1165 # the "/system" prefix, if we're actually extracting
1166 # from a system image.
Vladimir Olteand5773252018-06-25 00:05:56 +03001167 for CANDIDATE in "${DST_FILE}" "${SRC_FILE}"; do
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001168 get_file ${CANDIDATE} ${VENDOR_REPO_FILE} ${SRC} && {
1169 FOUND=true
1170 break
1171 }
1172 done
1173
1174 if [ "${FOUND}" = false ]; then
Vladimir Olteanc5034462019-01-17 03:04:16 +02001175 printf ' !! %s: file not found in source\n' "${BLOB_DISPLAY_NAME}"
Vladimir Olteanb8084ec2018-10-18 00:44:02 +03001176 continue
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001177 fi
1178 fi
Steve Kondika991cf12016-07-28 12:13:12 -07001179
Vladimir Oltean4818c232019-01-17 03:07:34 +02001180 # Blob fixup pipeline has 2 parts: one that is fixed and
1181 # one that is user-configurable
1182 local PRE_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE})
1183 # Deodex apk|jar if that's the case
1184 if [[ "$FULLY_DEODEXED" -ne "1" && "${VENDOR_REPO_FILE}" =~ .(apk|jar)$ ]]; then
1185 oat2dex "${VENDOR_REPO_FILE}" "${SRC_FILE}" "$SRC"
1186 if [ -f "$TMPDIR/classes.dex" ]; then
1187 zip -gjq "${VENDOR_REPO_FILE}" "$TMPDIR/classes.dex"
1188 rm "$TMPDIR/classes.dex"
1189 printf ' (updated %s from odex files)\n' "${SRC_FILE}"
Luca Stefani7f9fff22016-07-18 13:47:55 +02001190 fi
Vladimir Oltean4818c232019-01-17 03:07:34 +02001191 elif [[ "${VENDOR_REPO_FILE}" =~ .xml$ ]]; then
1192 fix_xml "${VENDOR_REPO_FILE}"
Luca Stefani7f9fff22016-07-18 13:47:55 +02001193 fi
Vladimir Oltean4818c232019-01-17 03:07:34 +02001194 # Now run user-supplied fixup function
1195 blob_fixup "${BLOB_DISPLAY_NAME}" "${VENDOR_REPO_FILE}"
1196 local POST_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE})
Luca Stefani7f9fff22016-07-18 13:47:55 +02001197
Vladimir Olteand6747712018-06-24 20:46:42 +03001198 if [ -f "${VENDOR_REPO_FILE}" ]; then
Vladimir Oltean5f15e3e2018-06-24 21:06:12 +03001199 local DIR=$(dirname "${VENDOR_REPO_FILE}")
Steve Kondik48f8df82016-08-14 03:55:08 -07001200 local TYPE="${DIR##*/}"
1201 if [ "$TYPE" = "bin" -o "$TYPE" = "sbin" ]; then
Vladimir Olteand6747712018-06-24 20:46:42 +03001202 chmod 755 "${VENDOR_REPO_FILE}"
Steve Kondik48f8df82016-08-14 03:55:08 -07001203 else
Vladimir Olteand6747712018-06-24 20:46:42 +03001204 chmod 644 "${VENDOR_REPO_FILE}"
Steve Kondik48f8df82016-08-14 03:55:08 -07001205 fi
1206 fi
1207
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001208 if [ "${KANG}" = true ]; then
Vladimir Oltean4818c232019-01-17 03:07:34 +02001209 print_spec "${IS_PRODUCT_PACKAGE}" "${SPEC_SRC_FILE}" "${SPEC_DST_FILE}" "${SPEC_ARGS}" "${PRE_FIXUP_HASH}" "${POST_FIXUP_HASH}"
1210 fi
1211
1212 # Check and print whether the fixup pipeline actually did anything.
1213 # This isn't done right after the fixup pipeline because we want this print
1214 # to come after print_spec above, when in kang mode.
1215 if [ "${PRE_FIXUP_HASH}" != "${POST_FIXUP_HASH}" ]; then
1216 printf " + Fixed up %s\n" "${BLOB_DISPLAY_NAME}"
1217 # Now sanity-check the spec for this blob.
1218 if [ "${KANG}" = false ] && [ "${FIXUP_HASH}" = "x" ] && [ "${HASH}" != "x" ]; then
1219 printf "WARNING: The %s file was fixed up, but it is pinned.\n" ${BLOB_DISPLAY_NAME}
1220 printf "This is a mistake and you want to either remove the hash completely, or add an extra one.\n"
1221 fi
Vladimir Olteanbec92eb2019-01-17 03:05:52 +02001222 fi
1223
Steve Kondik4e2aaab2016-07-15 10:39:58 -07001224 done
1225
1226 # Don't allow failing
1227 set -e
1228}
Louis Popia516c2f2016-07-25 15:51:13 +02001229
1230#
1231# extract_firmware:
1232#
1233# $1: file containing the list of items to extract
1234# $2: path to extracted radio folder
1235#
1236function extract_firmware() {
1237 if [ -z "$OUTDIR" ]; then
1238 echo "Output dir not set!"
1239 exit 1
1240 fi
1241
1242 parse_file_list "$1"
1243
1244 # Don't allow failing
1245 set -e
1246
1247 local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} )
1248 local COUNT=${#FILELIST[@]}
1249 local SRC="$2"
Luca Stefani5c60e4f2017-08-17 19:28:48 +02001250 local OUTPUT_DIR="$LINEAGE_ROOT"/"$OUTDIR"/radio
Louis Popia516c2f2016-07-25 15:51:13 +02001251
1252 if [ "$VENDOR_RADIO_STATE" -eq "0" ]; then
1253 echo "Cleaning firmware output directory ($OUTPUT_DIR).."
1254 rm -rf "${OUTPUT_DIR:?}/"*
1255 VENDOR_RADIO_STATE=1
1256 fi
1257
1258 echo "Extracting $COUNT files in $1 from $SRC:"
1259
1260 for (( i=1; i<COUNT+1; i++ )); do
1261 local FILE="${FILELIST[$i-1]}"
1262 printf ' - %s \n' "/radio/$FILE"
1263
1264 if [ ! -d "$OUTPUT_DIR" ]; then
1265 mkdir -p "$OUTPUT_DIR"
1266 fi
1267 cp "$SRC/$FILE" "$OUTPUT_DIR/$FILE"
1268 chmod 644 "$OUTPUT_DIR/$FILE"
1269 done
1270}