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