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