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