| Steve Kondik | 5bd6660 | 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=() |
| 19 | PRODUCT_COPY_FILES_HASHES=() |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 20 | PRODUCT_COPY_FILES_FIXUP_HASHES=() |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 21 | PRODUCT_PACKAGES_LIST=() |
| 22 | PRODUCT_PACKAGES_HASHES=() |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 23 | PRODUCT_PACKAGES_FIXUP_HASHES=() |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 24 | PRODUCT_SYMLINKS_LIST=() |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 25 | PACKAGE_LIST=() |
| SamarV-121 | 7e6b408 | 2024-02-26 14:39:34 +0530 | [diff] [blame] | 26 | REQUIRED_PACKAGES_LIST= |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 27 | VENDOR_STATE=-1 |
| 28 | VENDOR_RADIO_STATE=-1 |
| 29 | COMMON=-1 |
| 30 | ARCHES= |
| 31 | FULLY_DEODEXED=-1 |
| 32 | |
| Chirayu Desai | 51ddd8d | 2022-05-26 14:50:35 +0530 | [diff] [blame] | 33 | SKIP_CLEANUP=${SKIP_CLEANUP:-0} |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 34 | EXTRACT_TMP_DIR=$(mktemp -d) |
| Volodymyr Zhdanov | e54a159 | 2020-10-22 01:33:24 +0300 | [diff] [blame] | 35 | HOST="$(uname | tr '[:upper:]' '[:lower:]')" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 36 | |
| 37 | # |
| 38 | # cleanup |
| 39 | # |
| 40 | # kill our tmpfiles with fire on exit |
| 41 | # |
| 42 | function cleanup() { |
| Chirayu Desai | 51ddd8d | 2022-05-26 14:50:35 +0530 | [diff] [blame] | 43 | if [ "$SKIP_CLEANUP" == "true" ] || [ "$SKIP_CLEANUP" == "1" ]; then |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 44 | echo "Skipping cleanup of $EXTRACT_TMP_DIR" |
| Chirayu Desai | 51ddd8d | 2022-05-26 14:50:35 +0530 | [diff] [blame] | 45 | else |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 46 | rm -rf "${EXTRACT_TMP_DIR:?}" |
| Chirayu Desai | 51ddd8d | 2022-05-26 14:50:35 +0530 | [diff] [blame] | 47 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| Gabriele M | b8e5457 | 2017-10-11 12:55:51 +0200 | [diff] [blame] | 50 | trap cleanup 0 |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 51 | |
| 52 | # |
| 53 | # setup_vendor |
| 54 | # |
| 55 | # $1: device name |
| 56 | # $2: vendor name |
| theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 57 | # $3: OMNI root directory |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 58 | # $4: is common device - optional, default to false |
| 59 | # $5: cleanup - optional, default to true |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 60 | # $6: custom vendor makefile name - optional, default to false |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 61 | # |
| 62 | # Must be called before any other functions can be used. This |
| 63 | # sets up the internal state for a new vendor configuration. |
| 64 | # |
| 65 | function setup_vendor() { |
| 66 | local DEVICE="$1" |
| 67 | if [ -z "$DEVICE" ]; then |
| 68 | echo "\$DEVICE must be set before including this script!" |
| 69 | exit 1 |
| 70 | fi |
| 71 | |
| 72 | export VENDOR="$2" |
| 73 | if [ -z "$VENDOR" ]; then |
| 74 | echo "\$VENDOR must be set before including this script!" |
| 75 | exit 1 |
| 76 | fi |
| 77 | |
| theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 78 | export OMNI_ROOT="$3" |
| 79 | if [ ! -d "$OMNI_ROOT" ]; then |
| 80 | echo "\$OMNI_ROOT must be set and valid before including this script!" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 81 | exit 1 |
| 82 | fi |
| 83 | |
| 84 | export OUTDIR=vendor/"$VENDOR"/"$DEVICE" |
| theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 85 | if [ ! -d "$OMNI_ROOT/$OUTDIR" ]; then |
| 86 | mkdir -p "$OMNI_ROOT/$OUTDIR" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 87 | fi |
| 88 | |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 89 | VNDNAME="$6" |
| 90 | if [ -z "$VNDNAME" ]; then |
| 91 | VNDNAME="$DEVICE" |
| 92 | fi |
| 93 | |
| theimpulson | bb72ab8 | 2019-08-14 06:03:32 +0000 | [diff] [blame] | 94 | export PRODUCTMK="$OMNI_ROOT"/"$OUTDIR"/"$VNDNAME"-vendor.mk |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 95 | export ANDROIDBP="$OMNI_ROOT"/"$OUTDIR"/Android.bp |
| theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 96 | export ANDROIDMK="$OMNI_ROOT"/"$OUTDIR"/Android.mk |
| 97 | export BOARDMK="$OMNI_ROOT"/"$OUTDIR"/BoardConfigVendor.mk |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 98 | |
| 99 | if [ "$4" == "true" ] || [ "$4" == "1" ]; then |
| 100 | COMMON=1 |
| 101 | else |
| 102 | COMMON=0 |
| 103 | fi |
| 104 | |
| Gabriele M | c44696d | 2017-05-01 18:22:04 +0200 | [diff] [blame] | 105 | if [ "$5" == "false" ] || [ "$5" == "0" ]; then |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 106 | VENDOR_STATE=1 |
| 107 | VENDOR_RADIO_STATE=1 |
| 108 | else |
| 109 | VENDOR_STATE=0 |
| 110 | VENDOR_RADIO_STATE=0 |
| 111 | fi |
| Volodymyr Zhdanov | e54a159 | 2020-10-22 01:33:24 +0300 | [diff] [blame] | 112 | |
| Chirayu Desai | 501ffd6 | 2022-03-17 06:27:33 +0530 | [diff] [blame] | 113 | export BINARIES_LOCATION="$OMNI_ROOT"/vendor/omni/build/tools/${HOST}/bin |
| 114 | |
| 115 | export SIMG2IMG="$BINARIES_LOCATION"/simg2img |
| Michael Bestas | f2501c3 | 2022-02-18 23:45:09 +0200 | [diff] [blame] | 116 | export LPUNPACK="$BINARIES_LOCATION"/lpunpack |
| Michael Bestas | e04d4be | 2022-03-23 23:15:23 +0200 | [diff] [blame] | 117 | export SIGSCAN="$BINARIES_LOCATION"/SigScan |
| Chirayu Desai | 501ffd6 | 2022-03-17 06:27:33 +0530 | [diff] [blame] | 118 | |
| Woomymy | fad4e79 | 2023-02-26 16:47:57 +0100 | [diff] [blame] | 119 | for version in 0_8 0_9 0_17_2; do |
| Sebastiano Barezzi | caed759 | 2021-01-17 02:26:08 +0100 | [diff] [blame] | 120 | export PATCHELF_${version}="$BINARIES_LOCATION"/patchelf-"${version}" |
| 121 | done |
| 122 | |
| 123 | if [ -z "$PATCHELF_VERSION" ]; then |
| 124 | export PATCHELF_VERSION=0_9 |
| 125 | fi |
| 126 | |
| Volodymyr Zhdanov | e54a159 | 2020-10-22 01:33:24 +0300 | [diff] [blame] | 127 | if [ -z "$PATCHELF" ]; then |
| Sebastiano Barezzi | caed759 | 2021-01-17 02:26:08 +0100 | [diff] [blame] | 128 | local patchelf_variable="PATCHELF_${PATCHELF_VERSION}" |
| 129 | export PATCHELF=${!patchelf_variable} |
| Volodymyr Zhdanov | e54a159 | 2020-10-22 01:33:24 +0300 | [diff] [blame] | 130 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| Vladimir Oltean | 75d8e05 | 2018-06-24 20:22:41 +0300 | [diff] [blame] | 133 | # Helper functions for parsing a spec. |
| 134 | # notes: an optional "|SHA1" that may appear in the format is stripped |
| 135 | # early from the spec in the parse_file_list function, and |
| 136 | # should not be present inside the input parameter passed |
| 137 | # to these functions. |
| 138 | |
| 139 | # |
| 140 | # input: spec in the form of "src[:dst][;args]" |
| 141 | # output: "src" |
| 142 | # |
| 143 | function src_file() { |
| 144 | local SPEC="$1" |
| 145 | local SPLIT=(${SPEC//:/ }) |
| 146 | local ARGS="$(target_args ${SPEC})" |
| 147 | # Regardless of there being a ":" delimiter or not in the spec, |
| 148 | # the source file is always either the first, or the only entry. |
| 149 | local SRC="${SPLIT[0]}" |
| 150 | # Remove target_args suffix, if present |
| 151 | echo "${SRC%;${ARGS}}" |
| 152 | } |
| 153 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 154 | # |
| Vladimir Oltean | c70bc12 | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 155 | # input: spec in the form of "src[:dst][;args]" |
| 156 | # output: "dst" if present, "src" otherwise. |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 157 | # |
| 158 | function target_file() { |
| dianlujitao | 4918b8a | 2020-01-02 15:26:44 +0800 | [diff] [blame] | 159 | local SPEC="${1%%;*}" |
| Vladimir Oltean | c70bc12 | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 160 | local SPLIT=(${SPEC//:/ }) |
| 161 | local ARGS="$(target_args ${SPEC})" |
| 162 | local DST= |
| 163 | case ${#SPLIT[@]} in |
| 164 | 1) |
| 165 | # The spec doesn't have a : delimiter |
| 166 | DST="${SPLIT[0]}" |
| 167 | ;; |
| 168 | *) |
| 169 | # The spec actually has a src:dst format |
| 170 | DST="${SPLIT[1]}" |
| 171 | ;; |
| 172 | esac |
| 173 | # Remove target_args suffix, if present |
| 174 | echo "${DST%;${ARGS}}" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | # |
| Vladimir Oltean | c70bc12 | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 178 | # input: spec in the form of "src[:dst][;args]" |
| 179 | # output: "args" if present, "" otherwise. |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 180 | # |
| 181 | function target_args() { |
| Vladimir Oltean | c70bc12 | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 182 | local SPEC="$1" |
| 183 | local SPLIT=(${SPEC//;/ }) |
| 184 | local ARGS= |
| 185 | case ${#SPLIT[@]} in |
| 186 | 1) |
| 187 | # No ";" delimiter in the spec. |
| 188 | ;; |
| 189 | *) |
| 190 | # The "args" are whatever comes after the ";" character. |
| 191 | # Basically the spec stripped of whatever is to the left of ";". |
| 192 | ARGS="${SPEC#${SPLIT[0]};}" |
| 193 | ;; |
| 194 | esac |
| 195 | echo "${ARGS}" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | # |
| 199 | # prefix_match: |
| 200 | # |
| Vladimir Oltean | 011b6b6 | 2018-06-12 01:17:35 +0300 | [diff] [blame] | 201 | # input: |
| 202 | # - $1: prefix |
| 203 | # - (global variable) PRODUCT_PACKAGES_LIST: array of [src:]dst[;args] specs. |
| 204 | # output: |
| 205 | # - new array consisting of dst[;args] entries where $1 is a prefix of ${dst}. |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 206 | # |
| 207 | function prefix_match() { |
| 208 | local PREFIX="$1" |
| Sebastiano Barezzi | df527c7 | 2022-03-25 16:59:58 +0100 | [diff] [blame] | 209 | local NEW_ARRAY=() |
| Vladimir Oltean | 7220f36 | 2018-04-02 22:37:09 +0300 | [diff] [blame] | 210 | for LINE in "${PRODUCT_PACKAGES_LIST[@]}"; do |
| 211 | local FILE=$(target_file "$LINE") |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 212 | if [[ "$FILE" =~ ^"$PREFIX" ]]; then |
| Vladimir Oltean | 011b6b6 | 2018-06-12 01:17:35 +0300 | [diff] [blame] | 213 | local ARGS=$(target_args "$LINE") |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 214 | if [[ -z "${ARGS}" || "${ARGS}" =~ 'SYMLINK' ]]; then |
| Sebastiano Barezzi | df527c7 | 2022-03-25 16:59:58 +0100 | [diff] [blame] | 215 | NEW_ARRAY+=("${FILE#$PREFIX}") |
| Vladimir Oltean | 011b6b6 | 2018-06-12 01:17:35 +0300 | [diff] [blame] | 216 | else |
| Sebastiano Barezzi | df527c7 | 2022-03-25 16:59:58 +0100 | [diff] [blame] | 217 | NEW_ARRAY+=("${FILE#$PREFIX};${ARGS}") |
| Vladimir Oltean | 011b6b6 | 2018-06-12 01:17:35 +0300 | [diff] [blame] | 218 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 219 | fi |
| 220 | done |
| Sebastiano Barezzi | df527c7 | 2022-03-25 16:59:58 +0100 | [diff] [blame] | 221 | printf '%s\n' "${NEW_ARRAY[@]}" | LC_ALL=C sort |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | # |
| Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 225 | # prefix_match_file: |
| 226 | # |
| 227 | # $1: the prefix to match on |
| 228 | # $2: the file to match the prefix for |
| 229 | # |
| 230 | # Internal function which returns true if a filename contains the |
| 231 | # specified prefix. |
| 232 | # |
| 233 | function prefix_match_file() { |
| 234 | local PREFIX="$1" |
| 235 | local FILE="$2" |
| 236 | if [[ "$FILE" =~ ^"$PREFIX" ]]; then |
| 237 | return 0 |
| 238 | else |
| 239 | return 1 |
| 240 | fi |
| 241 | } |
| 242 | |
| 243 | # |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 244 | # suffix_match_file: |
| 245 | # |
| 246 | # $1: the suffix to match on |
| 247 | # $2: the file to match the suffix for |
| 248 | # |
| 249 | # Internal function which returns true if a filename contains the |
| 250 | # specified suffix. |
| 251 | # |
| 252 | function suffix_match_file() { |
| 253 | local SUFFIX="$1" |
| 254 | local FILE="$2" |
| 255 | if [[ "$FILE" = *"$SUFFIX" ]]; then |
| 256 | return 0 |
| 257 | else |
| 258 | return 1 |
| 259 | fi |
| 260 | } |
| 261 | |
| 262 | # |
| Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 263 | # truncate_file |
| 264 | # |
| 265 | # $1: the filename to truncate |
| 266 | # $2: the argument to output the truncated filename to |
| 267 | # |
| 268 | # Internal function which truncates a filename by removing the first dir |
| 269 | # in the path. ex. vendor/lib/libsdmextension.so -> lib/libsdmextension.so |
| 270 | # |
| 271 | function truncate_file() { |
| 272 | local FILE="$1" |
| 273 | RETURN_FILE="$2" |
| 274 | local FIND="${FILE%%/*}" |
| 275 | local LOCATION="${#FIND}+1" |
| 276 | echo ${FILE:$LOCATION} |
| 277 | } |
| 278 | |
| 279 | # |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 280 | # write_product_copy_files: |
| 281 | # |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 282 | # $1: make treble compatible makefile - optional and deprecated, default to true |
| Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 283 | # |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 284 | # Creates the PRODUCT_COPY_FILES section in the product makefile for all |
| 285 | # items in the list which do not start with a dash (-). |
| 286 | # |
| 287 | function write_product_copy_files() { |
| 288 | local COUNT=${#PRODUCT_COPY_FILES_LIST[@]} |
| 289 | local TARGET= |
| 290 | local FILE= |
| 291 | local LINEEND= |
| Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 292 | local TREBLE_COMPAT=$1 |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 293 | |
| 294 | if [ "$COUNT" -eq "0" ]; then |
| 295 | return 0 |
| 296 | fi |
| 297 | |
| 298 | printf '%s\n' "PRODUCT_COPY_FILES += \\" >> "$PRODUCTMK" |
| 299 | for (( i=1; i<COUNT+1; i++ )); do |
| 300 | FILE="${PRODUCT_COPY_FILES_LIST[$i-1]}" |
| 301 | LINEEND=" \\" |
| 302 | if [ "$i" -eq "$COUNT" ]; then |
| 303 | LINEEND="" |
| 304 | fi |
| 305 | |
| Vladimir Oltean | c70bc12 | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 306 | TARGET=$(target_file "$FILE") |
| Rashed Abdel-Tawab | 06688fc | 2019-10-05 00:09:41 -0400 | [diff] [blame] | 307 | if prefix_match_file "product/" $TARGET ; then |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 308 | local OUTTARGET=$(truncate_file $TARGET) |
| Rashed Abdel-Tawab | 06688fc | 2019-10-05 00:09:41 -0400 | [diff] [blame] | 309 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s%s\n' \ |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 310 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| Rashed Abdel-Tawab | 06688fc | 2019-10-05 00:09:41 -0400 | [diff] [blame] | 311 | elif prefix_match_file "system/product/" $TARGET ; then |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 312 | local OUTTARGET=$(truncate_file $TARGET) |
| 313 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s%s\n' \ |
| 314 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 315 | elif prefix_match_file "system_ext/" $TARGET ; then |
| 316 | local OUTTARGET=$(truncate_file $TARGET) |
| 317 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM_EXT)/%s%s\n' \ |
| 318 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| 319 | elif prefix_match_file "system/system_ext/" $TARGET ; then |
| 320 | local OUTTARGET=$(truncate_file $TARGET) |
| 321 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM_EXT)/%s%s\n' \ |
| 322 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 323 | elif prefix_match_file "odm/" $TARGET ; then |
| 324 | local OUTTARGET=$(truncate_file $TARGET) |
| 325 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \ |
| 326 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| Rashed Abdel-Tawab | 06688fc | 2019-10-05 00:09:41 -0400 | [diff] [blame] | 327 | elif prefix_match_file "vendor/odm/" $TARGET ; then |
| 328 | local OUTTARGET=$(truncate_file $TARGET) |
| 329 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \ |
| 330 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| 331 | elif prefix_match_file "system/vendor/odm/" $TARGET ; then |
| 332 | local OUTTARGET=$(truncate_file $TARGET) |
| 333 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \ |
| 334 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| 335 | elif prefix_match_file "vendor/" $TARGET ; then |
| 336 | local OUTTARGET=$(truncate_file $TARGET) |
| 337 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR)/%s%s\n' \ |
| 338 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| Alexander Koskovich | 44c8fac | 2022-01-22 22:27:29 -0700 | [diff] [blame] | 339 | elif prefix_match_file "vendor_dlkm/" $TARGET ; then |
| 340 | local OUTTARGET=$(truncate_file $TARGET) |
| 341 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR_DLKM)/%s%s\n' \ |
| 342 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| Rashed Abdel-Tawab | 06688fc | 2019-10-05 00:09:41 -0400 | [diff] [blame] | 343 | elif prefix_match_file "system/vendor/" $TARGET ; then |
| 344 | local OUTTARGET=$(truncate_file $TARGET) |
| 345 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR)/%s%s\n' \ |
| 346 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 347 | elif prefix_match_file "system/" $TARGET ; then |
| 348 | local OUTTARGET=$(truncate_file $TARGET) |
| 349 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM)/%s%s\n' \ |
| 350 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| Mohd Faraz | d683fe4 | 2022-07-23 14:33:59 +0200 | [diff] [blame] | 351 | elif prefix_match_file "recovery/" $TARGET ; then |
| 352 | local OUTTARGET=$(truncate_file $TARGET) |
| 353 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_RECOVERY)/%s%s\n' \ |
| 354 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| 355 | elif prefix_match_file "vendor_ramdisk/" $TARGET ; then |
| 356 | local OUTTARGET=$(truncate_file $TARGET) |
| 357 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR_RAMDISK)/%s%s\n' \ |
| 358 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 359 | else |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 360 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM)/%s%s\n' \ |
| Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 361 | "$OUTDIR" "$TARGET" "$TARGET" "$LINEEND" >> "$PRODUCTMK" |
| 362 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 363 | done |
| 364 | return 0 |
| 365 | } |
| 366 | |
| 367 | # |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 368 | # write_blueprint_packages: |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 369 | # |
| 370 | # $1: The LOCAL_MODULE_CLASS for the given module list |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 371 | # $2: /system, /odm, /product, /system_ext, or /vendor partition |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 372 | # $3: type-specific extra flags |
| 373 | # $4: Name of the array holding the target list |
| 374 | # |
| 375 | # Internal function which writes out the BUILD_PREBUILT stanzas |
| 376 | # for all modules in the list. This is called by write_product_packages |
| 377 | # after the modules are categorized. |
| 378 | # |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 379 | function write_blueprint_packages() { |
| 380 | |
| 381 | local CLASS="$1" |
| 382 | local PARTITION="$2" |
| 383 | local EXTRA="$3" |
| 384 | |
| 385 | # Yes, this is a horrible hack - we create a new array using indirection |
| 386 | local ARR_NAME="$4[@]" |
| 387 | local FILELIST=("${!ARR_NAME}") |
| 388 | |
| 389 | local FILE= |
| 390 | local ARGS= |
| 391 | local BASENAME= |
| 392 | local EXTENSION= |
| 393 | local PKGNAME= |
| 394 | local SRC= |
| Tim Zimmermann | d932076 | 2021-12-23 07:06:17 +0100 | [diff] [blame] | 395 | local STEM= |
| TheStrix | 6e24acc | 2020-04-10 18:20:19 +0530 | [diff] [blame] | 396 | local OVERRIDEPKG= |
| SamarV-121 | 7e6b408 | 2024-02-26 14:39:34 +0530 | [diff] [blame] | 397 | local REQUIREDPKG= |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 398 | |
| 399 | for P in "${FILELIST[@]}"; do |
| 400 | FILE=$(target_file "$P") |
| 401 | ARGS=$(target_args "$P") |
| Tim Zimmermann | d932076 | 2021-12-23 07:06:17 +0100 | [diff] [blame] | 402 | ARGS=(${ARGS//;/ }) |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 403 | |
| 404 | BASENAME=$(basename "$FILE") |
| 405 | DIRNAME=$(dirname "$FILE") |
| 406 | EXTENSION=${BASENAME##*.} |
| 407 | PKGNAME=${BASENAME%.*} |
| 408 | |
| Tim Zimmermann | e93bb1b | 2021-12-23 10:15:26 +0100 | [diff] [blame] | 409 | if [ "$CLASS" = "EXECUTABLES" ] && [ "$EXTENSION" != "sh" ]; then |
| 410 | PKGNAME="$BASENAME" |
| 411 | EXTENSION="" |
| 412 | fi |
| 413 | |
| Tim Zimmermann | d932076 | 2021-12-23 07:06:17 +0100 | [diff] [blame] | 414 | # Allow overriding module name |
| 415 | STEM= |
| 416 | for ARG in "${ARGS[@]}"; do |
| 417 | if [[ "$ARG" =~ "MODULE" ]]; then |
| 418 | STEM="$PKGNAME" |
| 419 | PKGNAME=${ARG#*=} |
| 420 | fi |
| 421 | done |
| 422 | |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 423 | # Add to final package list |
| 424 | PACKAGE_LIST+=("$PKGNAME") |
| 425 | |
| 426 | SRC="proprietary" |
| 427 | if [ "$PARTITION" = "system" ]; then |
| 428 | SRC+="/system" |
| 429 | elif [ "$PARTITION" = "vendor" ]; then |
| 430 | SRC+="/vendor" |
| 431 | elif [ "$PARTITION" = "product" ]; then |
| 432 | SRC+="/product" |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 433 | elif [ "$PARTITION" = "system_ext" ]; then |
| 434 | SRC+="/system_ext" |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 435 | elif [ "$PARTITION" = "odm" ]; then |
| 436 | SRC+="/odm" |
| 437 | fi |
| 438 | |
| 439 | if [ "$CLASS" = "SHARED_LIBRARIES" ]; then |
| 440 | printf 'cc_prebuilt_library_shared {\n' |
| 441 | printf '\tname: "%s",\n' "$PKGNAME" |
| Tim Zimmermann | d932076 | 2021-12-23 07:06:17 +0100 | [diff] [blame] | 442 | if [ ! -z "$STEM" ]; then |
| 443 | printf '\tstem: "%s",\n' "$STEM" |
| 444 | fi |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 445 | printf '\towner: "%s",\n' "$VENDOR" |
| 446 | printf '\tstrip: {\n' |
| 447 | printf '\t\tnone: true,\n' |
| 448 | printf '\t},\n' |
| 449 | printf '\ttarget: {\n' |
| 450 | if [ "$EXTRA" = "both" ]; then |
| 451 | printf '\t\tandroid_arm: {\n' |
| 452 | printf '\t\t\tsrcs: ["%s/lib/%s"],\n' "$SRC" "$FILE" |
| 453 | printf '\t\t},\n' |
| 454 | printf '\t\tandroid_arm64: {\n' |
| 455 | printf '\t\t\tsrcs: ["%s/lib64/%s"],\n' "$SRC" "$FILE" |
| 456 | printf '\t\t},\n' |
| 457 | elif [ "$EXTRA" = "64" ]; then |
| 458 | printf '\t\tandroid_arm64: {\n' |
| 459 | printf '\t\t\tsrcs: ["%s/lib64/%s"],\n' "$SRC" "$FILE" |
| 460 | printf '\t\t},\n' |
| 461 | else |
| 462 | printf '\t\tandroid_arm: {\n' |
| 463 | printf '\t\t\tsrcs: ["%s/lib/%s"],\n' "$SRC" "$FILE" |
| 464 | printf '\t\t},\n' |
| 465 | fi |
| 466 | printf '\t},\n' |
| 467 | if [ "$EXTRA" != "none" ]; then |
| 468 | printf '\tcompile_multilib: "%s",\n' "$EXTRA" |
| 469 | fi |
| dianlujitao | 848101c | 2020-09-12 00:15:13 +0800 | [diff] [blame] | 470 | printf '\tcheck_elf_files: false,\n' |
| Chirayu Desai | a774101 | 2021-12-04 07:17:28 +0530 | [diff] [blame] | 471 | elif [ "$CLASS" = "APEX" ]; then |
| 472 | printf 'prebuilt_apex {\n' |
| 473 | printf '\tname: "%s",\n' "$PKGNAME" |
| 474 | printf '\towner: "%s",\n' "$VENDOR" |
| 475 | SRC="$SRC/apex" |
| 476 | printf '\tsrc: "%s/%s",\n' "$SRC" "$FILE" |
| 477 | printf '\tfilename: "%s",\n' "$FILE" |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 478 | elif [ "$CLASS" = "APPS" ]; then |
| 479 | printf 'android_app_import {\n' |
| 480 | printf '\tname: "%s",\n' "$PKGNAME" |
| 481 | printf '\towner: "%s",\n' "$VENDOR" |
| 482 | if [ "$EXTRA" = "priv-app" ]; then |
| 483 | SRC="$SRC/priv-app" |
| 484 | else |
| 485 | SRC="$SRC/app" |
| 486 | fi |
| 487 | printf '\tapk: "%s/%s",\n' "$SRC" "$FILE" |
| LuK1337 | 508e85f | 2021-08-23 18:18:57 +0200 | [diff] [blame] | 488 | USE_PLATFORM_CERTIFICATE="true" |
| 489 | for ARG in "${ARGS[@]}"; do |
| 490 | if [ "$ARG" = "PRESIGNED" ]; then |
| 491 | USE_PLATFORM_CERTIFICATE="false" |
| Michael Bestas | ab47e91 | 2024-03-06 13:32:05 +0200 | [diff] [blame] | 492 | printf '\tpreprocessed: true,\n' |
| LuK1337 | 508e85f | 2021-08-23 18:18:57 +0200 | [diff] [blame] | 493 | printf '\tpresigned: true,\n' |
| 494 | elif [[ "$ARG" =~ "OVERRIDES" ]]; then |
| 495 | OVERRIDEPKG=${ARG#*=} |
| Arian | 72ac836 | 2021-09-27 17:49:19 +0200 | [diff] [blame] | 496 | OVERRIDEPKG=${OVERRIDEPKG//,/\", \"} |
| LuK1337 | 508e85f | 2021-08-23 18:18:57 +0200 | [diff] [blame] | 497 | printf '\toverrides: ["%s"],\n' "$OVERRIDEPKG" |
| SamarV-121 | 7e6b408 | 2024-02-26 14:39:34 +0530 | [diff] [blame] | 498 | elif [[ "$ARG" =~ "REQUIRED" ]]; then |
| 499 | REQUIREDPKG=${ARG#*=} |
| 500 | REQUIRED_PACKAGES_LIST+="$REQUIREDPKG," |
| 501 | printf '\trequired: ["%s"],\n' "${REQUIREDPKG//,/\", \"}" |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 502 | elif [[ "$ARG" =~ "SYMLINK" ]]; then |
| 503 | continue |
| LuK1337 | 508e85f | 2021-08-23 18:18:57 +0200 | [diff] [blame] | 504 | elif [ ! -z "$ARG" ]; then |
| 505 | USE_PLATFORM_CERTIFICATE="false" |
| 506 | printf '\tcertificate: "%s",\n' "$ARG" |
| 507 | fi |
| 508 | done |
| 509 | if [ "$USE_PLATFORM_CERTIFICATE" = "true" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 510 | printf '\tcertificate: "platform",\n' |
| 511 | fi |
| 512 | elif [ "$CLASS" = "JAVA_LIBRARIES" ]; then |
| 513 | printf 'dex_import {\n' |
| 514 | printf '\tname: "%s",\n' "$PKGNAME" |
| 515 | printf '\towner: "%s",\n' "$VENDOR" |
| 516 | printf '\tjars: ["%s/framework/%s"],\n' "$SRC" "$FILE" |
| 517 | elif [ "$CLASS" = "ETC" ]; then |
| 518 | if [ "$EXTENSION" = "xml" ]; then |
| 519 | printf 'prebuilt_etc_xml {\n' |
| 520 | else |
| 521 | printf 'prebuilt_etc {\n' |
| 522 | fi |
| 523 | printf '\tname: "%s",\n' "$PKGNAME" |
| 524 | printf '\towner: "%s",\n' "$VENDOR" |
| 525 | printf '\tsrc: "%s/etc/%s",\n' "$SRC" "$FILE" |
| LuK1337 | f7f1871 | 2020-10-06 19:29:02 +0200 | [diff] [blame] | 526 | printf '\tfilename_from_src: true,\n' |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 527 | elif [ "$CLASS" = "EXECUTABLES" ]; then |
| 528 | if [ "$EXTENSION" = "sh" ]; then |
| 529 | printf 'sh_binary {\n' |
| 530 | else |
| 531 | printf 'cc_prebuilt_binary {\n' |
| 532 | fi |
| 533 | printf '\tname: "%s",\n' "$PKGNAME" |
| 534 | printf '\towner: "%s",\n' "$VENDOR" |
| Sebastiano Barezzi | fd4b2b3 | 2021-07-14 21:33:10 +0200 | [diff] [blame] | 535 | if [ "$EXTENSION" != "sh" ]; then |
| Mohd Faraz | 2509b6e | 2022-10-02 09:48:52 +0200 | [diff] [blame] | 536 | printf '\tsrcs: ["%s/bin/%s"],\n' "$SRC" "$FILE" |
| Sebastiano Barezzi | fd4b2b3 | 2021-07-14 21:33:10 +0200 | [diff] [blame] | 537 | printf '\tcheck_elf_files: false,\n' |
| Tim Zimmermann | 54606d6 | 2021-12-23 09:26:54 +0100 | [diff] [blame] | 538 | printf '\tstrip: {\n' |
| 539 | printf '\t\tnone: true,\n' |
| 540 | printf '\t},\n' |
| Mohd Faraz | 2509b6e | 2022-10-02 09:48:52 +0200 | [diff] [blame] | 541 | printf '\tprefer: true,\n' |
| 542 | else |
| 543 | printf '\tsrc: "%s/bin/%s",\n' "$SRC" "$FILE" |
| Sebastiano Barezzi | fd4b2b3 | 2021-07-14 21:33:10 +0200 | [diff] [blame] | 544 | fi |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 545 | unset EXTENSION |
| 546 | else |
| 547 | printf '\tsrcs: ["%s/%s"],\n' "$SRC" "$FILE" |
| 548 | fi |
| 549 | if [ "$CLASS" = "APPS" ]; then |
| 550 | printf '\tdex_preopt: {\n' |
| 551 | printf '\t\tenabled: false,\n' |
| 552 | printf '\t},\n' |
| Jyotiraditya Panda | 45f50af | 2024-02-19 05:35:33 +0900 | [diff] [blame] | 553 | if [ "$DIRNAME" != "." ] && [[ "$DIRNAME" == */* ]]; then |
| 554 | printf '\trelative_install_path: "%s",\n' "$DIRNAME" |
| 555 | fi |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 556 | fi |
| Andreas Schneider | dbcf9db | 2020-05-25 17:03:17 +0200 | [diff] [blame] | 557 | if [ "$CLASS" = "SHARED_LIBRARIES" ] || [ "$CLASS" = "EXECUTABLES" ] ; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 558 | if [ "$DIRNAME" != "." ]; then |
| Andreas Schneider | 408526a | 2020-05-23 15:58:43 +0200 | [diff] [blame] | 559 | printf '\trelative_install_path: "%s",\n' "$DIRNAME" |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 560 | fi |
| 561 | fi |
| Andreas Schneider | dbcf9db | 2020-05-25 17:03:17 +0200 | [diff] [blame] | 562 | if [ "$CLASS" = "ETC" ] ; then |
| 563 | if [ "$DIRNAME" != "." ]; then |
| 564 | printf '\tsub_dir: "%s",\n' "$DIRNAME" |
| 565 | fi |
| 566 | fi |
| Mohd Faraz | 2509b6e | 2022-10-02 09:48:52 +0200 | [diff] [blame] | 567 | if [ "$CLASS" = "SHARED_LIBRARIES" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 568 | printf '\tprefer: true,\n' |
| 569 | fi |
| 570 | if [ "$EXTRA" = "priv-app" ]; then |
| 571 | printf '\tprivileged: true,\n' |
| 572 | fi |
| 573 | if [ "$PARTITION" = "vendor" ]; then |
| 574 | printf '\tsoc_specific: true,\n' |
| 575 | elif [ "$PARTITION" = "product" ]; then |
| 576 | printf '\tproduct_specific: true,\n' |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 577 | elif [ "$PARTITION" = "system_ext" ]; then |
| 578 | printf '\tsystem_ext_specific: true,\n' |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 579 | elif [ "$PARTITION" = "odm" ]; then |
| 580 | printf '\tdevice_specific: true,\n' |
| 581 | fi |
| 582 | printf '}\n\n' |
| 583 | done |
| 584 | } |
| 585 | |
| 586 | # |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 587 | # write_product_packages: |
| 588 | # |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 589 | # This function will create prebuilt entries in the |
| 590 | # Android.bp and associated PRODUCT_PACKAGES list in the |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 591 | # product makefile for all files in the blob list which |
| 592 | # start with a single dash (-) character. |
| 593 | # |
| 594 | function write_product_packages() { |
| 595 | PACKAGE_LIST=() |
| 596 | |
| Chenyang Zhong | c487f38 | 2022-02-10 21:40:41 -0500 | [diff] [blame] | 597 | # Sort the package list for comm |
| 598 | PRODUCT_PACKAGES_LIST=($( printf '%s\n' "${PRODUCT_PACKAGES_LIST[@]}" | LC_ALL=C sort)) |
| 599 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 600 | local COUNT=${#PRODUCT_PACKAGES_LIST[@]} |
| 601 | |
| 602 | if [ "$COUNT" = "0" ]; then |
| 603 | return 0 |
| 604 | fi |
| 605 | |
| 606 | # Figure out what's 32-bit, what's 64-bit, and what's multilib |
| 607 | # I really should not be doing this in bash due to shitty array passing :( |
| 608 | local T_LIB32=( $(prefix_match "lib/") ) |
| 609 | local T_LIB64=( $(prefix_match "lib64/") ) |
| Pablo Cholaky | 32d80cf | 2022-01-16 13:52:07 -0500 | [diff] [blame] | 610 | local MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${T_LIB64[@]}")) ) |
| 611 | local LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${MULTILIBS[@]}")) ) |
| 612 | local LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_LIB64[@]}") <(printf '%s\n' "${MULTILIBS[@]}")) ) |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 613 | |
| 614 | if [ "${#MULTILIBS[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 615 | write_blueprint_packages "SHARED_LIBRARIES" "" "both" "MULTILIBS" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 616 | fi |
| 617 | if [ "${#LIB32[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 618 | write_blueprint_packages "SHARED_LIBRARIES" "" "32" "LIB32" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 619 | fi |
| 620 | if [ "${#LIB64[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 621 | write_blueprint_packages "SHARED_LIBRARIES" "" "64" "LIB64" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 622 | fi |
| 623 | |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 624 | local T_S_LIB32=( $(prefix_match "system/lib/") ) |
| 625 | local T_S_LIB64=( $(prefix_match "system/lib64/") ) |
| Pablo Cholaky | 32d80cf | 2022-01-16 13:52:07 -0500 | [diff] [blame] | 626 | local S_MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_S_LIB32[@]}") <(printf '%s\n' "${T_S_LIB64[@]}")) ) |
| 627 | local S_LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_S_LIB32[@]}") <(printf '%s\n' "${S_MULTILIBS[@]}")) ) |
| 628 | local S_LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_S_LIB64[@]}") <(printf '%s\n' "${S_MULTILIBS[@]}")) ) |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 629 | |
| 630 | if [ "${#S_MULTILIBS[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 631 | write_blueprint_packages "SHARED_LIBRARIES" "system" "both" "S_MULTILIBS" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 632 | fi |
| 633 | if [ "${#S_LIB32[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 634 | write_blueprint_packages "SHARED_LIBRARIES" "system" "32" "S_LIB32" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 635 | fi |
| 636 | if [ "${#S_LIB64[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 637 | write_blueprint_packages "SHARED_LIBRARIES" "system" "64" "S_LIB64" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 638 | fi |
| 639 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 640 | local T_V_LIB32=( $(prefix_match "vendor/lib/") ) |
| 641 | local T_V_LIB64=( $(prefix_match "vendor/lib64/") ) |
| Pablo Cholaky | 32d80cf | 2022-01-16 13:52:07 -0500 | [diff] [blame] | 642 | local V_MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${T_V_LIB64[@]}")) ) |
| 643 | local V_LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${V_MULTILIBS[@]}")) ) |
| 644 | local V_LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_V_LIB64[@]}") <(printf '%s\n' "${V_MULTILIBS[@]}")) ) |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 645 | |
| 646 | if [ "${#V_MULTILIBS[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 647 | write_blueprint_packages "SHARED_LIBRARIES" "vendor" "both" "V_MULTILIBS" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 648 | fi |
| 649 | if [ "${#V_LIB32[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 650 | write_blueprint_packages "SHARED_LIBRARIES" "vendor" "32" "V_LIB32" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 651 | fi |
| 652 | if [ "${#V_LIB64[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 653 | write_blueprint_packages "SHARED_LIBRARIES" "vendor" "64" "V_LIB64" >> "$ANDROIDBP" |
| razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 654 | fi |
| 655 | |
| 656 | local T_P_LIB32=( $(prefix_match "product/lib/") ) |
| 657 | local T_P_LIB64=( $(prefix_match "product/lib64/") ) |
| Pablo Cholaky | 32d80cf | 2022-01-16 13:52:07 -0500 | [diff] [blame] | 658 | local P_MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_P_LIB32[@]}") <(printf '%s\n' "${T_P_LIB64[@]}")) ) |
| 659 | local P_LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_P_LIB32[@]}") <(printf '%s\n' "${P_MULTILIBS[@]}")) ) |
| 660 | local P_LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_P_LIB64[@]}") <(printf '%s\n' "${P_MULTILIBS[@]}")) ) |
| razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 661 | |
| 662 | if [ "${#P_MULTILIBS[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 663 | write_blueprint_packages "SHARED_LIBRARIES" "product" "both" "P_MULTILIBS" >> "$ANDROIDBP" |
| razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 664 | fi |
| 665 | if [ "${#P_LIB32[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 666 | write_blueprint_packages "SHARED_LIBRARIES" "product" "32" "P_LIB32" >> "$ANDROIDBP" |
| razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 667 | fi |
| 668 | if [ "${#P_LIB64[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 669 | write_blueprint_packages "SHARED_LIBRARIES" "product" "64" "P_LIB64" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 670 | fi |
| 671 | |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 672 | local T_SE_LIB32=( $(prefix_match "system_ext/lib/") ) |
| 673 | local T_SE_LIB64=( $(prefix_match "system_ext/lib64/") ) |
| Pablo Cholaky | 32d80cf | 2022-01-16 13:52:07 -0500 | [diff] [blame] | 674 | local SE_MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_SE_LIB32[@]}") <(printf '%s\n' "${T_SE_LIB64[@]}")) ) |
| 675 | local SE_LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_SE_LIB32[@]}") <(printf '%s\n' "${SE_MULTILIBS[@]}")) ) |
| 676 | local SE_LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_SE_LIB64[@]}") <(printf '%s\n' "${SE_MULTILIBS[@]}")) ) |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 677 | |
| 678 | if [ "${#SE_MULTILIBS[@]}" -gt "0" ]; then |
| 679 | write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "both" "SE_MULTILIBS" >> "$ANDROIDBP" |
| 680 | fi |
| 681 | if [ "${#SE_LIB32[@]}" -gt "0" ]; then |
| 682 | write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "32" "SE_LIB32" >> "$ANDROIDBP" |
| 683 | fi |
| 684 | if [ "${#SE_LIB64[@]}" -gt "0" ]; then |
| 685 | write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "64" "SE_LIB64" >> "$ANDROIDBP" |
| 686 | fi |
| 687 | |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 688 | local T_O_LIB32=( $(prefix_match "odm/lib/") ) |
| 689 | local T_O_LIB64=( $(prefix_match "odm/lib64/") ) |
| Pablo Cholaky | 32d80cf | 2022-01-16 13:52:07 -0500 | [diff] [blame] | 690 | local O_MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_O_LIB32[@]}") <(printf '%s\n' "${T_O_LIB64[@]}")) ) |
| 691 | local O_LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_O_LIB32[@]}") <(printf '%s\n' "${O_MULTILIBS[@]}")) ) |
| 692 | local O_LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_O_LIB64[@]}") <(printf '%s\n' "${O_MULTILIBS[@]}")) ) |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 693 | |
| 694 | if [ "${#O_MULTILIBS[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 695 | write_blueprint_packages "SHARED_LIBRARIES" "odm" "both" "O_MULTILIBS" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 696 | fi |
| 697 | if [ "${#O_LIB32[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 698 | write_blueprint_packages "SHARED_LIBRARIES" "odm" "32" "O_LIB32" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 699 | fi |
| 700 | if [ "${#O_LIB64[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 701 | write_blueprint_packages "SHARED_LIBRARIES" "odm" "64" "O_LIB64" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 702 | fi |
| 703 | |
| Chirayu Desai | a774101 | 2021-12-04 07:17:28 +0530 | [diff] [blame] | 704 | # APEX |
| 705 | local APEX=( $(prefix_match "apex/") ) |
| 706 | if [ "${#APEX[@]}" -gt "0" ]; then |
| 707 | write_blueprint_packages "APEX" "" "" "APEX" >> "$ANDROIDBP" |
| 708 | fi |
| 709 | local S_APEX=( $(prefix_match "system/apex/") ) |
| 710 | if [ "${#S_APEX[@]}" -gt "0" ]; then |
| 711 | write_blueprint_packages "APEX" "system" "" "S_APEX" >> "$ANDROIDBP" |
| 712 | fi |
| 713 | local V_APEX=( $(prefix_match "vendor/apex/") ) |
| 714 | if [ "${#V_APEX[@]}" -gt "0" ]; then |
| 715 | write_blueprint_packages "APEX" "vendor" "" "V_APEX" >> "$ANDROIDBP" |
| 716 | fi |
| 717 | local SE_APEX=( $(prefix_match "system_ext/apex/") ) |
| 718 | if [ "${#SE_APEX[@]}" -gt "0" ]; then |
| 719 | write_blueprint_packages "APEX" "system_ext" "" "SE_APEX" >> "$ANDROIDBP" |
| 720 | fi |
| 721 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 722 | # Apps |
| 723 | local APPS=( $(prefix_match "app/") ) |
| 724 | if [ "${#APPS[@]}" -gt "0" ]; then |
| mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 725 | write_blueprint_packages "APPS" "" "" "APPS" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 726 | fi |
| 727 | local PRIV_APPS=( $(prefix_match "priv-app/") ) |
| 728 | if [ "${#PRIV_APPS[@]}" -gt "0" ]; then |
| mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 729 | write_blueprint_packages "APPS" "" "priv-app" "PRIV_APPS" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 730 | fi |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 731 | local S_APPS=( $(prefix_match "system/app/") ) |
| 732 | if [ "${#S_APPS[@]}" -gt "0" ]; then |
| mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 733 | write_blueprint_packages "APPS" "system" "" "S_APPS" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 734 | fi |
| 735 | local S_PRIV_APPS=( $(prefix_match "system/priv-app/") ) |
| 736 | if [ "${#S_PRIV_APPS[@]}" -gt "0" ]; then |
| mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 737 | write_blueprint_packages "APPS" "system" "priv-app" "S_PRIV_APPS" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 738 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 739 | local V_APPS=( $(prefix_match "vendor/app/") ) |
| 740 | if [ "${#V_APPS[@]}" -gt "0" ]; then |
| mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 741 | write_blueprint_packages "APPS" "vendor" "" "V_APPS" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 742 | fi |
| 743 | local V_PRIV_APPS=( $(prefix_match "vendor/priv-app/") ) |
| 744 | if [ "${#V_PRIV_APPS[@]}" -gt "0" ]; then |
| mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 745 | write_blueprint_packages "APPS" "vendor" "priv-app" "V_PRIV_APPS" >> "$ANDROIDBP" |
| razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 746 | fi |
| 747 | local P_APPS=( $(prefix_match "product/app/") ) |
| 748 | if [ "${#P_APPS[@]}" -gt "0" ]; then |
| mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 749 | write_blueprint_packages "APPS" "product" "" "P_APPS" >> "$ANDROIDBP" |
| razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 750 | fi |
| 751 | local P_PRIV_APPS=( $(prefix_match "product/priv-app/") ) |
| 752 | if [ "${#P_PRIV_APPS[@]}" -gt "0" ]; then |
| mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 753 | write_blueprint_packages "APPS" "product" "priv-app" "P_PRIV_APPS" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 754 | fi |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 755 | local SE_APPS=( $(prefix_match "system_ext/app/") ) |
| 756 | if [ "${#SE_APPS[@]}" -gt "0" ]; then |
| 757 | write_blueprint_packages "APPS" "system_ext" "" "SE_APPS" >> "$ANDROIDBP" |
| 758 | fi |
| 759 | local SE_PRIV_APPS=( $(prefix_match "system_ext/priv-app/") ) |
| 760 | if [ "${#SE_PRIV_APPS[@]}" -gt "0" ]; then |
| 761 | write_blueprint_packages "APPS" "system_ext" "priv-app" "SE_PRIV_APPS" >> "$ANDROIDBP" |
| 762 | fi |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 763 | local O_APPS=( $(prefix_match "odm/app/") ) |
| 764 | if [ "${#O_APPS[@]}" -gt "0" ]; then |
| mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 765 | write_blueprint_packages "APPS" "odm" "" "O_APPS" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 766 | fi |
| 767 | local O_PRIV_APPS=( $(prefix_match "odm/priv-app/") ) |
| 768 | if [ "${#O_PRIV_APPS[@]}" -gt "0" ]; then |
| mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 769 | write_blueprint_packages "APPS" "odm" "priv-app" "O_PRIV_APPS" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 770 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 771 | |
| 772 | # Framework |
| 773 | local FRAMEWORK=( $(prefix_match "framework/") ) |
| 774 | if [ "${#FRAMEWORK[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 775 | write_blueprint_packages "JAVA_LIBRARIES" "" "" "FRAMEWORK" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 776 | fi |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 777 | local S_FRAMEWORK=( $(prefix_match "system/framework/") ) |
| 778 | if [ "${#S_FRAMEWORK[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 779 | write_blueprint_packages "JAVA_LIBRARIES" "system" "" "S_FRAMEWORK" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 780 | fi |
| Christian Oder | 974b590 | 2017-10-08 23:15:52 +0200 | [diff] [blame] | 781 | local V_FRAMEWORK=( $(prefix_match "vendor/framework/") ) |
| Michael Bestas | 26eb01e | 2018-02-27 22:31:55 +0200 | [diff] [blame] | 782 | if [ "${#V_FRAMEWORK[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 783 | write_blueprint_packages "JAVA_LIBRARIES" "vendor" "" "V_FRAMEWORK" >> "$ANDROIDBP" |
| razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 784 | fi |
| 785 | local P_FRAMEWORK=( $(prefix_match "product/framework/") ) |
| 786 | if [ "${#P_FRAMEWORK[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 787 | write_blueprint_packages "JAVA_LIBRARIES" "product" "" "P_FRAMEWORK" >> "$ANDROIDBP" |
| Christian Oder | 974b590 | 2017-10-08 23:15:52 +0200 | [diff] [blame] | 788 | fi |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 789 | local SE_FRAMEWORK=( $(prefix_match "system_ext/framework/") ) |
| Alexander Koskovich | 052c77d | 2020-09-16 17:58:53 -0700 | [diff] [blame] | 790 | if [ "${#SE_FRAMEWORK[@]}" -gt "0" ]; then |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 791 | write_blueprint_packages "JAVA_LIBRARIES" "system_ext" "" "SE_FRAMEWORK" >> "$ANDROIDBP" |
| 792 | fi |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 793 | local O_FRAMEWORK=( $(prefix_match "odm/framework/") ) |
| 794 | if [ "${#O_FRAMEWORK[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 795 | write_blueprint_packages "JAVA_LIBRARIES" "odm" "" "O_FRAMEWORK" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 796 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 797 | |
| 798 | # Etc |
| 799 | local ETC=( $(prefix_match "etc/") ) |
| 800 | if [ "${#ETC[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 801 | write_blueprint_packages "ETC" "" "" "ETC" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 802 | fi |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 803 | local S_ETC=( $(prefix_match "system/etc/") ) |
| Luca Weiss | 737940e | 2022-09-27 14:52:41 +0200 | [diff] [blame] | 804 | if [ "${#S_ETC[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 805 | write_blueprint_packages "ETC" "system" "" "S_ETC" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 806 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 807 | local V_ETC=( $(prefix_match "vendor/etc/") ) |
| 808 | if [ "${#V_ETC[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 809 | write_blueprint_packages "ETC" "vendor" "" "V_ETC" >> "$ANDROIDBP" |
| razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 810 | fi |
| 811 | local P_ETC=( $(prefix_match "product/etc/") ) |
| 812 | if [ "${#P_ETC[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 813 | write_blueprint_packages "ETC" "product" "" "P_ETC" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 814 | fi |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 815 | local SE_ETC=( $(prefix_match "system_ext/etc/") ) |
| 816 | if [ "${#SE_ETC[@]}" -gt "0" ]; then |
| 817 | write_blueprint_packages "ETC" "system_ext" "" "SE_ETC" >> "$ANDROIDBP" |
| 818 | fi |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 819 | local O_ETC=( $(prefix_match "odm/etc/") ) |
| 820 | if [ "${#O_ETC[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 821 | write_blueprint_packages "ETC" "odm" "" "O_ETC" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 822 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 823 | |
| 824 | # Executables |
| 825 | local BIN=( $(prefix_match "bin/") ) |
| 826 | if [ "${#BIN[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 827 | write_blueprint_packages "EXECUTABLES" "" "" "BIN" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 828 | fi |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 829 | local S_BIN=( $(prefix_match "system/bin/") ) |
| Luca Weiss | 737940e | 2022-09-27 14:52:41 +0200 | [diff] [blame] | 830 | if [ "${#S_BIN[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 831 | write_blueprint_packages "EXECUTABLES" "system" "" "S_BIN" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 832 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 833 | local V_BIN=( $(prefix_match "vendor/bin/") ) |
| 834 | if [ "${#V_BIN[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 835 | write_blueprint_packages "EXECUTABLES" "vendor" "" "V_BIN" >> "$ANDROIDBP" |
| razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 836 | fi |
| 837 | local P_BIN=( $(prefix_match "product/bin/") ) |
| 838 | if [ "${#P_BIN[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 839 | write_blueprint_packages "EXECUTABLES" "product" "" "P_BIN" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 840 | fi |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 841 | local SE_BIN=( $(prefix_match "system_ext/bin/") ) |
| 842 | if [ "${#SE_BIN[@]}" -gt "0" ]; then |
| 843 | write_blueprint_packages "EXECUTABLES" "system_ext" "" "SE_BIN" >> "$ANDROIDBP" |
| 844 | fi |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 845 | local O_BIN=( $(prefix_match "odm/bin/") ) |
| 846 | if [ "${#O_BIN[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 847 | write_blueprint_packages "EXECUTABLES" "odm" "" "O_BIN" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 848 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 849 | |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 850 | write_package_definition "${PACKAGE_LIST[@]}" >> "$PRODUCTMK" |
| 851 | } |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 852 | |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 853 | |
| 854 | # |
| 855 | # write_symlink_packages: |
| 856 | # |
| 857 | # Creates symlink entries in the Android.bp and related PRODUCT_PACKAGES |
| 858 | # list in the product makefile for all files in the blob list which has |
| 859 | # SYMLINK argument. |
| 860 | # |
| 861 | function write_symlink_packages() { |
| 862 | local FILE= |
| 863 | local ARGS= |
| 864 | local ARCH= |
| 865 | local BASENAME= |
| 866 | local PKGNAME= |
| 867 | local PREFIX= |
| 868 | local SYMLINK_BASENAME= |
| 869 | local SYMLINK_PACKAGES=() |
| 870 | |
| 871 | # Sort the symlinks list for comm |
| 872 | PRODUCT_SYMLINKS_LIST=($( printf '%s\n' "${PRODUCT_SYMLINKS_LIST[@]}" | LC_ALL=C sort)) |
| 873 | |
| 874 | local COUNT=${#PRODUCT_SYMLINKS_LIST[@]} |
| 875 | |
| 876 | if [ "$COUNT" = "0" ]; then |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 877 | return 0 |
| 878 | fi |
| 879 | |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 880 | for LINE in "${PRODUCT_SYMLINKS_LIST[@]}"; do |
| Bruno Martins | be7f3cb | 2024-06-23 15:54:02 +0100 | [diff] [blame] | 881 | FILE=$(target_file "$LINE") |
| Bruno Martins | f96fd12 | 2024-03-28 14:31:02 +0000 | [diff] [blame] | 882 | if [[ "$LINE" =~ '/lib64/' || "$LINE" =~ '/lib/arm64/' ]]; then |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 883 | ARCH="64" |
| Bruno Martins | f96fd12 | 2024-03-28 14:31:02 +0000 | [diff] [blame] | 884 | elif [[ "$LINE" =~ '/lib/' ]]; then |
| 885 | ARCH="32" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 886 | fi |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 887 | BASENAME=$(basename "$FILE") |
| 888 | ARGS=$(target_args "$LINE") |
| 889 | ARGS=(${ARGS//;/ }) |
| 890 | for ARG in "${ARGS[@]}"; do |
| 891 | if [[ "$ARG" =~ "SYMLINK" ]]; then |
| 892 | SYMLINKS=${ARG#*=} |
| 893 | SYMLINKS=(${SYMLINKS//,/ }) |
| 894 | for SYMLINK in "${SYMLINKS[@]}"; do |
| 895 | SYMLINK_BASENAME=$(basename "$SYMLINK") |
| Bruno Martins | ad05f51 | 2024-06-28 00:34:33 +0100 | [diff] [blame] | 896 | PKGNAME="${BASENAME%.*}_${SYMLINK_BASENAME%.*}_symlink${ARCH}" |
| 897 | if [[ "${SYMLINK_PACKAGES[@]}" =~ "$PKGNAME" ]]; then |
| 898 | PKGNAME+="_$(grep -o "$PKGNAME" <<< ${SYMLINK_PACKAGES[*]} | wc -l)" |
| 899 | fi |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 900 | { |
| 901 | printf 'install_symlink {\n' |
| 902 | printf '\tname: "%s",\n' "$PKGNAME" |
| Mashopy | 06100c9 | 2024-04-23 21:52:04 +0200 | [diff] [blame] | 903 | if prefix_match_file "vendor/" "$SYMLINK"; then |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 904 | PREFIX='vendor/' |
| 905 | printf '\tsoc_specific: true,\n' |
| Mashopy | 06100c9 | 2024-04-23 21:52:04 +0200 | [diff] [blame] | 906 | elif prefix_match_file "product/" "$SYMLINK"; then |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 907 | PREFIX='product/' |
| 908 | printf '\tproduct_specific: true,\n' |
| Mashopy | 06100c9 | 2024-04-23 21:52:04 +0200 | [diff] [blame] | 909 | elif prefix_match_file "system_ext/" "$SYMLINK"; then |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 910 | PREFIX='system_ext/' |
| 911 | printf '\tsystem_ext_specific: true,\n' |
| Mashopy | 06100c9 | 2024-04-23 21:52:04 +0200 | [diff] [blame] | 912 | elif prefix_match_file "odm/" "$SYMLINK"; then |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 913 | PREFIX='odm/' |
| 914 | printf '\tdevice_specific: true,\n' |
| 915 | fi |
| 916 | printf '\tinstalled_location: "%s",\n' "${SYMLINK#"$PREFIX"}" |
| 917 | printf '\tsymlink_target: "/%s",\n' "$FILE" |
| 918 | printf '}\n\n' |
| 919 | } >> "$ANDROIDBP" |
| 920 | SYMLINK_PACKAGES+=("$PKGNAME") |
| 921 | done |
| 922 | fi |
| 923 | done |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 924 | done |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 925 | |
| 926 | write_package_definition "${SYMLINK_PACKAGES[@]}" >> "$PRODUCTMK" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | # |
| Michael Bestas | fe71eb3 | 2023-06-11 18:59:10 +0300 | [diff] [blame] | 930 | # write_single_product_copy_files: |
| 931 | # |
| 932 | # $1: the file to be copied |
| 933 | # |
| 934 | # Creates a PRODUCT_COPY_FILES section in the product makefile for the |
| 935 | # item provided in $1. |
| 936 | # |
| 937 | function write_single_product_copy_files() { |
| 938 | local FILE="$1" |
| 939 | if [ -z "$FILE" ]; then |
| 940 | echo "A file must be provided to write_single_product_copy_files()!" |
| 941 | exit 1 |
| 942 | fi |
| 943 | |
| 944 | local TARGET=$(target_file "$FILE") |
| 945 | local OUTTARGET=$(truncate_file $TARGET) |
| 946 | |
| 947 | printf '%s\n' "PRODUCT_COPY_FILES += \\" >> "$PRODUCTMK" |
| 948 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s\n' \ |
| 949 | "$OUTDIR" "$TARGET" "$OUTTARGET" >> "$PRODUCTMK" |
| 950 | } |
| 951 | |
| 952 | # |
| 953 | # write_single_product_packages: |
| 954 | # |
| 955 | # $1: the package to be built |
| 956 | # |
| 957 | # Creates a PRODUCT_PACKAGES section in the product makefile for the |
| 958 | # item provided in $1. |
| 959 | # |
| 960 | function write_single_product_packages() { |
| 961 | local PACKAGE="$1" |
| 962 | if [ -z "$PACKAGE" ]; then |
| 963 | echo "A package must be provided to write_single_product_packages()!" |
| 964 | exit 1 |
| 965 | fi |
| 966 | |
| 967 | printf '\n%s\n' "PRODUCT_PACKAGES += \\" >> "$PRODUCTMK" |
| 968 | printf ' %s%s\n' "$PACKAGE" >> "$PRODUCTMK" |
| 969 | } |
| 970 | |
| 971 | # |
| Michael Bestas | 431a800 | 2023-06-11 20:04:45 +0300 | [diff] [blame] | 972 | # write_rro_androidmanifest: |
| 973 | # |
| 974 | # $2: target package for the RRO overlay |
| 975 | # |
| 976 | # Creates an AndroidManifest.xml for an RRO overlay. |
| 977 | # |
| 978 | function write_rro_androidmanifest() { |
| 979 | local TARGET_PACKAGE="$1" |
| 980 | |
| 981 | cat << EOF |
| 982 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
| 983 | package="$TARGET_PACKAGE.vendor" |
| 984 | android:versionCode="1" |
| 985 | android:versionName="1.0"> |
| 986 | <application android:hasCode="false" /> |
| 987 | <overlay |
| 988 | android:targetPackage="$TARGET_PACKAGE" |
| 989 | android:isStatic="true" |
| 990 | android:priority="0"/> |
| 991 | </manifest> |
| 992 | EOF |
| 993 | } |
| 994 | |
| 995 | # |
| 996 | # write_rro_blueprint: |
| 997 | # |
| 998 | # $1: package name for the RRO overlay |
| 999 | # $2: target partition for the RRO overlay |
| 1000 | # |
| 1001 | # Creates an Android.bp for an RRO overlay. |
| 1002 | # |
| 1003 | function write_rro_blueprint() { |
| 1004 | local PKGNAME="$1" |
| 1005 | local PARTITION="$2" |
| 1006 | |
| 1007 | printf 'runtime_resource_overlay {\n' |
| 1008 | printf '\tname: "%s",\n' "$PKGNAME" |
| 1009 | printf '\ttheme: "%s",\n' "$PKGNAME" |
| 1010 | printf '\tsdk_version: "%s",\n' "current" |
| 1011 | printf '\taaptflags: ["%s"],\n' "--keep-raw-values" |
| 1012 | |
| 1013 | if [ "$PARTITION" = "vendor" ]; then |
| 1014 | printf '\tsoc_specific: true,\n' |
| 1015 | elif [ "$PARTITION" = "product" ]; then |
| 1016 | printf '\tproduct_specific: true,\n' |
| 1017 | elif [ "$PARTITION" = "system_ext" ]; then |
| 1018 | printf '\tsystem_ext_specific: true,\n' |
| 1019 | elif [ "$PARTITION" = "odm" ]; then |
| 1020 | printf '\tdevice_specific: true,\n' |
| 1021 | fi |
| 1022 | printf '}\n' |
| 1023 | } |
| 1024 | |
| 1025 | # |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 1026 | # write_blueprint_header: |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1027 | # |
| 1028 | # $1: file which will be written to |
| 1029 | # |
| Michael Bestas | a2934df | 2020-12-19 03:50:32 +0200 | [diff] [blame] | 1030 | # writes out the warning message regarding manual file modifications. |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1031 | # note that this is not an append operation, and should |
| 1032 | # be executed first! |
| 1033 | # |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 1034 | function write_blueprint_header() { |
| 1035 | if [ -f $1 ]; then |
| 1036 | rm $1 |
| 1037 | fi |
| 1038 | |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 1039 | [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON" |
| 1040 | |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 1041 | cat << EOF >> $1 |
| Michael Bestas | a2934df | 2020-12-19 03:50:32 +0200 | [diff] [blame] | 1042 | // Automatically generated file. DO NOT MODIFY |
| 1043 | // |
| 1044 | // This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 1045 | |
| 1046 | EOF |
| 1047 | } |
| 1048 | |
| 1049 | # |
| 1050 | # write_makefile_header: |
| 1051 | # |
| 1052 | # $1: file which will be written to |
| 1053 | # |
| Michael Bestas | a2934df | 2020-12-19 03:50:32 +0200 | [diff] [blame] | 1054 | # writes out the warning message regarding manual file modifications. |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 1055 | # note that this is not an append operation, and should |
| 1056 | # be executed first! |
| 1057 | # |
| 1058 | function write_makefile_header() { |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1059 | if [ -f $1 ]; then |
| 1060 | rm $1 |
| 1061 | fi |
| 1062 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1063 | [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON" |
| 1064 | |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1065 | cat << EOF >> $1 |
| Michael Bestas | a2934df | 2020-12-19 03:50:32 +0200 | [diff] [blame] | 1066 | # Automatically generated file. DO NOT MODIFY |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1067 | # |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1068 | # This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh |
| 1069 | |
| 1070 | EOF |
| 1071 | } |
| 1072 | |
| 1073 | # |
| Michael Bestas | 431a800 | 2023-06-11 20:04:45 +0300 | [diff] [blame] | 1074 | # write_xml_header: |
| 1075 | # |
| 1076 | # $1: file which will be written to |
| 1077 | # |
| 1078 | # writes out the warning message regarding manual file modifications. |
| 1079 | # note that this is not an append operation, and should |
| 1080 | # be executed first! |
| 1081 | # |
| 1082 | function write_xml_header() { |
| 1083 | if [ -f $1 ]; then |
| 1084 | rm $1 |
| 1085 | fi |
| 1086 | |
| 1087 | [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON" |
| 1088 | [ "$COMMON" -eq 1 ] && local VENDOR="${VENDOR_COMMON:-$VENDOR}" |
| 1089 | |
| 1090 | cat << EOF >> $1 |
| 1091 | <?xml version="1.0" encoding="utf-8"?> |
| 1092 | <!-- |
| 1093 | Automatically generated file. DO NOT MODIFY |
| 1094 | |
| 1095 | This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh |
| 1096 | --> |
| 1097 | EOF |
| 1098 | } |
| 1099 | |
| 1100 | # |
| 1101 | # write_rro_package: |
| 1102 | # |
| 1103 | # $1: the RRO package name |
| 1104 | # $2: the RRO target package |
| 1105 | # $3: the partition for the RRO overlay |
| 1106 | # |
| 1107 | # Generates the file structure for an RRO overlay. |
| 1108 | # |
| 1109 | function write_rro_package() { |
| 1110 | local PKGNAME="$1" |
| 1111 | if [ -z "$PKGNAME" ]; then |
| 1112 | echo "A package name must be provided to write_rro_package()!" |
| 1113 | exit 1 |
| 1114 | fi |
| 1115 | |
| 1116 | local TARGET_PACKAGE="$2" |
| 1117 | if [ -z "$TARGET_PACKAGE" ]; then |
| 1118 | echo "A target package must be provided to write_rro_package()!" |
| 1119 | exit 1 |
| 1120 | fi |
| 1121 | |
| 1122 | local PARTITION="$3" |
| 1123 | if [ -z "$PARTITION" ]; then |
| 1124 | PARTITION="vendor" |
| 1125 | fi |
| 1126 | |
| 1127 | local RROBP="$ANDROID_ROOT"/"$OUTDIR"/rro_overlays/"$PKGNAME"/Android.bp |
| 1128 | local RROMANIFEST="$ANDROID_ROOT"/"$OUTDIR"/rro_overlays/"$PKGNAME"/AndroidManifest.xml |
| 1129 | |
| 1130 | write_blueprint_header "$RROBP" |
| 1131 | write_xml_header "$RROMANIFEST" |
| 1132 | |
| 1133 | write_rro_blueprint "$PKGNAME" "$PARTITION" >> "$RROBP" |
| 1134 | write_rro_androidmanifest "$TARGET_PACKAGE" >> "$RROMANIFEST" |
| 1135 | } |
| 1136 | |
| 1137 | # |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 1138 | # write_package_definition: |
| 1139 | # |
| 1140 | # $@: list of packages |
| 1141 | # |
| 1142 | # writes out the final PRODUCT_PACKAGES list |
| 1143 | # |
| 1144 | function write_package_definition() { |
| 1145 | local PACKAGE_LIST=("${@}") |
| 1146 | local PACKAGE_COUNT=${#PACKAGE_LIST[@]} |
| 1147 | |
| 1148 | if [ "$PACKAGE_COUNT" -eq "0" ]; then |
| 1149 | return 0 |
| 1150 | fi |
| 1151 | |
| 1152 | printf '\n%s\n' "PRODUCT_PACKAGES += \\" |
| 1153 | for (( i=1; i<PACKAGE_COUNT+1; i++ )); do |
| SamarV-121 | 7e6b408 | 2024-02-26 14:39:34 +0530 | [diff] [blame] | 1154 | local SKIP=false |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 1155 | local LINEEND=" \\" |
| 1156 | if [ "$i" -eq "$PACKAGE_COUNT" ]; then |
| 1157 | LINEEND="" |
| 1158 | fi |
| SamarV-121 | 7e6b408 | 2024-02-26 14:39:34 +0530 | [diff] [blame] | 1159 | for PKG in $(tr "," "\n" <<< "$REQUIRED_PACKAGES_LIST"); do |
| 1160 | if [[ $PKG == "${PACKAGE_LIST[$i - 1]}" ]]; then |
| 1161 | SKIP=true |
| 1162 | break |
| 1163 | fi |
| 1164 | done |
| 1165 | # Skip adding of the package to product makefile if it's in the required list |
| 1166 | if [[ $SKIP == false ]]; then |
| 1167 | printf ' %s%s\n' "${PACKAGE_LIST[$i - 1]}" "$LINEEND" >> "$PRODUCTMK" |
| 1168 | fi |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 1169 | done |
| 1170 | } |
| 1171 | |
| 1172 | # |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1173 | # write_headers: |
| 1174 | # |
| 1175 | # $1: devices falling under common to be added to guard - optional |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1176 | # $2: custom guard - optional |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1177 | # |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 1178 | # Calls write_makefile_header for each of the makefiles and |
| 1179 | # write_blueprint_header for Android.bp and creates the initial |
| 1180 | # path declaration and device guard for the Android.mk |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1181 | # |
| 1182 | function write_headers() { |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 1183 | write_makefile_header "$ANDROIDMK" |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1184 | |
| 1185 | GUARD="$2" |
| 1186 | if [ -z "$GUARD" ]; then |
| 1187 | GUARD="TARGET_DEVICE" |
| 1188 | fi |
| 1189 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1190 | cat << EOF >> "$ANDROIDMK" |
| 1191 | LOCAL_PATH := \$(call my-dir) |
| 1192 | |
| 1193 | EOF |
| 1194 | if [ "$COMMON" -ne 1 ]; then |
| 1195 | cat << EOF >> "$ANDROIDMK" |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1196 | ifeq (\$($GUARD),$DEVICE) |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1197 | |
| 1198 | EOF |
| 1199 | else |
| 1200 | if [ -z "$1" ]; then |
| 1201 | echo "Argument with devices to be added to guard must be set!" |
| 1202 | exit 1 |
| 1203 | fi |
| 1204 | cat << EOF >> "$ANDROIDMK" |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1205 | ifneq (\$(filter $1,\$($GUARD)),) |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1206 | |
| 1207 | EOF |
| 1208 | fi |
| 1209 | |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 1210 | write_makefile_header "$BOARDMK" |
| 1211 | write_makefile_header "$PRODUCTMK" |
| 1212 | write_blueprint_header "$ANDROIDBP" |
| 1213 | |
| 1214 | cat << EOF >> "$ANDROIDBP" |
| 1215 | soong_namespace { |
| 1216 | } |
| 1217 | |
| 1218 | EOF |
| 1219 | |
| 1220 | [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON" |
| 1221 | cat << EOF >> "$PRODUCTMK" |
| 1222 | PRODUCT_SOONG_NAMESPACES += \\ |
| 1223 | vendor/$VENDOR/$DEVICE |
| 1224 | |
| 1225 | EOF |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | # |
| 1229 | # write_footers: |
| 1230 | # |
| 1231 | # Closes the inital guard and any other finalization tasks. Must |
| 1232 | # be called as the final step. |
| 1233 | # |
| 1234 | function write_footers() { |
| 1235 | cat << EOF >> "$ANDROIDMK" |
| 1236 | endif |
| 1237 | EOF |
| 1238 | } |
| 1239 | |
| 1240 | # Return success if adb is up and not in recovery |
| 1241 | function _adb_connected { |
| 1242 | { |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1243 | if [[ "$(adb get-state)" == device ]] |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1244 | then |
| 1245 | return 0 |
| 1246 | fi |
| 1247 | } 2>/dev/null |
| 1248 | |
| 1249 | return 1 |
| 1250 | }; |
| 1251 | |
| 1252 | # |
| 1253 | # parse_file_list: |
| 1254 | # |
| 1255 | # $1: input file |
| Rashed Abdel-Tawab | b0d08e8 | 2017-04-04 02:48:18 -0400 | [diff] [blame] | 1256 | # $2: blob section in file - optional |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1257 | # |
| 1258 | # Sets PRODUCT_PACKAGES and PRODUCT_COPY_FILES while parsing the input file |
| 1259 | # |
| 1260 | function parse_file_list() { |
| 1261 | if [ -z "$1" ]; then |
| 1262 | echo "An input file is expected!" |
| 1263 | exit 1 |
| 1264 | elif [ ! -f "$1" ]; then |
| 1265 | echo "Input file "$1" does not exist!" |
| 1266 | exit 1 |
| 1267 | fi |
| 1268 | |
| Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1269 | if [ -n "$2" ]; then |
| 1270 | echo "Using section \"$2\"" |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1271 | LIST=$EXTRACT_TMP_DIR/files.txt |
| Vladimir Oltean | fa79f21 | 2019-01-19 00:44:07 +0200 | [diff] [blame] | 1272 | # Match all lines starting with first line found to start* with '#' |
| 1273 | # comment and contain** $2, and ending with first line to be empty*. |
| 1274 | # *whitespaces (tabs, spaces) at the beginning of lines are discarded |
| 1275 | # **the $2 match is case-insensitive |
| 1276 | cat $1 | sed -n '/^[[:space:]]*#.*'"$2"'/I,/^[[:space:]]*$/ p' > $LIST |
| Rashed Abdel-Tawab | b0d08e8 | 2017-04-04 02:48:18 -0400 | [diff] [blame] | 1277 | else |
| 1278 | LIST=$1 |
| 1279 | fi |
| 1280 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1281 | PRODUCT_PACKAGES_LIST=() |
| 1282 | PRODUCT_PACKAGES_HASHES=() |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1283 | PRODUCT_PACKAGES_FIXUP_HASHES=() |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 1284 | PRODUCT_SYMLINKS_LIST=() |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1285 | PRODUCT_COPY_FILES_LIST=() |
| 1286 | PRODUCT_COPY_FILES_HASHES=() |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1287 | PRODUCT_COPY_FILES_FIXUP_HASHES=() |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1288 | |
| 1289 | while read -r line; do |
| 1290 | if [ -z "$line" ]; then continue; fi |
| 1291 | |
| 1292 | # If the line has a pipe delimiter, a sha1 hash should follow. |
| 1293 | # This indicates the file should be pinned and not overwritten |
| 1294 | # when extracting files. |
| 1295 | local SPLIT=(${line//\|/ }) |
| 1296 | local COUNT=${#SPLIT[@]} |
| 1297 | local SPEC=${SPLIT[0]} |
| 1298 | local HASH="x" |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1299 | local FIXUP_HASH="x" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1300 | if [ "$COUNT" -gt "1" ]; then |
| 1301 | HASH=${SPLIT[1]} |
| 1302 | fi |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1303 | if [ "$COUNT" -gt "2" ]; then |
| 1304 | FIXUP_HASH=${SPLIT[2]} |
| 1305 | fi |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 1306 | if [[ "$SPEC" =~ 'SYMLINK=' ]]; then |
| 1307 | PRODUCT_SYMLINKS_LIST+=("${SPEC#-}") |
| 1308 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1309 | # if line starts with a dash, it needs to be packaged |
| 1310 | if [[ "$SPEC" =~ ^- ]]; then |
| 1311 | PRODUCT_PACKAGES_LIST+=("${SPEC#-}") |
| 1312 | PRODUCT_PACKAGES_HASHES+=("$HASH") |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1313 | PRODUCT_PACKAGES_FIXUP_HASHES+=("$FIXUP_HASH") |
| Chirayu Desai | a774101 | 2021-12-04 07:17:28 +0530 | [diff] [blame] | 1314 | # if line contains apex, apk, jar or vintf fragment, it needs to be packaged |
| 1315 | elif suffix_match_file ".apex" "$(src_file "$SPEC")" || \ |
| 1316 | suffix_match_file ".apk" "$(src_file "$SPEC")" || \ |
| Michael Bestas | ea90aef | 2021-11-15 22:18:04 +0200 | [diff] [blame] | 1317 | suffix_match_file ".jar" "$(src_file "$SPEC")" || \ |
| 1318 | [[ "$SPEC" == *"etc/vintf/manifest/"* ]]; then |
| 1319 | PRODUCT_PACKAGES_LIST+=("$SPEC") |
| 1320 | PRODUCT_PACKAGES_HASHES+=("$HASH") |
| 1321 | PRODUCT_PACKAGES_FIXUP_HASHES+=("$FIXUP_HASH") |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1322 | else |
| 1323 | PRODUCT_COPY_FILES_LIST+=("$SPEC") |
| 1324 | PRODUCT_COPY_FILES_HASHES+=("$HASH") |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1325 | PRODUCT_COPY_FILES_FIXUP_HASHES+=("$FIXUP_HASH") |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1326 | fi |
| 1327 | |
| Chirayu Desai | f1a2130 | 2022-09-13 00:29:33 +0530 | [diff] [blame] | 1328 | done < <(grep -v -E '(^#|^[[:space:]]*$)' "$LIST" | LC_ALL=C sort | uniq) |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | # |
| 1332 | # write_makefiles: |
| 1333 | # |
| 1334 | # $1: file containing the list of items to extract |
| Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 1335 | # $2: make treble compatible makefile - optional |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1336 | # |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 1337 | # Calls write_product_copy_files, write_product_packages and |
| 1338 | # lastly write_symlink_packages on the given file and appends |
| 1339 | # to the Android.bp as well as the product makefile. |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1340 | # |
| 1341 | function write_makefiles() { |
| 1342 | parse_file_list "$1" |
| Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 1343 | write_product_copy_files "$2" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1344 | write_product_packages |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 1345 | write_symlink_packages |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | # |
| 1349 | # append_firmware_calls_to_makefiles: |
| 1350 | # |
| Michael Bestas | f62d403 | 2022-02-22 19:06:41 +0200 | [diff] [blame] | 1351 | # $1: file containing the list of items to extract |
| 1352 | # |
| Michael Bestas | c72d0f6 | 2022-04-16 21:06:28 +0300 | [diff] [blame] | 1353 | # Appends the calls to all images present in radio folder to Android.mk |
| 1354 | # and radio AB_OTA_PARTITIONS to BoardConfigVendor.mk |
| Michael Bestas | f62d403 | 2022-02-22 19:06:41 +0200 | [diff] [blame] | 1355 | # |
| Michael Bestas | c72d0f6 | 2022-04-16 21:06:28 +0300 | [diff] [blame] | 1356 | function append_firmware_calls_to_makefiles() { |
| Michael Bestas | f62d403 | 2022-02-22 19:06:41 +0200 | [diff] [blame] | 1357 | parse_file_list "$1" |
| 1358 | |
| 1359 | local FILELIST=(${PRODUCT_COPY_FILES_LIST[@]}) |
| 1360 | local COUNT=${#FILELIST[@]} |
| 1361 | |
| SamarV-121 | 7e56a0b | 2024-03-09 12:58:18 +0530 | [diff] [blame^] | 1362 | if [[ ${FILELIST[*]} =~ ";AB" ]]; then |
| 1363 | printf '%s\n' "AB_OTA_PARTITIONS += \\" >> "$BOARDMK" |
| 1364 | fi |
| 1365 | |
| Michael Bestas | f62d403 | 2022-02-22 19:06:41 +0200 | [diff] [blame] | 1366 | for (( i=1; i<COUNT+1; i++ )); do |
| 1367 | local DST_FILE=$(target_file "${FILELIST[$i-1]}") |
| 1368 | local ARGS=$(target_args "${FILELIST[$i-1]}") |
| LuK1337 | 11d8686 | 2023-12-11 01:34:29 +0100 | [diff] [blame] | 1369 | local SHA1=$(get_hash "$ANDROID_ROOT"/"$OUTDIR"/radio/"$DST_FILE") |
| Michael Bestas | c72d0f6 | 2022-04-16 21:06:28 +0300 | [diff] [blame] | 1370 | DST_FILE_NAME=(${DST_FILE//.img/ }) |
| Michael Bestas | f62d403 | 2022-02-22 19:06:41 +0200 | [diff] [blame] | 1371 | ARGS=(${ARGS//;/ }) |
| 1372 | LINEEND=" \\" |
| 1373 | if [ "$i" -eq "$COUNT" ]; then |
| 1374 | LINEEND="" |
| 1375 | fi |
| 1376 | |
| 1377 | for ARG in "${ARGS[@]}"; do |
| 1378 | if [[ "$ARG" =~ "AB" ]]; then |
| Michael Bestas | c72d0f6 | 2022-04-16 21:06:28 +0300 | [diff] [blame] | 1379 | printf ' %s%s\n' "$DST_FILE_NAME" "$LINEEND" >> "$BOARDMK" |
| Michael Bestas | f62d403 | 2022-02-22 19:06:41 +0200 | [diff] [blame] | 1380 | fi |
| 1381 | done |
| LuK1337 | 11d8686 | 2023-12-11 01:34:29 +0100 | [diff] [blame] | 1382 | printf '%s\n' "\$(call add-radio-file-sha1-checked,radio/$DST_FILE,$SHA1)" >> "$ANDROIDMK" |
| Michael Bestas | f62d403 | 2022-02-22 19:06:41 +0200 | [diff] [blame] | 1383 | done |
| Michael Bestas | c72d0f6 | 2022-04-16 21:06:28 +0300 | [diff] [blame] | 1384 | printf '\n' >> "$ANDROIDMK" |
| Michael Bestas | f62d403 | 2022-02-22 19:06:41 +0200 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | # |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1388 | # get_file: |
| 1389 | # |
| 1390 | # $1: input file |
| 1391 | # $2: target file/folder |
| 1392 | # $3: source of the file (can be "adb" or a local folder) |
| 1393 | # |
| 1394 | # Silently extracts the input file to defined target |
| 1395 | # Returns success if file can be pulled from the device or found locally |
| 1396 | # |
| 1397 | function get_file() { |
| 1398 | local SRC="$3" |
| 1399 | |
| 1400 | if [ "$SRC" = "adb" ]; then |
| 1401 | # try to pull |
| LuK1337 | 0f7f0d1 | 2022-08-19 21:49:56 +0200 | [diff] [blame] | 1402 | adb pull "$1" "$2" >/dev/null 2>&1 && return 0 |
| 1403 | adb pull "${1#/system}" "$2" >/dev/null 2>&1 && return 0 |
| 1404 | adb pull "system/$1" "$2" >/dev/null 2>&1 && return 0 |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1405 | |
| 1406 | return 1 |
| 1407 | else |
| 1408 | # try to copy |
| Vladimir Oltean | fe49eae | 2018-06-25 00:05:56 +0300 | [diff] [blame] | 1409 | cp -r "$SRC/$1" "$2" 2>/dev/null && return 0 |
| 1410 | cp -r "$SRC/${1#/system}" "$2" 2>/dev/null && return 0 |
| Vladimir Oltean | 6780da3 | 2019-01-06 19:38:31 +0200 | [diff] [blame] | 1411 | cp -r "$SRC/system/$1" "$2" 2>/dev/null && return 0 |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1412 | |
| LuK1337 | dbb77cc | 2023-12-04 19:03:10 +0100 | [diff] [blame] | 1413 | # try /vendor/odm for devices without /odm partition |
| 1414 | [[ "$1" == /system/odm/* ]] && cp -r "$SRC/vendor/${1#/system}" "$2" 2>/dev/null && return 0 |
| 1415 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1416 | return 1 |
| 1417 | fi |
| 1418 | }; |
| 1419 | |
| 1420 | # |
| 1421 | # oat2dex: |
| 1422 | # |
| 1423 | # $1: extracted apk|jar (to check if deodex is required) |
| 1424 | # $2: odexed apk|jar to deodex |
| 1425 | # $3: source of the odexed apk|jar |
| 1426 | # |
| 1427 | # Convert apk|jar .odex in the corresposing classes.dex |
| 1428 | # |
| 1429 | function oat2dex() { |
| theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 1430 | local OMNI_TARGET="$1" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1431 | local OEM_TARGET="$2" |
| 1432 | local SRC="$3" |
| 1433 | local TARGET= |
| Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1434 | local OAT= |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1435 | |
| Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1436 | if [ -z "$BAKSMALIJAR" ] || [ -z "$SMALIJAR" ]; then |
| 1437 | export BAKSMALIJAR="$OMNI_ROOT"/vendor/omni/build/tools/smali/baksmali.jar |
| 1438 | export SMALIJAR="$OMNI_ROOT"/vendor/omni/build/tools/smali/smali.jar |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1439 | fi |
| 1440 | |
| Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1441 | if [ -z "$VDEXEXTRACTOR" ]; then |
| Han Wang | 7a0b0bd | 2020-03-10 09:40:47 +0200 | [diff] [blame] | 1442 | export VDEXEXTRACTOR="$OMNI_ROOT"/vendor/omni/build/tools/${HOST}/vdexExtractor |
| Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1443 | fi |
| Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1444 | |
| codeworkx | 85eda75 | 2018-09-23 12:36:57 +0200 | [diff] [blame] | 1445 | if [ -z "$CDEXCONVERTER" ]; then |
| Han Wang | 7a0b0bd | 2020-03-10 09:40:47 +0200 | [diff] [blame] | 1446 | export CDEXCONVERTER="$OMNI_ROOT"/vendor/omni/build/tools/${HOST}/compact_dex_converter |
| codeworkx | 85eda75 | 2018-09-23 12:36:57 +0200 | [diff] [blame] | 1447 | fi |
| 1448 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1449 | # Extract existing boot.oats to the temp folder |
| 1450 | if [ -z "$ARCHES" ]; then |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1451 | echo "Checking if system is odexed and locating boot.oats..." |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1452 | for ARCH in "arm64" "arm" "x86_64" "x86"; do |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1453 | mkdir -p "$EXTRACT_TMP_DIR/system/framework/$ARCH" |
| 1454 | if get_file "/system/framework/$ARCH" "$EXTRACT_TMP_DIR/system/framework/" "$SRC"; then |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1455 | ARCHES+="$ARCH " |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1456 | else |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1457 | rmdir "$EXTRACT_TMP_DIR/system/framework/$ARCH" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1458 | fi |
| 1459 | done |
| 1460 | fi |
| 1461 | |
| 1462 | if [ -z "$ARCHES" ]; then |
| 1463 | FULLY_DEODEXED=1 && return 0 # system is fully deodexed, return |
| 1464 | fi |
| 1465 | |
| theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 1466 | if [ ! -f "$OMNI_TARGET" ]; then |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1467 | return; |
| 1468 | fi |
| 1469 | |
| theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 1470 | if grep "classes.dex" "$OMNI_TARGET" >/dev/null; then |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1471 | return 0 # target apk|jar is already odexed, return |
| 1472 | fi |
| 1473 | |
| 1474 | for ARCH in $ARCHES; do |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1475 | BOOTOAT="$EXTRACT_TMP_DIR/system/framework/$ARCH/boot.oat" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1476 | |
| Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1477 | local OAT="$(dirname "$OEM_TARGET")/oat/$ARCH/$(basename "$OEM_TARGET" ."${OEM_TARGET##*.}").odex" |
| 1478 | local VDEX="$(dirname "$OEM_TARGET")/oat/$ARCH/$(basename "$OEM_TARGET" ."${OEM_TARGET##*.}").vdex" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1479 | |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1480 | if get_file "$OAT" "$EXTRACT_TMP_DIR" "$SRC"; then |
| 1481 | if get_file "$VDEX" "$EXTRACT_TMP_DIR" "$SRC"; then |
| 1482 | "$VDEXEXTRACTOR" -o "$EXTRACT_TMP_DIR/" -i "$EXTRACT_TMP_DIR/$(basename "$VDEX")" > /dev/null |
| 1483 | CLASSES=$(ls "$EXTRACT_TMP_DIR/$(basename "${OEM_TARGET%.*}")_classes"*) |
| Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1484 | for CLASS in $CLASSES; do |
| 1485 | NEWCLASS=$(echo "$CLASS" | sed 's/.*_//;s/cdex/dex/') |
| 1486 | # Check if we have to deal with CompactDex |
| 1487 | if [[ "$CLASS" == *.cdex ]]; then |
| 1488 | "$CDEXCONVERTER" "$CLASS" &>/dev/null |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1489 | mv "$CLASS.new" "$EXTRACT_TMP_DIR/$NEWCLASS" |
| Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1490 | else |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1491 | mv "$CLASS" "$EXTRACT_TMP_DIR/$NEWCLASS" |
| Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1492 | fi |
| 1493 | done |
| Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1494 | else |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1495 | java -jar "$BAKSMALIJAR" deodex -o "$EXTRACT_TMP_DIR/dexout" -b "$BOOTOAT" -d "$EXTRACT_TMP_DIR" "$EXTRACT_TMP_DIR/$(basename "$OAT")" |
| 1496 | java -jar "$SMALIJAR" assemble "$EXTRACT_TMP_DIR/dexout" -o "$EXTRACT_TMP_DIR/classes.dex" |
| Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1497 | fi |
| theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 1498 | elif [[ "$OMNI_TARGET" =~ .jar$ ]]; then |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1499 | JAROAT="$EXTRACT_TMP_DIR/system/framework/$ARCH/boot-$(basename ${OEM_TARGET%.*}).oat" |
| Luca Stefani | 082f1e8 | 2018-10-07 12:44:53 +0200 | [diff] [blame] | 1500 | JARVDEX="/system/framework/boot-$(basename ${OEM_TARGET%.*}).vdex" |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1501 | if [ ! -f "$JAROAT" ]; then |
| Luca Stefani | 082f1e8 | 2018-10-07 12:44:53 +0200 | [diff] [blame] | 1502 | JAROAT=$BOOTOAT |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1503 | fi |
| Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1504 | # try to extract classes.dex from boot.vdex for frameworks jars |
| 1505 | # fallback to boot.oat if vdex is not available |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1506 | if get_file "$JARVDEX" "$EXTRACT_TMP_DIR" "$SRC"; then |
| 1507 | "$VDEXEXTRACTOR" -o "$EXTRACT_TMP_DIR/" -i "$EXTRACT_TMP_DIR/$(basename "$JARVDEX")" > /dev/null |
| 1508 | CLASSES=$(ls "$EXTRACT_TMP_DIR/$(basename "${JARVDEX%.*}")_classes"*) |
| Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1509 | for CLASS in $CLASSES; do |
| 1510 | NEWCLASS=$(echo "$CLASS" | sed 's/.*_//;s/cdex/dex/') |
| 1511 | # Check if we have to deal with CompactDex |
| 1512 | if [[ "$CLASS" == *.cdex ]]; then |
| 1513 | "$CDEXCONVERTER" "$CLASS" &>/dev/null |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1514 | mv "$CLASS.new" "$EXTRACT_TMP_DIR/$NEWCLASS" |
| Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1515 | else |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1516 | mv "$CLASS" "$EXTRACT_TMP_DIR/$NEWCLASS" |
| Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1517 | fi |
| 1518 | done |
| Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1519 | else |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1520 | java -jar "$BAKSMALIJAR" deodex -o "$EXTRACT_TMP_DIR/dexout" -b "$BOOTOAT" -d "$EXTRACT_TMP_DIR" "$JAROAT/$OEM_TARGET" |
| 1521 | java -jar "$SMALIJAR" assemble "$EXTRACT_TMP_DIR/dexout" -o "$EXTRACT_TMP_DIR/classes.dex" |
| Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1522 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1523 | else |
| 1524 | continue |
| 1525 | fi |
| 1526 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1527 | done |
| Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1528 | |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1529 | rm -rf "$EXTRACT_TMP_DIR/dexout" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | # |
| 1533 | # init_adb_connection: |
| 1534 | # |
| 1535 | # Starts adb server and waits for the device |
| 1536 | # |
| 1537 | function init_adb_connection() { |
| 1538 | adb start-server # Prevent unexpected starting server message from adb get-state in the next line |
| 1539 | if ! _adb_connected; then |
| 1540 | echo "No device is online. Waiting for one..." |
| 1541 | echo "Please connect USB and/or enable USB debugging" |
| 1542 | until _adb_connected; do |
| 1543 | sleep 1 |
| 1544 | done |
| 1545 | echo "Device Found." |
| 1546 | fi |
| 1547 | |
| 1548 | # Retrieve IP and PORT info if we're using a TCP connection |
| Chirayu Desai | f1a2130 | 2022-09-13 00:29:33 +0530 | [diff] [blame] | 1549 | TCPIPPORT=$(adb devices | grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \ |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1550 | | head -1 | awk '{print $1}') |
| 1551 | adb root &> /dev/null |
| 1552 | sleep 0.3 |
| 1553 | if [ -n "$TCPIPPORT" ]; then |
| 1554 | # adb root just killed our connection |
| 1555 | # so reconnect... |
| 1556 | adb connect "$TCPIPPORT" |
| 1557 | fi |
| 1558 | adb wait-for-device &> /dev/null |
| 1559 | sleep 0.3 |
| 1560 | } |
| 1561 | |
| 1562 | # |
| 1563 | # fix_xml: |
| 1564 | # |
| 1565 | # $1: xml file to fix |
| 1566 | # |
| 1567 | function fix_xml() { |
| 1568 | local XML="$1" |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1569 | local TEMP_XML="$EXTRACT_TMP_DIR/`basename "$XML"`.temp" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1570 | |
| Dobroslaw Kijowski | 3af2a8d | 2017-05-18 12:35:02 +0200 | [diff] [blame] | 1571 | grep -a '^<?xml version' "$XML" > "$TEMP_XML" |
| 1572 | grep -av '^<?xml version' "$XML" >> "$TEMP_XML" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1573 | |
| 1574 | mv "$TEMP_XML" "$XML" |
| 1575 | } |
| 1576 | |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1577 | function get_hash() { |
| 1578 | local FILE="$1" |
| 1579 | |
| 1580 | if [ "$(uname)" == "Darwin" ]; then |
| 1581 | shasum "${FILE}" | awk '{print $1}' |
| 1582 | else |
| 1583 | sha1sum "${FILE}" | awk '{print $1}' |
| 1584 | fi |
| 1585 | } |
| 1586 | |
| Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1587 | function print_spec() { |
| 1588 | local SPEC_PRODUCT_PACKAGE="$1" |
| 1589 | local SPEC_SRC_FILE="$2" |
| 1590 | local SPEC_DST_FILE="$3" |
| 1591 | local SPEC_ARGS="$4" |
| 1592 | local SPEC_HASH="$5" |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1593 | local SPEC_FIXUP_HASH="$6" |
| Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1594 | |
| 1595 | local PRODUCT_PACKAGE="" |
| 1596 | if [ ${SPEC_PRODUCT_PACKAGE} = true ]; then |
| 1597 | PRODUCT_PACKAGE="-" |
| 1598 | fi |
| 1599 | local SRC="" |
| 1600 | if [ ! -z "${SPEC_SRC_FILE}" ] && [ "${SPEC_SRC_FILE}" != "${SPEC_DST_FILE}" ]; then |
| 1601 | SRC="${SPEC_SRC_FILE}:" |
| 1602 | fi |
| 1603 | local DST="" |
| 1604 | if [ ! -z "${SPEC_DST_FILE}" ]; then |
| 1605 | DST="${SPEC_DST_FILE}" |
| 1606 | fi |
| 1607 | local ARGS="" |
| 1608 | if [ ! -z "${SPEC_ARGS}" ]; then |
| 1609 | ARGS=";${SPEC_ARGS}" |
| 1610 | fi |
| 1611 | local HASH="" |
| 1612 | if [ ! -z "${SPEC_HASH}" ] && [ "${SPEC_HASH}" != "x" ]; then |
| 1613 | HASH="|${SPEC_HASH}" |
| 1614 | fi |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1615 | local FIXUP_HASH="" |
| 1616 | if [ ! -z "${SPEC_FIXUP_HASH}" ] && [ "${SPEC_FIXUP_HASH}" != "x" ] && [ "${SPEC_FIXUP_HASH}" != "${SPEC_HASH}" ]; then |
| 1617 | FIXUP_HASH="|${SPEC_FIXUP_HASH}" |
| 1618 | fi |
| 1619 | printf '%s%s%s%s%s%s\n' "${PRODUCT_PACKAGE}" "${SRC}" "${DST}" "${ARGS}" "${HASH}" "${FIXUP_HASH}" |
| 1620 | } |
| 1621 | |
| 1622 | # To be overridden by device-level extract-files.sh |
| 1623 | # Parameters: |
| 1624 | # $1: spec name of a blob. Can be used for filtering. |
| 1625 | # If the spec is "src:dest", then $1 is "dest". |
| 1626 | # If the spec is "src", then $1 is "src". |
| 1627 | # $2: path to blob file. Can be used for fixups. |
| 1628 | # |
| 1629 | function blob_fixup() { |
| 1630 | : |
| Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1631 | } |
| 1632 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1633 | # |
| 1634 | # extract: |
| 1635 | # |
| Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1636 | # Positional parameters: |
| 1637 | # $1: file containing the list of items to extract (aka proprietary-files.txt) |
| Dan Pasanen | 0cc0501 | 2017-03-21 09:06:11 -0500 | [diff] [blame] | 1638 | # $2: path to extracted system folder, an ota zip file, or "adb" to extract from device |
| Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1639 | # $3: section in list file to extract - optional. Setting section via $3 is deprecated. |
| 1640 | # |
| 1641 | # Non-positional parameters (coming after $2): |
| 1642 | # --section: preferred way of selecting the portion to parse and extract from |
| 1643 | # proprietary-files.txt |
| Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1644 | # --kang: if present, this option will activate the printing of hashes for the |
| 1645 | # extracted blobs. Useful with --section for subsequent pinning of |
| 1646 | # blobs taken from other origins. |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1647 | # |
| 1648 | function extract() { |
| Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1649 | # Consume positional parameters |
| 1650 | local PROPRIETARY_FILES_TXT="$1"; shift |
| 1651 | local SRC="$1"; shift |
| 1652 | local SECTION="" |
| Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1653 | local KANG=false |
| Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1654 | |
| 1655 | # Consume optional, non-positional parameters |
| 1656 | while [ "$#" -gt 0 ]; do |
| 1657 | case "$1" in |
| 1658 | -s|--section) |
| 1659 | SECTION="$2"; shift |
| 1660 | ;; |
| Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1661 | -k|--kang) |
| 1662 | KANG=true |
| 1663 | DISABLE_PINNING=1 |
| 1664 | ;; |
| Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1665 | *) |
| 1666 | # Backwards-compatibility with the old behavior, where $3, if |
| 1667 | # present, denoted an optional positional ${SECTION} argument. |
| 1668 | # Users of ${SECTION} are encouraged to migrate from setting it as |
| 1669 | # positional $3, to non-positional --section ${SECTION}, the |
| 1670 | # reason being that it doesn't scale to have more than 1 optional |
| 1671 | # positional argument. |
| 1672 | SECTION="$1" |
| 1673 | ;; |
| 1674 | esac |
| 1675 | shift |
| 1676 | done |
| 1677 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1678 | if [ -z "$OUTDIR" ]; then |
| 1679 | echo "Output dir not set!" |
| 1680 | exit 1 |
| 1681 | fi |
| 1682 | |
| Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1683 | parse_file_list "${PROPRIETARY_FILES_TXT}" "${SECTION}" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1684 | |
| 1685 | # Allow failing, so we can try $DEST and/or $FILE |
| 1686 | set +e |
| 1687 | |
| 1688 | local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ${PRODUCT_PACKAGES_LIST[@]} ) |
| 1689 | local HASHLIST=( ${PRODUCT_COPY_FILES_HASHES[@]} ${PRODUCT_PACKAGES_HASHES[@]} ) |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1690 | local FIXUP_HASHLIST=( ${PRODUCT_COPY_FILES_FIXUP_HASHES[@]} ${PRODUCT_PACKAGES_FIXUP_HASHES[@]} ) |
| Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1691 | local PRODUCT_COPY_FILES_COUNT=${#PRODUCT_COPY_FILES_LIST[@]} |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1692 | local COUNT=${#FILELIST[@]} |
| theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 1693 | local OUTPUT_ROOT="$OMNI_ROOT"/"$OUTDIR"/proprietary |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1694 | local OUTPUT_TMP="$EXTRACT_TMP_DIR"/"$OUTDIR"/proprietary |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1695 | |
| 1696 | if [ "$SRC" = "adb" ]; then |
| 1697 | init_adb_connection |
| 1698 | fi |
| 1699 | |
| Dan Pasanen | 0cc0501 | 2017-03-21 09:06:11 -0500 | [diff] [blame] | 1700 | if [ -f "$SRC" ] && [ "${SRC##*.}" == "zip" ]; then |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1701 | DUMPDIR="$EXTRACT_TMP_DIR"/system_dump |
| Dan Pasanen | 0cc0501 | 2017-03-21 09:06:11 -0500 | [diff] [blame] | 1702 | |
| 1703 | # Check if we're working with the same zip that was passed last time. |
| 1704 | # If so, let's just use what's already extracted. |
| 1705 | MD5=`md5sum "$SRC"| awk '{print $1}'` |
| 1706 | OLDMD5=`cat "$DUMPDIR"/zipmd5.txt` |
| 1707 | |
| 1708 | if [ "$MD5" != "$OLDMD5" ]; then |
| 1709 | rm -rf "$DUMPDIR" |
| 1710 | mkdir "$DUMPDIR" |
| 1711 | unzip "$SRC" -d "$DUMPDIR" |
| 1712 | echo "$MD5" > "$DUMPDIR"/zipmd5.txt |
| 1713 | |
| Chirayu Desai | 817dc76 | 2021-11-26 05:47:25 +0530 | [diff] [blame] | 1714 | # Extract A/B OTA |
| Dan Pasanen | 0cc0501 | 2017-03-21 09:06:11 -0500 | [diff] [blame] | 1715 | if [ -a "$DUMPDIR"/payload.bin ]; then |
| Chirayu Desai | 817dc76 | 2021-11-26 05:47:25 +0530 | [diff] [blame] | 1716 | python3 "$ANDROID_ROOT"/tools/extract-utils/extract_ota.py "$DUMPDIR"/payload.bin -o "$DUMPDIR" -p "system" "odm" "product" "system_ext" "vendor" 2>&1 |
| Dan Pasanen | 0cc0501 | 2017-03-21 09:06:11 -0500 | [diff] [blame] | 1717 | fi |
| dianlujitao | 85ddca6 | 2020-04-21 23:03:20 +0800 | [diff] [blame] | 1718 | |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 1719 | for PARTITION in "system" "odm" "product" "system_ext" "vendor" |
| dianlujitao | 85ddca6 | 2020-04-21 23:03:20 +0800 | [diff] [blame] | 1720 | do |
| 1721 | # If OTA is block based, extract it. |
| dianlujitao | e2cbe26 | 2020-04-21 23:01:13 +0800 | [diff] [blame] | 1722 | if [ -a "$DUMPDIR"/"$PARTITION".new.dat.br ]; then |
| 1723 | echo "Converting "$PARTITION".new.dat.br to "$PARTITION".new.dat" |
| 1724 | brotli -d "$DUMPDIR"/"$PARTITION".new.dat.br |
| 1725 | rm "$DUMPDIR"/"$PARTITION".new.dat.br |
| 1726 | fi |
| dianlujitao | 85ddca6 | 2020-04-21 23:03:20 +0800 | [diff] [blame] | 1727 | if [ -a "$DUMPDIR"/"$PARTITION".new.dat ]; then |
| 1728 | echo "Converting "$PARTITION".new.dat to "$PARTITION".img" |
| 1729 | python "$OMNI_ROOT"/vendor/omni/build/tools/sdat2img.py "$DUMPDIR"/"$PARTITION".transfer.list "$DUMPDIR"/"$PARTITION".new.dat "$DUMPDIR"/"$PARTITION".img 2>&1 |
| 1730 | rm -rf "$DUMPDIR"/"$PARTITION".new.dat "$DUMPDIR"/"$PARTITION" |
| 1731 | mkdir "$DUMPDIR"/"$PARTITION" "$DUMPDIR"/tmp |
| Chirayu Desai | 62ed12a | 2021-11-26 05:47:25 +0530 | [diff] [blame] | 1732 | extract_img_data "$DUMPDIR"/"$PARTITION".img "$DUMPDIR"/"$PARTITION"/ |
| 1733 | rm "$DUMPDIR"/"$PARTITION".img |
| dianlujitao | 85ddca6 | 2020-04-21 23:03:20 +0800 | [diff] [blame] | 1734 | fi |
| Chirayu Desai | 817dc76 | 2021-11-26 05:47:25 +0530 | [diff] [blame] | 1735 | if [ -a "$DUMPDIR"/"$PARTITION".img ]; then |
| 1736 | extract_img_data "$DUMPDIR"/"$PARTITION".img "$DUMPDIR"/"$PARTITION"/ |
| 1737 | fi |
| dianlujitao | 85ddca6 | 2020-04-21 23:03:20 +0800 | [diff] [blame] | 1738 | done |
| Dan Pasanen | 0cc0501 | 2017-03-21 09:06:11 -0500 | [diff] [blame] | 1739 | fi |
| 1740 | |
| 1741 | SRC="$DUMPDIR" |
| 1742 | fi |
| 1743 | |
| Michael Bestas | f2501c3 | 2022-02-18 23:45:09 +0200 | [diff] [blame] | 1744 | if [ -d "$SRC" ] && [ -f "$SRC"/super.img ]; then |
| 1745 | DUMPDIR="$TMPDIR"/super_dump |
| 1746 | mkdir -p "$DUMPDIR" |
| 1747 | |
| 1748 | echo "Unpacking super.img" |
| 1749 | "$SIMG2IMG" "$SRC"/super.img "$DUMPDIR"/super.raw |
| 1750 | |
| 1751 | for PARTITION in "system" "odm" "product" "system_ext" "vendor" |
| 1752 | do |
| 1753 | echo "Preparing "$PARTITION"" |
| 1754 | if "$LPUNPACK" -p "$PARTITION"_a "$DUMPDIR"/super.raw "$DUMPDIR" ; then |
| 1755 | mv "$DUMPDIR"/"$PARTITION"_a.img "$DUMPDIR"/"$PARTITION".img |
| 1756 | else |
| 1757 | "$LPUNPACK" -p "$PARTITION" "$DUMPDIR"/super.raw "$DUMPDIR" |
| 1758 | fi |
| 1759 | done |
| 1760 | |
| 1761 | SRC="$DUMPDIR" |
| 1762 | fi |
| 1763 | |
| Chirayu Desai | a3850bd | 2021-11-26 05:47:25 +0530 | [diff] [blame] | 1764 | if [ -d "$SRC" ] && [ -f "$SRC"/system.img ]; then |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1765 | DUMPDIR="$EXTRACT_TMP_DIR"/system_dump |
| Chirayu Desai | a3850bd | 2021-11-26 05:47:25 +0530 | [diff] [blame] | 1766 | mkdir -p "$DUMPDIR" |
| 1767 | |
| 1768 | for PARTITION in "system" "odm" "product" "system_ext" "vendor" |
| 1769 | do |
| 1770 | echo "Extracting "$PARTITION"" |
| 1771 | local IMAGE="$SRC"/"$PARTITION".img |
| 1772 | if [ -f "$IMAGE" ]; then |
| LuK1337 | 07657db | 2023-11-30 18:11:51 +0100 | [diff] [blame] | 1773 | if [[ $(file -b "$IMAGE") == EROFS* ]]; then |
| 1774 | fsck.erofs --extract="$DUMPDIR"/"$PARTITION" "$IMAGE" |
| 1775 | elif [[ $(file -b "$IMAGE") == Linux* ]]; then |
| Chirayu Desai | a3850bd | 2021-11-26 05:47:25 +0530 | [diff] [blame] | 1776 | extract_img_data "$IMAGE" "$DUMPDIR"/"$PARTITION" |
| 1777 | elif [[ $(file -b "$IMAGE") == Android* ]]; then |
| Chirayu Desai | 501ffd6 | 2022-03-17 06:27:33 +0530 | [diff] [blame] | 1778 | "$SIMG2IMG" "$IMAGE" "$DUMPDIR"/"$PARTITION".raw |
| Chirayu Desai | a3850bd | 2021-11-26 05:47:25 +0530 | [diff] [blame] | 1779 | extract_img_data "$DUMPDIR"/"$PARTITION".raw "$DUMPDIR"/"$PARTITION"/ |
| 1780 | else |
| 1781 | echo "Unsupported "$IMAGE"" |
| 1782 | fi |
| 1783 | fi |
| 1784 | done |
| 1785 | |
| 1786 | SRC="$DUMPDIR" |
| 1787 | fi |
| 1788 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1789 | if [ "$VENDOR_STATE" -eq "0" ]; then |
| 1790 | echo "Cleaning output directory ($OUTPUT_ROOT).." |
| 1791 | rm -rf "${OUTPUT_TMP:?}" |
| 1792 | mkdir -p "${OUTPUT_TMP:?}" |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1793 | if [ -d "$OUTPUT_ROOT" ]; then |
| 1794 | mv "${OUTPUT_ROOT:?}/"* "${OUTPUT_TMP:?}/" |
| 1795 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1796 | VENDOR_STATE=1 |
| 1797 | fi |
| 1798 | |
| Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1799 | echo "Extracting ${COUNT} files in ${PROPRIETARY_FILES_TXT} from ${SRC}:" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1800 | |
| 1801 | for (( i=1; i<COUNT+1; i++ )); do |
| 1802 | |
| Vladimir Oltean | 8e2de65 | 2018-06-24 20:41:30 +0300 | [diff] [blame] | 1803 | local SPEC_SRC_FILE=$(src_file "${FILELIST[$i-1]}") |
| Vladimir Oltean | b06f3aa | 2018-06-24 20:38:04 +0300 | [diff] [blame] | 1804 | local SPEC_DST_FILE=$(target_file "${FILELIST[$i-1]}") |
| Vladimir Oltean | d639133 | 2018-06-24 20:42:01 +0300 | [diff] [blame] | 1805 | local SPEC_ARGS=$(target_args "${FILELIST[$i-1]}") |
| Vladimir Oltean | b5500d7 | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1806 | local OUTPUT_DIR= |
| 1807 | local TMP_DIR= |
| 1808 | local SRC_FILE= |
| 1809 | local DST_FILE= |
| Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1810 | local IS_PRODUCT_PACKAGE=false |
| 1811 | |
| 1812 | # Note: this relies on the fact that the ${FILELIST[@]} array |
| 1813 | # contains first ${PRODUCT_COPY_FILES_LIST[@]}, then ${PRODUCT_PACKAGES_LIST[@]}. |
| 1814 | if [ "${i}" -gt "${PRODUCT_COPY_FILES_COUNT}" ]; then |
| 1815 | IS_PRODUCT_PACKAGE=true |
| 1816 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1817 | |
| Michael Bestas | bda3020 | 2020-12-28 04:44:52 +0200 | [diff] [blame] | 1818 | OUTPUT_DIR="${OUTPUT_ROOT}" |
| 1819 | TMP_DIR="${OUTPUT_TMP}" |
| 1820 | SRC_FILE="/system/${SPEC_SRC_FILE}" |
| 1821 | DST_FILE="/system/${SPEC_DST_FILE}" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1822 | |
| Vladimir Oltean | b5500d7 | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1823 | # Strip the file path in the vendor repo of "system", if present |
| Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1824 | local BLOB_DISPLAY_NAME="${DST_FILE#/system/}" |
| dianlujitao | 4ddcfb7 | 2020-04-06 12:43:16 +0800 | [diff] [blame] | 1825 | local VENDOR_REPO_FILE="$OUTPUT_DIR/${BLOB_DISPLAY_NAME}" |
| Vladimir Oltean | b5500d7 | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1826 | mkdir -p $(dirname "${VENDOR_REPO_FILE}") |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1827 | |
| Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 1828 | # Check pinned files |
| Vladimir Oltean | e688cf9 | 2019-01-17 02:47:02 +0200 | [diff] [blame] | 1829 | local HASH="$(echo ${HASHLIST[$i-1]} | awk '{ print tolower($0); }')" |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1830 | local FIXUP_HASH="$(echo ${FIXUP_HASHLIST[$i-1]} | awk '{ print tolower($0); }')" |
| Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 1831 | local KEEP="" |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1832 | if [ "$DISABLE_PINNING" != "1" ] && [ "$HASH" != "x" ]; then |
| Vladimir Oltean | 4daf559 | 2018-06-24 20:46:42 +0300 | [diff] [blame] | 1833 | if [ -f "${VENDOR_REPO_FILE}" ]; then |
| 1834 | local PINNED="${VENDOR_REPO_FILE}" |
| Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 1835 | else |
| Vladimir Oltean | b5500d7 | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1836 | local PINNED="${TMP_DIR}${DST_FILE#/system}" |
| Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 1837 | fi |
| 1838 | if [ -f "$PINNED" ]; then |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1839 | local TMP_HASH=$(get_hash "${PINNED}") |
| 1840 | if [ "${TMP_HASH}" = "${HASH}" ] || [ "${TMP_HASH}" = "${FIXUP_HASH}" ]; then |
| Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 1841 | KEEP="1" |
| Vladimir Oltean | 4daf559 | 2018-06-24 20:46:42 +0300 | [diff] [blame] | 1842 | if [ ! -f "${VENDOR_REPO_FILE}" ]; then |
| 1843 | cp -p "$PINNED" "${VENDOR_REPO_FILE}" |
| Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 1844 | fi |
| 1845 | fi |
| 1846 | fi |
| 1847 | fi |
| 1848 | |
| Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1849 | if [ "${KANG}" = false ]; then |
| 1850 | printf ' - %s\n' "${BLOB_DISPLAY_NAME}" |
| 1851 | fi |
| 1852 | |
| Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 1853 | if [ "$KEEP" = "1" ]; then |
| Arian | 2d80238 | 2021-09-09 15:18:35 +0200 | [diff] [blame] | 1854 | if [ "${FIXUP_HASH}" != "x" ]; then |
| 1855 | printf ' + keeping pinned file with hash %s\n' "${FIXUP_HASH}" |
| 1856 | else |
| 1857 | printf ' + keeping pinned file with hash %s\n' "${HASH}" |
| 1858 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1859 | else |
| Vladimir Oltean | b5500d7 | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1860 | FOUND=false |
| 1861 | # Try Lineage target first. |
| 1862 | # Also try to search for files stripped of |
| 1863 | # the "/system" prefix, if we're actually extracting |
| 1864 | # from a system image. |
| Vladimir Oltean | fe49eae | 2018-06-25 00:05:56 +0300 | [diff] [blame] | 1865 | for CANDIDATE in "${DST_FILE}" "${SRC_FILE}"; do |
| Vladimir Oltean | b5500d7 | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1866 | get_file ${CANDIDATE} ${VENDOR_REPO_FILE} ${SRC} && { |
| 1867 | FOUND=true |
| 1868 | break |
| 1869 | } |
| 1870 | done |
| 1871 | |
| 1872 | if [ "${FOUND}" = false ]; then |
| Bruno Martins | 74e00eb | 2021-04-10 14:36:50 +0100 | [diff] [blame] | 1873 | colored_echo red " !! ${BLOB_DISPLAY_NAME}: file not found in source" |
| Vladimir Oltean | 1132937 | 2018-10-18 00:44:02 +0300 | [diff] [blame] | 1874 | continue |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1875 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1876 | |
| Arian | 5f98d79 | 2021-09-09 15:24:25 +0200 | [diff] [blame] | 1877 | # Blob fixup pipeline has 2 parts: one that is fixed and |
| 1878 | # one that is user-configurable |
| 1879 | local PRE_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE}) |
| 1880 | # Deodex apk|jar if that's the case |
| 1881 | if [[ "$FULLY_DEODEXED" -ne "1" && "${VENDOR_REPO_FILE}" =~ .(apk|jar)$ ]]; then |
| 1882 | oat2dex "${VENDOR_REPO_FILE}" "${SRC_FILE}" "$SRC" |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1883 | if [ -f "$EXTRACT_TMP_DIR/classes.dex" ]; then |
| 1884 | touch -t 200901010000 "$EXTRACT_TMP_DIR/classes"* |
| 1885 | zip -gjq "${VENDOR_REPO_FILE}" "$EXTRACT_TMP_DIR/classes"* |
| 1886 | rm "$EXTRACT_TMP_DIR/classes"* |
| Arian | 5f98d79 | 2021-09-09 15:24:25 +0200 | [diff] [blame] | 1887 | printf ' (updated %s from odex files)\n' "${SRC_FILE}" |
| 1888 | fi |
| 1889 | elif [[ "${VENDOR_REPO_FILE}" =~ .xml$ ]]; then |
| 1890 | fix_xml "${VENDOR_REPO_FILE}" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1891 | fi |
| Arian | 5f98d79 | 2021-09-09 15:24:25 +0200 | [diff] [blame] | 1892 | # Now run user-supplied fixup function |
| 1893 | blob_fixup "${BLOB_DISPLAY_NAME}" "${VENDOR_REPO_FILE}" |
| 1894 | local POST_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE}) |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1895 | |
| Arian | 5f98d79 | 2021-09-09 15:24:25 +0200 | [diff] [blame] | 1896 | if [ -f "${VENDOR_REPO_FILE}" ]; then |
| 1897 | local DIR=$(dirname "${VENDOR_REPO_FILE}") |
| 1898 | local TYPE="${DIR##*/}" |
| Michael Bestas | bda3020 | 2020-12-28 04:44:52 +0200 | [diff] [blame] | 1899 | if [ "$TYPE" = "bin" ]; then |
| Arian | 5f98d79 | 2021-09-09 15:24:25 +0200 | [diff] [blame] | 1900 | chmod 755 "${VENDOR_REPO_FILE}" |
| 1901 | else |
| 1902 | chmod 644 "${VENDOR_REPO_FILE}" |
| 1903 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1904 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1905 | |
| Arian | 5f98d79 | 2021-09-09 15:24:25 +0200 | [diff] [blame] | 1906 | if [ "${KANG}" = true ]; then |
| 1907 | print_spec "${IS_PRODUCT_PACKAGE}" "${SPEC_SRC_FILE}" "${SPEC_DST_FILE}" "${SPEC_ARGS}" "${PRE_FIXUP_HASH}" "${POST_FIXUP_HASH}" |
| 1908 | fi |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1909 | |
| Arian | 5f98d79 | 2021-09-09 15:24:25 +0200 | [diff] [blame] | 1910 | # Check and print whether the fixup pipeline actually did anything. |
| 1911 | # This isn't done right after the fixup pipeline because we want this print |
| 1912 | # to come after print_spec above, when in kang mode. |
| 1913 | if [ "${PRE_FIXUP_HASH}" != "${POST_FIXUP_HASH}" ]; then |
| 1914 | printf " + Fixed up %s\n" "${BLOB_DISPLAY_NAME}" |
| 1915 | # Now sanity-check the spec for this blob. |
| 1916 | if [ "${KANG}" = false ] && [ "${FIXUP_HASH}" = "x" ] && [ "${HASH}" != "x" ]; then |
| 1917 | colored_echo yellow "WARNING: The ${BLOB_DISPLAY_NAME} file was fixed up, but it is pinned." |
| 1918 | colored_echo yellow "This is a mistake and you want to either remove the hash completely, or add an extra one." |
| 1919 | fi |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1920 | fi |
| Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1921 | fi |
| 1922 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1923 | done |
| 1924 | |
| 1925 | # Don't allow failing |
| 1926 | set -e |
| 1927 | } |
| 1928 | |
| 1929 | # |
| Rashed Abdel-Tawab | 5b97a98 | 2019-09-29 01:19:57 -0400 | [diff] [blame] | 1930 | # extract2: |
| 1931 | # |
| 1932 | # Positional parameters: |
| 1933 | # $1: file containing the list of items to extract (aka proprietary-files.txt) |
| 1934 | # |
| 1935 | # Non-positional parameters (coming after $2): |
| 1936 | # --section: selects the portion to parse and extracts from proprietary-files.txt |
| 1937 | # --kang: if present, this option will activate the printing of hashes for the |
| 1938 | # extracted blobs. Useful with --section for subsequent pinning of |
| 1939 | # blobs taken from other origins. |
| 1940 | # |
| 1941 | function extract2() { |
| 1942 | # Consume positional parameters |
| 1943 | local PROPRIETARY_FILES_TXT="$1"; shift |
| 1944 | local SECTION="" |
| 1945 | local KANG=false |
| 1946 | |
| 1947 | # Consume optional, non-positional parameters |
| 1948 | while [ "$#" -gt 0 ]; do |
| 1949 | case "$1" in |
| 1950 | --adb) |
| 1951 | ADB=true |
| 1952 | ;; |
| 1953 | --system) |
| 1954 | SYSTEM_SRC="$2"; shift |
| 1955 | ;; |
| 1956 | --vendor) |
| 1957 | VENDOR_SRC="$2"; shift |
| 1958 | ;; |
| 1959 | --odm) |
| 1960 | ODM_SRC="$2"; shift |
| 1961 | ;; |
| 1962 | --product) |
| 1963 | PRODUCT_SRC="$2"; shift |
| 1964 | ;; |
| 1965 | -s|--section) |
| 1966 | SECTION="$2"; shift |
| 1967 | ;; |
| 1968 | -k|--kang) |
| 1969 | KANG=true |
| 1970 | DISABLE_PINNING=1 |
| 1971 | ;; |
| 1972 | esac |
| 1973 | shift |
| 1974 | done |
| 1975 | |
| 1976 | if [ -z "$ADB" ] || [ -z "$SYSTEM_SRC" && -z "$VENDOR_SRC" && -z "$ODM_SRC" && -z "$PRODUCT_SRC" ]; then |
| 1977 | echo "No sources set! You must select --adb or pass paths to partition dumps." |
| 1978 | exit 1 |
| 1979 | fi |
| 1980 | |
| 1981 | if [ -z "$OUTDIR" ]; then |
| 1982 | echo "Output dir not set!" |
| 1983 | exit 1 |
| 1984 | fi |
| 1985 | |
| 1986 | parse_file_list "${PROPRIETARY_FILES_TXT}" "${SECTION}" |
| 1987 | |
| 1988 | # Allow failing, so we can try $DEST and/or $FILE |
| 1989 | set +e |
| 1990 | |
| 1991 | local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ${PRODUCT_PACKAGES_LIST[@]} ) |
| 1992 | local HASHLIST=( ${PRODUCT_COPY_FILES_HASHES[@]} ${PRODUCT_PACKAGES_HASHES[@]} ) |
| 1993 | local FIXUP_HASHLIST=( ${PRODUCT_COPY_FILES_FIXUP_HASHES[@]} ${PRODUCT_PACKAGES_FIXUP_HASHES[@]} ) |
| 1994 | local PRODUCT_COPY_FILES_COUNT=${#PRODUCT_COPY_FILES_LIST[@]} |
| 1995 | local COUNT=${#FILELIST[@]} |
| 1996 | local OUTPUT_ROOT="$OMNI_ROOT"/"$OUTDIR"/proprietary |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1997 | local OUTPUT_TMP="$EXTRACT_TMP_DIR"/"$OUTDIR"/proprietary |
| Rashed Abdel-Tawab | 5b97a98 | 2019-09-29 01:19:57 -0400 | [diff] [blame] | 1998 | |
| 1999 | if [ "$ADB" = true ]; then |
| 2000 | init_adb_connection |
| 2001 | fi |
| 2002 | |
| 2003 | if [ "$VENDOR_STATE" -eq "0" ]; then |
| 2004 | echo "Cleaning output directory ($OUTPUT_ROOT).." |
| 2005 | rm -rf "${OUTPUT_TMP:?}" |
| 2006 | mkdir -p "${OUTPUT_TMP:?}" |
| 2007 | if [ -d "$OUTPUT_ROOT" ]; then |
| 2008 | mv "${OUTPUT_ROOT:?}/"* "${OUTPUT_TMP:?}/" |
| 2009 | fi |
| 2010 | VENDOR_STATE=1 |
| 2011 | fi |
| 2012 | |
| 2013 | echo "Extracting ${COUNT} files in ${PROPRIETARY_FILES_TXT} from ${SRC}:" |
| 2014 | |
| 2015 | for (( i=1; i<COUNT+1; i++ )); do |
| 2016 | |
| 2017 | local SPEC_SRC_FILE=$(src_file "${FILELIST[$i-1]}") |
| 2018 | local SPEC_DST_FILE=$(target_file "${FILELIST[$i-1]}") |
| 2019 | local SPEC_ARGS=$(target_args "${FILELIST[$i-1]}") |
| 2020 | local OUTPUT_DIR= |
| 2021 | local TMP_DIR= |
| 2022 | local SRC_FILE= |
| 2023 | local DST_FILE= |
| 2024 | local IS_PRODUCT_PACKAGE=false |
| 2025 | |
| 2026 | # Note: this relies on the fact that the ${FILELIST[@]} array |
| 2027 | # contains first ${PRODUCT_COPY_FILES_LIST[@]}, then ${PRODUCT_PACKAGES_LIST[@]}. |
| 2028 | if [ "${i}" -gt "${PRODUCT_COPY_FILES_COUNT}" ]; then |
| 2029 | IS_PRODUCT_PACKAGE=true |
| 2030 | fi |
| 2031 | |
| 2032 | if [ "${SPEC_ARGS}" = "rootfs" ]; then |
| 2033 | OUTPUT_DIR="${OUTPUT_ROOT}/rootfs" |
| 2034 | TMP_DIR="${OUTPUT_TMP}/rootfs" |
| 2035 | else |
| 2036 | OUTPUT_DIR="${OUTPUT_ROOT}" |
| 2037 | TMP_DIR="${OUTPUT_TMP}" |
| 2038 | fi |
| 2039 | SRC_FILE="${SPEC_SRC_FILE}" |
| 2040 | DST_FILE="${SPEC_DST_FILE}" |
| 2041 | |
| 2042 | local VENDOR_REPO_FILE="$OUTPUT_DIR/${DST_FILE}" |
| 2043 | local BLOB_DISPLAY_NAME="${DST_FILE}" |
| 2044 | mkdir -p $(dirname "${VENDOR_REPO_FILE}") |
| 2045 | |
| 2046 | # Check pinned files |
| 2047 | local HASH="$(echo ${HASHLIST[$i-1]} | awk '{ print tolower($0); }')" |
| 2048 | local FIXUP_HASH="$(echo ${FIXUP_HASHLIST[$i-1]} | awk '{ print tolower($0); }')" |
| 2049 | local KEEP="" |
| 2050 | if [ "$DISABLE_PINNING" != "1" ] && [ "$HASH" != "x" ]; then |
| 2051 | if [ -f "${VENDOR_REPO_FILE}" ]; then |
| 2052 | local PINNED="${VENDOR_REPO_FILE}" |
| 2053 | else |
| 2054 | local PINNED="${TMP_DIR}${DST_FILE}" |
| 2055 | fi |
| 2056 | if [ -f "$PINNED" ]; then |
| 2057 | local TMP_HASH=$(get_hash "${PINNED}") |
| 2058 | if [ "${TMP_HASH}" = "${HASH}" ] || [ "${TMP_HASH}" = "${FIXUP_HASH}" ]; then |
| 2059 | KEEP="1" |
| 2060 | if [ ! -f "${VENDOR_REPO_FILE}" ]; then |
| 2061 | cp -p "$PINNED" "${VENDOR_REPO_FILE}" |
| 2062 | fi |
| 2063 | fi |
| 2064 | fi |
| 2065 | fi |
| 2066 | |
| 2067 | if [ "${KANG}" = false ]; then |
| 2068 | printf ' - %s\n' "${BLOB_DISPLAY_NAME}" |
| 2069 | fi |
| 2070 | |
| 2071 | if [ "$KEEP" = "1" ]; then |
| 2072 | printf ' + keeping pinned file with hash %s\n' "${HASH}" |
| 2073 | else |
| 2074 | FOUND=false |
| 2075 | PARTITION_SOURCE_DIR= |
| 2076 | # Try Lineage target first. |
| 2077 | for CANDIDATE in "${DST_FILE}" "${SRC_FILE}"; do |
| 2078 | PARTITION=$(echo "$CANDIDATE" | cut -d/ -f1) |
| 2079 | if [ "$PARTITION" = "system" ]; then |
| 2080 | PARTITION_SOURCE_DIR="$SYSTEM_SRC" |
| 2081 | elif [ "$PARTITION" = "vendor" ]; then |
| 2082 | PARTITION_SOURCE_DIR="$VENDOR_SRC" |
| 2083 | elif [ "$PARTITION" = "product" ]; then |
| 2084 | PARTITION_SOURCE_DIR="$PRODUCT_SRC" |
| 2085 | elif [ "$PARTITION" = "odm" ]; then |
| 2086 | PARTITION_SOURCE_DIR="$ODM_SRC" |
| 2087 | fi |
| 2088 | CANDIDATE_RELATIVE_NAME=$(echo "$CANDIDATE" | cut -d/ -f2-) |
| 2089 | get_file ${CANDIDATE_RELATIVE_NAME} ${VENDOR_REPO_FILE} ${PARTITION_SOURCE_DIR} && { |
| 2090 | FOUND=true |
| 2091 | break |
| 2092 | } |
| 2093 | # Search with the full system/ prefix if the file was not found on the system partition |
| 2094 | # because we may be searching in a mounted system-as-root system.img |
| 2095 | if [[ "${FOUND}" = false && "$PARTITION" = "system" ]]; then |
| 2096 | get_file ${CANDIDATE} ${VENDOR_REPO_FILE} ${PARTITION_SOURCE_DIR} && { |
| 2097 | FOUND=true |
| 2098 | break |
| 2099 | } |
| 2100 | fi |
| 2101 | done |
| 2102 | |
| 2103 | if [ -z "${PARTITION_SOURCE_DIR}" ]; then |
| 2104 | echo "$CANDIDATE has no preceeding partition path. Prepend system/, vendor/, product/, or odm/ to this entry." |
| 2105 | fi |
| 2106 | |
| 2107 | if [ "${FOUND}" = false ]; then |
| 2108 | printf ' !! %s: file not found in source\n' "${BLOB_DISPLAY_NAME}" |
| 2109 | continue |
| 2110 | fi |
| 2111 | fi |
| 2112 | |
| 2113 | # Blob fixup pipeline has 2 parts: one that is fixed and |
| 2114 | # one that is user-configurable |
| 2115 | local PRE_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE}) |
| 2116 | # Deodex apk|jar if that's the case |
| 2117 | if [[ "$FULLY_DEODEXED" -ne "1" && "${VENDOR_REPO_FILE}" =~ .(apk|jar)$ ]]; then |
| 2118 | oat2dex "${VENDOR_REPO_FILE}" "${SRC_FILE}" "${SYSTEM_SRC}" |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 2119 | if [ -f "$EXTRACT_TMP_DIR/classes.dex" ]; then |
| 2120 | zip -gjq "${VENDOR_REPO_FILE}" "$EXTRACT_TMP_DIR/classes"* |
| 2121 | rm "$EXTRACT_TMP_DIR/classes"* |
| Rashed Abdel-Tawab | 5b97a98 | 2019-09-29 01:19:57 -0400 | [diff] [blame] | 2122 | printf ' (updated %s from odex files)\n' "${SRC_FILE}" |
| 2123 | fi |
| 2124 | elif [[ "${VENDOR_REPO_FILE}" =~ .xml$ ]]; then |
| 2125 | fix_xml "${VENDOR_REPO_FILE}" |
| 2126 | fi |
| 2127 | # Now run user-supplied fixup function |
| 2128 | blob_fixup "${BLOB_DISPLAY_NAME}" "${VENDOR_REPO_FILE}" |
| 2129 | local POST_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE}) |
| 2130 | |
| 2131 | if [ -f "${VENDOR_REPO_FILE}" ]; then |
| 2132 | local DIR=$(dirname "${VENDOR_REPO_FILE}") |
| 2133 | local TYPE="${DIR##*/}" |
| 2134 | if [ "$TYPE" = "bin" -o "$TYPE" = "sbin" ]; then |
| 2135 | chmod 755 "${VENDOR_REPO_FILE}" |
| 2136 | else |
| 2137 | chmod 644 "${VENDOR_REPO_FILE}" |
| 2138 | fi |
| 2139 | fi |
| 2140 | |
| 2141 | if [ "${KANG}" = true ]; then |
| 2142 | print_spec "${IS_PRODUCT_PACKAGE}" "${SPEC_SRC_FILE}" "${SPEC_DST_FILE}" "${SPEC_ARGS}" "${PRE_FIXUP_HASH}" "${POST_FIXUP_HASH}" |
| 2143 | fi |
| 2144 | |
| 2145 | # Check and print whether the fixup pipeline actually did anything. |
| 2146 | # This isn't done right after the fixup pipeline because we want this print |
| 2147 | # to come after print_spec above, when in kang mode. |
| 2148 | if [ "${PRE_FIXUP_HASH}" != "${POST_FIXUP_HASH}" ]; then |
| 2149 | printf " + Fixed up %s\n" "${BLOB_DISPLAY_NAME}" |
| 2150 | # Now sanity-check the spec for this blob. |
| 2151 | if [ "${KANG}" = false ] && [ "${FIXUP_HASH}" = "x" ] && [ "${HASH}" != "x" ]; then |
| 2152 | printf "WARNING: The %s file was fixed up, but it is pinned.\n" ${BLOB_DISPLAY_NAME} |
| 2153 | printf "This is a mistake and you want to either remove the hash completely, or add an extra one.\n" |
| 2154 | fi |
| 2155 | fi |
| 2156 | |
| 2157 | done |
| 2158 | |
| 2159 | # Don't allow failing |
| 2160 | set -e |
| 2161 | } |
| 2162 | |
| 2163 | # |
| Michael Bestas | f3c5908 | 2023-11-30 20:26:02 +0200 | [diff] [blame] | 2164 | # To be overridden by device-level extract-files.sh |
| 2165 | # |
| 2166 | function prepare_firmware() { |
| 2167 | : |
| 2168 | } |
| 2169 | |
| 2170 | # |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 2171 | # extract_firmware: |
| 2172 | # |
| 2173 | # $1: file containing the list of items to extract |
| 2174 | # $2: path to extracted radio folder |
| 2175 | # |
| 2176 | function extract_firmware() { |
| 2177 | if [ -z "$OUTDIR" ]; then |
| 2178 | echo "Output dir not set!" |
| 2179 | exit 1 |
| 2180 | fi |
| 2181 | |
| 2182 | parse_file_list "$1" |
| 2183 | |
| 2184 | # Don't allow failing |
| 2185 | set -e |
| 2186 | |
| 2187 | local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ) |
| 2188 | local COUNT=${#FILELIST[@]} |
| 2189 | local SRC="$2" |
| theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 2190 | local OUTPUT_DIR="$OMNI_ROOT"/"$OUTDIR"/radio |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 2191 | |
| 2192 | if [ "$VENDOR_RADIO_STATE" -eq "0" ]; then |
| 2193 | echo "Cleaning firmware output directory ($OUTPUT_DIR).." |
| 2194 | rm -rf "${OUTPUT_DIR:?}/"* |
| 2195 | VENDOR_RADIO_STATE=1 |
| 2196 | fi |
| 2197 | |
| 2198 | echo "Extracting $COUNT files in $1 from $SRC:" |
| 2199 | |
| Michael Bestas | f3c5908 | 2023-11-30 20:26:02 +0200 | [diff] [blame] | 2200 | prepare_firmware |
| 2201 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 2202 | for (( i=1; i<COUNT+1; i++ )); do |
| Michael Bestas | f62d403 | 2022-02-22 19:06:41 +0200 | [diff] [blame] | 2203 | local SRC_FILE=$(src_file "${FILELIST[$i-1]}") |
| 2204 | local DST_FILE=$(target_file "${FILELIST[$i-1]}") |
| 2205 | |
| 2206 | printf ' - %s \n' "radio/$DST_FILE" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 2207 | |
| 2208 | if [ ! -d "$OUTPUT_DIR" ]; then |
| 2209 | mkdir -p "$OUTPUT_DIR" |
| 2210 | fi |
| Chirayu Desai | 1041868 | 2022-05-25 23:37:27 +0530 | [diff] [blame] | 2211 | if [ -f "$SRC" ] && [ "${SRC##*.}" == "zip" ]; then |
| 2212 | # Extract A/B OTA |
| 2213 | if [ -a "$DUMPDIR"/payload.bin ]; then |
| 2214 | python3 "$ANDROID_ROOT"/tools/extract-utils/extract_ota.py "$DUMPDIR"/payload.bin -o "$DUMPDIR" -p $(basename "${DST_FILE%.*}") 2>&1 |
| 2215 | cp "$DUMPDIR/$(basename $DST_FILE)" "$OUTPUT_DIR/$DST_FILE" |
| 2216 | fi |
| Michael Bestas | ed3cae9 | 2023-04-13 16:38:34 +0300 | [diff] [blame] | 2217 | else |
| Chirayu Desai | 1041868 | 2022-05-25 23:37:27 +0530 | [diff] [blame] | 2218 | if [ -f "$SRC/$SRC_FILE" ]; then |
| 2219 | cp "$SRC/$SRC_FILE" "$OUTPUT_DIR/$DST_FILE" |
| 2220 | else |
| 2221 | cp "$SRC/$DST_FILE" "$OUTPUT_DIR/$DST_FILE" |
| 2222 | fi |
| Michael Bestas | ed3cae9 | 2023-04-13 16:38:34 +0300 | [diff] [blame] | 2223 | fi |
| Michael Bestas | f62d403 | 2022-02-22 19:06:41 +0200 | [diff] [blame] | 2224 | chmod 644 "$OUTPUT_DIR/$DST_FILE" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 2225 | done |
| 2226 | } |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2227 | |
| 2228 | function extract_img_data() { |
| 2229 | local image_file="$1" |
| 2230 | local out_dir="$2" |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 2231 | local logFile="$EXTRACT_TMP_DIR/debugfs.log" |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2232 | |
| 2233 | if [ ! -d "$out_dir" ]; then |
| 2234 | mkdir -p "$out_dir" |
| 2235 | fi |
| 2236 | |
| 2237 | if [[ "$HOST_OS" == "Darwin" ]]; then |
| 2238 | debugfs -R "rdump / \"$out_dir\"" "$image_file" &> "$logFile" || { |
| 2239 | echo "[-] Failed to extract data from '$image_file'" |
| 2240 | abort 1 |
| 2241 | } |
| 2242 | else |
| 2243 | debugfs -R 'ls -p' "$image_file" 2>/dev/null | cut -d '/' -f6 | while read -r entry |
| 2244 | do |
| 2245 | debugfs -R "rdump \"$entry\" \"$out_dir\"" "$image_file" >> "$logFile" 2>&1 || { |
| 2246 | echo "[-] Failed to extract data from '$image_file'" |
| 2247 | abort 1 |
| 2248 | } |
| 2249 | done |
| 2250 | fi |
| 2251 | |
| 2252 | local symlink_err="rdump: Attempt to read block from filesystem resulted in short read while reading symlink" |
| 2253 | if grep -Fq "$symlink_err" "$logFile"; then |
| 2254 | echo "[-] Symlinks have not been properly processed from $image_file" |
| Michael Bestas | 1b57025 | 2021-12-02 21:05:36 +0200 | [diff] [blame] | 2255 | echo "[!] You might not have a compatible debugfs version" |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2256 | abort 1 |
| 2257 | fi |
| 2258 | } |
| 2259 | |
| 2260 | declare -ra VENDOR_SKIP_FILES=( |
| 2261 | "bin/toybox_vendor" |
| 2262 | "bin/toolbox" |
| 2263 | "bin/grep" |
| 2264 | "build.prop" |
| 2265 | "compatibility_matrix.xml" |
| 2266 | "default.prop" |
| 2267 | "etc/NOTICE.xml.gz" |
| 2268 | "etc/vintf/compatibility_matrix.xml" |
| 2269 | "etc/vintf/manifest.xml" |
| 2270 | "etc/wifi/wpa_supplicant.conf" |
| 2271 | "manifest.xml" |
| 2272 | "overlay/DisplayCutoutEmulationCorner/DisplayCutoutEmulationCornerOverlay.apk" |
| 2273 | "overlay/DisplayCutoutEmulationDouble/DisplayCutoutEmulationDoubleOverlay.apk" |
| 2274 | "overlay/DisplayCutoutEmulationTall/DisplayCutoutEmulationTallOverlay.apk" |
| 2275 | "overlay/DisplayCutoutNoCutout/NoCutoutOverlay.apk" |
| 2276 | "overlay/framework-res__auto_generated_rro.apk" |
| 2277 | "overlay/SysuiDarkTheme/SysuiDarkThemeOverlay.apk" |
| 2278 | ) |
| 2279 | |
| 2280 | function array_contains() { |
| 2281 | local element |
| 2282 | for element in "${@:2}"; do [[ "$element" == "$1" ]] && return 0; done |
| 2283 | return 1 |
| 2284 | } |
| 2285 | |
| 2286 | function generate_prop_list_from_image() { |
| 2287 | local image_file="$1" |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 2288 | local image_dir="$EXTRACT_TMP_DIR/image-temp" |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2289 | local output_list="$2" |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 2290 | local output_list_tmp="$EXTRACT_TMP_DIR/_proprietary-blobs.txt" |
| Michael Bestas | ca5d78a | 2021-12-02 20:58:40 +0200 | [diff] [blame] | 2291 | local -n skipped_files="$3" |
| Michael Bestas | fc1a22e | 2023-06-11 17:45:46 +0300 | [diff] [blame] | 2292 | local component="$4" |
| 2293 | local partition="$component" |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2294 | |
| Chirayu Desai | 203cc52 | 2021-12-04 01:18:45 +0530 | [diff] [blame] | 2295 | mkdir -p "$image_dir" |
| 2296 | |
| LuK1337 | 07657db | 2023-11-30 18:11:51 +0100 | [diff] [blame] | 2297 | if [[ $(file -b "$image_file") == EROFS* ]]; then |
| 2298 | fsck.erofs --extract="$image_dir" "$image_file" |
| 2299 | elif [[ $(file -b "$image_file") == Linux* ]]; then |
| Chirayu Desai | 203cc52 | 2021-12-04 01:18:45 +0530 | [diff] [blame] | 2300 | extract_img_data "$image_file" "$image_dir" |
| 2301 | elif [[ $(file -b "$image_file") == Android* ]]; then |
| Chirayu Desai | 501ffd6 | 2022-03-17 06:27:33 +0530 | [diff] [blame] | 2302 | "$SIMG2IMG" "$image_file" "$image_dir"/"$(basename "$image_file").raw" |
| Chirayu Desai | 203cc52 | 2021-12-04 01:18:45 +0530 | [diff] [blame] | 2303 | extract_img_data "$image_dir"/"$(basename "$image_file").raw" "$image_dir" |
| 2304 | rm "$image_dir"/"$(basename "$image_file").raw" |
| 2305 | else |
| 2306 | echo "Unsupported "$image_file"" |
| 2307 | fi |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2308 | |
| Michael Bestas | fc1a22e | 2023-06-11 17:45:46 +0300 | [diff] [blame] | 2309 | if [ -z "$component" ]; then |
| 2310 | partition="vendor" |
| 2311 | elif [[ "$component" == "carriersettings" ]]; then |
| 2312 | partition="product" |
| 2313 | fi |
| 2314 | |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2315 | find "$image_dir" -not -type d | sed "s#^$image_dir/##" | while read -r FILE |
| 2316 | do |
| Michael Bestas | fc1a22e | 2023-06-11 17:45:46 +0300 | [diff] [blame] | 2317 | if [[ "$component" == "carriersettings" ]] && ! prefix_match_file "etc/CarrierSettings" "$FILE" ; then |
| 2318 | continue |
| 2319 | fi |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2320 | # Skip VENDOR_SKIP_FILES since it will be re-generated at build time |
| 2321 | if array_contains "$FILE" "${VENDOR_SKIP_FILES[@]}"; then |
| 2322 | continue |
| 2323 | fi |
| 2324 | # Skip device defined skipped files since they will be re-generated at build time |
| Michael Bestas | ca5d78a | 2021-12-02 20:58:40 +0200 | [diff] [blame] | 2325 | if array_contains "$FILE" "${skipped_files[@]}"; then |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2326 | continue |
| 2327 | fi |
| Michael Bestas | fc1a22e | 2023-06-11 17:45:46 +0300 | [diff] [blame] | 2328 | echo "$partition/$FILE" >> "$output_list_tmp" |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2329 | done |
| 2330 | |
| 2331 | # Sort merged file with all lists |
| Michael Bestas | 1e6efb3 | 2021-11-15 19:28:56 +0200 | [diff] [blame] | 2332 | LC_ALL=C sort -u "$output_list_tmp" > "$output_list" |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2333 | |
| 2334 | # Clean-up |
| 2335 | rm -f "$output_list_tmp" |
| 2336 | } |
| Bruno Martins | 0f425f1 | 2021-04-10 14:57:32 +0100 | [diff] [blame] | 2337 | |
| 2338 | function colored_echo() { |
| 2339 | IFS=" " |
| 2340 | local color=$1; |
| 2341 | shift |
| 2342 | if ! [[ $color =~ '^[0-9]$' ]] ; then |
| 2343 | case $(echo $color | tr '[:upper:]' '[:lower:]') in |
| 2344 | black) color=0 ;; |
| 2345 | red) color=1 ;; |
| 2346 | green) color=2 ;; |
| 2347 | yellow) color=3 ;; |
| 2348 | blue) color=4 ;; |
| 2349 | magenta) color=5 ;; |
| 2350 | cyan) color=6 ;; |
| 2351 | white|*) color=7 ;; # white or invalid color |
| 2352 | esac |
| 2353 | fi |
| Bruno Martins | 5064db2 | 2021-06-21 14:47:40 +0100 | [diff] [blame] | 2354 | if [ -t 1 ] ; then tput setaf $color; fi |
| Bruno Martins | 0f425f1 | 2021-04-10 14:57:32 +0100 | [diff] [blame] | 2355 | printf '%s\n' "$*" |
| Bruno Martins | 5064db2 | 2021-06-21 14:47:40 +0100 | [diff] [blame] | 2356 | if [ -t 1 ] ; then tput sgr0; fi |
| Bruno Martins | 0f425f1 | 2021-04-10 14:57:32 +0100 | [diff] [blame] | 2357 | } |