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