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