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