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