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