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