Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1 | #!/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 | |
| 18 | PRODUCT_COPY_FILES_LIST=() |
| 19 | PRODUCT_COPY_FILES_HASHES=() |
Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 20 | PRODUCT_COPY_FILES_FIXUP_HASHES=() |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 21 | PRODUCT_PACKAGES_LIST=() |
| 22 | PRODUCT_PACKAGES_HASHES=() |
Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 23 | PRODUCT_PACKAGES_FIXUP_HASHES=() |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 24 | PACKAGE_LIST=() |
| 25 | VENDOR_STATE=-1 |
| 26 | VENDOR_RADIO_STATE=-1 |
| 27 | COMMON=-1 |
| 28 | ARCHES= |
| 29 | FULLY_DEODEXED=-1 |
| 30 | |
Rashed Abdel-Tawab | e7d9b5c | 2017-08-05 23:11:35 -0400 | [diff] [blame] | 31 | TMPDIR=$(mktemp -d) |
Volodymyr Zhdanov | e54a159 | 2020-10-22 01:33:24 +0300 | [diff] [blame] | 32 | HOST="$(uname | tr '[:upper:]' '[:lower:]')" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 33 | |
| 34 | # |
| 35 | # cleanup |
| 36 | # |
| 37 | # kill our tmpfiles with fire on exit |
| 38 | # |
| 39 | function cleanup() { |
| 40 | rm -rf "${TMPDIR:?}" |
| 41 | } |
| 42 | |
Gabriele M | b8e5457 | 2017-10-11 12:55:51 +0200 | [diff] [blame] | 43 | trap cleanup 0 |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 44 | |
| 45 | # |
| 46 | # setup_vendor |
| 47 | # |
| 48 | # $1: device name |
| 49 | # $2: vendor name |
theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 50 | # $3: OMNI root directory |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 51 | # $4: is common device - optional, default to false |
| 52 | # $5: cleanup - optional, default to true |
Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 53 | # $6: custom vendor makefile name - optional, default to false |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 54 | # |
| 55 | # Must be called before any other functions can be used. This |
| 56 | # sets up the internal state for a new vendor configuration. |
| 57 | # |
| 58 | function setup_vendor() { |
| 59 | local DEVICE="$1" |
| 60 | if [ -z "$DEVICE" ]; then |
| 61 | echo "\$DEVICE must be set before including this script!" |
| 62 | exit 1 |
| 63 | fi |
| 64 | |
| 65 | export VENDOR="$2" |
| 66 | if [ -z "$VENDOR" ]; then |
| 67 | echo "\$VENDOR must be set before including this script!" |
| 68 | exit 1 |
| 69 | fi |
| 70 | |
theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 71 | export OMNI_ROOT="$3" |
| 72 | if [ ! -d "$OMNI_ROOT" ]; then |
| 73 | echo "\$OMNI_ROOT must be set and valid before including this script!" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 74 | exit 1 |
| 75 | fi |
| 76 | |
| 77 | export OUTDIR=vendor/"$VENDOR"/"$DEVICE" |
theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 78 | if [ ! -d "$OMNI_ROOT/$OUTDIR" ]; then |
| 79 | mkdir -p "$OMNI_ROOT/$OUTDIR" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 80 | fi |
| 81 | |
Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 82 | VNDNAME="$6" |
| 83 | if [ -z "$VNDNAME" ]; then |
| 84 | VNDNAME="$DEVICE" |
| 85 | fi |
| 86 | |
theimpulson | bb72ab8 | 2019-08-14 06:03:32 +0000 | [diff] [blame] | 87 | export PRODUCTMK="$OMNI_ROOT"/"$OUTDIR"/"$VNDNAME"-vendor.mk |
Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 88 | export ANDROIDBP="$OMNI_ROOT"/"$OUTDIR"/Android.bp |
theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 89 | export ANDROIDMK="$OMNI_ROOT"/"$OUTDIR"/Android.mk |
| 90 | export BOARDMK="$OMNI_ROOT"/"$OUTDIR"/BoardConfigVendor.mk |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 91 | |
| 92 | if [ "$4" == "true" ] || [ "$4" == "1" ]; then |
| 93 | COMMON=1 |
| 94 | else |
| 95 | COMMON=0 |
| 96 | fi |
| 97 | |
Gabriele M | c44696d | 2017-05-01 18:22:04 +0200 | [diff] [blame] | 98 | if [ "$5" == "false" ] || [ "$5" == "0" ]; then |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 99 | VENDOR_STATE=1 |
| 100 | VENDOR_RADIO_STATE=1 |
| 101 | else |
| 102 | VENDOR_STATE=0 |
| 103 | VENDOR_RADIO_STATE=0 |
| 104 | fi |
Volodymyr Zhdanov | e54a159 | 2020-10-22 01:33:24 +0300 | [diff] [blame] | 105 | |
| 106 | if [ -z "$PATCHELF" ]; then |
| 107 | export PATCHELF="$OMNI_ROOT"/vendor/omni/build/tools/${HOST}/bin/patchelf |
| 108 | fi |
Michael Bestas | f55ac29 | 2022-03-23 23:15:23 +0200 | [diff] [blame] | 109 | |
| 110 | if [ -z "$SIGSCAN" ]; then |
| 111 | export SIGSCAN="$OMNI_ROOT"/vendor/omni/build/tools/${HOST}/bin/SigScan |
| 112 | fi |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Vladimir Oltean | 75d8e05 | 2018-06-24 20:22:41 +0300 | [diff] [blame] | 115 | # Helper functions for parsing a spec. |
| 116 | # notes: an optional "|SHA1" that may appear in the format is stripped |
| 117 | # early from the spec in the parse_file_list function, and |
| 118 | # should not be present inside the input parameter passed |
| 119 | # to these functions. |
| 120 | |
| 121 | # |
| 122 | # input: spec in the form of "src[:dst][;args]" |
| 123 | # output: "src" |
| 124 | # |
| 125 | function src_file() { |
| 126 | local SPEC="$1" |
| 127 | local SPLIT=(${SPEC//:/ }) |
| 128 | local ARGS="$(target_args ${SPEC})" |
| 129 | # Regardless of there being a ":" delimiter or not in the spec, |
| 130 | # the source file is always either the first, or the only entry. |
| 131 | local SRC="${SPLIT[0]}" |
| 132 | # Remove target_args suffix, if present |
| 133 | echo "${SRC%;${ARGS}}" |
| 134 | } |
| 135 | |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 136 | # |
Vladimir Oltean | c70bc12 | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 137 | # input: spec in the form of "src[:dst][;args]" |
| 138 | # output: "dst" if present, "src" otherwise. |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 139 | # |
| 140 | function target_file() { |
dianlujitao | 4918b8a | 2020-01-02 15:26:44 +0800 | [diff] [blame] | 141 | local SPEC="${1%%;*}" |
Vladimir Oltean | c70bc12 | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 142 | local SPLIT=(${SPEC//:/ }) |
| 143 | local ARGS="$(target_args ${SPEC})" |
| 144 | local DST= |
| 145 | case ${#SPLIT[@]} in |
| 146 | 1) |
| 147 | # The spec doesn't have a : delimiter |
| 148 | DST="${SPLIT[0]}" |
| 149 | ;; |
| 150 | *) |
| 151 | # The spec actually has a src:dst format |
| 152 | DST="${SPLIT[1]}" |
| 153 | ;; |
| 154 | esac |
| 155 | # Remove target_args suffix, if present |
| 156 | echo "${DST%;${ARGS}}" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | # |
Vladimir Oltean | c70bc12 | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 160 | # input: spec in the form of "src[:dst][;args]" |
| 161 | # output: "args" if present, "" otherwise. |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 162 | # |
| 163 | function target_args() { |
Vladimir Oltean | c70bc12 | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 164 | local SPEC="$1" |
| 165 | local SPLIT=(${SPEC//;/ }) |
| 166 | local ARGS= |
| 167 | case ${#SPLIT[@]} in |
| 168 | 1) |
| 169 | # No ";" delimiter in the spec. |
| 170 | ;; |
| 171 | *) |
| 172 | # The "args" are whatever comes after the ";" character. |
| 173 | # Basically the spec stripped of whatever is to the left of ";". |
| 174 | ARGS="${SPEC#${SPLIT[0]};}" |
| 175 | ;; |
| 176 | esac |
| 177 | echo "${ARGS}" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | # |
| 181 | # prefix_match: |
| 182 | # |
Vladimir Oltean | 011b6b6 | 2018-06-12 01:17:35 +0300 | [diff] [blame] | 183 | # input: |
| 184 | # - $1: prefix |
| 185 | # - (global variable) PRODUCT_PACKAGES_LIST: array of [src:]dst[;args] specs. |
| 186 | # output: |
| 187 | # - new array consisting of dst[;args] entries where $1 is a prefix of ${dst}. |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 188 | # |
| 189 | function prefix_match() { |
| 190 | local PREFIX="$1" |
Vladimir Oltean | 7220f36 | 2018-04-02 22:37:09 +0300 | [diff] [blame] | 191 | for LINE in "${PRODUCT_PACKAGES_LIST[@]}"; do |
| 192 | local FILE=$(target_file "$LINE") |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 193 | if [[ "$FILE" =~ ^"$PREFIX" ]]; then |
Vladimir Oltean | 011b6b6 | 2018-06-12 01:17:35 +0300 | [diff] [blame] | 194 | local ARGS=$(target_args "$LINE") |
| 195 | if [ -z "${ARGS}" ]; then |
| 196 | echo "${FILE#$PREFIX}" |
| 197 | else |
| 198 | echo "${FILE#$PREFIX};${ARGS}" |
| 199 | fi |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 200 | fi |
| 201 | done |
| 202 | } |
| 203 | |
| 204 | # |
Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 205 | # prefix_match_file: |
| 206 | # |
| 207 | # $1: the prefix to match on |
| 208 | # $2: the file to match the prefix for |
| 209 | # |
| 210 | # Internal function which returns true if a filename contains the |
| 211 | # specified prefix. |
| 212 | # |
| 213 | function prefix_match_file() { |
| 214 | local PREFIX="$1" |
| 215 | local FILE="$2" |
| 216 | if [[ "$FILE" =~ ^"$PREFIX" ]]; then |
| 217 | return 0 |
| 218 | else |
| 219 | return 1 |
| 220 | fi |
| 221 | } |
| 222 | |
| 223 | # |
Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 224 | # suffix_match_file: |
| 225 | # |
| 226 | # $1: the suffix to match on |
| 227 | # $2: the file to match the suffix for |
| 228 | # |
| 229 | # Internal function which returns true if a filename contains the |
| 230 | # specified suffix. |
| 231 | # |
| 232 | function suffix_match_file() { |
| 233 | local SUFFIX="$1" |
| 234 | local FILE="$2" |
| 235 | if [[ "$FILE" = *"$SUFFIX" ]]; then |
| 236 | return 0 |
| 237 | else |
| 238 | return 1 |
| 239 | fi |
| 240 | } |
| 241 | |
| 242 | # |
Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 243 | # truncate_file |
| 244 | # |
| 245 | # $1: the filename to truncate |
| 246 | # $2: the argument to output the truncated filename to |
| 247 | # |
| 248 | # Internal function which truncates a filename by removing the first dir |
| 249 | # in the path. ex. vendor/lib/libsdmextension.so -> lib/libsdmextension.so |
| 250 | # |
| 251 | function truncate_file() { |
| 252 | local FILE="$1" |
| 253 | RETURN_FILE="$2" |
| 254 | local FIND="${FILE%%/*}" |
| 255 | local LOCATION="${#FIND}+1" |
| 256 | echo ${FILE:$LOCATION} |
| 257 | } |
| 258 | |
| 259 | # |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 260 | # write_product_copy_files: |
| 261 | # |
Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 262 | # $1: make treble compatible makefile - optional and deprecated, default to true |
Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 263 | # |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 264 | # Creates the PRODUCT_COPY_FILES section in the product makefile for all |
| 265 | # items in the list which do not start with a dash (-). |
| 266 | # |
| 267 | function write_product_copy_files() { |
| 268 | local COUNT=${#PRODUCT_COPY_FILES_LIST[@]} |
| 269 | local TARGET= |
| 270 | local FILE= |
| 271 | local LINEEND= |
Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 272 | local TREBLE_COMPAT=$1 |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 273 | |
| 274 | if [ "$COUNT" -eq "0" ]; then |
| 275 | return 0 |
| 276 | fi |
| 277 | |
| 278 | printf '%s\n' "PRODUCT_COPY_FILES += \\" >> "$PRODUCTMK" |
| 279 | for (( i=1; i<COUNT+1; i++ )); do |
| 280 | FILE="${PRODUCT_COPY_FILES_LIST[$i-1]}" |
| 281 | LINEEND=" \\" |
| 282 | if [ "$i" -eq "$COUNT" ]; then |
| 283 | LINEEND="" |
| 284 | fi |
| 285 | |
Vladimir Oltean | c70bc12 | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 286 | TARGET=$(target_file "$FILE") |
Rashed Abdel-Tawab | 06688fc | 2019-10-05 00:09:41 -0400 | [diff] [blame] | 287 | if prefix_match_file "product/" $TARGET ; then |
Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 288 | local OUTTARGET=$(truncate_file $TARGET) |
Rashed Abdel-Tawab | 06688fc | 2019-10-05 00:09:41 -0400 | [diff] [blame] | 289 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s%s\n' \ |
Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 290 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
Rashed Abdel-Tawab | 06688fc | 2019-10-05 00:09:41 -0400 | [diff] [blame] | 291 | elif prefix_match_file "system/product/" $TARGET ; then |
Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 292 | local OUTTARGET=$(truncate_file $TARGET) |
| 293 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s%s\n' \ |
| 294 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 295 | elif prefix_match_file "system_ext/" $TARGET ; then |
| 296 | local OUTTARGET=$(truncate_file $TARGET) |
| 297 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM_EXT)/%s%s\n' \ |
| 298 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| 299 | elif prefix_match_file "system/system_ext/" $TARGET ; then |
| 300 | local OUTTARGET=$(truncate_file $TARGET) |
| 301 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM_EXT)/%s%s\n' \ |
| 302 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 303 | elif prefix_match_file "odm/" $TARGET ; then |
| 304 | local OUTTARGET=$(truncate_file $TARGET) |
| 305 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \ |
| 306 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
Rashed Abdel-Tawab | 06688fc | 2019-10-05 00:09:41 -0400 | [diff] [blame] | 307 | elif prefix_match_file "vendor/odm/" $TARGET ; then |
| 308 | local OUTTARGET=$(truncate_file $TARGET) |
| 309 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \ |
| 310 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| 311 | elif prefix_match_file "system/vendor/odm/" $TARGET ; then |
| 312 | local OUTTARGET=$(truncate_file $TARGET) |
| 313 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \ |
| 314 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| 315 | elif prefix_match_file "vendor/" $TARGET ; then |
| 316 | local OUTTARGET=$(truncate_file $TARGET) |
| 317 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR)/%s%s\n' \ |
| 318 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
Alexander Koskovich | 44c8fac | 2022-01-22 22:27:29 -0700 | [diff] [blame] | 319 | elif prefix_match_file "vendor_dlkm/" $TARGET ; then |
| 320 | local OUTTARGET=$(truncate_file $TARGET) |
| 321 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR_DLKM)/%s%s\n' \ |
| 322 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
Rashed Abdel-Tawab | 06688fc | 2019-10-05 00:09:41 -0400 | [diff] [blame] | 323 | elif prefix_match_file "system/vendor/" $TARGET ; then |
| 324 | local OUTTARGET=$(truncate_file $TARGET) |
| 325 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR)/%s%s\n' \ |
| 326 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 327 | elif prefix_match_file "system/" $TARGET ; then |
| 328 | local OUTTARGET=$(truncate_file $TARGET) |
| 329 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM)/%s%s\n' \ |
| 330 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 331 | else |
Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 332 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM)/%s%s\n' \ |
Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 333 | "$OUTDIR" "$TARGET" "$TARGET" "$LINEEND" >> "$PRODUCTMK" |
| 334 | fi |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 335 | done |
| 336 | return 0 |
| 337 | } |
| 338 | |
| 339 | # |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 340 | # write_blueprint_packages: |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 341 | # |
| 342 | # $1: The LOCAL_MODULE_CLASS for the given module list |
Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 343 | # $2: /system, /odm, /product, /system_ext, or /vendor partition |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 344 | # $3: type-specific extra flags |
| 345 | # $4: Name of the array holding the target list |
| 346 | # |
| 347 | # Internal function which writes out the BUILD_PREBUILT stanzas |
| 348 | # for all modules in the list. This is called by write_product_packages |
| 349 | # after the modules are categorized. |
| 350 | # |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 351 | function write_blueprint_packages() { |
| 352 | |
| 353 | local CLASS="$1" |
| 354 | local PARTITION="$2" |
| 355 | local EXTRA="$3" |
| 356 | |
| 357 | # Yes, this is a horrible hack - we create a new array using indirection |
| 358 | local ARR_NAME="$4[@]" |
| 359 | local FILELIST=("${!ARR_NAME}") |
| 360 | |
| 361 | local FILE= |
| 362 | local ARGS= |
| 363 | local BASENAME= |
| 364 | local EXTENSION= |
| 365 | local PKGNAME= |
| 366 | local SRC= |
TheStrix | 6e24acc | 2020-04-10 18:20:19 +0530 | [diff] [blame] | 367 | local OVERRIDEPKG= |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 368 | |
| 369 | for P in "${FILELIST[@]}"; do |
| 370 | FILE=$(target_file "$P") |
| 371 | ARGS=$(target_args "$P") |
| 372 | |
| 373 | BASENAME=$(basename "$FILE") |
| 374 | DIRNAME=$(dirname "$FILE") |
| 375 | EXTENSION=${BASENAME##*.} |
| 376 | PKGNAME=${BASENAME%.*} |
| 377 | |
| 378 | # Add to final package list |
| 379 | PACKAGE_LIST+=("$PKGNAME") |
| 380 | |
| 381 | SRC="proprietary" |
| 382 | if [ "$PARTITION" = "system" ]; then |
| 383 | SRC+="/system" |
| 384 | elif [ "$PARTITION" = "vendor" ]; then |
| 385 | SRC+="/vendor" |
| 386 | elif [ "$PARTITION" = "product" ]; then |
| 387 | SRC+="/product" |
Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 388 | elif [ "$PARTITION" = "system_ext" ]; then |
| 389 | SRC+="/system_ext" |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 390 | elif [ "$PARTITION" = "odm" ]; then |
| 391 | SRC+="/odm" |
| 392 | fi |
| 393 | |
| 394 | if [ "$CLASS" = "SHARED_LIBRARIES" ]; then |
| 395 | printf 'cc_prebuilt_library_shared {\n' |
| 396 | printf '\tname: "%s",\n' "$PKGNAME" |
| 397 | printf '\towner: "%s",\n' "$VENDOR" |
| 398 | printf '\tstrip: {\n' |
| 399 | printf '\t\tnone: true,\n' |
| 400 | printf '\t},\n' |
| 401 | printf '\ttarget: {\n' |
| 402 | if [ "$EXTRA" = "both" ]; then |
| 403 | printf '\t\tandroid_arm: {\n' |
| 404 | printf '\t\t\tsrcs: ["%s/lib/%s"],\n' "$SRC" "$FILE" |
| 405 | printf '\t\t},\n' |
| 406 | printf '\t\tandroid_arm64: {\n' |
| 407 | printf '\t\t\tsrcs: ["%s/lib64/%s"],\n' "$SRC" "$FILE" |
| 408 | printf '\t\t},\n' |
| 409 | elif [ "$EXTRA" = "64" ]; then |
| 410 | printf '\t\tandroid_arm64: {\n' |
| 411 | printf '\t\t\tsrcs: ["%s/lib64/%s"],\n' "$SRC" "$FILE" |
| 412 | printf '\t\t},\n' |
| 413 | else |
| 414 | printf '\t\tandroid_arm: {\n' |
| 415 | printf '\t\t\tsrcs: ["%s/lib/%s"],\n' "$SRC" "$FILE" |
| 416 | printf '\t\t},\n' |
| 417 | fi |
| 418 | printf '\t},\n' |
| 419 | if [ "$EXTRA" != "none" ]; then |
| 420 | printf '\tcompile_multilib: "%s",\n' "$EXTRA" |
| 421 | fi |
dianlujitao | 848101c | 2020-09-12 00:15:13 +0800 | [diff] [blame] | 422 | printf '\tcheck_elf_files: false,\n' |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 423 | elif [ "$CLASS" = "APPS" ]; then |
| 424 | printf 'android_app_import {\n' |
| 425 | printf '\tname: "%s",\n' "$PKGNAME" |
| 426 | printf '\towner: "%s",\n' "$VENDOR" |
| 427 | if [ "$EXTRA" = "priv-app" ]; then |
| 428 | SRC="$SRC/priv-app" |
| 429 | else |
| 430 | SRC="$SRC/app" |
| 431 | fi |
| 432 | printf '\tapk: "%s/%s",\n' "$SRC" "$FILE" |
TheStrix | 6e24acc | 2020-04-10 18:20:19 +0530 | [diff] [blame] | 433 | ARGS=(${ARGS//;/ }) |
LuK1337 | 508e85f | 2021-08-23 18:18:57 +0200 | [diff] [blame] | 434 | USE_PLATFORM_CERTIFICATE="true" |
| 435 | for ARG in "${ARGS[@]}"; do |
| 436 | if [ "$ARG" = "PRESIGNED" ]; then |
| 437 | USE_PLATFORM_CERTIFICATE="false" |
| 438 | printf '\tpresigned: true,\n' |
| 439 | elif [[ "$ARG" =~ "OVERRIDES" ]]; then |
| 440 | OVERRIDEPKG=${ARG#*=} |
Arian | 72ac836 | 2021-09-27 17:49:19 +0200 | [diff] [blame] | 441 | OVERRIDEPKG=${OVERRIDEPKG//,/\", \"} |
LuK1337 | 508e85f | 2021-08-23 18:18:57 +0200 | [diff] [blame] | 442 | printf '\toverrides: ["%s"],\n' "$OVERRIDEPKG" |
| 443 | elif [ ! -z "$ARG" ]; then |
| 444 | USE_PLATFORM_CERTIFICATE="false" |
| 445 | printf '\tcertificate: "%s",\n' "$ARG" |
| 446 | fi |
| 447 | done |
| 448 | if [ "$USE_PLATFORM_CERTIFICATE" = "true" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 449 | printf '\tcertificate: "platform",\n' |
| 450 | fi |
| 451 | elif [ "$CLASS" = "JAVA_LIBRARIES" ]; then |
| 452 | printf 'dex_import {\n' |
| 453 | printf '\tname: "%s",\n' "$PKGNAME" |
| 454 | printf '\towner: "%s",\n' "$VENDOR" |
| 455 | printf '\tjars: ["%s/framework/%s"],\n' "$SRC" "$FILE" |
| 456 | elif [ "$CLASS" = "ETC" ]; then |
| 457 | if [ "$EXTENSION" = "xml" ]; then |
| 458 | printf 'prebuilt_etc_xml {\n' |
| 459 | else |
| 460 | printf 'prebuilt_etc {\n' |
| 461 | fi |
| 462 | printf '\tname: "%s",\n' "$PKGNAME" |
| 463 | printf '\towner: "%s",\n' "$VENDOR" |
| 464 | printf '\tsrc: "%s/etc/%s",\n' "$SRC" "$FILE" |
LuK1337 | f7f1871 | 2020-10-06 19:29:02 +0200 | [diff] [blame] | 465 | printf '\tfilename_from_src: true,\n' |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 466 | elif [ "$CLASS" = "EXECUTABLES" ]; then |
| 467 | if [ "$EXTENSION" = "sh" ]; then |
| 468 | printf 'sh_binary {\n' |
| 469 | else |
| 470 | printf 'cc_prebuilt_binary {\n' |
| 471 | fi |
| 472 | printf '\tname: "%s",\n' "$PKGNAME" |
| 473 | printf '\towner: "%s",\n' "$VENDOR" |
Michael Bestas | bda3020 | 2020-12-28 04:44:52 +0200 | [diff] [blame] | 474 | printf '\tsrcs: ["%s/bin/%s"],\n' "$SRC" "$FILE" |
Sebastiano Barezzi | fd4b2b3 | 2021-07-14 21:33:10 +0200 | [diff] [blame] | 475 | if [ "$EXTENSION" != "sh" ]; then |
| 476 | printf '\tcheck_elf_files: false,\n' |
| 477 | fi |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 478 | unset EXTENSION |
| 479 | else |
| 480 | printf '\tsrcs: ["%s/%s"],\n' "$SRC" "$FILE" |
| 481 | fi |
| 482 | if [ "$CLASS" = "APPS" ]; then |
| 483 | printf '\tdex_preopt: {\n' |
| 484 | printf '\t\tenabled: false,\n' |
| 485 | printf '\t},\n' |
| 486 | fi |
Andreas Schneider | dbcf9db | 2020-05-25 17:03:17 +0200 | [diff] [blame] | 487 | if [ "$CLASS" = "SHARED_LIBRARIES" ] || [ "$CLASS" = "EXECUTABLES" ] ; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 488 | if [ "$DIRNAME" != "." ]; then |
Andreas Schneider | 408526a | 2020-05-23 15:58:43 +0200 | [diff] [blame] | 489 | printf '\trelative_install_path: "%s",\n' "$DIRNAME" |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 490 | fi |
| 491 | fi |
Andreas Schneider | dbcf9db | 2020-05-25 17:03:17 +0200 | [diff] [blame] | 492 | if [ "$CLASS" = "ETC" ] ; then |
| 493 | if [ "$DIRNAME" != "." ]; then |
| 494 | printf '\tsub_dir: "%s",\n' "$DIRNAME" |
| 495 | fi |
| 496 | fi |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 497 | if [ "$CLASS" = "SHARED_LIBRARIES" ] || [ "$CLASS" = "EXECUTABLES" ] ; then |
| 498 | printf '\tprefer: true,\n' |
| 499 | fi |
| 500 | if [ "$EXTRA" = "priv-app" ]; then |
| 501 | printf '\tprivileged: true,\n' |
| 502 | fi |
| 503 | if [ "$PARTITION" = "vendor" ]; then |
| 504 | printf '\tsoc_specific: true,\n' |
| 505 | elif [ "$PARTITION" = "product" ]; then |
| 506 | printf '\tproduct_specific: true,\n' |
Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 507 | elif [ "$PARTITION" = "system_ext" ]; then |
| 508 | printf '\tsystem_ext_specific: true,\n' |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 509 | elif [ "$PARTITION" = "odm" ]; then |
| 510 | printf '\tdevice_specific: true,\n' |
| 511 | fi |
| 512 | printf '}\n\n' |
| 513 | done |
| 514 | } |
| 515 | |
| 516 | # |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 517 | # write_product_packages: |
| 518 | # |
Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 519 | # This function will create prebuilt entries in the |
| 520 | # Android.bp and associated PRODUCT_PACKAGES list in the |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 521 | # product makefile for all files in the blob list which |
| 522 | # start with a single dash (-) character. |
| 523 | # |
| 524 | function write_product_packages() { |
| 525 | PACKAGE_LIST=() |
| 526 | |
| 527 | local COUNT=${#PRODUCT_PACKAGES_LIST[@]} |
| 528 | |
| 529 | if [ "$COUNT" = "0" ]; then |
| 530 | return 0 |
| 531 | fi |
| 532 | |
| 533 | # Figure out what's 32-bit, what's 64-bit, and what's multilib |
| 534 | # I really should not be doing this in bash due to shitty array passing :( |
| 535 | local T_LIB32=( $(prefix_match "lib/") ) |
| 536 | local T_LIB64=( $(prefix_match "lib64/") ) |
| 537 | local MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${T_LIB64[@]}")) ) |
| 538 | local LIB32=( $(comm -23 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${MULTILIBS[@]}")) ) |
| 539 | local LIB64=( $(comm -23 <(printf '%s\n' "${T_LIB64[@]}") <(printf '%s\n' "${MULTILIBS[@]}")) ) |
| 540 | |
| 541 | if [ "${#MULTILIBS[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 542 | write_blueprint_packages "SHARED_LIBRARIES" "" "both" "MULTILIBS" >> "$ANDROIDBP" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 543 | fi |
| 544 | if [ "${#LIB32[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 545 | write_blueprint_packages "SHARED_LIBRARIES" "" "32" "LIB32" >> "$ANDROIDBP" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 546 | fi |
| 547 | if [ "${#LIB64[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 548 | write_blueprint_packages "SHARED_LIBRARIES" "" "64" "LIB64" >> "$ANDROIDBP" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 549 | fi |
| 550 | |
Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 551 | local T_S_LIB32=( $(prefix_match "system/lib/") ) |
| 552 | local T_S_LIB64=( $(prefix_match "system/lib64/") ) |
| 553 | local S_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_S_LIB32[@]}") <(printf '%s\n' "${T_S_LIB64[@]}")) ) |
| 554 | local S_LIB32=( $(comm -23 <(printf '%s\n' "${T_S_LIB32[@]}") <(printf '%s\n' "${S_MULTILIBS[@]}")) ) |
| 555 | local S_LIB64=( $(comm -23 <(printf '%s\n' "${T_S_LIB64[@]}") <(printf '%s\n' "${S_MULTILIBS[@]}")) ) |
| 556 | |
| 557 | if [ "${#S_MULTILIBS[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 558 | write_blueprint_packages "SHARED_LIBRARIES" "system" "both" "S_MULTILIBS" >> "$ANDROIDBP" |
Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 559 | fi |
| 560 | if [ "${#S_LIB32[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 561 | write_blueprint_packages "SHARED_LIBRARIES" "system" "32" "S_LIB32" >> "$ANDROIDBP" |
Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 562 | fi |
| 563 | if [ "${#S_LIB64[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 564 | write_blueprint_packages "SHARED_LIBRARIES" "system" "64" "S_LIB64" >> "$ANDROIDBP" |
Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 565 | fi |
| 566 | |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 567 | local T_V_LIB32=( $(prefix_match "vendor/lib/") ) |
| 568 | local T_V_LIB64=( $(prefix_match "vendor/lib64/") ) |
| 569 | local V_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${T_V_LIB64[@]}")) ) |
| 570 | local V_LIB32=( $(comm -23 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${V_MULTILIBS[@]}")) ) |
| 571 | local V_LIB64=( $(comm -23 <(printf '%s\n' "${T_V_LIB64[@]}") <(printf '%s\n' "${V_MULTILIBS[@]}")) ) |
| 572 | |
| 573 | if [ "${#V_MULTILIBS[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 574 | write_blueprint_packages "SHARED_LIBRARIES" "vendor" "both" "V_MULTILIBS" >> "$ANDROIDBP" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 575 | fi |
| 576 | if [ "${#V_LIB32[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 577 | write_blueprint_packages "SHARED_LIBRARIES" "vendor" "32" "V_LIB32" >> "$ANDROIDBP" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 578 | fi |
| 579 | if [ "${#V_LIB64[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 580 | write_blueprint_packages "SHARED_LIBRARIES" "vendor" "64" "V_LIB64" >> "$ANDROIDBP" |
razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 581 | fi |
| 582 | |
| 583 | local T_P_LIB32=( $(prefix_match "product/lib/") ) |
| 584 | local T_P_LIB64=( $(prefix_match "product/lib64/") ) |
| 585 | local P_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_P_LIB32[@]}") <(printf '%s\n' "${T_P_LIB64[@]}")) ) |
| 586 | local P_LIB32=( $(comm -23 <(printf '%s\n' "${T_P_LIB32[@]}") <(printf '%s\n' "${P_MULTILIBS[@]}")) ) |
| 587 | local P_LIB64=( $(comm -23 <(printf '%s\n' "${T_P_LIB64[@]}") <(printf '%s\n' "${P_MULTILIBS[@]}")) ) |
| 588 | |
| 589 | if [ "${#P_MULTILIBS[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 590 | write_blueprint_packages "SHARED_LIBRARIES" "product" "both" "P_MULTILIBS" >> "$ANDROIDBP" |
razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 591 | fi |
| 592 | if [ "${#P_LIB32[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 593 | write_blueprint_packages "SHARED_LIBRARIES" "product" "32" "P_LIB32" >> "$ANDROIDBP" |
razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 594 | fi |
| 595 | if [ "${#P_LIB64[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 596 | write_blueprint_packages "SHARED_LIBRARIES" "product" "64" "P_LIB64" >> "$ANDROIDBP" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 597 | fi |
| 598 | |
Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 599 | local T_SE_LIB32=( $(prefix_match "system_ext/lib/") ) |
| 600 | local T_SE_LIB64=( $(prefix_match "system_ext/lib64/") ) |
| 601 | local SE_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_SE_LIB32[@]}") <(printf '%s\n' "${T_SE_LIB64[@]}")) ) |
| 602 | local SE_LIB32=( $(comm -23 <(printf '%s\n' "${T_SE_LIB32[@]}") <(printf '%s\n' "${SE_MULTILIBS[@]}")) ) |
| 603 | local SE_LIB64=( $(comm -23 <(printf '%s\n' "${T_SE_LIB64[@]}") <(printf '%s\n' "${SE_MULTILIBS[@]}")) ) |
| 604 | |
| 605 | if [ "${#SE_MULTILIBS[@]}" -gt "0" ]; then |
| 606 | write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "both" "SE_MULTILIBS" >> "$ANDROIDBP" |
| 607 | fi |
| 608 | if [ "${#SE_LIB32[@]}" -gt "0" ]; then |
| 609 | write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "32" "SE_LIB32" >> "$ANDROIDBP" |
| 610 | fi |
| 611 | if [ "${#SE_LIB64[@]}" -gt "0" ]; then |
| 612 | write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "64" "SE_LIB64" >> "$ANDROIDBP" |
| 613 | fi |
| 614 | |
Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 615 | local T_O_LIB32=( $(prefix_match "odm/lib/") ) |
| 616 | local T_O_LIB64=( $(prefix_match "odm/lib64/") ) |
| 617 | local O_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_O_LIB32[@]}") <(printf '%s\n' "${T_O_LIB64[@]}")) ) |
| 618 | local O_LIB32=( $(comm -23 <(printf '%s\n' "${T_O_LIB32[@]}") <(printf '%s\n' "${O_MULTILIBS[@]}")) ) |
| 619 | local O_LIB64=( $(comm -23 <(printf '%s\n' "${T_O_LIB64[@]}") <(printf '%s\n' "${O_MULTILIBS[@]}")) ) |
| 620 | |
| 621 | if [ "${#O_MULTILIBS[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 622 | write_blueprint_packages "SHARED_LIBRARIES" "odm" "both" "O_MULTILIBS" >> "$ANDROIDBP" |
Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 623 | fi |
| 624 | if [ "${#O_LIB32[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 625 | write_blueprint_packages "SHARED_LIBRARIES" "odm" "32" "O_LIB32" >> "$ANDROIDBP" |
Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 626 | fi |
| 627 | if [ "${#O_LIB64[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 628 | write_blueprint_packages "SHARED_LIBRARIES" "odm" "64" "O_LIB64" >> "$ANDROIDBP" |
Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 629 | fi |
| 630 | |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 631 | # Apps |
| 632 | local APPS=( $(prefix_match "app/") ) |
| 633 | if [ "${#APPS[@]}" -gt "0" ]; then |
mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 634 | write_blueprint_packages "APPS" "" "" "APPS" >> "$ANDROIDBP" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 635 | fi |
| 636 | local PRIV_APPS=( $(prefix_match "priv-app/") ) |
| 637 | if [ "${#PRIV_APPS[@]}" -gt "0" ]; then |
mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 638 | write_blueprint_packages "APPS" "" "priv-app" "PRIV_APPS" >> "$ANDROIDBP" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 639 | fi |
Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 640 | local S_APPS=( $(prefix_match "system/app/") ) |
| 641 | if [ "${#S_APPS[@]}" -gt "0" ]; then |
mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 642 | write_blueprint_packages "APPS" "system" "" "S_APPS" >> "$ANDROIDBP" |
Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 643 | fi |
| 644 | local S_PRIV_APPS=( $(prefix_match "system/priv-app/") ) |
| 645 | if [ "${#S_PRIV_APPS[@]}" -gt "0" ]; then |
mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 646 | write_blueprint_packages "APPS" "system" "priv-app" "S_PRIV_APPS" >> "$ANDROIDBP" |
Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 647 | fi |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 648 | local V_APPS=( $(prefix_match "vendor/app/") ) |
| 649 | if [ "${#V_APPS[@]}" -gt "0" ]; then |
mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 650 | write_blueprint_packages "APPS" "vendor" "" "V_APPS" >> "$ANDROIDBP" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 651 | fi |
| 652 | local V_PRIV_APPS=( $(prefix_match "vendor/priv-app/") ) |
| 653 | if [ "${#V_PRIV_APPS[@]}" -gt "0" ]; then |
mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 654 | write_blueprint_packages "APPS" "vendor" "priv-app" "V_PRIV_APPS" >> "$ANDROIDBP" |
razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 655 | fi |
| 656 | local P_APPS=( $(prefix_match "product/app/") ) |
| 657 | if [ "${#P_APPS[@]}" -gt "0" ]; then |
mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 658 | write_blueprint_packages "APPS" "product" "" "P_APPS" >> "$ANDROIDBP" |
razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 659 | fi |
| 660 | local P_PRIV_APPS=( $(prefix_match "product/priv-app/") ) |
| 661 | if [ "${#P_PRIV_APPS[@]}" -gt "0" ]; then |
mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 662 | write_blueprint_packages "APPS" "product" "priv-app" "P_PRIV_APPS" >> "$ANDROIDBP" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 663 | fi |
Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 664 | local SE_APPS=( $(prefix_match "system_ext/app/") ) |
| 665 | if [ "${#SE_APPS[@]}" -gt "0" ]; then |
| 666 | write_blueprint_packages "APPS" "system_ext" "" "SE_APPS" >> "$ANDROIDBP" |
| 667 | fi |
| 668 | local SE_PRIV_APPS=( $(prefix_match "system_ext/priv-app/") ) |
| 669 | if [ "${#SE_PRIV_APPS[@]}" -gt "0" ]; then |
| 670 | write_blueprint_packages "APPS" "system_ext" "priv-app" "SE_PRIV_APPS" >> "$ANDROIDBP" |
| 671 | fi |
Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 672 | local O_APPS=( $(prefix_match "odm/app/") ) |
| 673 | if [ "${#O_APPS[@]}" -gt "0" ]; then |
mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 674 | write_blueprint_packages "APPS" "odm" "" "O_APPS" >> "$ANDROIDBP" |
Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 675 | fi |
| 676 | local O_PRIV_APPS=( $(prefix_match "odm/priv-app/") ) |
| 677 | if [ "${#O_PRIV_APPS[@]}" -gt "0" ]; then |
mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 678 | write_blueprint_packages "APPS" "odm" "priv-app" "O_PRIV_APPS" >> "$ANDROIDBP" |
Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 679 | fi |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 680 | |
| 681 | # Framework |
| 682 | local FRAMEWORK=( $(prefix_match "framework/") ) |
| 683 | if [ "${#FRAMEWORK[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 684 | write_blueprint_packages "JAVA_LIBRARIES" "" "" "FRAMEWORK" >> "$ANDROIDBP" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 685 | fi |
Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 686 | local S_FRAMEWORK=( $(prefix_match "system/framework/") ) |
| 687 | if [ "${#S_FRAMEWORK[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 688 | write_blueprint_packages "JAVA_LIBRARIES" "system" "" "S_FRAMEWORK" >> "$ANDROIDBP" |
Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 689 | fi |
Christian Oder | 974b590 | 2017-10-08 23:15:52 +0200 | [diff] [blame] | 690 | local V_FRAMEWORK=( $(prefix_match "vendor/framework/") ) |
Michael Bestas | 26eb01e | 2018-02-27 22:31:55 +0200 | [diff] [blame] | 691 | if [ "${#V_FRAMEWORK[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 692 | write_blueprint_packages "JAVA_LIBRARIES" "vendor" "" "V_FRAMEWORK" >> "$ANDROIDBP" |
razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 693 | fi |
| 694 | local P_FRAMEWORK=( $(prefix_match "product/framework/") ) |
| 695 | if [ "${#P_FRAMEWORK[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 696 | write_blueprint_packages "JAVA_LIBRARIES" "product" "" "P_FRAMEWORK" >> "$ANDROIDBP" |
Christian Oder | 974b590 | 2017-10-08 23:15:52 +0200 | [diff] [blame] | 697 | fi |
Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 698 | local SE_FRAMEWORK=( $(prefix_match "system_ext/framework/") ) |
Alexander Koskovich | 052c77d | 2020-09-16 17:58:53 -0700 | [diff] [blame] | 699 | if [ "${#SE_FRAMEWORK[@]}" -gt "0" ]; then |
Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 700 | write_blueprint_packages "JAVA_LIBRARIES" "system_ext" "" "SE_FRAMEWORK" >> "$ANDROIDBP" |
| 701 | fi |
Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 702 | local O_FRAMEWORK=( $(prefix_match "odm/framework/") ) |
| 703 | if [ "${#O_FRAMEWORK[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 704 | write_blueprint_packages "JAVA_LIBRARIES" "odm" "" "O_FRAMEWORK" >> "$ANDROIDBP" |
Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 705 | fi |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 706 | |
| 707 | # Etc |
| 708 | local ETC=( $(prefix_match "etc/") ) |
| 709 | if [ "${#ETC[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 710 | write_blueprint_packages "ETC" "" "" "ETC" >> "$ANDROIDBP" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 711 | fi |
Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 712 | local S_ETC=( $(prefix_match "system/etc/") ) |
| 713 | if [ "${#ETC[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 714 | write_blueprint_packages "ETC" "system" "" "S_ETC" >> "$ANDROIDBP" |
Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 715 | fi |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 716 | local V_ETC=( $(prefix_match "vendor/etc/") ) |
| 717 | if [ "${#V_ETC[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 718 | write_blueprint_packages "ETC" "vendor" "" "V_ETC" >> "$ANDROIDBP" |
razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 719 | fi |
| 720 | local P_ETC=( $(prefix_match "product/etc/") ) |
| 721 | if [ "${#P_ETC[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 722 | write_blueprint_packages "ETC" "product" "" "P_ETC" >> "$ANDROIDBP" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 723 | fi |
Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 724 | local SE_ETC=( $(prefix_match "system_ext/etc/") ) |
| 725 | if [ "${#SE_ETC[@]}" -gt "0" ]; then |
| 726 | write_blueprint_packages "ETC" "system_ext" "" "SE_ETC" >> "$ANDROIDBP" |
| 727 | fi |
Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 728 | local O_ETC=( $(prefix_match "odm/etc/") ) |
| 729 | if [ "${#O_ETC[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 730 | write_blueprint_packages "ETC" "odm" "" "O_ETC" >> "$ANDROIDBP" |
Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 731 | fi |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 732 | |
| 733 | # Executables |
| 734 | local BIN=( $(prefix_match "bin/") ) |
| 735 | if [ "${#BIN[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 736 | write_blueprint_packages "EXECUTABLES" "" "" "BIN" >> "$ANDROIDBP" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 737 | fi |
Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 738 | local S_BIN=( $(prefix_match "system/bin/") ) |
| 739 | if [ "${#BIN[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 740 | write_blueprint_packages "EXECUTABLES" "system" "" "S_BIN" >> "$ANDROIDBP" |
Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 741 | fi |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 742 | local V_BIN=( $(prefix_match "vendor/bin/") ) |
| 743 | if [ "${#V_BIN[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 744 | write_blueprint_packages "EXECUTABLES" "vendor" "" "V_BIN" >> "$ANDROIDBP" |
razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 745 | fi |
| 746 | local P_BIN=( $(prefix_match "product/bin/") ) |
| 747 | if [ "${#P_BIN[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 748 | write_blueprint_packages "EXECUTABLES" "product" "" "P_BIN" >> "$ANDROIDBP" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 749 | fi |
Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 750 | local SE_BIN=( $(prefix_match "system_ext/bin/") ) |
| 751 | if [ "${#SE_BIN[@]}" -gt "0" ]; then |
| 752 | write_blueprint_packages "EXECUTABLES" "system_ext" "" "SE_BIN" >> "$ANDROIDBP" |
| 753 | fi |
Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 754 | local O_BIN=( $(prefix_match "odm/bin/") ) |
| 755 | if [ "${#O_BIN[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 756 | write_blueprint_packages "EXECUTABLES" "odm" "" "O_BIN" >> "$ANDROIDBP" |
Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 757 | fi |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 758 | |
| 759 | # Actually write out the final PRODUCT_PACKAGES list |
| 760 | local PACKAGE_COUNT=${#PACKAGE_LIST[@]} |
| 761 | |
| 762 | if [ "$PACKAGE_COUNT" -eq "0" ]; then |
| 763 | return 0 |
| 764 | fi |
| 765 | |
| 766 | printf '\n%s\n' "PRODUCT_PACKAGES += \\" >> "$PRODUCTMK" |
| 767 | for (( i=1; i<PACKAGE_COUNT+1; i++ )); do |
| 768 | local LINEEND=" \\" |
| 769 | if [ "$i" -eq "$PACKAGE_COUNT" ]; then |
| 770 | LINEEND="" |
| 771 | fi |
| 772 | printf ' %s%s\n' "${PACKAGE_LIST[$i-1]}" "$LINEEND" >> "$PRODUCTMK" |
| 773 | done |
| 774 | } |
| 775 | |
| 776 | # |
Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 777 | # write_blueprint_header: |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 778 | # |
| 779 | # $1: file which will be written to |
| 780 | # |
Michael Bestas | a2934df | 2020-12-19 03:50:32 +0200 | [diff] [blame] | 781 | # writes out the warning message regarding manual file modifications. |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 782 | # note that this is not an append operation, and should |
| 783 | # be executed first! |
| 784 | # |
Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 785 | function write_blueprint_header() { |
| 786 | if [ -f $1 ]; then |
| 787 | rm $1 |
| 788 | fi |
| 789 | |
Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 790 | [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON" |
| 791 | |
Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 792 | cat << EOF >> $1 |
Michael Bestas | a2934df | 2020-12-19 03:50:32 +0200 | [diff] [blame] | 793 | // Automatically generated file. DO NOT MODIFY |
| 794 | // |
| 795 | // This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh |
Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 796 | |
| 797 | EOF |
| 798 | } |
| 799 | |
| 800 | # |
| 801 | # write_makefile_header: |
| 802 | # |
| 803 | # $1: file which will be written to |
| 804 | # |
Michael Bestas | a2934df | 2020-12-19 03:50:32 +0200 | [diff] [blame] | 805 | # writes out the warning message regarding manual file modifications. |
Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 806 | # note that this is not an append operation, and should |
| 807 | # be executed first! |
| 808 | # |
| 809 | function write_makefile_header() { |
Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 810 | if [ -f $1 ]; then |
| 811 | rm $1 |
| 812 | fi |
| 813 | |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 814 | [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON" |
| 815 | |
Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 816 | cat << EOF >> $1 |
Michael Bestas | a2934df | 2020-12-19 03:50:32 +0200 | [diff] [blame] | 817 | # Automatically generated file. DO NOT MODIFY |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 818 | # |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 819 | # This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh |
| 820 | |
| 821 | EOF |
| 822 | } |
| 823 | |
| 824 | # |
| 825 | # write_headers: |
| 826 | # |
| 827 | # $1: devices falling under common to be added to guard - optional |
Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 828 | # $2: custom guard - optional |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 829 | # |
Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 830 | # Calls write_makefile_header for each of the makefiles and |
| 831 | # write_blueprint_header for Android.bp and creates the initial |
| 832 | # path declaration and device guard for the Android.mk |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 833 | # |
| 834 | function write_headers() { |
Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 835 | write_makefile_header "$ANDROIDMK" |
Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 836 | |
| 837 | GUARD="$2" |
| 838 | if [ -z "$GUARD" ]; then |
| 839 | GUARD="TARGET_DEVICE" |
| 840 | fi |
| 841 | |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 842 | cat << EOF >> "$ANDROIDMK" |
| 843 | LOCAL_PATH := \$(call my-dir) |
| 844 | |
| 845 | EOF |
| 846 | if [ "$COMMON" -ne 1 ]; then |
| 847 | cat << EOF >> "$ANDROIDMK" |
Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 848 | ifeq (\$($GUARD),$DEVICE) |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 849 | |
| 850 | EOF |
| 851 | else |
| 852 | if [ -z "$1" ]; then |
| 853 | echo "Argument with devices to be added to guard must be set!" |
| 854 | exit 1 |
| 855 | fi |
| 856 | cat << EOF >> "$ANDROIDMK" |
Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 857 | ifneq (\$(filter $1,\$($GUARD)),) |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 858 | |
| 859 | EOF |
| 860 | fi |
| 861 | |
Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 862 | write_makefile_header "$BOARDMK" |
| 863 | write_makefile_header "$PRODUCTMK" |
| 864 | write_blueprint_header "$ANDROIDBP" |
| 865 | |
| 866 | cat << EOF >> "$ANDROIDBP" |
| 867 | soong_namespace { |
| 868 | } |
| 869 | |
| 870 | EOF |
| 871 | |
| 872 | [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON" |
| 873 | cat << EOF >> "$PRODUCTMK" |
| 874 | PRODUCT_SOONG_NAMESPACES += \\ |
| 875 | vendor/$VENDOR/$DEVICE |
| 876 | |
| 877 | EOF |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | # |
| 881 | # write_footers: |
| 882 | # |
| 883 | # Closes the inital guard and any other finalization tasks. Must |
| 884 | # be called as the final step. |
| 885 | # |
| 886 | function write_footers() { |
| 887 | cat << EOF >> "$ANDROIDMK" |
| 888 | endif |
| 889 | EOF |
| 890 | } |
| 891 | |
| 892 | # Return success if adb is up and not in recovery |
| 893 | function _adb_connected { |
| 894 | { |
Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 895 | if [[ "$(adb get-state)" == device ]] |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 896 | then |
| 897 | return 0 |
| 898 | fi |
| 899 | } 2>/dev/null |
| 900 | |
| 901 | return 1 |
| 902 | }; |
| 903 | |
| 904 | # |
| 905 | # parse_file_list: |
| 906 | # |
| 907 | # $1: input file |
Rashed Abdel-Tawab | b0d08e8 | 2017-04-04 02:48:18 -0400 | [diff] [blame] | 908 | # $2: blob section in file - optional |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 909 | # |
| 910 | # Sets PRODUCT_PACKAGES and PRODUCT_COPY_FILES while parsing the input file |
| 911 | # |
| 912 | function parse_file_list() { |
| 913 | if [ -z "$1" ]; then |
| 914 | echo "An input file is expected!" |
| 915 | exit 1 |
| 916 | elif [ ! -f "$1" ]; then |
| 917 | echo "Input file "$1" does not exist!" |
| 918 | exit 1 |
| 919 | fi |
| 920 | |
Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 921 | if [ -n "$2" ]; then |
| 922 | echo "Using section \"$2\"" |
Rashed Abdel-Tawab | b0d08e8 | 2017-04-04 02:48:18 -0400 | [diff] [blame] | 923 | LIST=$TMPDIR/files.txt |
Vladimir Oltean | fa79f21 | 2019-01-19 00:44:07 +0200 | [diff] [blame] | 924 | # Match all lines starting with first line found to start* with '#' |
| 925 | # comment and contain** $2, and ending with first line to be empty*. |
| 926 | # *whitespaces (tabs, spaces) at the beginning of lines are discarded |
| 927 | # **the $2 match is case-insensitive |
| 928 | cat $1 | sed -n '/^[[:space:]]*#.*'"$2"'/I,/^[[:space:]]*$/ p' > $LIST |
Rashed Abdel-Tawab | b0d08e8 | 2017-04-04 02:48:18 -0400 | [diff] [blame] | 929 | else |
| 930 | LIST=$1 |
| 931 | fi |
| 932 | |
| 933 | |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 934 | PRODUCT_PACKAGES_LIST=() |
| 935 | PRODUCT_PACKAGES_HASHES=() |
Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 936 | PRODUCT_PACKAGES_FIXUP_HASHES=() |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 937 | PRODUCT_COPY_FILES_LIST=() |
| 938 | PRODUCT_COPY_FILES_HASHES=() |
Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 939 | PRODUCT_COPY_FILES_FIXUP_HASHES=() |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 940 | |
| 941 | while read -r line; do |
| 942 | if [ -z "$line" ]; then continue; fi |
| 943 | |
| 944 | # If the line has a pipe delimiter, a sha1 hash should follow. |
| 945 | # This indicates the file should be pinned and not overwritten |
| 946 | # when extracting files. |
| 947 | local SPLIT=(${line//\|/ }) |
| 948 | local COUNT=${#SPLIT[@]} |
| 949 | local SPEC=${SPLIT[0]} |
| 950 | local HASH="x" |
Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 951 | local FIXUP_HASH="x" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 952 | if [ "$COUNT" -gt "1" ]; then |
| 953 | HASH=${SPLIT[1]} |
| 954 | fi |
Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 955 | if [ "$COUNT" -gt "2" ]; then |
| 956 | FIXUP_HASH=${SPLIT[2]} |
| 957 | fi |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 958 | |
| 959 | # if line starts with a dash, it needs to be packaged |
| 960 | if [[ "$SPEC" =~ ^- ]]; then |
| 961 | PRODUCT_PACKAGES_LIST+=("${SPEC#-}") |
| 962 | PRODUCT_PACKAGES_HASHES+=("$HASH") |
Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 963 | PRODUCT_PACKAGES_FIXUP_HASHES+=("$FIXUP_HASH") |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 964 | else |
| 965 | PRODUCT_COPY_FILES_LIST+=("$SPEC") |
| 966 | PRODUCT_COPY_FILES_HASHES+=("$HASH") |
Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 967 | PRODUCT_COPY_FILES_FIXUP_HASHES+=("$FIXUP_HASH") |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 968 | fi |
| 969 | |
Rashed Abdel-Tawab | b0d08e8 | 2017-04-04 02:48:18 -0400 | [diff] [blame] | 970 | done < <(egrep -v '(^#|^[[:space:]]*$)' "$LIST" | LC_ALL=C sort | uniq) |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | # |
| 974 | # write_makefiles: |
| 975 | # |
| 976 | # $1: file containing the list of items to extract |
Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 977 | # $2: make treble compatible makefile - optional |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 978 | # |
| 979 | # Calls write_product_copy_files and write_product_packages on |
Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 980 | # the given file and appends to the Android.bp as well as |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 981 | # the product makefile. |
| 982 | # |
| 983 | function write_makefiles() { |
| 984 | parse_file_list "$1" |
Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 985 | write_product_copy_files "$2" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 986 | write_product_packages |
| 987 | } |
| 988 | |
| 989 | # |
| 990 | # append_firmware_calls_to_makefiles: |
| 991 | # |
| 992 | # Appends to Android.mk the calls to all images present in radio folder |
| 993 | # (filesmap file used by releasetools to map firmware images should be kept in the device tree) |
| 994 | # |
| 995 | function append_firmware_calls_to_makefiles() { |
| 996 | cat << EOF >> "$ANDROIDMK" |
| 997 | ifeq (\$(LOCAL_PATH)/radio, \$(wildcard \$(LOCAL_PATH)/radio)) |
| 998 | |
| 999 | RADIO_FILES := \$(wildcard \$(LOCAL_PATH)/radio/*) |
| 1000 | \$(foreach f, \$(notdir \$(RADIO_FILES)), \\ |
| 1001 | \$(call add-radio-file,radio/\$(f))) |
| 1002 | \$(call add-radio-file,../../../device/$VENDOR/$DEVICE/radio/filesmap) |
| 1003 | |
| 1004 | endif |
| 1005 | |
| 1006 | EOF |
| 1007 | } |
| 1008 | |
| 1009 | # |
| 1010 | # get_file: |
| 1011 | # |
| 1012 | # $1: input file |
| 1013 | # $2: target file/folder |
| 1014 | # $3: source of the file (can be "adb" or a local folder) |
| 1015 | # |
| 1016 | # Silently extracts the input file to defined target |
| 1017 | # Returns success if file can be pulled from the device or found locally |
| 1018 | # |
| 1019 | function get_file() { |
| 1020 | local SRC="$3" |
| 1021 | |
| 1022 | if [ "$SRC" = "adb" ]; then |
| 1023 | # try to pull |
| 1024 | adb pull "$1" "$2" >/dev/null 2>&1 && return 0 |
| 1025 | |
| 1026 | return 1 |
| 1027 | else |
| 1028 | # try to copy |
Vladimir Oltean | fe49eae | 2018-06-25 00:05:56 +0300 | [diff] [blame] | 1029 | cp -r "$SRC/$1" "$2" 2>/dev/null && return 0 |
| 1030 | cp -r "$SRC/${1#/system}" "$2" 2>/dev/null && return 0 |
Vladimir Oltean | 6780da3 | 2019-01-06 19:38:31 +0200 | [diff] [blame] | 1031 | cp -r "$SRC/system/$1" "$2" 2>/dev/null && return 0 |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1032 | |
| 1033 | return 1 |
| 1034 | fi |
| 1035 | }; |
| 1036 | |
| 1037 | # |
| 1038 | # oat2dex: |
| 1039 | # |
| 1040 | # $1: extracted apk|jar (to check if deodex is required) |
| 1041 | # $2: odexed apk|jar to deodex |
| 1042 | # $3: source of the odexed apk|jar |
| 1043 | # |
| 1044 | # Convert apk|jar .odex in the corresposing classes.dex |
| 1045 | # |
| 1046 | function oat2dex() { |
theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 1047 | local OMNI_TARGET="$1" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1048 | local OEM_TARGET="$2" |
| 1049 | local SRC="$3" |
| 1050 | local TARGET= |
Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1051 | local OAT= |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1052 | |
Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1053 | if [ -z "$BAKSMALIJAR" ] || [ -z "$SMALIJAR" ]; then |
| 1054 | export BAKSMALIJAR="$OMNI_ROOT"/vendor/omni/build/tools/smali/baksmali.jar |
| 1055 | export SMALIJAR="$OMNI_ROOT"/vendor/omni/build/tools/smali/smali.jar |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1056 | fi |
| 1057 | |
Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1058 | if [ -z "$VDEXEXTRACTOR" ]; then |
Han Wang | 7a0b0bd | 2020-03-10 09:40:47 +0200 | [diff] [blame] | 1059 | export VDEXEXTRACTOR="$OMNI_ROOT"/vendor/omni/build/tools/${HOST}/vdexExtractor |
Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1060 | fi |
Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1061 | |
codeworkx | 85eda75 | 2018-09-23 12:36:57 +0200 | [diff] [blame] | 1062 | if [ -z "$CDEXCONVERTER" ]; then |
Han Wang | 7a0b0bd | 2020-03-10 09:40:47 +0200 | [diff] [blame] | 1063 | export CDEXCONVERTER="$OMNI_ROOT"/vendor/omni/build/tools/${HOST}/compact_dex_converter |
codeworkx | 85eda75 | 2018-09-23 12:36:57 +0200 | [diff] [blame] | 1064 | fi |
| 1065 | |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1066 | # Extract existing boot.oats to the temp folder |
| 1067 | if [ -z "$ARCHES" ]; then |
Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1068 | echo "Checking if system is odexed and locating boot.oats..." |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1069 | for ARCH in "arm64" "arm" "x86_64" "x86"; do |
Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1070 | mkdir -p "$TMPDIR/system/framework/$ARCH" |
Vladimir Oltean | fe49eae | 2018-06-25 00:05:56 +0300 | [diff] [blame] | 1071 | if get_file "/system/framework/$ARCH" "$TMPDIR/system/framework/" "$SRC"; then |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1072 | ARCHES+="$ARCH " |
Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1073 | else |
| 1074 | rmdir "$TMPDIR/system/framework/$ARCH" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1075 | fi |
| 1076 | done |
| 1077 | fi |
| 1078 | |
| 1079 | if [ -z "$ARCHES" ]; then |
| 1080 | FULLY_DEODEXED=1 && return 0 # system is fully deodexed, return |
| 1081 | fi |
| 1082 | |
theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 1083 | if [ ! -f "$OMNI_TARGET" ]; then |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1084 | return; |
| 1085 | fi |
| 1086 | |
theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 1087 | if grep "classes.dex" "$OMNI_TARGET" >/dev/null; then |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1088 | return 0 # target apk|jar is already odexed, return |
| 1089 | fi |
| 1090 | |
| 1091 | for ARCH in $ARCHES; do |
Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1092 | BOOTOAT="$TMPDIR/system/framework/$ARCH/boot.oat" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1093 | |
Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1094 | local OAT="$(dirname "$OEM_TARGET")/oat/$ARCH/$(basename "$OEM_TARGET" ."${OEM_TARGET##*.}").odex" |
| 1095 | local VDEX="$(dirname "$OEM_TARGET")/oat/$ARCH/$(basename "$OEM_TARGET" ."${OEM_TARGET##*.}").vdex" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1096 | |
Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1097 | if get_file "$OAT" "$TMPDIR" "$SRC"; then |
| 1098 | if get_file "$VDEX" "$TMPDIR" "$SRC"; then |
| 1099 | "$VDEXEXTRACTOR" -o "$TMPDIR/" -i "$TMPDIR/$(basename "$VDEX")" > /dev/null |
Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1100 | CLASSES=$(ls "$TMPDIR/$(basename "${OEM_TARGET%.*}")_classes"*) |
| 1101 | for CLASS in $CLASSES; do |
| 1102 | NEWCLASS=$(echo "$CLASS" | sed 's/.*_//;s/cdex/dex/') |
| 1103 | # Check if we have to deal with CompactDex |
| 1104 | if [[ "$CLASS" == *.cdex ]]; then |
| 1105 | "$CDEXCONVERTER" "$CLASS" &>/dev/null |
| 1106 | mv "$CLASS.new" "$TMPDIR/$NEWCLASS" |
| 1107 | else |
| 1108 | mv "$CLASS" "$TMPDIR/$NEWCLASS" |
| 1109 | fi |
| 1110 | done |
Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1111 | else |
Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1112 | java -jar "$BAKSMALIJAR" deodex -o "$TMPDIR/dexout" -b "$BOOTOAT" -d "$TMPDIR" "$TMPDIR/$(basename "$OAT")" |
| 1113 | java -jar "$SMALIJAR" assemble "$TMPDIR/dexout" -o "$TMPDIR/classes.dex" |
Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1114 | fi |
theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 1115 | elif [[ "$OMNI_TARGET" =~ .jar$ ]]; then |
Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1116 | JAROAT="$TMPDIR/system/framework/$ARCH/boot-$(basename ${OEM_TARGET%.*}).oat" |
Luca Stefani | 082f1e8 | 2018-10-07 12:44:53 +0200 | [diff] [blame] | 1117 | JARVDEX="/system/framework/boot-$(basename ${OEM_TARGET%.*}).vdex" |
Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1118 | if [ ! -f "$JAROAT" ]; then |
Luca Stefani | 082f1e8 | 2018-10-07 12:44:53 +0200 | [diff] [blame] | 1119 | JAROAT=$BOOTOAT |
Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1120 | fi |
Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1121 | # try to extract classes.dex from boot.vdex for frameworks jars |
| 1122 | # fallback to boot.oat if vdex is not available |
Luca Stefani | 082f1e8 | 2018-10-07 12:44:53 +0200 | [diff] [blame] | 1123 | if get_file "$JARVDEX" "$TMPDIR" "$SRC"; then |
Luca Stefani | 6f92e6b | 2018-10-31 19:16:05 +0100 | [diff] [blame] | 1124 | "$VDEXEXTRACTOR" -o "$TMPDIR/" -i "$TMPDIR/$(basename "$JARVDEX")" > /dev/null |
Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1125 | CLASSES=$(ls "$TMPDIR/$(basename "${JARVDEX%.*}")_classes"*) |
| 1126 | for CLASS in $CLASSES; do |
| 1127 | NEWCLASS=$(echo "$CLASS" | sed 's/.*_//;s/cdex/dex/') |
| 1128 | # Check if we have to deal with CompactDex |
| 1129 | if [[ "$CLASS" == *.cdex ]]; then |
| 1130 | "$CDEXCONVERTER" "$CLASS" &>/dev/null |
| 1131 | mv "$CLASS.new" "$TMPDIR/$NEWCLASS" |
| 1132 | else |
| 1133 | mv "$CLASS" "$TMPDIR/$NEWCLASS" |
| 1134 | fi |
| 1135 | done |
Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1136 | else |
Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1137 | java -jar "$BAKSMALIJAR" deodex -o "$TMPDIR/dexout" -b "$BOOTOAT" -d "$TMPDIR" "$JAROAT/$OEM_TARGET" |
| 1138 | java -jar "$SMALIJAR" assemble "$TMPDIR/dexout" -o "$TMPDIR/classes.dex" |
Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1139 | fi |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1140 | else |
| 1141 | continue |
| 1142 | fi |
| 1143 | |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1144 | done |
Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1145 | |
| 1146 | rm -rf "$TMPDIR/dexout" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | # |
| 1150 | # init_adb_connection: |
| 1151 | # |
| 1152 | # Starts adb server and waits for the device |
| 1153 | # |
| 1154 | function init_adb_connection() { |
| 1155 | adb start-server # Prevent unexpected starting server message from adb get-state in the next line |
| 1156 | if ! _adb_connected; then |
| 1157 | echo "No device is online. Waiting for one..." |
| 1158 | echo "Please connect USB and/or enable USB debugging" |
| 1159 | until _adb_connected; do |
| 1160 | sleep 1 |
| 1161 | done |
| 1162 | echo "Device Found." |
| 1163 | fi |
| 1164 | |
| 1165 | # Retrieve IP and PORT info if we're using a TCP connection |
| 1166 | TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \ |
| 1167 | | head -1 | awk '{print $1}') |
| 1168 | adb root &> /dev/null |
| 1169 | sleep 0.3 |
| 1170 | if [ -n "$TCPIPPORT" ]; then |
| 1171 | # adb root just killed our connection |
| 1172 | # so reconnect... |
| 1173 | adb connect "$TCPIPPORT" |
| 1174 | fi |
| 1175 | adb wait-for-device &> /dev/null |
| 1176 | sleep 0.3 |
| 1177 | } |
| 1178 | |
| 1179 | # |
| 1180 | # fix_xml: |
| 1181 | # |
| 1182 | # $1: xml file to fix |
| 1183 | # |
| 1184 | function fix_xml() { |
| 1185 | local XML="$1" |
| 1186 | local TEMP_XML="$TMPDIR/`basename "$XML"`.temp" |
| 1187 | |
Dobroslaw Kijowski | 3af2a8d | 2017-05-18 12:35:02 +0200 | [diff] [blame] | 1188 | grep -a '^<?xml version' "$XML" > "$TEMP_XML" |
| 1189 | grep -av '^<?xml version' "$XML" >> "$TEMP_XML" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1190 | |
| 1191 | mv "$TEMP_XML" "$XML" |
| 1192 | } |
| 1193 | |
Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1194 | function get_hash() { |
| 1195 | local FILE="$1" |
| 1196 | |
| 1197 | if [ "$(uname)" == "Darwin" ]; then |
| 1198 | shasum "${FILE}" | awk '{print $1}' |
| 1199 | else |
| 1200 | sha1sum "${FILE}" | awk '{print $1}' |
| 1201 | fi |
| 1202 | } |
| 1203 | |
Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1204 | function print_spec() { |
| 1205 | local SPEC_PRODUCT_PACKAGE="$1" |
| 1206 | local SPEC_SRC_FILE="$2" |
| 1207 | local SPEC_DST_FILE="$3" |
| 1208 | local SPEC_ARGS="$4" |
| 1209 | local SPEC_HASH="$5" |
Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1210 | local SPEC_FIXUP_HASH="$6" |
Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1211 | |
| 1212 | local PRODUCT_PACKAGE="" |
| 1213 | if [ ${SPEC_PRODUCT_PACKAGE} = true ]; then |
| 1214 | PRODUCT_PACKAGE="-" |
| 1215 | fi |
| 1216 | local SRC="" |
| 1217 | if [ ! -z "${SPEC_SRC_FILE}" ] && [ "${SPEC_SRC_FILE}" != "${SPEC_DST_FILE}" ]; then |
| 1218 | SRC="${SPEC_SRC_FILE}:" |
| 1219 | fi |
| 1220 | local DST="" |
| 1221 | if [ ! -z "${SPEC_DST_FILE}" ]; then |
| 1222 | DST="${SPEC_DST_FILE}" |
| 1223 | fi |
| 1224 | local ARGS="" |
| 1225 | if [ ! -z "${SPEC_ARGS}" ]; then |
| 1226 | ARGS=";${SPEC_ARGS}" |
| 1227 | fi |
| 1228 | local HASH="" |
| 1229 | if [ ! -z "${SPEC_HASH}" ] && [ "${SPEC_HASH}" != "x" ]; then |
| 1230 | HASH="|${SPEC_HASH}" |
| 1231 | fi |
Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1232 | local FIXUP_HASH="" |
| 1233 | if [ ! -z "${SPEC_FIXUP_HASH}" ] && [ "${SPEC_FIXUP_HASH}" != "x" ] && [ "${SPEC_FIXUP_HASH}" != "${SPEC_HASH}" ]; then |
| 1234 | FIXUP_HASH="|${SPEC_FIXUP_HASH}" |
| 1235 | fi |
| 1236 | printf '%s%s%s%s%s%s\n' "${PRODUCT_PACKAGE}" "${SRC}" "${DST}" "${ARGS}" "${HASH}" "${FIXUP_HASH}" |
| 1237 | } |
| 1238 | |
| 1239 | # To be overridden by device-level extract-files.sh |
| 1240 | # Parameters: |
| 1241 | # $1: spec name of a blob. Can be used for filtering. |
| 1242 | # If the spec is "src:dest", then $1 is "dest". |
| 1243 | # If the spec is "src", then $1 is "src". |
| 1244 | # $2: path to blob file. Can be used for fixups. |
| 1245 | # |
| 1246 | function blob_fixup() { |
| 1247 | : |
Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1248 | } |
| 1249 | |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1250 | # |
| 1251 | # extract: |
| 1252 | # |
Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1253 | # Positional parameters: |
| 1254 | # $1: file containing the list of items to extract (aka proprietary-files.txt) |
Dan Pasanen | 0cc0501 | 2017-03-21 09:06:11 -0500 | [diff] [blame] | 1255 | # $2: path to extracted system folder, an ota zip file, or "adb" to extract from device |
Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1256 | # $3: section in list file to extract - optional. Setting section via $3 is deprecated. |
| 1257 | # |
| 1258 | # Non-positional parameters (coming after $2): |
| 1259 | # --section: preferred way of selecting the portion to parse and extract from |
| 1260 | # proprietary-files.txt |
Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1261 | # --kang: if present, this option will activate the printing of hashes for the |
| 1262 | # extracted blobs. Useful with --section for subsequent pinning of |
| 1263 | # blobs taken from other origins. |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1264 | # |
| 1265 | function extract() { |
Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1266 | # Consume positional parameters |
| 1267 | local PROPRIETARY_FILES_TXT="$1"; shift |
| 1268 | local SRC="$1"; shift |
| 1269 | local SECTION="" |
Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1270 | local KANG=false |
Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1271 | |
| 1272 | # Consume optional, non-positional parameters |
| 1273 | while [ "$#" -gt 0 ]; do |
| 1274 | case "$1" in |
| 1275 | -s|--section) |
| 1276 | SECTION="$2"; shift |
| 1277 | ;; |
Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1278 | -k|--kang) |
| 1279 | KANG=true |
| 1280 | DISABLE_PINNING=1 |
| 1281 | ;; |
Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1282 | *) |
| 1283 | # Backwards-compatibility with the old behavior, where $3, if |
| 1284 | # present, denoted an optional positional ${SECTION} argument. |
| 1285 | # Users of ${SECTION} are encouraged to migrate from setting it as |
| 1286 | # positional $3, to non-positional --section ${SECTION}, the |
| 1287 | # reason being that it doesn't scale to have more than 1 optional |
| 1288 | # positional argument. |
| 1289 | SECTION="$1" |
| 1290 | ;; |
| 1291 | esac |
| 1292 | shift |
| 1293 | done |
| 1294 | |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1295 | if [ -z "$OUTDIR" ]; then |
| 1296 | echo "Output dir not set!" |
| 1297 | exit 1 |
| 1298 | fi |
| 1299 | |
Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1300 | parse_file_list "${PROPRIETARY_FILES_TXT}" "${SECTION}" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1301 | |
| 1302 | # Allow failing, so we can try $DEST and/or $FILE |
| 1303 | set +e |
| 1304 | |
| 1305 | local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ${PRODUCT_PACKAGES_LIST[@]} ) |
| 1306 | local HASHLIST=( ${PRODUCT_COPY_FILES_HASHES[@]} ${PRODUCT_PACKAGES_HASHES[@]} ) |
Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1307 | local FIXUP_HASHLIST=( ${PRODUCT_COPY_FILES_FIXUP_HASHES[@]} ${PRODUCT_PACKAGES_FIXUP_HASHES[@]} ) |
Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1308 | local PRODUCT_COPY_FILES_COUNT=${#PRODUCT_COPY_FILES_LIST[@]} |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1309 | local COUNT=${#FILELIST[@]} |
theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 1310 | local OUTPUT_ROOT="$OMNI_ROOT"/"$OUTDIR"/proprietary |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1311 | local OUTPUT_TMP="$TMPDIR"/"$OUTDIR"/proprietary |
| 1312 | |
| 1313 | if [ "$SRC" = "adb" ]; then |
| 1314 | init_adb_connection |
| 1315 | fi |
| 1316 | |
Dan Pasanen | 0cc0501 | 2017-03-21 09:06:11 -0500 | [diff] [blame] | 1317 | if [ -f "$SRC" ] && [ "${SRC##*.}" == "zip" ]; then |
conbold | 9baced4 | 2017-11-10 16:33:38 +0100 | [diff] [blame] | 1318 | DUMPDIR="$TMPDIR"/system_dump |
Dan Pasanen | 0cc0501 | 2017-03-21 09:06:11 -0500 | [diff] [blame] | 1319 | |
| 1320 | # Check if we're working with the same zip that was passed last time. |
| 1321 | # If so, let's just use what's already extracted. |
| 1322 | MD5=`md5sum "$SRC"| awk '{print $1}'` |
| 1323 | OLDMD5=`cat "$DUMPDIR"/zipmd5.txt` |
| 1324 | |
| 1325 | if [ "$MD5" != "$OLDMD5" ]; then |
| 1326 | rm -rf "$DUMPDIR" |
| 1327 | mkdir "$DUMPDIR" |
| 1328 | unzip "$SRC" -d "$DUMPDIR" |
| 1329 | echo "$MD5" > "$DUMPDIR"/zipmd5.txt |
| 1330 | |
| 1331 | # Stop if an A/B OTA zip is detected. We cannot extract these. |
| 1332 | if [ -a "$DUMPDIR"/payload.bin ]; then |
| 1333 | echo "A/B style OTA zip detected. This is not supported at this time. Stopping..." |
| 1334 | exit 1 |
Dan Pasanen | 0cc0501 | 2017-03-21 09:06:11 -0500 | [diff] [blame] | 1335 | fi |
dianlujitao | 85ddca6 | 2020-04-21 23:03:20 +0800 | [diff] [blame] | 1336 | |
Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 1337 | for PARTITION in "system" "odm" "product" "system_ext" "vendor" |
dianlujitao | 85ddca6 | 2020-04-21 23:03:20 +0800 | [diff] [blame] | 1338 | do |
| 1339 | # If OTA is block based, extract it. |
dianlujitao | e2cbe26 | 2020-04-21 23:01:13 +0800 | [diff] [blame] | 1340 | if [ -a "$DUMPDIR"/"$PARTITION".new.dat.br ]; then |
| 1341 | echo "Converting "$PARTITION".new.dat.br to "$PARTITION".new.dat" |
| 1342 | brotli -d "$DUMPDIR"/"$PARTITION".new.dat.br |
| 1343 | rm "$DUMPDIR"/"$PARTITION".new.dat.br |
| 1344 | fi |
dianlujitao | 85ddca6 | 2020-04-21 23:03:20 +0800 | [diff] [blame] | 1345 | if [ -a "$DUMPDIR"/"$PARTITION".new.dat ]; then |
| 1346 | echo "Converting "$PARTITION".new.dat to "$PARTITION".img" |
| 1347 | python "$OMNI_ROOT"/vendor/omni/build/tools/sdat2img.py "$DUMPDIR"/"$PARTITION".transfer.list "$DUMPDIR"/"$PARTITION".new.dat "$DUMPDIR"/"$PARTITION".img 2>&1 |
| 1348 | rm -rf "$DUMPDIR"/"$PARTITION".new.dat "$DUMPDIR"/"$PARTITION" |
| 1349 | mkdir "$DUMPDIR"/"$PARTITION" "$DUMPDIR"/tmp |
| 1350 | echo "Requesting sudo access to mount the "$PARTITION".img" |
| 1351 | sudo mount -o loop "$DUMPDIR"/"$PARTITION".img "$DUMPDIR"/tmp |
| 1352 | cp -r "$DUMPDIR"/tmp/* "$DUMPDIR"/"$PARTITION"/ |
| 1353 | sudo umount "$DUMPDIR"/tmp |
| 1354 | rm -rf "$DUMPDIR"/tmp "$DUMPDIR"/"$PARTITION".img |
| 1355 | fi |
| 1356 | done |
Dan Pasanen | 0cc0501 | 2017-03-21 09:06:11 -0500 | [diff] [blame] | 1357 | fi |
| 1358 | |
| 1359 | SRC="$DUMPDIR" |
| 1360 | fi |
| 1361 | |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1362 | if [ "$VENDOR_STATE" -eq "0" ]; then |
| 1363 | echo "Cleaning output directory ($OUTPUT_ROOT).." |
| 1364 | rm -rf "${OUTPUT_TMP:?}" |
| 1365 | mkdir -p "${OUTPUT_TMP:?}" |
Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1366 | if [ -d "$OUTPUT_ROOT" ]; then |
| 1367 | mv "${OUTPUT_ROOT:?}/"* "${OUTPUT_TMP:?}/" |
| 1368 | fi |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1369 | VENDOR_STATE=1 |
| 1370 | fi |
| 1371 | |
Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1372 | echo "Extracting ${COUNT} files in ${PROPRIETARY_FILES_TXT} from ${SRC}:" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1373 | |
| 1374 | for (( i=1; i<COUNT+1; i++ )); do |
| 1375 | |
Vladimir Oltean | 8e2de65 | 2018-06-24 20:41:30 +0300 | [diff] [blame] | 1376 | local SPEC_SRC_FILE=$(src_file "${FILELIST[$i-1]}") |
Vladimir Oltean | b06f3aa | 2018-06-24 20:38:04 +0300 | [diff] [blame] | 1377 | local SPEC_DST_FILE=$(target_file "${FILELIST[$i-1]}") |
Vladimir Oltean | d639133 | 2018-06-24 20:42:01 +0300 | [diff] [blame] | 1378 | local SPEC_ARGS=$(target_args "${FILELIST[$i-1]}") |
Vladimir Oltean | b5500d7 | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1379 | local OUTPUT_DIR= |
| 1380 | local TMP_DIR= |
| 1381 | local SRC_FILE= |
| 1382 | local DST_FILE= |
Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1383 | local IS_PRODUCT_PACKAGE=false |
| 1384 | |
| 1385 | # Note: this relies on the fact that the ${FILELIST[@]} array |
| 1386 | # contains first ${PRODUCT_COPY_FILES_LIST[@]}, then ${PRODUCT_PACKAGES_LIST[@]}. |
| 1387 | if [ "${i}" -gt "${PRODUCT_COPY_FILES_COUNT}" ]; then |
| 1388 | IS_PRODUCT_PACKAGE=true |
| 1389 | fi |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1390 | |
Michael Bestas | bda3020 | 2020-12-28 04:44:52 +0200 | [diff] [blame] | 1391 | OUTPUT_DIR="${OUTPUT_ROOT}" |
| 1392 | TMP_DIR="${OUTPUT_TMP}" |
| 1393 | SRC_FILE="/system/${SPEC_SRC_FILE}" |
| 1394 | DST_FILE="/system/${SPEC_DST_FILE}" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1395 | |
Vladimir Oltean | b5500d7 | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1396 | # Strip the file path in the vendor repo of "system", if present |
Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1397 | local BLOB_DISPLAY_NAME="${DST_FILE#/system/}" |
dianlujitao | 4ddcfb7 | 2020-04-06 12:43:16 +0800 | [diff] [blame] | 1398 | local VENDOR_REPO_FILE="$OUTPUT_DIR/${BLOB_DISPLAY_NAME}" |
Vladimir Oltean | b5500d7 | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1399 | mkdir -p $(dirname "${VENDOR_REPO_FILE}") |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1400 | |
Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 1401 | # Check pinned files |
Vladimir Oltean | e688cf9 | 2019-01-17 02:47:02 +0200 | [diff] [blame] | 1402 | local HASH="$(echo ${HASHLIST[$i-1]} | awk '{ print tolower($0); }')" |
Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1403 | local FIXUP_HASH="$(echo ${FIXUP_HASHLIST[$i-1]} | awk '{ print tolower($0); }')" |
Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 1404 | local KEEP="" |
Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1405 | if [ "$DISABLE_PINNING" != "1" ] && [ "$HASH" != "x" ]; then |
Vladimir Oltean | 4daf559 | 2018-06-24 20:46:42 +0300 | [diff] [blame] | 1406 | if [ -f "${VENDOR_REPO_FILE}" ]; then |
| 1407 | local PINNED="${VENDOR_REPO_FILE}" |
Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 1408 | else |
Vladimir Oltean | b5500d7 | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1409 | local PINNED="${TMP_DIR}${DST_FILE#/system}" |
Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 1410 | fi |
| 1411 | if [ -f "$PINNED" ]; then |
Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1412 | local TMP_HASH=$(get_hash "${PINNED}") |
| 1413 | if [ "${TMP_HASH}" = "${HASH}" ] || [ "${TMP_HASH}" = "${FIXUP_HASH}" ]; then |
Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 1414 | KEEP="1" |
Vladimir Oltean | 4daf559 | 2018-06-24 20:46:42 +0300 | [diff] [blame] | 1415 | if [ ! -f "${VENDOR_REPO_FILE}" ]; then |
| 1416 | cp -p "$PINNED" "${VENDOR_REPO_FILE}" |
Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 1417 | fi |
| 1418 | fi |
| 1419 | fi |
| 1420 | fi |
| 1421 | |
Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1422 | if [ "${KANG}" = false ]; then |
| 1423 | printf ' - %s\n' "${BLOB_DISPLAY_NAME}" |
| 1424 | fi |
| 1425 | |
Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 1426 | if [ "$KEEP" = "1" ]; then |
Arian | 2d80238 | 2021-09-09 15:18:35 +0200 | [diff] [blame] | 1427 | if [ "${FIXUP_HASH}" != "x" ]; then |
| 1428 | printf ' + keeping pinned file with hash %s\n' "${FIXUP_HASH}" |
| 1429 | else |
| 1430 | printf ' + keeping pinned file with hash %s\n' "${HASH}" |
| 1431 | fi |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1432 | else |
Vladimir Oltean | b5500d7 | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1433 | FOUND=false |
| 1434 | # Try Lineage target first. |
| 1435 | # Also try to search for files stripped of |
| 1436 | # the "/system" prefix, if we're actually extracting |
| 1437 | # from a system image. |
Vladimir Oltean | fe49eae | 2018-06-25 00:05:56 +0300 | [diff] [blame] | 1438 | for CANDIDATE in "${DST_FILE}" "${SRC_FILE}"; do |
Vladimir Oltean | b5500d7 | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1439 | get_file ${CANDIDATE} ${VENDOR_REPO_FILE} ${SRC} && { |
| 1440 | FOUND=true |
| 1441 | break |
| 1442 | } |
| 1443 | done |
| 1444 | |
| 1445 | if [ "${FOUND}" = false ]; then |
Bruno Martins | 74e00eb | 2021-04-10 14:36:50 +0100 | [diff] [blame] | 1446 | colored_echo red " !! ${BLOB_DISPLAY_NAME}: file not found in source" |
Vladimir Oltean | 1132937 | 2018-10-18 00:44:02 +0300 | [diff] [blame] | 1447 | continue |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1448 | fi |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1449 | |
Arian | 5f98d79 | 2021-09-09 15:24:25 +0200 | [diff] [blame] | 1450 | # Blob fixup pipeline has 2 parts: one that is fixed and |
| 1451 | # one that is user-configurable |
| 1452 | local PRE_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE}) |
| 1453 | # Deodex apk|jar if that's the case |
| 1454 | if [[ "$FULLY_DEODEXED" -ne "1" && "${VENDOR_REPO_FILE}" =~ .(apk|jar)$ ]]; then |
| 1455 | oat2dex "${VENDOR_REPO_FILE}" "${SRC_FILE}" "$SRC" |
| 1456 | if [ -f "$TMPDIR/classes.dex" ]; then |
| 1457 | touch -t 200901010000 "$TMPDIR/classes"* |
| 1458 | zip -gjq "${VENDOR_REPO_FILE}" "$TMPDIR/classes"* |
| 1459 | rm "$TMPDIR/classes"* |
| 1460 | printf ' (updated %s from odex files)\n' "${SRC_FILE}" |
| 1461 | fi |
| 1462 | elif [[ "${VENDOR_REPO_FILE}" =~ .xml$ ]]; then |
| 1463 | fix_xml "${VENDOR_REPO_FILE}" |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1464 | fi |
Arian | 5f98d79 | 2021-09-09 15:24:25 +0200 | [diff] [blame] | 1465 | # Now run user-supplied fixup function |
| 1466 | blob_fixup "${BLOB_DISPLAY_NAME}" "${VENDOR_REPO_FILE}" |
| 1467 | local POST_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE}) |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1468 | |
Arian | 5f98d79 | 2021-09-09 15:24:25 +0200 | [diff] [blame] | 1469 | if [ -f "${VENDOR_REPO_FILE}" ]; then |
| 1470 | local DIR=$(dirname "${VENDOR_REPO_FILE}") |
| 1471 | local TYPE="${DIR##*/}" |
Michael Bestas | bda3020 | 2020-12-28 04:44:52 +0200 | [diff] [blame] | 1472 | if [ "$TYPE" = "bin" ]; then |
Arian | 5f98d79 | 2021-09-09 15:24:25 +0200 | [diff] [blame] | 1473 | chmod 755 "${VENDOR_REPO_FILE}" |
| 1474 | else |
| 1475 | chmod 644 "${VENDOR_REPO_FILE}" |
| 1476 | fi |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1477 | fi |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1478 | |
Arian | 5f98d79 | 2021-09-09 15:24:25 +0200 | [diff] [blame] | 1479 | if [ "${KANG}" = true ]; then |
| 1480 | print_spec "${IS_PRODUCT_PACKAGE}" "${SPEC_SRC_FILE}" "${SPEC_DST_FILE}" "${SPEC_ARGS}" "${PRE_FIXUP_HASH}" "${POST_FIXUP_HASH}" |
| 1481 | fi |
Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1482 | |
Arian | 5f98d79 | 2021-09-09 15:24:25 +0200 | [diff] [blame] | 1483 | # Check and print whether the fixup pipeline actually did anything. |
| 1484 | # This isn't done right after the fixup pipeline because we want this print |
| 1485 | # to come after print_spec above, when in kang mode. |
| 1486 | if [ "${PRE_FIXUP_HASH}" != "${POST_FIXUP_HASH}" ]; then |
| 1487 | printf " + Fixed up %s\n" "${BLOB_DISPLAY_NAME}" |
| 1488 | # Now sanity-check the spec for this blob. |
| 1489 | if [ "${KANG}" = false ] && [ "${FIXUP_HASH}" = "x" ] && [ "${HASH}" != "x" ]; then |
| 1490 | colored_echo yellow "WARNING: The ${BLOB_DISPLAY_NAME} file was fixed up, but it is pinned." |
| 1491 | colored_echo yellow "This is a mistake and you want to either remove the hash completely, or add an extra one." |
| 1492 | fi |
Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1493 | fi |
Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1494 | fi |
| 1495 | |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1496 | done |
| 1497 | |
| 1498 | # Don't allow failing |
| 1499 | set -e |
| 1500 | } |
| 1501 | |
| 1502 | # |
Rashed Abdel-Tawab | 5b97a98 | 2019-09-29 01:19:57 -0400 | [diff] [blame] | 1503 | # extract2: |
| 1504 | # |
| 1505 | # Positional parameters: |
| 1506 | # $1: file containing the list of items to extract (aka proprietary-files.txt) |
| 1507 | # |
| 1508 | # Non-positional parameters (coming after $2): |
| 1509 | # --section: selects the portion to parse and extracts from proprietary-files.txt |
| 1510 | # --kang: if present, this option will activate the printing of hashes for the |
| 1511 | # extracted blobs. Useful with --section for subsequent pinning of |
| 1512 | # blobs taken from other origins. |
| 1513 | # |
| 1514 | function extract2() { |
| 1515 | # Consume positional parameters |
| 1516 | local PROPRIETARY_FILES_TXT="$1"; shift |
| 1517 | local SECTION="" |
| 1518 | local KANG=false |
| 1519 | |
| 1520 | # Consume optional, non-positional parameters |
| 1521 | while [ "$#" -gt 0 ]; do |
| 1522 | case "$1" in |
| 1523 | --adb) |
| 1524 | ADB=true |
| 1525 | ;; |
| 1526 | --system) |
| 1527 | SYSTEM_SRC="$2"; shift |
| 1528 | ;; |
| 1529 | --vendor) |
| 1530 | VENDOR_SRC="$2"; shift |
| 1531 | ;; |
| 1532 | --odm) |
| 1533 | ODM_SRC="$2"; shift |
| 1534 | ;; |
| 1535 | --product) |
| 1536 | PRODUCT_SRC="$2"; shift |
| 1537 | ;; |
| 1538 | -s|--section) |
| 1539 | SECTION="$2"; shift |
| 1540 | ;; |
| 1541 | -k|--kang) |
| 1542 | KANG=true |
| 1543 | DISABLE_PINNING=1 |
| 1544 | ;; |
| 1545 | esac |
| 1546 | shift |
| 1547 | done |
| 1548 | |
| 1549 | if [ -z "$ADB" ] || [ -z "$SYSTEM_SRC" && -z "$VENDOR_SRC" && -z "$ODM_SRC" && -z "$PRODUCT_SRC" ]; then |
| 1550 | echo "No sources set! You must select --adb or pass paths to partition dumps." |
| 1551 | exit 1 |
| 1552 | fi |
| 1553 | |
| 1554 | if [ -z "$OUTDIR" ]; then |
| 1555 | echo "Output dir not set!" |
| 1556 | exit 1 |
| 1557 | fi |
| 1558 | |
| 1559 | parse_file_list "${PROPRIETARY_FILES_TXT}" "${SECTION}" |
| 1560 | |
| 1561 | # Allow failing, so we can try $DEST and/or $FILE |
| 1562 | set +e |
| 1563 | |
| 1564 | local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ${PRODUCT_PACKAGES_LIST[@]} ) |
| 1565 | local HASHLIST=( ${PRODUCT_COPY_FILES_HASHES[@]} ${PRODUCT_PACKAGES_HASHES[@]} ) |
| 1566 | local FIXUP_HASHLIST=( ${PRODUCT_COPY_FILES_FIXUP_HASHES[@]} ${PRODUCT_PACKAGES_FIXUP_HASHES[@]} ) |
| 1567 | local PRODUCT_COPY_FILES_COUNT=${#PRODUCT_COPY_FILES_LIST[@]} |
| 1568 | local COUNT=${#FILELIST[@]} |
| 1569 | local OUTPUT_ROOT="$OMNI_ROOT"/"$OUTDIR"/proprietary |
| 1570 | local OUTPUT_TMP="$TMPDIR"/"$OUTDIR"/proprietary |
| 1571 | |
| 1572 | if [ "$ADB" = true ]; then |
| 1573 | init_adb_connection |
| 1574 | fi |
| 1575 | |
| 1576 | if [ "$VENDOR_STATE" -eq "0" ]; then |
| 1577 | echo "Cleaning output directory ($OUTPUT_ROOT).." |
| 1578 | rm -rf "${OUTPUT_TMP:?}" |
| 1579 | mkdir -p "${OUTPUT_TMP:?}" |
| 1580 | if [ -d "$OUTPUT_ROOT" ]; then |
| 1581 | mv "${OUTPUT_ROOT:?}/"* "${OUTPUT_TMP:?}/" |
| 1582 | fi |
| 1583 | VENDOR_STATE=1 |
| 1584 | fi |
| 1585 | |
| 1586 | echo "Extracting ${COUNT} files in ${PROPRIETARY_FILES_TXT} from ${SRC}:" |
| 1587 | |
| 1588 | for (( i=1; i<COUNT+1; i++ )); do |
| 1589 | |
| 1590 | local SPEC_SRC_FILE=$(src_file "${FILELIST[$i-1]}") |
| 1591 | local SPEC_DST_FILE=$(target_file "${FILELIST[$i-1]}") |
| 1592 | local SPEC_ARGS=$(target_args "${FILELIST[$i-1]}") |
| 1593 | local OUTPUT_DIR= |
| 1594 | local TMP_DIR= |
| 1595 | local SRC_FILE= |
| 1596 | local DST_FILE= |
| 1597 | local IS_PRODUCT_PACKAGE=false |
| 1598 | |
| 1599 | # Note: this relies on the fact that the ${FILELIST[@]} array |
| 1600 | # contains first ${PRODUCT_COPY_FILES_LIST[@]}, then ${PRODUCT_PACKAGES_LIST[@]}. |
| 1601 | if [ "${i}" -gt "${PRODUCT_COPY_FILES_COUNT}" ]; then |
| 1602 | IS_PRODUCT_PACKAGE=true |
| 1603 | fi |
| 1604 | |
| 1605 | if [ "${SPEC_ARGS}" = "rootfs" ]; then |
| 1606 | OUTPUT_DIR="${OUTPUT_ROOT}/rootfs" |
| 1607 | TMP_DIR="${OUTPUT_TMP}/rootfs" |
| 1608 | else |
| 1609 | OUTPUT_DIR="${OUTPUT_ROOT}" |
| 1610 | TMP_DIR="${OUTPUT_TMP}" |
| 1611 | fi |
| 1612 | SRC_FILE="${SPEC_SRC_FILE}" |
| 1613 | DST_FILE="${SPEC_DST_FILE}" |
| 1614 | |
| 1615 | local VENDOR_REPO_FILE="$OUTPUT_DIR/${DST_FILE}" |
| 1616 | local BLOB_DISPLAY_NAME="${DST_FILE}" |
| 1617 | mkdir -p $(dirname "${VENDOR_REPO_FILE}") |
| 1618 | |
| 1619 | # Check pinned files |
| 1620 | local HASH="$(echo ${HASHLIST[$i-1]} | awk '{ print tolower($0); }')" |
| 1621 | local FIXUP_HASH="$(echo ${FIXUP_HASHLIST[$i-1]} | awk '{ print tolower($0); }')" |
| 1622 | local KEEP="" |
| 1623 | if [ "$DISABLE_PINNING" != "1" ] && [ "$HASH" != "x" ]; then |
| 1624 | if [ -f "${VENDOR_REPO_FILE}" ]; then |
| 1625 | local PINNED="${VENDOR_REPO_FILE}" |
| 1626 | else |
| 1627 | local PINNED="${TMP_DIR}${DST_FILE}" |
| 1628 | fi |
| 1629 | if [ -f "$PINNED" ]; then |
| 1630 | local TMP_HASH=$(get_hash "${PINNED}") |
| 1631 | if [ "${TMP_HASH}" = "${HASH}" ] || [ "${TMP_HASH}" = "${FIXUP_HASH}" ]; then |
| 1632 | KEEP="1" |
| 1633 | if [ ! -f "${VENDOR_REPO_FILE}" ]; then |
| 1634 | cp -p "$PINNED" "${VENDOR_REPO_FILE}" |
| 1635 | fi |
| 1636 | fi |
| 1637 | fi |
| 1638 | fi |
| 1639 | |
| 1640 | if [ "${KANG}" = false ]; then |
| 1641 | printf ' - %s\n' "${BLOB_DISPLAY_NAME}" |
| 1642 | fi |
| 1643 | |
| 1644 | if [ "$KEEP" = "1" ]; then |
| 1645 | printf ' + keeping pinned file with hash %s\n' "${HASH}" |
| 1646 | else |
| 1647 | FOUND=false |
| 1648 | PARTITION_SOURCE_DIR= |
| 1649 | # Try Lineage target first. |
| 1650 | for CANDIDATE in "${DST_FILE}" "${SRC_FILE}"; do |
| 1651 | PARTITION=$(echo "$CANDIDATE" | cut -d/ -f1) |
| 1652 | if [ "$PARTITION" = "system" ]; then |
| 1653 | PARTITION_SOURCE_DIR="$SYSTEM_SRC" |
| 1654 | elif [ "$PARTITION" = "vendor" ]; then |
| 1655 | PARTITION_SOURCE_DIR="$VENDOR_SRC" |
| 1656 | elif [ "$PARTITION" = "product" ]; then |
| 1657 | PARTITION_SOURCE_DIR="$PRODUCT_SRC" |
| 1658 | elif [ "$PARTITION" = "odm" ]; then |
| 1659 | PARTITION_SOURCE_DIR="$ODM_SRC" |
| 1660 | fi |
| 1661 | CANDIDATE_RELATIVE_NAME=$(echo "$CANDIDATE" | cut -d/ -f2-) |
| 1662 | get_file ${CANDIDATE_RELATIVE_NAME} ${VENDOR_REPO_FILE} ${PARTITION_SOURCE_DIR} && { |
| 1663 | FOUND=true |
| 1664 | break |
| 1665 | } |
| 1666 | # Search with the full system/ prefix if the file was not found on the system partition |
| 1667 | # because we may be searching in a mounted system-as-root system.img |
| 1668 | if [[ "${FOUND}" = false && "$PARTITION" = "system" ]]; then |
| 1669 | get_file ${CANDIDATE} ${VENDOR_REPO_FILE} ${PARTITION_SOURCE_DIR} && { |
| 1670 | FOUND=true |
| 1671 | break |
| 1672 | } |
| 1673 | fi |
| 1674 | done |
| 1675 | |
| 1676 | if [ -z "${PARTITION_SOURCE_DIR}" ]; then |
| 1677 | echo "$CANDIDATE has no preceeding partition path. Prepend system/, vendor/, product/, or odm/ to this entry." |
| 1678 | fi |
| 1679 | |
| 1680 | if [ "${FOUND}" = false ]; then |
| 1681 | printf ' !! %s: file not found in source\n' "${BLOB_DISPLAY_NAME}" |
| 1682 | continue |
| 1683 | fi |
| 1684 | fi |
| 1685 | |
| 1686 | # Blob fixup pipeline has 2 parts: one that is fixed and |
| 1687 | # one that is user-configurable |
| 1688 | local PRE_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE}) |
| 1689 | # Deodex apk|jar if that's the case |
| 1690 | if [[ "$FULLY_DEODEXED" -ne "1" && "${VENDOR_REPO_FILE}" =~ .(apk|jar)$ ]]; then |
| 1691 | oat2dex "${VENDOR_REPO_FILE}" "${SRC_FILE}" "${SYSTEM_SRC}" |
| 1692 | if [ -f "$TMPDIR/classes.dex" ]; then |
| 1693 | zip -gjq "${VENDOR_REPO_FILE}" "$TMPDIR/classes"* |
| 1694 | rm "$TMPDIR/classes"* |
| 1695 | printf ' (updated %s from odex files)\n' "${SRC_FILE}" |
| 1696 | fi |
| 1697 | elif [[ "${VENDOR_REPO_FILE}" =~ .xml$ ]]; then |
| 1698 | fix_xml "${VENDOR_REPO_FILE}" |
| 1699 | fi |
| 1700 | # Now run user-supplied fixup function |
| 1701 | blob_fixup "${BLOB_DISPLAY_NAME}" "${VENDOR_REPO_FILE}" |
| 1702 | local POST_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE}) |
| 1703 | |
| 1704 | if [ -f "${VENDOR_REPO_FILE}" ]; then |
| 1705 | local DIR=$(dirname "${VENDOR_REPO_FILE}") |
| 1706 | local TYPE="${DIR##*/}" |
| 1707 | if [ "$TYPE" = "bin" -o "$TYPE" = "sbin" ]; then |
| 1708 | chmod 755 "${VENDOR_REPO_FILE}" |
| 1709 | else |
| 1710 | chmod 644 "${VENDOR_REPO_FILE}" |
| 1711 | fi |
| 1712 | fi |
| 1713 | |
| 1714 | if [ "${KANG}" = true ]; then |
| 1715 | print_spec "${IS_PRODUCT_PACKAGE}" "${SPEC_SRC_FILE}" "${SPEC_DST_FILE}" "${SPEC_ARGS}" "${PRE_FIXUP_HASH}" "${POST_FIXUP_HASH}" |
| 1716 | fi |
| 1717 | |
| 1718 | # Check and print whether the fixup pipeline actually did anything. |
| 1719 | # This isn't done right after the fixup pipeline because we want this print |
| 1720 | # to come after print_spec above, when in kang mode. |
| 1721 | if [ "${PRE_FIXUP_HASH}" != "${POST_FIXUP_HASH}" ]; then |
| 1722 | printf " + Fixed up %s\n" "${BLOB_DISPLAY_NAME}" |
| 1723 | # Now sanity-check the spec for this blob. |
| 1724 | if [ "${KANG}" = false ] && [ "${FIXUP_HASH}" = "x" ] && [ "${HASH}" != "x" ]; then |
| 1725 | printf "WARNING: The %s file was fixed up, but it is pinned.\n" ${BLOB_DISPLAY_NAME} |
| 1726 | printf "This is a mistake and you want to either remove the hash completely, or add an extra one.\n" |
| 1727 | fi |
| 1728 | fi |
| 1729 | |
| 1730 | done |
| 1731 | |
| 1732 | # Don't allow failing |
| 1733 | set -e |
| 1734 | } |
| 1735 | |
| 1736 | # |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1737 | # extract_firmware: |
| 1738 | # |
| 1739 | # $1: file containing the list of items to extract |
| 1740 | # $2: path to extracted radio folder |
| 1741 | # |
| 1742 | function extract_firmware() { |
| 1743 | if [ -z "$OUTDIR" ]; then |
| 1744 | echo "Output dir not set!" |
| 1745 | exit 1 |
| 1746 | fi |
| 1747 | |
| 1748 | parse_file_list "$1" |
| 1749 | |
| 1750 | # Don't allow failing |
| 1751 | set -e |
| 1752 | |
| 1753 | local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ) |
| 1754 | local COUNT=${#FILELIST[@]} |
| 1755 | local SRC="$2" |
theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 1756 | local OUTPUT_DIR="$OMNI_ROOT"/"$OUTDIR"/radio |
Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1757 | |
| 1758 | if [ "$VENDOR_RADIO_STATE" -eq "0" ]; then |
| 1759 | echo "Cleaning firmware output directory ($OUTPUT_DIR).." |
| 1760 | rm -rf "${OUTPUT_DIR:?}/"* |
| 1761 | VENDOR_RADIO_STATE=1 |
| 1762 | fi |
| 1763 | |
| 1764 | echo "Extracting $COUNT files in $1 from $SRC:" |
| 1765 | |
| 1766 | for (( i=1; i<COUNT+1; i++ )); do |
| 1767 | local FILE="${FILELIST[$i-1]}" |
| 1768 | printf ' - %s \n' "/radio/$FILE" |
| 1769 | |
| 1770 | if [ ! -d "$OUTPUT_DIR" ]; then |
| 1771 | mkdir -p "$OUTPUT_DIR" |
| 1772 | fi |
| 1773 | cp "$SRC/$FILE" "$OUTPUT_DIR/$FILE" |
| 1774 | chmod 644 "$OUTPUT_DIR/$FILE" |
| 1775 | done |
| 1776 | } |
Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 1777 | |
| 1778 | function extract_img_data() { |
| 1779 | local image_file="$1" |
| 1780 | local out_dir="$2" |
| 1781 | local logFile="$TMPDIR/debugfs.log" |
| 1782 | |
| 1783 | if [ ! -d "$out_dir" ]; then |
| 1784 | mkdir -p "$out_dir" |
| 1785 | fi |
| 1786 | |
| 1787 | if [[ "$HOST_OS" == "Darwin" ]]; then |
| 1788 | debugfs -R "rdump / \"$out_dir\"" "$image_file" &> "$logFile" || { |
| 1789 | echo "[-] Failed to extract data from '$image_file'" |
| 1790 | abort 1 |
| 1791 | } |
| 1792 | else |
| 1793 | debugfs -R 'ls -p' "$image_file" 2>/dev/null | cut -d '/' -f6 | while read -r entry |
| 1794 | do |
| 1795 | debugfs -R "rdump \"$entry\" \"$out_dir\"" "$image_file" >> "$logFile" 2>&1 || { |
| 1796 | echo "[-] Failed to extract data from '$image_file'" |
| 1797 | abort 1 |
| 1798 | } |
| 1799 | done |
| 1800 | fi |
| 1801 | |
| 1802 | local symlink_err="rdump: Attempt to read block from filesystem resulted in short read while reading symlink" |
| 1803 | if grep -Fq "$symlink_err" "$logFile"; then |
| 1804 | echo "[-] Symlinks have not been properly processed from $image_file" |
| 1805 | echo "[!] If you don't have a compatible debugfs version, modify 'execute-all.sh' to disable 'USE_DEBUGFS' flag" |
| 1806 | abort 1 |
| 1807 | fi |
| 1808 | } |
| 1809 | |
| 1810 | declare -ra VENDOR_SKIP_FILES=( |
| 1811 | "bin/toybox_vendor" |
| 1812 | "bin/toolbox" |
| 1813 | "bin/grep" |
| 1814 | "build.prop" |
| 1815 | "compatibility_matrix.xml" |
| 1816 | "default.prop" |
| 1817 | "etc/NOTICE.xml.gz" |
| 1818 | "etc/vintf/compatibility_matrix.xml" |
| 1819 | "etc/vintf/manifest.xml" |
| 1820 | "etc/wifi/wpa_supplicant.conf" |
| 1821 | "manifest.xml" |
| 1822 | "overlay/DisplayCutoutEmulationCorner/DisplayCutoutEmulationCornerOverlay.apk" |
| 1823 | "overlay/DisplayCutoutEmulationDouble/DisplayCutoutEmulationDoubleOverlay.apk" |
| 1824 | "overlay/DisplayCutoutEmulationTall/DisplayCutoutEmulationTallOverlay.apk" |
| 1825 | "overlay/DisplayCutoutNoCutout/NoCutoutOverlay.apk" |
| 1826 | "overlay/framework-res__auto_generated_rro.apk" |
| 1827 | "overlay/SysuiDarkTheme/SysuiDarkThemeOverlay.apk" |
| 1828 | ) |
| 1829 | |
| 1830 | function array_contains() { |
| 1831 | local element |
| 1832 | for element in "${@:2}"; do [[ "$element" == "$1" ]] && return 0; done |
| 1833 | return 1 |
| 1834 | } |
| 1835 | |
| 1836 | function generate_prop_list_from_image() { |
| 1837 | local image_file="$1" |
| 1838 | local image_dir="$TMPDIR/image-temp" |
| 1839 | local output_list="$2" |
| 1840 | local output_list_tmp="$TMPDIR/_proprietary-blobs.txt" |
| 1841 | local -n skipped_vendor_files="$3" |
| 1842 | |
| 1843 | extract_img_data "$image_file" "$image_dir" |
| 1844 | |
| 1845 | find "$image_dir" -not -type d | sed "s#^$image_dir/##" | while read -r FILE |
| 1846 | do |
| 1847 | # Skip VENDOR_SKIP_FILES since it will be re-generated at build time |
| 1848 | if array_contains "$FILE" "${VENDOR_SKIP_FILES[@]}"; then |
| 1849 | continue |
| 1850 | fi |
| 1851 | # Skip device defined skipped files since they will be re-generated at build time |
| 1852 | if array_contains "$FILE" "${skipped_vendor_files[@]}"; then |
| 1853 | continue |
| 1854 | fi |
| 1855 | if suffix_match_file ".apk" "$FILE" ; then |
| 1856 | echo "-vendor/$FILE" >> "$output_list_tmp" |
| 1857 | else |
| 1858 | echo "vendor/$FILE" >> "$output_list_tmp" |
| 1859 | fi |
| 1860 | done |
| 1861 | |
| 1862 | # Sort merged file with all lists |
| 1863 | sort -u "$output_list_tmp" > "$output_list" |
| 1864 | |
| 1865 | # Clean-up |
| 1866 | rm -f "$output_list_tmp" |
| 1867 | } |
Bruno Martins | 0f425f1 | 2021-04-10 14:57:32 +0100 | [diff] [blame] | 1868 | |
| 1869 | function colored_echo() { |
| 1870 | IFS=" " |
| 1871 | local color=$1; |
| 1872 | shift |
| 1873 | if ! [[ $color =~ '^[0-9]$' ]] ; then |
| 1874 | case $(echo $color | tr '[:upper:]' '[:lower:]') in |
| 1875 | black) color=0 ;; |
| 1876 | red) color=1 ;; |
| 1877 | green) color=2 ;; |
| 1878 | yellow) color=3 ;; |
| 1879 | blue) color=4 ;; |
| 1880 | magenta) color=5 ;; |
| 1881 | cyan) color=6 ;; |
| 1882 | white|*) color=7 ;; # white or invalid color |
| 1883 | esac |
| 1884 | fi |
Bruno Martins | 5064db2 | 2021-06-21 14:47:40 +0100 | [diff] [blame] | 1885 | if [ -t 1 ] ; then tput setaf $color; fi |
Bruno Martins | 0f425f1 | 2021-04-10 14:57:32 +0100 | [diff] [blame] | 1886 | printf '%s\n' "$*" |
Bruno Martins | 5064db2 | 2021-06-21 14:47:40 +0100 | [diff] [blame] | 1887 | if [ -t 1 ] ; then tput sgr0; fi |
Bruno Martins | 0f425f1 | 2021-04-10 14:57:32 +0100 | [diff] [blame] | 1888 | } |