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