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 | |
| 29 | TMPDIR="/tmp/extractfiles.$$" |
| 30 | mkdir "$TMPDIR" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 31 | |
| 32 | # |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 33 | # cleanup |
| 34 | # |
| 35 | # kill our tmpfiles with fire on exit |
| 36 | # |
| 37 | function cleanup() { |
| 38 | rm -rf "${TMPDIR:?}" |
| 39 | } |
| 40 | |
| 41 | trap cleanup EXIT INT TERM ERR |
| 42 | |
| 43 | # |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 44 | # setup_vendor |
| 45 | # |
| 46 | # $1: device name |
| 47 | # $2: vendor name |
| 48 | # $3: CM root directory |
| 49 | # $4: is common device - optional, default to false |
| 50 | # $5: cleanup - optional, default to true |
Rashed Abdel-Tawab | 5f17315 | 2016-10-01 20:33:00 -0400 | [diff] [blame] | 51 | # $6: custom vendor makefile name - optional, default to false |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 52 | # |
| 53 | # Must be called before any other functions can be used. This |
| 54 | # sets up the internal state for a new vendor configuration. |
| 55 | # |
| 56 | function setup_vendor() { |
| 57 | local DEVICE="$1" |
| 58 | if [ -z "$DEVICE" ]; then |
| 59 | echo "\$DEVICE must be set before including this script!" |
| 60 | exit 1 |
| 61 | fi |
| 62 | |
| 63 | export VENDOR="$2" |
| 64 | if [ -z "$VENDOR" ]; then |
| 65 | echo "\$VENDOR must be set before including this script!" |
| 66 | exit 1 |
| 67 | fi |
| 68 | |
| 69 | export CM_ROOT="$3" |
| 70 | if [ ! -d "$CM_ROOT" ]; then |
| 71 | echo "\$CM_ROOT must be set and valid before including this script!" |
| 72 | exit 1 |
| 73 | fi |
| 74 | |
| 75 | export OUTDIR=vendor/"$VENDOR"/"$DEVICE" |
| 76 | if [ ! -d "$CM_ROOT/$OUTDIR" ]; then |
| 77 | mkdir -p "$CM_ROOT/$OUTDIR" |
| 78 | fi |
| 79 | |
Rashed Abdel-Tawab | 5f17315 | 2016-10-01 20:33:00 -0400 | [diff] [blame] | 80 | VNDNAME="$6" |
| 81 | if [ -z "$VNDNAME" ]; then |
| 82 | VNDNAME="$DEVICE" |
| 83 | fi |
| 84 | |
| 85 | export PRODUCTMK="$CM_ROOT"/"$OUTDIR"/"$VNDNAME"-vendor.mk |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 86 | export ANDROIDMK="$CM_ROOT"/"$OUTDIR"/Android.mk |
| 87 | export BOARDMK="$CM_ROOT"/"$OUTDIR"/BoardConfigVendor.mk |
| 88 | |
| 89 | if [ "$4" == "true" ] || [ "$4" == "1" ]; then |
| 90 | COMMON=1 |
| 91 | else |
| 92 | COMMON=0 |
| 93 | fi |
| 94 | |
| 95 | if [ "$5" == "true" ] || [ "$5" == "1" ]; then |
| 96 | VENDOR_STATE=1 |
Louis Popi | a516c2f | 2016-07-25 15:51:13 +0200 | [diff] [blame] | 97 | VENDOR_RADIO_STATE=1 |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 98 | else |
| 99 | VENDOR_STATE=0 |
Louis Popi | a516c2f | 2016-07-25 15:51:13 +0200 | [diff] [blame] | 100 | VENDOR_RADIO_STATE=0 |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 101 | fi |
| 102 | } |
| 103 | |
| 104 | # |
| 105 | # target_file: |
| 106 | # |
| 107 | # $1: colon delimited list |
| 108 | # |
| 109 | # Returns destination filename without args |
| 110 | # |
| 111 | function target_file() { |
| 112 | local LINE="$1" |
| 113 | local SPLIT=(${LINE//:/ }) |
| 114 | local COUNT=${#SPLIT[@]} |
| 115 | if [ "$COUNT" -gt "1" ]; then |
| 116 | if [[ "${SPLIT[1]}" =~ .*/.* ]]; then |
| 117 | printf '%s\n' "${SPLIT[1]}" |
| 118 | return 0 |
| 119 | fi |
| 120 | fi |
| 121 | printf '%s\n' "${SPLIT[0]}" |
| 122 | } |
| 123 | |
| 124 | # |
| 125 | # target_args: |
| 126 | # |
| 127 | # $1: colon delimited list |
| 128 | # |
| 129 | # Returns optional arguments (last value) for given target |
| 130 | # |
| 131 | function target_args() { |
| 132 | local LINE="$1" |
| 133 | local SPLIT=(${LINE//:/ }) |
| 134 | local COUNT=${#SPLIT[@]} |
| 135 | if [ "$COUNT" -gt "1" ]; then |
| 136 | if [[ ! "${SPLIT[$COUNT-1]}" =~ .*/.* ]]; then |
| 137 | printf '%s\n' "${SPLIT[$COUNT-1]}" |
| 138 | fi |
| 139 | fi |
| 140 | } |
| 141 | |
| 142 | # |
| 143 | # prefix_match: |
| 144 | # |
| 145 | # $1: the prefix to match on |
| 146 | # |
| 147 | # Internal function which loops thru the packages list and returns a new |
| 148 | # list containing the matched files with the prefix stripped away. |
| 149 | # |
| 150 | function prefix_match() { |
| 151 | local PREFIX="$1" |
| 152 | for FILE in "${PRODUCT_PACKAGES_LIST[@]}"; do |
| 153 | if [[ "$FILE" =~ ^"$PREFIX" ]]; then |
| 154 | printf '%s\n' "${FILE#$PREFIX}" |
| 155 | fi |
| 156 | done |
| 157 | } |
| 158 | |
| 159 | # |
| 160 | # write_product_copy_files: |
| 161 | # |
| 162 | # Creates the PRODUCT_COPY_FILES section in the product makefile for all |
| 163 | # items in the list which do not start with a dash (-). |
| 164 | # |
| 165 | function write_product_copy_files() { |
| 166 | local COUNT=${#PRODUCT_COPY_FILES_LIST[@]} |
| 167 | local TARGET= |
| 168 | local FILE= |
| 169 | local LINEEND= |
| 170 | |
| 171 | if [ "$COUNT" -eq "0" ]; then |
| 172 | return 0 |
| 173 | fi |
| 174 | |
| 175 | printf '%s\n' "PRODUCT_COPY_FILES += \\" >> "$PRODUCTMK" |
| 176 | for (( i=1; i<COUNT+1; i++ )); do |
| 177 | FILE="${PRODUCT_COPY_FILES_LIST[$i-1]}" |
| 178 | LINEEND=" \\" |
| 179 | if [ "$i" -eq "$COUNT" ]; then |
| 180 | LINEEND="" |
| 181 | fi |
| 182 | |
| 183 | TARGET=$(target_file "$FILE") |
| 184 | printf ' %s/proprietary/%s:system/%s%s\n' \ |
| 185 | "$OUTDIR" "$TARGET" "$TARGET" "$LINEEND" >> "$PRODUCTMK" |
| 186 | done |
| 187 | return 0 |
| 188 | } |
| 189 | |
| 190 | # |
| 191 | # write_packages: |
| 192 | # |
| 193 | # $1: The LOCAL_MODULE_CLASS for the given module list |
| 194 | # $2: "true" if this package is part of the vendor/ path |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 195 | # $3: type-specific extra flags |
| 196 | # $4: Name of the array holding the target list |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 197 | # |
| 198 | # Internal function which writes out the BUILD_PREBUILT stanzas |
| 199 | # for all modules in the list. This is called by write_product_packages |
| 200 | # after the modules are categorized. |
| 201 | # |
| 202 | function write_packages() { |
| 203 | |
| 204 | local CLASS="$1" |
| 205 | local VENDOR_PKG="$2" |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 206 | local EXTRA="$3" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 207 | |
| 208 | # 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] | 209 | local ARR_NAME="$4[@]" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 210 | local FILELIST=("${!ARR_NAME}") |
| 211 | |
| 212 | local FILE= |
| 213 | local ARGS= |
| 214 | local BASENAME= |
| 215 | local EXTENSION= |
| 216 | local PKGNAME= |
| 217 | local SRC= |
| 218 | |
| 219 | for P in "${FILELIST[@]}"; do |
| 220 | FILE=$(target_file "$P") |
| 221 | ARGS=$(target_args "$P") |
| 222 | |
| 223 | BASENAME=$(basename "$FILE") |
| 224 | EXTENSION=${BASENAME##*.} |
| 225 | PKGNAME=${BASENAME%.*} |
| 226 | |
| 227 | # Add to final package list |
| 228 | PACKAGE_LIST+=("$PKGNAME") |
| 229 | |
| 230 | SRC="proprietary" |
| 231 | if [ "$VENDOR_PKG" = "true" ]; then |
| 232 | SRC+="/vendor" |
| 233 | fi |
| 234 | |
| 235 | printf 'include $(CLEAR_VARS)\n' |
| 236 | printf 'LOCAL_MODULE := %s\n' "$PKGNAME" |
| 237 | printf 'LOCAL_MODULE_OWNER := %s\n' "$VENDOR" |
| 238 | if [ "$CLASS" = "SHARED_LIBRARIES" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 239 | if [ "$EXTRA" = "both" ]; then |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 240 | printf 'LOCAL_SRC_FILES_64 := %s/lib64/%s\n' "$SRC" "$FILE" |
| 241 | printf 'LOCAL_SRC_FILES_32 := %s/lib/%s\n' "$SRC" "$FILE" |
| 242 | #if [ "$VENDOR_PKG" = "true" ]; then |
| 243 | # echo "LOCAL_MODULE_PATH_64 := \$(TARGET_OUT_VENDOR_SHARED_LIBRARIES)" |
| 244 | # echo "LOCAL_MODULE_PATH_32 := \$(2ND_TARGET_OUT_VENDOR_SHARED_LIBRARIES)" |
| 245 | #else |
| 246 | # echo "LOCAL_MODULE_PATH_64 := \$(TARGET_OUT_SHARED_LIBRARIES)" |
| 247 | # echo "LOCAL_MODULE_PATH_32 := \$(2ND_TARGET_OUT_SHARED_LIBRARIES)" |
| 248 | #fi |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 249 | elif [ "$EXTRA" = "64" ]; then |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 250 | printf 'LOCAL_SRC_FILES := %s/lib64/%s\n' "$SRC" "$FILE" |
| 251 | else |
| 252 | printf 'LOCAL_SRC_FILES := %s/lib/%s\n' "$SRC" "$FILE" |
| 253 | fi |
Steve Kondik | 03ce400 | 2016-07-29 00:00:16 -0700 | [diff] [blame] | 254 | if [ "$EXTRA" != "none" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 255 | printf 'LOCAL_MULTILIB := %s\n' "$EXTRA" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 256 | fi |
| 257 | elif [ "$CLASS" = "APPS" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 258 | if [ "$EXTRA" = "priv-app" ]; then |
| 259 | SRC="$SRC/priv-app" |
| 260 | else |
| 261 | SRC="$SRC/app" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 262 | fi |
| 263 | printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE" |
| 264 | local CERT=platform |
| 265 | if [ ! -z "$ARGS" ]; then |
| 266 | CERT="$ARGS" |
| 267 | fi |
| 268 | printf 'LOCAL_CERTIFICATE := %s\n' "$CERT" |
| 269 | elif [ "$CLASS" = "JAVA_LIBRARIES" ]; then |
| 270 | printf 'LOCAL_SRC_FILES := %s/framework/%s\n' "$SRC" "$FILE" |
| 271 | elif [ "$CLASS" = "ETC" ]; then |
| 272 | printf 'LOCAL_SRC_FILES := %s/etc/%s\n' "$SRC" "$FILE" |
| 273 | elif [ "$CLASS" = "EXECUTABLES" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 274 | if [ "$ARGS" = "rootfs" ]; then |
| 275 | SRC="$SRC/rootfs" |
| 276 | if [ "$EXTRA" = "sbin" ]; then |
| 277 | SRC="$SRC/sbin" |
| 278 | printf '%s\n' "LOCAL_MODULE_PATH := \$(TARGET_ROOT_OUT_SBIN)" |
| 279 | printf '%s\n' "LOCAL_UNSTRIPPED_PATH := \$(TARGET_ROOT_OUT_SBIN_UNSTRIPPED)" |
| 280 | fi |
| 281 | else |
| 282 | SRC="$SRC/bin" |
| 283 | fi |
| 284 | printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE" |
| 285 | unset EXTENSION |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 286 | else |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 287 | printf 'LOCAL_SRC_FILES := %s/%s\n' "$SRC" "$FILE" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 288 | fi |
| 289 | printf 'LOCAL_MODULE_TAGS := optional\n' |
| 290 | printf 'LOCAL_MODULE_CLASS := %s\n' "$CLASS" |
Hashbang173 | 3b3a0e1 | 2016-08-28 20:38:45 -0400 | [diff] [blame] | 291 | if [ "$CLASS" = "APPS" ]; then |
| 292 | printf 'LOCAL_DEX_PREOPT := false\n' |
| 293 | fi |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 294 | if [ ! -z "$EXTENSION" ]; then |
| 295 | printf 'LOCAL_MODULE_SUFFIX := .%s\n' "$EXTENSION" |
| 296 | fi |
| 297 | if [ "$EXTRA" = "priv-app" ]; then |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 298 | printf 'LOCAL_PRIVILEGED_MODULE := true\n' |
| 299 | fi |
| 300 | if [ "$VENDOR_PKG" = "true" ]; then |
| 301 | printf 'LOCAL_PROPRIETARY_MODULE := true\n' |
| 302 | fi |
| 303 | printf 'include $(BUILD_PREBUILT)\n\n' |
| 304 | done |
| 305 | } |
| 306 | |
| 307 | # |
| 308 | # write_product_packages: |
| 309 | # |
| 310 | # This function will create BUILD_PREBUILT entries in the |
| 311 | # Android.mk and associated PRODUCT_PACKAGES list in the |
| 312 | # product makefile for all files in the blob list which |
| 313 | # start with a single dash (-) character. |
| 314 | # |
| 315 | function write_product_packages() { |
| 316 | PACKAGE_LIST=() |
| 317 | |
| 318 | local COUNT=${#PRODUCT_PACKAGES_LIST[@]} |
| 319 | |
| 320 | if [ "$COUNT" = "0" ]; then |
| 321 | return 0 |
| 322 | fi |
| 323 | |
| 324 | # Figure out what's 32-bit, what's 64-bit, and what's multilib |
| 325 | # I really should not be doing this in bash due to shitty array passing :( |
| 326 | local T_LIB32=( $(prefix_match "lib/") ) |
| 327 | local T_LIB64=( $(prefix_match "lib64/") ) |
| 328 | local MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${T_LIB64[@]}")) ) |
| 329 | 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] | 330 | 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] | 331 | |
Steve Kondik | 03ce400 | 2016-07-29 00:00:16 -0700 | [diff] [blame] | 332 | if [ "${#MULTILIBS[@]}" -gt "0" ]; then |
| 333 | write_packages "SHARED_LIBRARIES" "false" "both" "MULTILIBS" >> "$ANDROIDMK" |
| 334 | fi |
| 335 | if [ "${#LIB32[@]}" -gt "0" ]; then |
| 336 | write_packages "SHARED_LIBRARIES" "false" "32" "LIB32" >> "$ANDROIDMK" |
| 337 | fi |
| 338 | if [ "${#LIB64[@]}" -gt "0" ]; then |
| 339 | write_packages "SHARED_LIBRARIES" "false" "64" "LIB64" >> "$ANDROIDMK" |
| 340 | fi |
| 341 | |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 342 | local T_V_LIB32=( $(prefix_match "vendor/lib/") ) |
| 343 | local T_V_LIB64=( $(prefix_match "vendor/lib64/") ) |
| 344 | local V_MULTILIBS=( $(comm -12 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${T_V_LIB64[@]}")) ) |
| 345 | 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] | 346 | 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] | 347 | |
| 348 | if [ "${#V_MULTILIBS[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 349 | write_packages "SHARED_LIBRARIES" "true" "both" "V_MULTILIBS" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 350 | fi |
| 351 | if [ "${#V_LIB32[@]}" -gt "0" ]; then |
Steve Kondik | 03ce400 | 2016-07-29 00:00:16 -0700 | [diff] [blame] | 352 | write_packages "SHARED_LIBRARIES" "true" "32" "V_LIB32" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 353 | fi |
| 354 | if [ "${#V_LIB64[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 355 | write_packages "SHARED_LIBRARIES" "true" "64" "V_LIB64" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 356 | fi |
| 357 | |
| 358 | # Apps |
| 359 | local APPS=( $(prefix_match "app/") ) |
| 360 | if [ "${#APPS[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 361 | write_packages "APPS" "false" "" "APPS" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 362 | fi |
| 363 | local PRIV_APPS=( $(prefix_match "priv-app/") ) |
| 364 | if [ "${#PRIV_APPS[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 365 | write_packages "APPS" "false" "priv-app" "PRIV_APPS" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 366 | fi |
| 367 | local V_APPS=( $(prefix_match "vendor/app/") ) |
| 368 | if [ "${#V_APPS[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 369 | write_packages "APPS" "true" "" "V_APPS" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 370 | fi |
| 371 | local V_PRIV_APPS=( $(prefix_match "vendor/priv-app/") ) |
| 372 | if [ "${#V_PRIV_APPS[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 373 | write_packages "APPS" "true" "priv-app" "V_PRIV_APPS" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 374 | fi |
| 375 | |
| 376 | # Framework |
| 377 | local FRAMEWORK=( $(prefix_match "framework/") ) |
| 378 | if [ "${#FRAMEWORK[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 379 | write_packages "JAVA_LIBRARIES" "false" "" "FRAMEWORK" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 380 | fi |
| 381 | |
| 382 | # Etc |
| 383 | local ETC=( $(prefix_match "etc/") ) |
| 384 | if [ "${#ETC[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 385 | write_packages "ETC" "false" "" "ETC" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 386 | fi |
| 387 | local V_ETC=( $(prefix_match "vendor/etc/") ) |
| 388 | if [ "${#V_ETC[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 389 | write_packages "ETC" "false" "" "V_ETC" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 390 | fi |
| 391 | |
| 392 | # Executables |
| 393 | local BIN=( $(prefix_match "bin/") ) |
| 394 | if [ "${#BIN[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 395 | write_packages "EXECUTABLES" "false" "" "BIN" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 396 | fi |
| 397 | local V_BIN=( $(prefix_match "vendor/bin/") ) |
| 398 | if [ "${#V_BIN[@]}" -gt "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 399 | write_packages "EXECUTABLES" "true" "" "V_BIN" >> "$ANDROIDMK" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 400 | fi |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 401 | local SBIN=( $(prefix_match "sbin/") ) |
| 402 | if [ "${#SBIN[@]}" -gt "0" ]; then |
| 403 | write_packages "EXECUTABLES" "false" "sbin" "SBIN" >> "$ANDROIDMK" |
| 404 | fi |
| 405 | |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 406 | |
| 407 | # Actually write out the final PRODUCT_PACKAGES list |
| 408 | local PACKAGE_COUNT=${#PACKAGE_LIST[@]} |
| 409 | |
| 410 | if [ "$PACKAGE_COUNT" -eq "0" ]; then |
| 411 | return 0 |
| 412 | fi |
| 413 | |
| 414 | printf '\n%s\n' "PRODUCT_PACKAGES += \\" >> "$PRODUCTMK" |
| 415 | for (( i=1; i<PACKAGE_COUNT+1; i++ )); do |
| 416 | local LINEEND=" \\" |
| 417 | if [ "$i" -eq "$PACKAGE_COUNT" ]; then |
| 418 | LINEEND="" |
| 419 | fi |
| 420 | printf ' %s%s\n' "${PACKAGE_LIST[$i-1]}" "$LINEEND" >> "$PRODUCTMK" |
| 421 | done |
| 422 | } |
| 423 | |
| 424 | # |
| 425 | # write_header: |
| 426 | # |
| 427 | # $1: file which will be written to |
| 428 | # |
| 429 | # writes out the copyright header with the current year. |
| 430 | # note that this is not an append operation, and should |
| 431 | # be executed first! |
| 432 | # |
| 433 | function write_header() { |
| 434 | YEAR=$(date +"%Y") |
| 435 | |
| 436 | [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON" |
| 437 | |
| 438 | cat << EOF > $1 |
| 439 | # Copyright (C) $YEAR The CyanogenMod Project |
| 440 | # |
| 441 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 442 | # you may not use this file except in compliance with the License. |
| 443 | # You may obtain a copy of the License at |
| 444 | # |
| 445 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 446 | # |
| 447 | # Unless required by applicable law or agreed to in writing, software |
| 448 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 449 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 450 | # See the License for the specific language governing permissions and |
| 451 | # limitations under the License. |
| 452 | |
| 453 | # This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh |
| 454 | |
| 455 | EOF |
| 456 | } |
| 457 | |
| 458 | # |
| 459 | # write_headers: |
| 460 | # |
| 461 | # $1: devices falling under common to be added to guard - optional |
Rashed Abdel-Tawab | d53bff1 | 2016-10-02 01:00:54 -0400 | [diff] [blame^] | 462 | # $2: custom guard - optional |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 463 | # |
| 464 | # Calls write_header for each of the makefiles and creates |
| 465 | # the initial path declaration and device guard for the |
| 466 | # Android.mk |
| 467 | # |
| 468 | function write_headers() { |
| 469 | write_header "$ANDROIDMK" |
Rashed Abdel-Tawab | d53bff1 | 2016-10-02 01:00:54 -0400 | [diff] [blame^] | 470 | |
| 471 | GUARD="$2" |
| 472 | if [ -z "$GUARD" ]; then |
| 473 | GUARD="TARGET_DEVICE" |
| 474 | fi |
| 475 | |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 476 | cat << EOF >> "$ANDROIDMK" |
| 477 | LOCAL_PATH := \$(call my-dir) |
| 478 | |
| 479 | EOF |
| 480 | if [ "$COMMON" -ne 1 ]; then |
| 481 | cat << EOF >> "$ANDROIDMK" |
Rashed Abdel-Tawab | d53bff1 | 2016-10-02 01:00:54 -0400 | [diff] [blame^] | 482 | ifeq (\$($GUARD),$DEVICE) |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 483 | |
| 484 | EOF |
| 485 | else |
| 486 | if [ -z "$1" ]; then |
| 487 | echo "Argument with devices to be added to guard must be set!" |
| 488 | exit 1 |
| 489 | fi |
| 490 | cat << EOF >> "$ANDROIDMK" |
Rashed Abdel-Tawab | d53bff1 | 2016-10-02 01:00:54 -0400 | [diff] [blame^] | 491 | ifneq (\$(filter $1,\$($GUARD)),) |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 492 | |
| 493 | EOF |
| 494 | fi |
| 495 | |
| 496 | write_header "$BOARDMK" |
| 497 | write_header "$PRODUCTMK" |
| 498 | } |
| 499 | |
| 500 | # |
| 501 | # write_footers: |
| 502 | # |
| 503 | # Closes the inital guard and any other finalization tasks. Must |
| 504 | # be called as the final step. |
| 505 | # |
| 506 | function write_footers() { |
| 507 | cat << EOF >> "$ANDROIDMK" |
| 508 | endif |
| 509 | EOF |
| 510 | } |
| 511 | |
| 512 | # Return success if adb is up and not in recovery |
| 513 | function _adb_connected { |
| 514 | { |
Steve Kondik | 7561d19 | 2016-09-01 21:40:27 -0700 | [diff] [blame] | 515 | if [[ "$(adb get-state)" == device ]] |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 516 | then |
| 517 | return 0 |
| 518 | fi |
| 519 | } 2>/dev/null |
| 520 | |
| 521 | return 1 |
| 522 | }; |
| 523 | |
| 524 | # |
Bruno Martins | 3b96ba5 | 2016-07-27 15:00:05 +0100 | [diff] [blame] | 525 | # parse_file_list: |
| 526 | # |
| 527 | # $1: input file |
| 528 | # |
| 529 | # Sets PRODUCT_PACKAGES and PRODUCT_COPY_FILES while parsing the input file |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 530 | # |
| 531 | function parse_file_list() { |
Bruno Martins | 3b96ba5 | 2016-07-27 15:00:05 +0100 | [diff] [blame] | 532 | if [ -z "$1" ]; then |
| 533 | echo "An input file is expected!" |
| 534 | exit 1 |
| 535 | elif [ ! -f "$1" ]; then |
| 536 | echo "Input file "$1" does not exist!" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 537 | exit 1 |
| 538 | fi |
| 539 | |
| 540 | PRODUCT_PACKAGES_LIST=() |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 541 | PRODUCT_PACKAGES_HASHES=() |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 542 | PRODUCT_COPY_FILES_LIST=() |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 543 | PRODUCT_COPY_FILES_HASHES=() |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 544 | |
| 545 | while read -r line; do |
| 546 | if [ -z "$line" ]; then continue; fi |
| 547 | |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 548 | # If the line has a pipe delimiter, a sha1 hash should follow. |
| 549 | # This indicates the file should be pinned and not overwritten |
| 550 | # when extracting files. |
| 551 | local SPLIT=(${line//\|/ }) |
| 552 | local COUNT=${#SPLIT[@]} |
| 553 | local SPEC=${SPLIT[0]} |
| 554 | local HASH="x" |
| 555 | if [ "$COUNT" -gt "1" ]; then |
| 556 | HASH=${SPLIT[1]} |
| 557 | fi |
| 558 | |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 559 | # if line starts with a dash, it needs to be packaged |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 560 | if [[ "$SPEC" =~ ^- ]]; then |
| 561 | PRODUCT_PACKAGES_LIST+=("${SPEC#-}") |
| 562 | PRODUCT_PACKAGES_HASHES+=("$HASH") |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 563 | else |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 564 | PRODUCT_COPY_FILES_LIST+=("$SPEC") |
| 565 | PRODUCT_COPY_FILES_HASHES+=("$HASH") |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 566 | fi |
| 567 | |
| 568 | done < <(egrep -v '(^#|^[[:space:]]*$)' "$1" | sort | uniq) |
| 569 | } |
| 570 | |
| 571 | # |
| 572 | # write_makefiles: |
| 573 | # |
| 574 | # $1: file containing the list of items to extract |
| 575 | # |
| 576 | # Calls write_product_copy_files and write_product_packages on |
| 577 | # the given file and appends to the Android.mk as well as |
| 578 | # the product makefile. |
| 579 | # |
| 580 | function write_makefiles() { |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 581 | parse_file_list "$1" |
| 582 | write_product_copy_files |
| 583 | write_product_packages |
| 584 | } |
| 585 | |
| 586 | # |
Louis Popi | a516c2f | 2016-07-25 15:51:13 +0200 | [diff] [blame] | 587 | # append_firmware_calls_to_makefiles: |
| 588 | # |
| 589 | # Appends to Android.mk the calls to all images present in radio folder |
| 590 | # (filesmap file used by releasetools to map firmware images should be kept in the device tree) |
| 591 | # |
| 592 | function append_firmware_calls_to_makefiles() { |
| 593 | cat << EOF >> "$ANDROIDMK" |
| 594 | ifeq (\$(LOCAL_PATH)/radio, \$(wildcard \$(LOCAL_PATH)/radio)) |
| 595 | |
| 596 | RADIO_FILES := \$(wildcard \$(LOCAL_PATH)/radio/*) |
| 597 | \$(foreach f, \$(notdir \$(RADIO_FILES)), \\ |
| 598 | \$(call add-radio-file,radio/\$(f))) |
| 599 | \$(call add-radio-file,../../../device/$VENDOR/$DEVICE/radio/filesmap) |
| 600 | |
| 601 | endif |
| 602 | |
| 603 | EOF |
| 604 | } |
| 605 | |
| 606 | # |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 607 | # get_file: |
| 608 | # |
| 609 | # $1: input file |
| 610 | # $2: target file/folder |
| 611 | # $3: source of the file (can be "adb" or a local folder) |
| 612 | # |
| 613 | # Silently extracts the input file to defined target |
| 614 | # Returns success if file can be pulled from the device or found locally |
| 615 | # |
| 616 | function get_file() { |
| 617 | local SRC="$3" |
| 618 | |
| 619 | if [ "$SRC" = "adb" ]; then |
| 620 | # try to pull |
| 621 | adb pull "$1" "$2" >/dev/null 2>&1 && return 0 |
| 622 | |
| 623 | return 1 |
| 624 | else |
| 625 | # try to copy |
| 626 | cp "$SRC/$1" "$2" 2>/dev/null && return 0 |
| 627 | |
| 628 | return 1 |
| 629 | fi |
| 630 | }; |
| 631 | |
| 632 | # |
| 633 | # oat2dex: |
| 634 | # |
| 635 | # $1: extracted apk|jar (to check if deodex is required) |
| 636 | # $2: odexed apk|jar to deodex |
| 637 | # $3: source of the odexed apk|jar |
| 638 | # |
| 639 | # Convert apk|jar .odex in the corresposing classes.dex |
| 640 | # |
| 641 | function oat2dex() { |
| 642 | local CM_TARGET="$1" |
| 643 | local OEM_TARGET="$2" |
| 644 | local SRC="$3" |
| 645 | local TARGET= |
| 646 | local OAT= |
| 647 | |
| 648 | if [ -z "$BAKSMALIJAR" ] || [ -z "$SMALIJAR" ]; then |
| 649 | export BAKSMALIJAR="$CM_ROOT"/vendor/cm/build/tools/smali/baksmali.jar |
| 650 | export SMALIJAR="$CM_ROOT"/vendor/cm/build/tools/smali/smali.jar |
| 651 | fi |
| 652 | |
| 653 | # Extract existing boot.oats to the temp folder |
| 654 | if [ -z "$ARCHES" ]; then |
| 655 | echo "Checking if system is odexed and extracting boot.oats, if applicable. This may take a while..." |
| 656 | for ARCH in "arm64" "arm" "x86_64" "x86"; do |
| 657 | if get_file "system/framework/$ARCH/boot.oat" "$TMPDIR/boot_$ARCH.oat" "$SRC"; then |
| 658 | ARCHES+="$ARCH " |
| 659 | fi |
| 660 | done |
| 661 | fi |
| 662 | |
| 663 | if [ -z "$ARCHES" ]; then |
| 664 | FULLY_DEODEXED=1 && return 0 # system is fully deodexed, return |
| 665 | fi |
| 666 | |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 667 | if [ ! -f "$CM_TARGET" ]; then |
| 668 | return; |
| 669 | fi |
| 670 | |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 671 | if grep "classes.dex" "$CM_TARGET" >/dev/null; then |
| 672 | return 0 # target apk|jar is already odexed, return |
| 673 | fi |
| 674 | |
| 675 | for ARCH in $ARCHES; do |
| 676 | BOOTOAT="$TMPDIR/boot_$ARCH.oat" |
| 677 | |
| 678 | local OAT="$(dirname "$OEM_TARGET")/oat/$ARCH/$(basename "$OEM_TARGET" ."${OEM_TARGET##*.}").odex" |
| 679 | |
| 680 | if get_file "$OAT" "$TMPDIR" "$SRC"; then |
| 681 | java -jar "$BAKSMALIJAR" -x -o "$TMPDIR/dexout" -c "$BOOTOAT" -d "$TMPDIR" "$TMPDIR/$(basename "$OAT")" |
| 682 | elif [[ "$CM_TARGET" =~ .jar$ ]]; then |
| 683 | # try to extract classes.dex from boot.oat for framework jars |
| 684 | java -jar "$BAKSMALIJAR" -x -o "$TMPDIR/dexout" -c "$BOOTOAT" -d "$TMPDIR" -e "/$OEM_TARGET" "$BOOTOAT" |
| 685 | else |
| 686 | continue |
| 687 | fi |
| 688 | |
| 689 | java -jar "$SMALIJAR" "$TMPDIR/dexout" -o "$TMPDIR/classes.dex" && break |
| 690 | done |
| 691 | |
| 692 | rm -rf "$TMPDIR/dexout" |
| 693 | } |
| 694 | |
| 695 | # |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 696 | # init_adb_connection: |
| 697 | # |
| 698 | # Starts adb server and waits for the device |
| 699 | # |
| 700 | function init_adb_connection() { |
| 701 | adb start-server # Prevent unexpected starting server message from adb get-state in the next line |
| 702 | if ! _adb_connected; then |
| 703 | echo "No device is online. Waiting for one..." |
| 704 | echo "Please connect USB and/or enable USB debugging" |
| 705 | until _adb_connected; do |
| 706 | sleep 1 |
| 707 | done |
| 708 | echo "Device Found." |
| 709 | fi |
| 710 | |
| 711 | # Retrieve IP and PORT info if we're using a TCP connection |
| 712 | TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \ |
| 713 | | head -1 | awk '{print $1}') |
| 714 | adb root &> /dev/null |
| 715 | sleep 0.3 |
| 716 | if [ -n "$TCPIPPORT" ]; then |
| 717 | # adb root just killed our connection |
| 718 | # so reconnect... |
| 719 | adb connect "$TCPIPPORT" |
| 720 | fi |
| 721 | adb wait-for-device &> /dev/null |
| 722 | sleep 0.3 |
| 723 | } |
| 724 | |
| 725 | # |
Luca Stefani | 3a03012 | 2016-07-30 12:08:25 +0200 | [diff] [blame] | 726 | # fix_xml: |
| 727 | # |
| 728 | # $1: xml file to fix |
| 729 | # |
| 730 | function fix_xml() { |
| 731 | local XML="$1" |
| 732 | local TEMP_XML="$TMPDIR/`basename "$XML"`.temp" |
| 733 | |
| 734 | grep '^<?xml version' "$XML" > "$TEMP_XML" |
| 735 | grep -v '^<?xml version' "$XML" >> "$TEMP_XML" |
| 736 | |
| 737 | mv "$TEMP_XML" "$XML" |
| 738 | } |
| 739 | |
| 740 | # |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 741 | # extract: |
| 742 | # |
| 743 | # $1: file containing the list of items to extract |
| 744 | # $2: path to extracted system folder, or "adb" to extract from device |
| 745 | # |
| 746 | function extract() { |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 747 | if [ -z "$OUTDIR" ]; then |
| 748 | echo "Output dir not set!" |
| 749 | exit 1 |
| 750 | fi |
| 751 | |
| 752 | parse_file_list "$1" |
| 753 | |
| 754 | # Allow failing, so we can try $DEST and/or $FILE |
| 755 | set +e |
| 756 | |
| 757 | local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ${PRODUCT_PACKAGES_LIST[@]} ) |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 758 | local HASHLIST=( ${PRODUCT_COPY_FILES_HASHES[@]} ${PRODUCT_PACKAGES_HASHES[@]} ) |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 759 | local COUNT=${#FILELIST[@]} |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 760 | local SRC="$2" |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 761 | local OUTPUT_ROOT="$CM_ROOT"/"$OUTDIR"/proprietary |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 762 | local OUTPUT_TMP="$TMPDIR"/"$OUTDIR"/proprietary |
| 763 | |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 764 | if [ "$SRC" = "adb" ]; then |
| 765 | init_adb_connection |
| 766 | fi |
| 767 | |
| 768 | if [ "$VENDOR_STATE" -eq "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 769 | echo "Cleaning output directory ($OUTPUT_ROOT).." |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 770 | rm -rf "${OUTPUT_TMP:?}" |
| 771 | mkdir -p "${OUTPUT_TMP:?}" |
| 772 | mv "${OUTPUT_ROOT:?}/"* "${OUTPUT_TMP:?}/" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 773 | VENDOR_STATE=1 |
| 774 | fi |
| 775 | |
| 776 | echo "Extracting $COUNT files in $1 from $SRC:" |
| 777 | |
| 778 | for (( i=1; i<COUNT+1; i++ )); do |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 779 | |
| 780 | local FROM=$(target_file "${FILELIST[$i-1]}") |
| 781 | local ARGS=$(target_args "${FILELIST[$i-1]}") |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 782 | local SPLIT=(${FILELIST[$i-1]//:/ }) |
| 783 | local FILE="${SPLIT[0]#-}" |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 784 | local OUTPUT_DIR="$OUTPUT_ROOT" |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 785 | local TMP_DIR="$OUTPUT_TMP" |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 786 | local TARGET= |
| 787 | |
| 788 | if [ "$ARGS" = "rootfs" ]; then |
| 789 | TARGET="$FROM" |
| 790 | OUTPUT_DIR="$OUTPUT_DIR/rootfs" |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 791 | TMP_DIR="$TMP_DIR/rootfs" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 792 | else |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 793 | TARGET="system/$FROM" |
| 794 | FILE="system/$FILE" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 795 | fi |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 796 | |
| 797 | if [ "$SRC" = "adb" ]; then |
| 798 | printf ' - %s .. ' "/$TARGET" |
| 799 | else |
| 800 | printf ' - %s \n' "/$TARGET" |
| 801 | fi |
| 802 | |
| 803 | local DIR=$(dirname "$FROM") |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 804 | if [ ! -d "$OUTPUT_DIR/$DIR" ]; then |
| 805 | mkdir -p "$OUTPUT_DIR/$DIR" |
| 806 | fi |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 807 | local DEST="$OUTPUT_DIR/$FROM" |
| 808 | |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 809 | if [ "$SRC" = "adb" ]; then |
| 810 | # Try CM target first |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 811 | adb pull "/$TARGET" "$DEST" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 812 | # if file does not exist try OEM target |
| 813 | if [ "$?" != "0" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 814 | adb pull "/$FILE" "$DEST" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 815 | fi |
| 816 | else |
| 817 | # Try OEM target first |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 818 | if [ -f "$SRC/$FILE" ]; then |
| 819 | cp "$SRC/$FILE" "$DEST" |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 820 | # if file does not exist try CM target |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 821 | elif [ -f "$SRC/$TARGET" ]; then |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 822 | cp "$SRC/$TARGET" "$DEST" |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 823 | else |
| 824 | printf ' !! file not found in source\n' |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 825 | fi |
| 826 | fi |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 827 | |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 828 | if [ "$?" == "0" ]; then |
| 829 | # Deodex apk|jar if that's the case |
| 830 | if [[ "$FULLY_DEODEXED" -ne "1" && "$DEST" =~ .(apk|jar)$ ]]; then |
| 831 | oat2dex "$DEST" "$FILE" "$SRC" |
| 832 | if [ -f "$TMPDIR/classes.dex" ]; then |
| 833 | zip -gjq "$DEST" "$TMPDIR/classes.dex" |
| 834 | rm "$TMPDIR/classes.dex" |
| 835 | printf ' (updated %s from odex files)\n' "/$FILE" |
| 836 | fi |
Luca Stefani | 3a03012 | 2016-07-30 12:08:25 +0200 | [diff] [blame] | 837 | elif [[ "$DEST" =~ .xml$ ]]; then |
| 838 | fix_xml "$DEST" |
Luca Stefani | 7f9fff2 | 2016-07-18 13:47:55 +0200 | [diff] [blame] | 839 | fi |
| 840 | fi |
| 841 | |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 842 | # Check pinned files |
| 843 | local HASH="${HASHLIST[$i-1]}" |
Steve Kondik | 79fa59b | 2016-09-02 21:10:02 -0700 | [diff] [blame] | 844 | if [ "$DISABLE_PINNING" != "1" ] && [ ! -z "$HASH" ] && [ "$HASH" != "x" ]; then |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 845 | local KEEP="" |
| 846 | local TMP="$TMP_DIR/$FROM" |
| 847 | if [ -f "$TMP" ]; then |
| 848 | if [ ! -f "$DEST" ]; then |
| 849 | KEEP="1" |
| 850 | else |
| 851 | local DEST_HASH=$(sha1sum "$DEST" | awk '{print $1}' ) |
| 852 | if [ "$DEST_HASH" != "$HASH" ]; then |
| 853 | KEEP="1" |
| 854 | fi |
| 855 | fi |
| 856 | if [ "$KEEP" = "1" ]; then |
| 857 | local TMP_HASH=$(sha1sum "$TMP" | awk '{print $1}' ) |
| 858 | if [ "$TMP_HASH" = "$HASH" ]; then |
| 859 | printf ' + (keeping pinned file with hash %s)\n' "$HASH" |
| 860 | cp -p "$TMP" "$DEST" |
| 861 | fi |
| 862 | fi |
| 863 | fi |
Steve Kondik | a991cf1 | 2016-07-28 12:13:12 -0700 | [diff] [blame] | 864 | fi |
Steve Kondik | 48f8df8 | 2016-08-14 03:55:08 -0700 | [diff] [blame] | 865 | |
| 866 | if [ -f "$DEST" ]; then |
| 867 | local TYPE="${DIR##*/}" |
| 868 | if [ "$TYPE" = "bin" -o "$TYPE" = "sbin" ]; then |
| 869 | chmod 755 "$DEST" |
| 870 | else |
| 871 | chmod 644 "$DEST" |
| 872 | fi |
| 873 | fi |
| 874 | |
Steve Kondik | 4e2aaab | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 875 | done |
| 876 | |
| 877 | # Don't allow failing |
| 878 | set -e |
| 879 | } |
Louis Popi | a516c2f | 2016-07-25 15:51:13 +0200 | [diff] [blame] | 880 | |
| 881 | # |
| 882 | # extract_firmware: |
| 883 | # |
| 884 | # $1: file containing the list of items to extract |
| 885 | # $2: path to extracted radio folder |
| 886 | # |
| 887 | function extract_firmware() { |
| 888 | if [ -z "$OUTDIR" ]; then |
| 889 | echo "Output dir not set!" |
| 890 | exit 1 |
| 891 | fi |
| 892 | |
| 893 | parse_file_list "$1" |
| 894 | |
| 895 | # Don't allow failing |
| 896 | set -e |
| 897 | |
| 898 | local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ) |
| 899 | local COUNT=${#FILELIST[@]} |
| 900 | local SRC="$2" |
| 901 | local OUTPUT_DIR="$CM_ROOT"/"$OUTDIR"/radio |
| 902 | |
| 903 | if [ "$VENDOR_RADIO_STATE" -eq "0" ]; then |
| 904 | echo "Cleaning firmware output directory ($OUTPUT_DIR).." |
| 905 | rm -rf "${OUTPUT_DIR:?}/"* |
| 906 | VENDOR_RADIO_STATE=1 |
| 907 | fi |
| 908 | |
| 909 | echo "Extracting $COUNT files in $1 from $SRC:" |
| 910 | |
| 911 | for (( i=1; i<COUNT+1; i++ )); do |
| 912 | local FILE="${FILELIST[$i-1]}" |
| 913 | printf ' - %s \n' "/radio/$FILE" |
| 914 | |
| 915 | if [ ! -d "$OUTPUT_DIR" ]; then |
| 916 | mkdir -p "$OUTPUT_DIR" |
| 917 | fi |
| 918 | cp "$SRC/$FILE" "$OUTPUT_DIR/$FILE" |
| 919 | chmod 644 "$OUTPUT_DIR/$FILE" |
| 920 | done |
| 921 | } |