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=() |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 20 | PRODUCT_PACKAGES_LIST=() |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 21 | PRODUCT_PACKAGES_HASHES=() |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 22 | PACKAGE_LIST=() |
| 23 | VENDOR_STATE=-1 |
Louis Popi | a516c2f | 2016-07-25 15:51:13 +0200 | [diff] [blame] | 24 | VENDOR_RADIO_STATE=-1 |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 25 | COMMON=-1 |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 26 | ARCHES= |
| 27 | FULLY_DEODEXED=-1 |
| 28 | |
Rashed Abdel-Tawab | 11186d6 | 2017-08-05 23:11:35 -0400 | [diff] [blame] | 29 | TMPDIR=$(mktemp -d) |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 30 | |
| 31 | # |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 32 | # cleanup |
| 33 | # |
| 34 | # kill our tmpfiles with fire on exit |
| 35 | # |
| 36 | function cleanup() { |
| 37 | rm -rf "${TMPDIR:?}" |
| 38 | } |
| 39 | |
Gabriele M | 6c3c2c0 | 2017-10-11 12:55:51 +0200 | [diff] [blame] | 40 | trap cleanup 0 |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 41 | |
| 42 | # |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 43 | # setup_vendor |
| 44 | # |
| 45 | # $1: device name |
| 46 | # $2: vendor name |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 47 | # $3: Lineage root directory |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 48 | # $4: is common device - optional, default to false |
| 49 | # $5: cleanup - optional, default to true |
Rashed Abdel-Tawab | 5f17315 | 2016-10-01 20:33:00 -0400 | [diff] [blame] | 50 | # $6: custom vendor makefile name - optional, default to false |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 51 | # |
| 52 | # Must be called before any other functions can be used. This |
| 53 | # sets up the internal state for a new vendor configuration. |
| 54 | # |
| 55 | function setup_vendor() { |
| 56 | local DEVICE="$1" |
| 57 | if [ -z "$DEVICE" ]; then |
| 58 | echo "\$DEVICE must be set before including this script!" |
| 59 | exit 1 |
| 60 | fi |
| 61 | |
| 62 | export VENDOR="$2" |
| 63 | if [ -z "$VENDOR" ]; then |
| 64 | echo "\$VENDOR must be set before including this script!" |
| 65 | exit 1 |
| 66 | fi |
| 67 | |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 68 | export LINEAGE_ROOT="$3" |
| 69 | if [ ! -d "$LINEAGE_ROOT" ]; then |
| 70 | echo "\$LINEAGE_ROOT must be set and valid before including this script!" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 71 | exit 1 |
| 72 | fi |
| 73 | |
| 74 | export OUTDIR=vendor/"$VENDOR"/"$DEVICE" |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 75 | if [ ! -d "$LINEAGE_ROOT/$OUTDIR" ]; then |
| 76 | mkdir -p "$LINEAGE_ROOT/$OUTDIR" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 77 | fi |
| 78 | |
Rashed Abdel-Tawab | 5f17315 | 2016-10-01 20:33:00 -0400 | [diff] [blame] | 79 | VNDNAME="$6" |
| 80 | if [ -z "$VNDNAME" ]; then |
| 81 | VNDNAME="$DEVICE" |
| 82 | fi |
| 83 | |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 84 | export PRODUCTMK="$LINEAGE_ROOT"/"$OUTDIR"/"$VNDNAME"-vendor.mk |
| 85 | export ANDROIDMK="$LINEAGE_ROOT"/"$OUTDIR"/Android.mk |
| 86 | export BOARDMK="$LINEAGE_ROOT"/"$OUTDIR"/BoardConfigVendor.mk |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 87 | |
| 88 | if [ "$4" == "true" ] || [ "$4" == "1" ]; then |
| 89 | COMMON=1 |
| 90 | else |
| 91 | COMMON=0 |
| 92 | fi |
| 93 | |
Gabriele M | b6effb3 | 2017-05-01 18:22:04 +0200 | [diff] [blame] | 94 | if [ "$5" == "false" ] || [ "$5" == "0" ]; then |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 95 | VENDOR_STATE=1 |
Louis Popi | a516c2f | 2016-07-25 15:51:13 +0200 | [diff] [blame] | 96 | VENDOR_RADIO_STATE=1 |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 97 | else |
| 98 | VENDOR_STATE=0 |
Louis Popi | a516c2f | 2016-07-25 15:51:13 +0200 | [diff] [blame] | 99 | VENDOR_RADIO_STATE=0 |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 100 | fi |
| 101 | } |
| 102 | |
Vladimir Oltean | 9564328 | 2018-06-24 20:22:41 +0300 | [diff] [blame] | 103 | # Helper functions for parsing a spec. |
| 104 | # notes: an optional "|SHA1" that may appear in the format is stripped |
| 105 | # early from the spec in the parse_file_list function, and |
| 106 | # should not be present inside the input parameter passed |
| 107 | # to these functions. |
| 108 | |
| 109 | # |
| 110 | # input: spec in the form of "src[:dst][;args]" |
| 111 | # output: "src" |
| 112 | # |
| 113 | function src_file() { |
| 114 | local SPEC="$1" |
| 115 | local SPLIT=(${SPEC//:/ }) |
| 116 | local ARGS="$(target_args ${SPEC})" |
| 117 | # Regardless of there being a ":" delimiter or not in the spec, |
| 118 | # the source file is always either the first, or the only entry. |
| 119 | local SRC="${SPLIT[0]}" |
| 120 | # Remove target_args suffix, if present |
| 121 | echo "${SRC%;${ARGS}}" |
| 122 | } |
| 123 | |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 124 | # |
Vladimir Oltean | 6a7946b | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 125 | # input: spec in the form of "src[:dst][;args]" |
| 126 | # output: "dst" if present, "src" otherwise. |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 127 | # |
| 128 | function target_file() { |
Vladimir Oltean | 6a7946b | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 129 | local SPEC="$1" |
| 130 | local SPLIT=(${SPEC//:/ }) |
| 131 | local ARGS="$(target_args ${SPEC})" |
| 132 | local DST= |
| 133 | case ${#SPLIT[@]} in |
| 134 | 1) |
| 135 | # The spec doesn't have a : delimiter |
| 136 | DST="${SPLIT[0]}" |
| 137 | ;; |
| 138 | *) |
| 139 | # The spec actually has a src:dst format |
| 140 | DST="${SPLIT[1]}" |
| 141 | ;; |
| 142 | esac |
| 143 | # Remove target_args suffix, if present |
| 144 | echo "${DST%;${ARGS}}" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | # |
Vladimir Oltean | 6a7946b | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 148 | # input: spec in the form of "src[:dst][;args]" |
| 149 | # output: "args" if present, "" otherwise. |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 150 | # |
| 151 | function target_args() { |
Vladimir Oltean | 6a7946b | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 152 | local SPEC="$1" |
| 153 | local SPLIT=(${SPEC//;/ }) |
| 154 | local ARGS= |
| 155 | case ${#SPLIT[@]} in |
| 156 | 1) |
| 157 | # No ";" delimiter in the spec. |
| 158 | ;; |
| 159 | *) |
| 160 | # The "args" are whatever comes after the ";" character. |
| 161 | # Basically the spec stripped of whatever is to the left of ";". |
| 162 | ARGS="${SPEC#${SPLIT[0]};}" |
| 163 | ;; |
| 164 | esac |
| 165 | echo "${ARGS}" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | # |
| 169 | # prefix_match: |
| 170 | # |
Vladimir Oltean | 2654eaa | 2018-06-12 01:17:35 +0300 | [diff] [blame] | 171 | # input: |
| 172 | # - $1: prefix |
| 173 | # - (global variable) PRODUCT_PACKAGES_LIST: array of [src:]dst[;args] specs. |
| 174 | # output: |
| 175 | # - 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] | 176 | # |
| 177 | function prefix_match() { |
| 178 | local PREFIX="$1" |
Vladimir Oltean | a48b9fe | 2018-04-02 22:37:09 +0300 | [diff] [blame] | 179 | for LINE in "${PRODUCT_PACKAGES_LIST[@]}"; do |
| 180 | local FILE=$(target_file "$LINE") |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 181 | if [[ "$FILE" =~ ^"$PREFIX" ]]; then |
Vladimir Oltean | 2654eaa | 2018-06-12 01:17:35 +0300 | [diff] [blame] | 182 | local ARGS=$(target_args "$LINE") |
| 183 | if [ -z "${ARGS}" ]; then |
| 184 | echo "${FILE#$PREFIX}" |
| 185 | else |
| 186 | echo "${FILE#$PREFIX};${ARGS}" |
| 187 | fi |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 188 | fi |
| 189 | done |
| 190 | } |
| 191 | |
| 192 | # |
Rashed Abdel-Tawab | 0ca7643 | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 193 | # prefix_match_file: |
| 194 | # |
| 195 | # $1: the prefix to match on |
| 196 | # $2: the file to match the prefix for |
| 197 | # |
| 198 | # Internal function which returns true if a filename contains the |
| 199 | # specified prefix. |
| 200 | # |
| 201 | function prefix_match_file() { |
| 202 | local PREFIX="$1" |
| 203 | local FILE="$2" |
| 204 | if [[ "$FILE" =~ ^"$PREFIX" ]]; then |
| 205 | return 0 |
| 206 | else |
| 207 | return 1 |
| 208 | fi |
| 209 | } |
| 210 | |
| 211 | # |
| 212 | # truncate_file |
| 213 | # |
| 214 | # $1: the filename to truncate |
| 215 | # $2: the argument to output the truncated filename to |
| 216 | # |
| 217 | # Internal function which truncates a filename by removing the first dir |
| 218 | # in the path. ex. vendor/lib/libsdmextension.so -> lib/libsdmextension.so |
| 219 | # |
| 220 | function truncate_file() { |
| 221 | local FILE="$1" |
| 222 | RETURN_FILE="$2" |
| 223 | local FIND="${FILE%%/*}" |
| 224 | local LOCATION="${#FIND}+1" |
| 225 | echo ${FILE:$LOCATION} |
| 226 | } |
| 227 | |
| 228 | # |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 229 | # write_product_copy_files: |
| 230 | # |
Rashed Abdel-Tawab | 0ca7643 | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 231 | # $1: make treble compatible makefile - optional, default to false |
| 232 | # |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 233 | # Creates the PRODUCT_COPY_FILES section in the product makefile for all |
| 234 | # items in the list which do not start with a dash (-). |
| 235 | # |
| 236 | function write_product_copy_files() { |
| 237 | local COUNT=${#PRODUCT_COPY_FILES_LIST[@]} |
| 238 | local TARGET= |
| 239 | local FILE= |
| 240 | local LINEEND= |
Rashed Abdel-Tawab | 0ca7643 | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 241 | local TREBLE_COMPAT=$1 |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 242 | |
| 243 | if [ "$COUNT" -eq "0" ]; then |
| 244 | return 0 |
| 245 | fi |
| 246 | |
| 247 | printf '%s\n' "PRODUCT_COPY_FILES += \\" >> "$PRODUCTMK" |
| 248 | for (( i=1; i<COUNT+1; i++ )); do |
| 249 | FILE="${PRODUCT_COPY_FILES_LIST[$i-1]}" |
| 250 | LINEEND=" \\" |
| 251 | if [ "$i" -eq "$COUNT" ]; then |
| 252 | LINEEND="" |
| 253 | fi |
| 254 | |
Vladimir Oltean | 6a7946b | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 255 | TARGET=$(target_file "$FILE") |
Rashed Abdel-Tawab | 0ca7643 | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 256 | if [ "$TREBLE_COMPAT" == "true" ] || [ "$TREBLE_COMPAT" == "1" ]; then |
| 257 | if prefix_match_file "vendor/" $TARGET ; then |
| 258 | local OUTTARGET=$(truncate_file $TARGET) |
| 259 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR)/%s%s\n' \ |
| 260 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| 261 | else |
| 262 | printf ' %s/proprietary/%s:system/%s%s\n' \ |
| 263 | "$OUTDIR" "$TARGET" "$TARGET" "$LINEEND" >> "$PRODUCTMK" |
| 264 | fi |
| 265 | else |
| 266 | printf ' %s/proprietary/%s:system/%s%s\n' \ |
| 267 | "$OUTDIR" "$TARGET" "$TARGET" "$LINEEND" >> "$PRODUCTMK" |
| 268 | fi |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 269 | done |
| 270 | return 0 |
| 271 | } |
| 272 | |
| 273 | # |
| 274 | # write_packages: |
| 275 | # |
| 276 | # $1: The LOCAL_MODULE_CLASS for the given module list |
| 277 | # $2: "true" if this package is part of the vendor/ path |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 278 | # $3: type-specific extra flags |
| 279 | # $4: Name of the array holding the target list |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 280 | # |
| 281 | # Internal function which writes out the BUILD_PREBUILT stanzas |
| 282 | # for all modules in the list. This is called by write_product_packages |
| 283 | # after the modules are categorized. |
| 284 | # |
| 285 | function write_packages() { |
| 286 | |
| 287 | local CLASS="$1" |
| 288 | local VENDOR_PKG="$2" |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 289 | local EXTRA="$3" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 290 | |
| 291 | # 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] | 292 | local ARR_NAME="$4[@]" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 293 | local FILELIST=("${!ARR_NAME}") |
| 294 | |
| 295 | local FILE= |
| 296 | local ARGS= |
| 297 | local BASENAME= |
| 298 | local EXTENSION= |
| 299 | local PKGNAME= |
| 300 | local SRC= |
| 301 | |
| 302 | for P in "${FILELIST[@]}"; do |
Vladimir Oltean | 6a7946b | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 303 | FILE=$(target_file "$P") |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 304 | ARGS=$(target_args "$P") |
| 305 | |
| 306 | BASENAME=$(basename "$FILE") |
M1cha | 15f226c | 2017-01-04 09:00:11 +0100 | [diff] [blame] | 307 | DIRNAME=$(dirname "$FILE") |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 308 | EXTENSION=${BASENAME##*.} |
| 309 | PKGNAME=${BASENAME%.*} |
| 310 | |
| 311 | # Add to final package list |
| 312 | PACKAGE_LIST+=("$PKGNAME") |
| 313 | |
| 314 | SRC="proprietary" |
| 315 | if [ "$VENDOR_PKG" = "true" ]; then |
| 316 | SRC+="/vendor" |
| 317 | fi |
| 318 | |
| 319 | printf 'include $(CLEAR_VARS)\n' |
| 320 | printf 'LOCAL_MODULE := %s\n' "$PKGNAME" |
| 321 | printf 'LOCAL_MODULE_OWNER := %s\n' "$VENDOR" |
| 322 | if [ "$CLASS" = "SHARED_LIBRARIES" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 323 | if [ "$EXTRA" = "both" ]; then |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 324 | printf 'LOCAL_SRC_FILES_64 := %s/lib64/%s\n' "$SRC" "$FILE" |
| 325 | printf 'LOCAL_SRC_FILES_32 := %s/lib/%s\n' "$SRC" "$FILE" |
| 326 | #if [ "$VENDOR_PKG" = "true" ]; then |
| 327 | # echo "LOCAL_MODULE_PATH_64 := \$(TARGET_OUT_VENDOR_SHARED_LIBRARIES)" |
| 328 | # echo "LOCAL_MODULE_PATH_32 := \$(2ND_TARGET_OUT_VENDOR_SHARED_LIBRARIES)" |
| 329 | #else |
| 330 | # echo "LOCAL_MODULE_PATH_64 := \$(TARGET_OUT_SHARED_LIBRARIES)" |
| 331 | # echo "LOCAL_MODULE_PATH_32 := \$(2ND_TARGET_OUT_SHARED_LIBRARIES)" |
| 332 | #fi |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 333 | elif [ "$EXTRA" = "64" ]; then |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 334 | printf 'LOCAL_SRC_FILES := %s/lib64/%s\n' "$SRC" "$FILE" |
| 335 | else |
| 336 | printf 'LOCAL_SRC_FILES := %s/lib/%s\n' "$SRC" "$FILE" |
| 337 | fi |
Steve Kondik | 03ce400 | 2016-07-29 00:00:16 -0700 | [diff] [blame] | 338 | if [ "$EXTRA" != "none" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 339 | printf 'LOCAL_MULTILIB := %s\n' "$EXTRA" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 340 | fi |
| 341 | elif [ "$CLASS" = "APPS" ]; then |
Michael Bestas | 3f9b94c | 2018-01-25 21:05:36 +0200 | [diff] [blame] | 342 | if [ "$EXTRA" = "priv-app" ]; then |
| 343 | SRC="$SRC/priv-app" |
| 344 | else |
| 345 | SRC="$SRC/app" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 346 | fi |
| 347 | printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE" |
| 348 | local CERT=platform |
| 349 | if [ ! -z "$ARGS" ]; then |
| 350 | CERT="$ARGS" |
| 351 | fi |
| 352 | printf 'LOCAL_CERTIFICATE := %s\n' "$CERT" |
| 353 | elif [ "$CLASS" = "JAVA_LIBRARIES" ]; then |
| 354 | printf 'LOCAL_SRC_FILES := %s/framework/%s\n' "$SRC" "$FILE" |
Elektroschmock | 082e0ec | 2016-10-04 21:11:43 +0200 | [diff] [blame] | 355 | local CERT=platform |
| 356 | if [ ! -z "$ARGS" ]; then |
| 357 | CERT="$ARGS" |
| 358 | fi |
| 359 | printf 'LOCAL_CERTIFICATE := %s\n' "$CERT" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 360 | elif [ "$CLASS" = "ETC" ]; then |
| 361 | printf 'LOCAL_SRC_FILES := %s/etc/%s\n' "$SRC" "$FILE" |
| 362 | elif [ "$CLASS" = "EXECUTABLES" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 363 | if [ "$ARGS" = "rootfs" ]; then |
| 364 | SRC="$SRC/rootfs" |
| 365 | if [ "$EXTRA" = "sbin" ]; then |
| 366 | SRC="$SRC/sbin" |
| 367 | printf '%s\n' "LOCAL_MODULE_PATH := \$(TARGET_ROOT_OUT_SBIN)" |
| 368 | printf '%s\n' "LOCAL_UNSTRIPPED_PATH := \$(TARGET_ROOT_OUT_SBIN_UNSTRIPPED)" |
| 369 | fi |
| 370 | else |
| 371 | SRC="$SRC/bin" |
| 372 | fi |
| 373 | printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE" |
| 374 | unset EXTENSION |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 375 | else |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 376 | printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 377 | fi |
| 378 | printf 'LOCAL_MODULE_TAGS := optional\n' |
| 379 | printf 'LOCAL_MODULE_CLASS := %s\n' "$CLASS" |
Hashbang173 | 3b3a0e1 | 2016-08-28 20:38:45 -0400 | [diff] [blame] | 380 | if [ "$CLASS" = "APPS" ]; then |
| 381 | printf 'LOCAL_DEX_PREOPT := false\n' |
| 382 | fi |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 383 | if [ ! -z "$EXTENSION" ]; then |
| 384 | printf 'LOCAL_MODULE_SUFFIX := .%s\n' "$EXTENSION" |
| 385 | fi |
M1cha | 15f226c | 2017-01-04 09:00:11 +0100 | [diff] [blame] | 386 | if [ "$CLASS" = "SHARED_LIBRARIES" ] || [ "$CLASS" = "EXECUTABLES" ]; then |
| 387 | if [ "$DIRNAME" != "." ]; then |
| 388 | printf 'LOCAL_MODULE_RELATIVE_PATH := %s\n' "$DIRNAME" |
| 389 | fi |
| 390 | fi |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 391 | if [ "$EXTRA" = "priv-app" ]; then |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 392 | printf 'LOCAL_PRIVILEGED_MODULE := true\n' |
| 393 | fi |
| 394 | if [ "$VENDOR_PKG" = "true" ]; then |
Ethan Chen | 5bc3c84 | 2018-02-17 20:03:54 -0800 | [diff] [blame] | 395 | printf 'LOCAL_VENDOR_MODULE := true\n' |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 396 | fi |
| 397 | printf 'include $(BUILD_PREBUILT)\n\n' |
| 398 | done |
| 399 | } |
| 400 | |
| 401 | # |
| 402 | # write_product_packages: |
| 403 | # |
| 404 | # This function will create BUILD_PREBUILT entries in the |
| 405 | # Android.mk and associated PRODUCT_PACKAGES list in the |
| 406 | # product makefile for all files in the blob list which |
| 407 | # start with a single dash (-) character. |
| 408 | # |
| 409 | function write_product_packages() { |
| 410 | PACKAGE_LIST=() |
| 411 | |
| 412 | local COUNT=${#PRODUCT_PACKAGES_LIST[@]} |
| 413 | |
| 414 | if [ "$COUNT" = "0" ]; then |
| 415 | return 0 |
| 416 | fi |
| 417 | |
| 418 | # Figure out what's 32-bit, what's 64-bit, and what's multilib |
| 419 | # I really should not be doing this in bash due to shitty array passing :( |
| 420 | local T_LIB32=( $(prefix_match "lib/") ) |
| 421 | local T_LIB64=( $(prefix_match "lib64/") ) |
| 422 | local MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${T_LIB64[@]}")) ) |
| 423 | 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] | 424 | 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] | 425 | |
Steve Kondik | 03ce400 | 2016-07-29 00:00:16 -0700 | [diff] [blame] | 426 | if [ "${#MULTILIBS[@]}" -gt "0" ]; then |
| 427 | write_packages "SHARED_LIBRARIES" "false" "both" "MULTILIBS" >> "$ANDROIDMK" |
| 428 | fi |
| 429 | if [ "${#LIB32[@]}" -gt "0" ]; then |
| 430 | write_packages "SHARED_LIBRARIES" "false" "32" "LIB32" >> "$ANDROIDMK" |
| 431 | fi |
| 432 | if [ "${#LIB64[@]}" -gt "0" ]; then |
| 433 | write_packages "SHARED_LIBRARIES" "false" "64" "LIB64" >> "$ANDROIDMK" |
| 434 | fi |
| 435 | |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 436 | local T_V_LIB32=( $(prefix_match "vendor/lib/") ) |
| 437 | local T_V_LIB64=( $(prefix_match "vendor/lib64/") ) |
| 438 | local V_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${T_V_LIB64[@]}")) ) |
| 439 | 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] | 440 | 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] | 441 | |
| 442 | if [ "${#V_MULTILIBS[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 443 | write_packages "SHARED_LIBRARIES" "true" "both" "V_MULTILIBS" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 444 | fi |
| 445 | if [ "${#V_LIB32[@]}" -gt "0" ]; then |
Steve Kondik | 03ce400 | 2016-07-29 00:00:16 -0700 | [diff] [blame] | 446 | write_packages "SHARED_LIBRARIES" "true" "32" "V_LIB32" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 447 | fi |
| 448 | if [ "${#V_LIB64[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 449 | write_packages "SHARED_LIBRARIES" "true" "64" "V_LIB64" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 450 | fi |
| 451 | |
| 452 | # Apps |
| 453 | local APPS=( $(prefix_match "app/") ) |
| 454 | if [ "${#APPS[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 455 | write_packages "APPS" "false" "" "APPS" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 456 | fi |
| 457 | local PRIV_APPS=( $(prefix_match "priv-app/") ) |
| 458 | if [ "${#PRIV_APPS[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 459 | write_packages "APPS" "false" "priv-app" "PRIV_APPS" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 460 | fi |
| 461 | local V_APPS=( $(prefix_match "vendor/app/") ) |
| 462 | if [ "${#V_APPS[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 463 | write_packages "APPS" "true" "" "V_APPS" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 464 | fi |
| 465 | local V_PRIV_APPS=( $(prefix_match "vendor/priv-app/") ) |
| 466 | if [ "${#V_PRIV_APPS[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 467 | write_packages "APPS" "true" "priv-app" "V_PRIV_APPS" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 468 | fi |
| 469 | |
| 470 | # Framework |
| 471 | local FRAMEWORK=( $(prefix_match "framework/") ) |
| 472 | if [ "${#FRAMEWORK[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 473 | write_packages "JAVA_LIBRARIES" "false" "" "FRAMEWORK" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 474 | fi |
Christian Oder | c16f327 | 2017-10-08 23:15:52 +0200 | [diff] [blame] | 475 | local V_FRAMEWORK=( $(prefix_match "vendor/framework/") ) |
Michael Bestas | a3f97c7 | 2018-02-27 22:31:55 +0200 | [diff] [blame] | 476 | if [ "${#V_FRAMEWORK[@]}" -gt "0" ]; then |
Christian Oder | c16f327 | 2017-10-08 23:15:52 +0200 | [diff] [blame] | 477 | write_packages "JAVA_LIBRARIES" "true" "" "V_FRAMEWORK" >> "$ANDROIDMK" |
| 478 | fi |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 479 | |
| 480 | # Etc |
| 481 | local ETC=( $(prefix_match "etc/") ) |
| 482 | if [ "${#ETC[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 483 | write_packages "ETC" "false" "" "ETC" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 484 | fi |
| 485 | local V_ETC=( $(prefix_match "vendor/etc/") ) |
| 486 | if [ "${#V_ETC[@]}" -gt "0" ]; then |
Rashed Abdel-Tawab | 00c0766 | 2017-10-08 17:33:42 -0400 | [diff] [blame] | 487 | write_packages "ETC" "true" "" "V_ETC" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 488 | fi |
| 489 | |
| 490 | # Executables |
| 491 | local BIN=( $(prefix_match "bin/") ) |
| 492 | if [ "${#BIN[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 493 | write_packages "EXECUTABLES" "false" "" "BIN" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 494 | fi |
| 495 | local V_BIN=( $(prefix_match "vendor/bin/") ) |
| 496 | if [ "${#V_BIN[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 497 | write_packages "EXECUTABLES" "true" "" "V_BIN" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 498 | fi |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 499 | local SBIN=( $(prefix_match "sbin/") ) |
| 500 | if [ "${#SBIN[@]}" -gt "0" ]; then |
| 501 | write_packages "EXECUTABLES" "false" "sbin" "SBIN" >> "$ANDROIDMK" |
| 502 | fi |
| 503 | |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 504 | |
| 505 | # Actually write out the final PRODUCT_PACKAGES list |
| 506 | local PACKAGE_COUNT=${#PACKAGE_LIST[@]} |
| 507 | |
| 508 | if [ "$PACKAGE_COUNT" -eq "0" ]; then |
| 509 | return 0 |
| 510 | fi |
| 511 | |
| 512 | printf '\n%s\n' "PRODUCT_PACKAGES += \\" >> "$PRODUCTMK" |
| 513 | for (( i=1; i<PACKAGE_COUNT+1; i++ )); do |
| 514 | local LINEEND=" \\" |
| 515 | if [ "$i" -eq "$PACKAGE_COUNT" ]; then |
| 516 | LINEEND="" |
| 517 | fi |
| 518 | printf ' %s%s\n' "${PACKAGE_LIST[$i-1]}" "$LINEEND" >> "$PRODUCTMK" |
| 519 | done |
| 520 | } |
| 521 | |
| 522 | # |
| 523 | # write_header: |
| 524 | # |
| 525 | # $1: file which will be written to |
| 526 | # |
| 527 | # writes out the copyright header with the current year. |
| 528 | # note that this is not an append operation, and should |
| 529 | # be executed first! |
| 530 | # |
| 531 | function write_header() { |
Matt Mower | 8945f5e | 2017-01-07 14:08:17 -0600 | [diff] [blame] | 532 | if [ -f $1 ]; then |
| 533 | rm $1 |
| 534 | fi |
| 535 | |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 536 | YEAR=$(date +"%Y") |
| 537 | |
| 538 | [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON" |
| 539 | |
Matt Mower | 8945f5e | 2017-01-07 14:08:17 -0600 | [diff] [blame] | 540 | NUM_REGEX='^[0-9]+$' |
| 541 | if [[ $INITIAL_COPYRIGHT_YEAR =~ $NUM_REGEX ]] && [ $INITIAL_COPYRIGHT_YEAR -le $YEAR ]; then |
| 542 | if [ $INITIAL_COPYRIGHT_YEAR -lt 2016 ]; then |
| 543 | printf "# Copyright (C) $INITIAL_COPYRIGHT_YEAR-2016 The CyanogenMod Project\n" > $1 |
| 544 | elif [ $INITIAL_COPYRIGHT_YEAR -eq 2016 ]; then |
| 545 | printf "# Copyright (C) 2016 The CyanogenMod Project\n" > $1 |
| 546 | fi |
| 547 | if [ $YEAR -eq 2017 ]; then |
| 548 | printf "# Copyright (C) 2017 The LineageOS Project\n" >> $1 |
| 549 | elif [ $INITIAL_COPYRIGHT_YEAR -eq $YEAR ]; then |
| 550 | printf "# Copyright (C) $YEAR The LineageOS Project\n" >> $1 |
| 551 | elif [ $INITIAL_COPYRIGHT_YEAR -le 2017 ]; then |
| 552 | printf "# Copyright (C) 2017-$YEAR The LineageOS Project\n" >> $1 |
| 553 | else |
| 554 | printf "# Copyright (C) $INITIAL_COPYRIGHT_YEAR-$YEAR The LineageOS Project\n" >> $1 |
| 555 | fi |
| 556 | else |
| 557 | printf "# Copyright (C) $YEAR The LineageOS Project\n" > $1 |
| 558 | fi |
| 559 | |
| 560 | cat << EOF >> $1 |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 561 | # |
| 562 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 563 | # you may not use this file except in compliance with the License. |
| 564 | # You may obtain a copy of the License at |
| 565 | # |
| 566 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 567 | # |
| 568 | # Unless required by applicable law or agreed to in writing, software |
| 569 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 570 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 571 | # See the License for the specific language governing permissions and |
| 572 | # limitations under the License. |
| 573 | |
| 574 | # This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh |
| 575 | |
| 576 | EOF |
| 577 | } |
| 578 | |
| 579 | # |
| 580 | # write_headers: |
| 581 | # |
| 582 | # $1: devices falling under common to be added to guard - optional |
Rashed Abdel-Tawab | d53bff1 | 2016-10-02 01:00:54 -0400 | [diff] [blame] | 583 | # $2: custom guard - optional |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 584 | # |
| 585 | # Calls write_header for each of the makefiles and creates |
| 586 | # the initial path declaration and device guard for the |
| 587 | # Android.mk |
| 588 | # |
| 589 | function write_headers() { |
| 590 | write_header "$ANDROIDMK" |
Rashed Abdel-Tawab | d53bff1 | 2016-10-02 01:00:54 -0400 | [diff] [blame] | 591 | |
| 592 | GUARD="$2" |
| 593 | if [ -z "$GUARD" ]; then |
| 594 | GUARD="TARGET_DEVICE" |
| 595 | fi |
| 596 | |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 597 | cat << EOF >> "$ANDROIDMK" |
| 598 | LOCAL_PATH := \$(call my-dir) |
| 599 | |
| 600 | EOF |
| 601 | if [ "$COMMON" -ne 1 ]; then |
| 602 | cat << EOF >> "$ANDROIDMK" |
Rashed Abdel-Tawab | d53bff1 | 2016-10-02 01:00:54 -0400 | [diff] [blame] | 603 | ifeq (\$($GUARD),$DEVICE) |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 604 | |
| 605 | EOF |
| 606 | else |
| 607 | if [ -z "$1" ]; then |
| 608 | echo "Argument with devices to be added to guard must be set!" |
| 609 | exit 1 |
| 610 | fi |
| 611 | cat << EOF >> "$ANDROIDMK" |
Rashed Abdel-Tawab | d53bff1 | 2016-10-02 01:00:54 -0400 | [diff] [blame] | 612 | ifneq (\$(filter $1,\$($GUARD)),) |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 613 | |
| 614 | EOF |
| 615 | fi |
| 616 | |
| 617 | write_header "$BOARDMK" |
| 618 | write_header "$PRODUCTMK" |
| 619 | } |
| 620 | |
| 621 | # |
| 622 | # write_footers: |
| 623 | # |
| 624 | # Closes the inital guard and any other finalization tasks. Must |
| 625 | # be called as the final step. |
| 626 | # |
| 627 | function write_footers() { |
| 628 | cat << EOF >> "$ANDROIDMK" |
| 629 | endif |
| 630 | EOF |
| 631 | } |
| 632 | |
| 633 | # Return success if adb is up and not in recovery |
| 634 | function _adb_connected { |
| 635 | { |
Steve Kondik | 7561d19 | 2016-09-01 21:40:27 -0700 | [diff] [blame] | 636 | if [[ "$(adb get-state)" == device ]] |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 637 | then |
| 638 | return 0 |
| 639 | fi |
| 640 | } 2>/dev/null |
| 641 | |
| 642 | return 1 |
| 643 | }; |
| 644 | |
| 645 | # |
Bruno Martins | 3b96ba5 | 2016-07-27 15:00:05 +0100 | [diff] [blame] | 646 | # parse_file_list: |
| 647 | # |
| 648 | # $1: input file |
Rashed Abdel-Tawab | 855fbdd | 2017-04-04 02:48:18 -0400 | [diff] [blame] | 649 | # $2: blob section in file - optional |
Bruno Martins | 3b96ba5 | 2016-07-27 15:00:05 +0100 | [diff] [blame] | 650 | # |
| 651 | # Sets PRODUCT_PACKAGES and PRODUCT_COPY_FILES while parsing the input file |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 652 | # |
| 653 | function parse_file_list() { |
Bruno Martins | 3b96ba5 | 2016-07-27 15:00:05 +0100 | [diff] [blame] | 654 | if [ -z "$1" ]; then |
| 655 | echo "An input file is expected!" |
| 656 | exit 1 |
| 657 | elif [ ! -f "$1" ]; then |
| 658 | echo "Input file "$1" does not exist!" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 659 | exit 1 |
| 660 | fi |
| 661 | |
Rashed Abdel-Tawab | 855fbdd | 2017-04-04 02:48:18 -0400 | [diff] [blame] | 662 | if [ $# -eq 2 ]; then |
| 663 | LIST=$TMPDIR/files.txt |
| 664 | cat $1 | sed -n '/# '"$2"'/I,/^\s*$/p' > $LIST |
| 665 | else |
| 666 | LIST=$1 |
| 667 | fi |
| 668 | |
| 669 | |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 670 | PRODUCT_PACKAGES_LIST=() |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 671 | PRODUCT_PACKAGES_HASHES=() |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 672 | PRODUCT_COPY_FILES_LIST=() |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 673 | PRODUCT_COPY_FILES_HASHES=() |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 674 | |
| 675 | while read -r line; do |
| 676 | if [ -z "$line" ]; then continue; fi |
| 677 | |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 678 | # If the line has a pipe delimiter, a sha1 hash should follow. |
| 679 | # This indicates the file should be pinned and not overwritten |
| 680 | # when extracting files. |
| 681 | local SPLIT=(${line//\|/ }) |
| 682 | local COUNT=${#SPLIT[@]} |
| 683 | local SPEC=${SPLIT[0]} |
| 684 | local HASH="x" |
| 685 | if [ "$COUNT" -gt "1" ]; then |
| 686 | HASH=${SPLIT[1]} |
| 687 | fi |
| 688 | |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 689 | # if line starts with a dash, it needs to be packaged |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 690 | if [[ "$SPEC" =~ ^- ]]; then |
| 691 | PRODUCT_PACKAGES_LIST+=("${SPEC#-}") |
| 692 | PRODUCT_PACKAGES_HASHES+=("$HASH") |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 693 | else |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 694 | PRODUCT_COPY_FILES_LIST+=("$SPEC") |
| 695 | PRODUCT_COPY_FILES_HASHES+=("$HASH") |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 696 | fi |
| 697 | |
Rashed Abdel-Tawab | 855fbdd | 2017-04-04 02:48:18 -0400 | [diff] [blame] | 698 | done < <(egrep -v '(^#|^[[:space:]]*$)' "$LIST" | LC_ALL=C sort | uniq) |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | # |
| 702 | # write_makefiles: |
| 703 | # |
| 704 | # $1: file containing the list of items to extract |
Rashed Abdel-Tawab | 0ca7643 | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 705 | # $2: make treble compatible makefile - optional |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 706 | # |
| 707 | # Calls write_product_copy_files and write_product_packages on |
| 708 | # the given file and appends to the Android.mk as well as |
| 709 | # the product makefile. |
| 710 | # |
| 711 | function write_makefiles() { |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 712 | parse_file_list "$1" |
Rashed Abdel-Tawab | 0ca7643 | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 713 | write_product_copy_files "$2" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 714 | write_product_packages |
| 715 | } |
| 716 | |
| 717 | # |
Louis Popi | a516c2f | 2016-07-25 15:51:13 +0200 | [diff] [blame] | 718 | # append_firmware_calls_to_makefiles: |
| 719 | # |
| 720 | # Appends to Android.mk the calls to all images present in radio folder |
| 721 | # (filesmap file used by releasetools to map firmware images should be kept in the device tree) |
| 722 | # |
| 723 | function append_firmware_calls_to_makefiles() { |
| 724 | cat << EOF >> "$ANDROIDMK" |
| 725 | ifeq (\$(LOCAL_PATH)/radio, \$(wildcard \$(LOCAL_PATH)/radio)) |
| 726 | |
| 727 | RADIO_FILES := \$(wildcard \$(LOCAL_PATH)/radio/*) |
| 728 | \$(foreach f, \$(notdir \$(RADIO_FILES)), \\ |
| 729 | \$(call add-radio-file,radio/\$(f))) |
| 730 | \$(call add-radio-file,../../../device/$VENDOR/$DEVICE/radio/filesmap) |
| 731 | |
| 732 | endif |
| 733 | |
| 734 | EOF |
| 735 | } |
| 736 | |
| 737 | # |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 738 | # get_file: |
| 739 | # |
| 740 | # $1: input file |
| 741 | # $2: target file/folder |
| 742 | # $3: source of the file (can be "adb" or a local folder) |
| 743 | # |
| 744 | # Silently extracts the input file to defined target |
| 745 | # Returns success if file can be pulled from the device or found locally |
| 746 | # |
| 747 | function get_file() { |
| 748 | local SRC="$3" |
| 749 | |
| 750 | if [ "$SRC" = "adb" ]; then |
| 751 | # try to pull |
| 752 | adb pull "$1" "$2" >/dev/null 2>&1 && return 0 |
| 753 | |
| 754 | return 1 |
| 755 | else |
| 756 | # try to copy |
Vladimir Oltean | d577325 | 2018-06-25 00:05:56 +0300 | [diff] [blame] | 757 | cp -r "$SRC/$1" "$2" 2>/dev/null && return 0 |
| 758 | cp -r "$SRC/${1#/system}" "$2" 2>/dev/null && return 0 |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 759 | |
| 760 | return 1 |
| 761 | fi |
| 762 | }; |
| 763 | |
| 764 | # |
| 765 | # oat2dex: |
| 766 | # |
| 767 | # $1: extracted apk|jar (to check if deodex is required) |
| 768 | # $2: odexed apk|jar to deodex |
| 769 | # $3: source of the odexed apk|jar |
| 770 | # |
| 771 | # Convert apk|jar .odex in the corresposing classes.dex |
| 772 | # |
| 773 | function oat2dex() { |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 774 | local LINEAGE_TARGET="$1" |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 775 | local OEM_TARGET="$2" |
| 776 | local SRC="$3" |
| 777 | local TARGET= |
| 778 | local OAT= |
Joe Maples | 9be579f | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 779 | local HOST="$(uname)" |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 780 | |
| 781 | if [ -z "$BAKSMALIJAR" ] || [ -z "$SMALIJAR" ]; then |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 782 | export BAKSMALIJAR="$LINEAGE_ROOT"/vendor/lineage/build/tools/smali/baksmali.jar |
| 783 | export SMALIJAR="$LINEAGE_ROOT"/vendor/lineage/build/tools/smali/smali.jar |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 784 | fi |
| 785 | |
Joe Maples | 9be579f | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 786 | if [ -z "$VDEXEXTRACTOR" ]; then |
| 787 | export VDEXEXTRACTOR="$LINEAGE_ROOT"/vendor/lineage/build/tools/"$HOST"/vdexExtractor |
| 788 | fi |
| 789 | |
codeworkx | 1c29bf6 | 2018-09-23 12:36:57 +0200 | [diff] [blame] | 790 | if [ -z "$CDEXCONVERTER" ]; then |
| 791 | export CDEXCONVERTER="$LINEAGE_ROOT"/vendor/lineage/build/tools/"$HOST"/compact_dex_converter |
| 792 | fi |
| 793 | |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 794 | # Extract existing boot.oats to the temp folder |
| 795 | if [ -z "$ARCHES" ]; then |
Sam Mortimer | 2e994ce | 2016-10-05 09:50:49 -0700 | [diff] [blame] | 796 | echo "Checking if system is odexed and locating boot.oats..." |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 797 | for ARCH in "arm64" "arm" "x86_64" "x86"; do |
Sam Mortimer | 2e994ce | 2016-10-05 09:50:49 -0700 | [diff] [blame] | 798 | mkdir -p "$TMPDIR/system/framework/$ARCH" |
Vladimir Oltean | d577325 | 2018-06-25 00:05:56 +0300 | [diff] [blame] | 799 | if get_file "/system/framework/$ARCH" "$TMPDIR/system/framework/" "$SRC"; then |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 800 | ARCHES+="$ARCH " |
Sam Mortimer | 2e994ce | 2016-10-05 09:50:49 -0700 | [diff] [blame] | 801 | else |
| 802 | rmdir "$TMPDIR/system/framework/$ARCH" |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 803 | fi |
| 804 | done |
| 805 | fi |
| 806 | |
| 807 | if [ -z "$ARCHES" ]; then |
| 808 | FULLY_DEODEXED=1 && return 0 # system is fully deodexed, return |
| 809 | fi |
| 810 | |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 811 | if [ ! -f "$LINEAGE_TARGET" ]; then |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 812 | return; |
| 813 | fi |
| 814 | |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 815 | if grep "classes.dex" "$LINEAGE_TARGET" >/dev/null; then |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 816 | return 0 # target apk|jar is already odexed, return |
| 817 | fi |
| 818 | |
| 819 | for ARCH in $ARCHES; do |
Sam Mortimer | 2e994ce | 2016-10-05 09:50:49 -0700 | [diff] [blame] | 820 | BOOTOAT="$TMPDIR/system/framework/$ARCH/boot.oat" |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 821 | |
| 822 | 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] | 823 | 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] | 824 | |
| 825 | if get_file "$OAT" "$TMPDIR" "$SRC"; then |
Rashed Abdel-Tawab | 54b5d5e | 2017-08-23 15:13:17 -0400 | [diff] [blame] | 826 | if get_file "$VDEX" "$TMPDIR" "$SRC"; then |
Joe Maples | 9be579f | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 827 | "$VDEXEXTRACTOR" -o "$TMPDIR/" -i "$TMPDIR/$(basename "$VDEX")" > /dev/null |
codeworkx | 1c29bf6 | 2018-09-23 12:36:57 +0200 | [diff] [blame] | 828 | # Check if we have to deal with CompactDex |
| 829 | if [ -f "$TMPDIR/$(basename "${OEM_TARGET%.*}")_classes.cdex" ]; then |
| 830 | "$CDEXCONVERTER" "$TMPDIR/$(basename "${OEM_TARGET%.*}")_classes.cdex" &> /dev/null |
| 831 | mv "$TMPDIR/$(basename "${OEM_TARGET%.*}")_classes.cdex.new" "$TMPDIR/classes.dex" |
| 832 | else |
TheStrix | 5aad074 | 2018-10-03 19:06:49 +0530 | [diff] [blame^] | 833 | mv "$TMPDIR/$(basename "${OEM_TARGET%.*}")_classes.dex" "$TMPDIR/classes.dex" |
codeworkx | 1c29bf6 | 2018-09-23 12:36:57 +0200 | [diff] [blame] | 834 | fi |
Joe Maples | 9be579f | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 835 | else |
| 836 | java -jar "$BAKSMALIJAR" deodex -o "$TMPDIR/dexout" -b "$BOOTOAT" -d "$TMPDIR" "$TMPDIR/$(basename "$OAT")" |
| 837 | java -jar "$SMALIJAR" assemble "$TMPDIR/dexout" -o "$TMPDIR/classes.dex" |
Rashed Abdel-Tawab | 54b5d5e | 2017-08-23 15:13:17 -0400 | [diff] [blame] | 838 | fi |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 839 | elif [[ "$LINEAGE_TARGET" =~ .jar$ ]]; then |
Gabriele M | 4cf635a | 2017-01-05 22:10:00 +0100 | [diff] [blame] | 840 | JAROAT="$TMPDIR/system/framework/$ARCH/boot-$(basename ${OEM_TARGET%.*}).oat" |
TheStrix | 5aad074 | 2018-10-03 19:06:49 +0530 | [diff] [blame^] | 841 | JARVDEX="$TMPDIR/system/framework/oat/$ARCH/$(basename ${OEM_TARGET%.*}).vdex" |
Gabriele M | 4cf635a | 2017-01-05 22:10:00 +0100 | [diff] [blame] | 842 | if [ ! -f "$JAROAT" ]; then |
| 843 | JAROAT=$BOOTOAT; |
| 844 | fi |
Joe Maples | 9be579f | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 845 | |
| 846 | # try to extract classes.dex from boot.vdex for frameworks jars |
| 847 | # fallback to boot.oat if vdex is not available |
| 848 | if [ -f "$JARVDEX" ]; then |
| 849 | "$VDEXEXTRACTOR" -o "$TMPDIR/" -i "$JARVDEX" > /dev/null |
TheStrix | 5aad074 | 2018-10-03 19:06:49 +0530 | [diff] [blame^] | 850 | mv "$TMPDIR/$(basename "${OEM_TARGET%.*}")_classes.dex" "$TMPDIR/classes.dex" |
Joe Maples | 9be579f | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 851 | else |
| 852 | java -jar "$BAKSMALIJAR" deodex -o "$TMPDIR/dexout" -b "$BOOTOAT" -d "$TMPDIR" "$JAROAT/$OEM_TARGET" |
| 853 | java -jar "$SMALIJAR" assemble "$TMPDIR/dexout" -o "$TMPDIR/classes.dex" |
| 854 | fi |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 855 | else |
| 856 | continue |
| 857 | fi |
| 858 | |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 859 | done |
| 860 | |
| 861 | rm -rf "$TMPDIR/dexout" |
| 862 | } |
| 863 | |
| 864 | # |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 865 | # init_adb_connection: |
| 866 | # |
| 867 | # Starts adb server and waits for the device |
| 868 | # |
| 869 | function init_adb_connection() { |
| 870 | adb start-server # Prevent unexpected starting server message from adb get-state in the next line |
| 871 | if ! _adb_connected; then |
| 872 | echo "No device is online. Waiting for one..." |
| 873 | echo "Please connect USB and/or enable USB debugging" |
| 874 | until _adb_connected; do |
| 875 | sleep 1 |
| 876 | done |
| 877 | echo "Device Found." |
| 878 | fi |
| 879 | |
| 880 | # Retrieve IP and PORT info if we're using a TCP connection |
| 881 | TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \ |
| 882 | | head -1 | awk '{print $1}') |
| 883 | adb root &> /dev/null |
| 884 | sleep 0.3 |
| 885 | if [ -n "$TCPIPPORT" ]; then |
| 886 | # adb root just killed our connection |
| 887 | # so reconnect... |
| 888 | adb connect "$TCPIPPORT" |
| 889 | fi |
| 890 | adb wait-for-device &> /dev/null |
| 891 | sleep 0.3 |
| 892 | } |
| 893 | |
| 894 | # |
Luca Stefani | 3a03012 | 2016-07-30 12:08:25 +0200 | [diff] [blame] | 895 | # fix_xml: |
| 896 | # |
| 897 | # $1: xml file to fix |
| 898 | # |
| 899 | function fix_xml() { |
| 900 | local XML="$1" |
| 901 | local TEMP_XML="$TMPDIR/`basename "$XML"`.temp" |
| 902 | |
Dobroslaw Kijowski | 65f03f1 | 2017-05-18 12:35:02 +0200 | [diff] [blame] | 903 | grep -a '^<?xml version' "$XML" > "$TEMP_XML" |
| 904 | grep -av '^<?xml version' "$XML" >> "$TEMP_XML" |
Luca Stefani | 3a03012 | 2016-07-30 12:08:25 +0200 | [diff] [blame] | 905 | |
| 906 | mv "$TEMP_XML" "$XML" |
| 907 | } |
| 908 | |
| 909 | # |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 910 | # extract: |
| 911 | # |
| 912 | # $1: file containing the list of items to extract |
Dan Pasanen | 7dc287f | 2017-03-21 09:06:11 -0500 | [diff] [blame] | 913 | # $2: path to extracted system folder, an ota zip file, or "adb" to extract from device |
Rashed Abdel-Tawab | 855fbdd | 2017-04-04 02:48:18 -0400 | [diff] [blame] | 914 | # $3: section in list file to extract - optional |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 915 | # |
| 916 | function extract() { |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 917 | if [ -z "$OUTDIR" ]; then |
| 918 | echo "Output dir not set!" |
| 919 | exit 1 |
| 920 | fi |
| 921 | |
Harry Youd | 9c5d129 | 2017-08-05 09:18:56 +0100 | [diff] [blame] | 922 | if [ -z "$3" ]; then |
| 923 | parse_file_list "$1" |
| 924 | else |
| 925 | parse_file_list "$1" "$3" |
| 926 | fi |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 927 | |
| 928 | # Allow failing, so we can try $DEST and/or $FILE |
| 929 | set +e |
| 930 | |
| 931 | local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ${PRODUCT_PACKAGES_LIST[@]} ) |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 932 | local HASHLIST=( ${PRODUCT_COPY_FILES_HASHES[@]} ${PRODUCT_PACKAGES_HASHES[@]} ) |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 933 | local COUNT=${#FILELIST[@]} |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 934 | local SRC="$2" |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 935 | local OUTPUT_ROOT="$LINEAGE_ROOT"/"$OUTDIR"/proprietary |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 936 | local OUTPUT_TMP="$TMPDIR"/"$OUTDIR"/proprietary |
| 937 | |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 938 | if [ "$SRC" = "adb" ]; then |
| 939 | init_adb_connection |
| 940 | fi |
| 941 | |
Dan Pasanen | 7dc287f | 2017-03-21 09:06:11 -0500 | [diff] [blame] | 942 | if [ -f "$SRC" ] && [ "${SRC##*.}" == "zip" ]; then |
conbold | 575c635 | 2017-11-10 16:33:38 +0100 | [diff] [blame] | 943 | DUMPDIR="$TMPDIR"/system_dump |
Dan Pasanen | 7dc287f | 2017-03-21 09:06:11 -0500 | [diff] [blame] | 944 | |
| 945 | # Check if we're working with the same zip that was passed last time. |
| 946 | # If so, let's just use what's already extracted. |
| 947 | MD5=`md5sum "$SRC"| awk '{print $1}'` |
| 948 | OLDMD5=`cat "$DUMPDIR"/zipmd5.txt` |
| 949 | |
| 950 | if [ "$MD5" != "$OLDMD5" ]; then |
| 951 | rm -rf "$DUMPDIR" |
| 952 | mkdir "$DUMPDIR" |
| 953 | unzip "$SRC" -d "$DUMPDIR" |
| 954 | echo "$MD5" > "$DUMPDIR"/zipmd5.txt |
| 955 | |
| 956 | # Stop if an A/B OTA zip is detected. We cannot extract these. |
| 957 | if [ -a "$DUMPDIR"/payload.bin ]; then |
| 958 | echo "A/B style OTA zip detected. This is not supported at this time. Stopping..." |
| 959 | exit 1 |
| 960 | # If OTA is block based, extract it. |
| 961 | elif [ -a "$DUMPDIR"/system.new.dat ]; then |
| 962 | echo "Converting system.new.dat to system.img" |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 963 | 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] | 964 | rm -rf "$DUMPDIR"/system.new.dat "$DUMPDIR"/system |
| 965 | mkdir "$DUMPDIR"/system "$DUMPDIR"/tmp |
| 966 | echo "Requesting sudo access to mount the system.img" |
| 967 | sudo mount -o loop "$DUMPDIR"/system.img "$DUMPDIR"/tmp |
| 968 | cp -r "$DUMPDIR"/tmp/* "$DUMPDIR"/system/ |
| 969 | sudo umount "$DUMPDIR"/tmp |
| 970 | rm -rf "$DUMPDIR"/tmp "$DUMPDIR"/system.img |
| 971 | fi |
| 972 | fi |
| 973 | |
| 974 | SRC="$DUMPDIR" |
| 975 | fi |
| 976 | |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 977 | if [ "$VENDOR_STATE" -eq "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 978 | echo "Cleaning output directory ($OUTPUT_ROOT).." |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 979 | rm -rf "${OUTPUT_TMP:?}" |
| 980 | mkdir -p "${OUTPUT_TMP:?}" |
Adrian DC | 3c6bdac | 2017-01-15 14:03:26 +0100 | [diff] [blame] | 981 | if [ -d "$OUTPUT_ROOT" ]; then |
| 982 | mv "${OUTPUT_ROOT:?}/"* "${OUTPUT_TMP:?}/" |
| 983 | fi |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 984 | VENDOR_STATE=1 |
| 985 | fi |
| 986 | |
| 987 | echo "Extracting $COUNT files in $1 from $SRC:" |
| 988 | |
| 989 | for (( i=1; i<COUNT+1; i++ )); do |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 990 | |
Vladimir Oltean | da3b644 | 2018-06-24 20:41:30 +0300 | [diff] [blame] | 991 | local SPEC_SRC_FILE=$(src_file "${FILELIST[$i-1]}") |
Vladimir Oltean | 411e069 | 2018-06-24 20:38:04 +0300 | [diff] [blame] | 992 | local SPEC_DST_FILE=$(target_file "${FILELIST[$i-1]}") |
Vladimir Oltean | d652a06 | 2018-06-24 20:42:01 +0300 | [diff] [blame] | 993 | local SPEC_ARGS=$(target_args "${FILELIST[$i-1]}") |
Vladimir Oltean | 5f15e3e | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 994 | local OUTPUT_DIR= |
| 995 | local TMP_DIR= |
| 996 | local SRC_FILE= |
| 997 | local DST_FILE= |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 998 | |
Vladimir Oltean | d652a06 | 2018-06-24 20:42:01 +0300 | [diff] [blame] | 999 | if [ "${SPEC_ARGS}" = "rootfs" ]; then |
Vladimir Oltean | 5f15e3e | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1000 | OUTPUT_DIR="${OUTPUT_ROOT}/rootfs" |
| 1001 | TMP_DIR="${OUTPUT_TMP}/rootfs" |
| 1002 | SRC_FILE="/${SPEC_SRC_FILE}" |
| 1003 | DST_FILE="/${SPEC_DST_FILE}" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1004 | else |
Vladimir Oltean | 5f15e3e | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1005 | OUTPUT_DIR="${OUTPUT_ROOT}" |
| 1006 | TMP_DIR="${OUTPUT_TMP}" |
| 1007 | SRC_FILE="/system/${SPEC_SRC_FILE}" |
| 1008 | DST_FILE="/system/${SPEC_DST_FILE}" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1009 | fi |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 1010 | |
| 1011 | if [ "$SRC" = "adb" ]; then |
Luca Stefani | a9a9cc7 | 2018-07-12 21:26:30 +0200 | [diff] [blame] | 1012 | printf ' - %s .. \n' "${DST_FILE}" |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 1013 | else |
Vladimir Oltean | 5f15e3e | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1014 | printf ' - %s \n' "${DST_FILE}" |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 1015 | fi |
| 1016 | |
Vladimir Oltean | 5f15e3e | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1017 | # Strip the file path in the vendor repo of "system", if present |
| 1018 | local VENDOR_REPO_FILE="$OUTPUT_DIR/${DST_FILE#/system}" |
| 1019 | mkdir -p $(dirname "${VENDOR_REPO_FILE}") |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 1020 | |
Gabriele M | e6df25b | 2017-10-11 00:58:59 +0200 | [diff] [blame] | 1021 | # Check pinned files |
| 1022 | local HASH="${HASHLIST[$i-1]}" |
| 1023 | local KEEP="" |
| 1024 | if [ "$DISABLE_PINNING" != "1" ] && [ ! -z "$HASH" ] && [ "$HASH" != "x" ]; then |
Vladimir Oltean | d674771 | 2018-06-24 20:46:42 +0300 | [diff] [blame] | 1025 | if [ -f "${VENDOR_REPO_FILE}" ]; then |
| 1026 | local PINNED="${VENDOR_REPO_FILE}" |
Gabriele M | e6df25b | 2017-10-11 00:58:59 +0200 | [diff] [blame] | 1027 | else |
Vladimir Oltean | 5f15e3e | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1028 | local PINNED="${TMP_DIR}${DST_FILE#/system}" |
Gabriele M | e6df25b | 2017-10-11 00:58:59 +0200 | [diff] [blame] | 1029 | fi |
| 1030 | if [ -f "$PINNED" ]; then |
| 1031 | if [ "$(uname)" == "Darwin" ]; then |
| 1032 | local TMP_HASH=$(shasum "$PINNED" | awk '{print $1}' ) |
| 1033 | else |
| 1034 | local TMP_HASH=$(sha1sum "$PINNED" | awk '{print $1}' ) |
| 1035 | fi |
| 1036 | if [ "$TMP_HASH" = "$HASH" ]; then |
| 1037 | KEEP="1" |
Vladimir Oltean | d674771 | 2018-06-24 20:46:42 +0300 | [diff] [blame] | 1038 | if [ ! -f "${VENDOR_REPO_FILE}" ]; then |
| 1039 | cp -p "$PINNED" "${VENDOR_REPO_FILE}" |
Gabriele M | e6df25b | 2017-10-11 00:58:59 +0200 | [diff] [blame] | 1040 | fi |
| 1041 | fi |
| 1042 | fi |
| 1043 | fi |
| 1044 | |
| 1045 | if [ "$KEEP" = "1" ]; then |
| 1046 | printf ' + (keeping pinned file with hash %s)\n' "$HASH" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1047 | else |
Vladimir Oltean | 5f15e3e | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1048 | FOUND=false |
| 1049 | # Try Lineage target first. |
| 1050 | # Also try to search for files stripped of |
| 1051 | # the "/system" prefix, if we're actually extracting |
| 1052 | # from a system image. |
Vladimir Oltean | d577325 | 2018-06-25 00:05:56 +0300 | [diff] [blame] | 1053 | for CANDIDATE in "${DST_FILE}" "${SRC_FILE}"; do |
Vladimir Oltean | 5f15e3e | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1054 | get_file ${CANDIDATE} ${VENDOR_REPO_FILE} ${SRC} && { |
| 1055 | FOUND=true |
| 1056 | break |
| 1057 | } |
| 1058 | done |
| 1059 | |
| 1060 | if [ "${FOUND}" = false ]; then |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 1061 | printf ' !! file not found in source\n' |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1062 | fi |
| 1063 | fi |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 1064 | |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 1065 | if [ "$?" == "0" ]; then |
| 1066 | # Deodex apk|jar if that's the case |
Vladimir Oltean | d674771 | 2018-06-24 20:46:42 +0300 | [diff] [blame] | 1067 | if [[ "$FULLY_DEODEXED" -ne "1" && "${VENDOR_REPO_FILE}" =~ .(apk|jar)$ ]]; then |
Vladimir Oltean | d577325 | 2018-06-25 00:05:56 +0300 | [diff] [blame] | 1068 | oat2dex "${VENDOR_REPO_FILE}" "${SRC_FILE}" "$SRC" |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 1069 | if [ -f "$TMPDIR/classes.dex" ]; then |
Vladimir Oltean | d674771 | 2018-06-24 20:46:42 +0300 | [diff] [blame] | 1070 | zip -gjq "${VENDOR_REPO_FILE}" "$TMPDIR/classes.dex" |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 1071 | rm "$TMPDIR/classes.dex" |
Vladimir Oltean | d577325 | 2018-06-25 00:05:56 +0300 | [diff] [blame] | 1072 | printf ' (updated %s from odex files)\n' "${SRC_FILE}" |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 1073 | fi |
Vladimir Oltean | d674771 | 2018-06-24 20:46:42 +0300 | [diff] [blame] | 1074 | elif [[ "${VENDOR_REPO_FILE}" =~ .xml$ ]]; then |
| 1075 | fix_xml "${VENDOR_REPO_FILE}" |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 1076 | fi |
| 1077 | fi |
| 1078 | |
Vladimir Oltean | d674771 | 2018-06-24 20:46:42 +0300 | [diff] [blame] | 1079 | if [ -f "${VENDOR_REPO_FILE}" ]; then |
Vladimir Oltean | 5f15e3e | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1080 | local DIR=$(dirname "${VENDOR_REPO_FILE}") |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 1081 | local TYPE="${DIR##*/}" |
| 1082 | if [ "$TYPE" = "bin" -o "$TYPE" = "sbin" ]; then |
Vladimir Oltean | d674771 | 2018-06-24 20:46:42 +0300 | [diff] [blame] | 1083 | chmod 755 "${VENDOR_REPO_FILE}" |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 1084 | else |
Vladimir Oltean | d674771 | 2018-06-24 20:46:42 +0300 | [diff] [blame] | 1085 | chmod 644 "${VENDOR_REPO_FILE}" |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 1086 | fi |
| 1087 | fi |
| 1088 | |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1089 | done |
| 1090 | |
| 1091 | # Don't allow failing |
| 1092 | set -e |
| 1093 | } |
Louis Popi | a516c2f | 2016-07-25 15:51:13 +0200 | [diff] [blame] | 1094 | |
| 1095 | # |
| 1096 | # extract_firmware: |
| 1097 | # |
| 1098 | # $1: file containing the list of items to extract |
| 1099 | # $2: path to extracted radio folder |
| 1100 | # |
| 1101 | function extract_firmware() { |
| 1102 | if [ -z "$OUTDIR" ]; then |
| 1103 | echo "Output dir not set!" |
| 1104 | exit 1 |
| 1105 | fi |
| 1106 | |
| 1107 | parse_file_list "$1" |
| 1108 | |
| 1109 | # Don't allow failing |
| 1110 | set -e |
| 1111 | |
| 1112 | local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ) |
| 1113 | local COUNT=${#FILELIST[@]} |
| 1114 | local SRC="$2" |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 1115 | local OUTPUT_DIR="$LINEAGE_ROOT"/"$OUTDIR"/radio |
Louis Popi | a516c2f | 2016-07-25 15:51:13 +0200 | [diff] [blame] | 1116 | |
| 1117 | if [ "$VENDOR_RADIO_STATE" -eq "0" ]; then |
| 1118 | echo "Cleaning firmware output directory ($OUTPUT_DIR).." |
| 1119 | rm -rf "${OUTPUT_DIR:?}/"* |
| 1120 | VENDOR_RADIO_STATE=1 |
| 1121 | fi |
| 1122 | |
| 1123 | echo "Extracting $COUNT files in $1 from $SRC:" |
| 1124 | |
| 1125 | for (( i=1; i<COUNT+1; i++ )); do |
| 1126 | local FILE="${FILELIST[$i-1]}" |
| 1127 | printf ' - %s \n' "/radio/$FILE" |
| 1128 | |
| 1129 | if [ ! -d "$OUTPUT_DIR" ]; then |
| 1130 | mkdir -p "$OUTPUT_DIR" |
| 1131 | fi |
| 1132 | cp "$SRC/$FILE" "$OUTPUT_DIR/$FILE" |
| 1133 | chmod 644 "$OUTPUT_DIR/$FILE" |
| 1134 | done |
| 1135 | } |