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