omarismail | d255c56 | 2024-11-08 15:48:53 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright 2024 The Android Open Source 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 | # Merge kzip files (source files for the indexing pipeline) for the given configuration, and place |
| 19 | # the resulting all.kzip into $DIST_DIR. |
| 20 | # Most code from: |
| 21 | # https://cs.android.com/android/platform/superproject/main/+/main:build/soong/build_kzip.bash; |
| 22 | |
| 23 | set -e |
| 24 | |
| 25 | # Absolute path of the directory where this script lives |
| 26 | SCRIPT_DIR="$(cd $(dirname $0) && pwd)" |
| 27 | |
| 28 | PREBUILTS_DIR=$SCRIPT_DIR/../../../../prebuilts |
| 29 | |
| 30 | cd "$SCRIPT_DIR/../.." |
| 31 | if [ "$OUT_DIR" == "" ]; then |
| 32 | OUT_DIR="../../out" |
| 33 | fi |
| 34 | mkdir -p "$OUT_DIR" |
| 35 | export OUT_DIR="$(cd $OUT_DIR && pwd)" |
| 36 | if [ "$DIST_DIR" == "" ]; then |
| 37 | DIST_DIR="$OUT_DIR/dist" |
| 38 | fi |
| 39 | mkdir -p "$DIST_DIR" |
| 40 | export DIST_DIR="$DIST_DIR" |
| 41 | |
Omar Ismail | 28b2e5d | 2024-11-15 17:05:23 +0000 | [diff] [blame] | 42 | REVISION=$(grep 'path="frameworks/support"' "$MANIFEST" | sed -n 's/.*revision="\([^"]*\).*/\1/p') |
| 43 | |
| 44 | # Default KZIP_NAME to the revision value from the XML file |
| 45 | : ${KZIP_NAME:=$REVISION} |
| 46 | |
| 47 | # Fallback to the latest Git commit hash if revision is not found |
Omar Ismail | 3b9a057 | 2024-11-15 12:21:32 +0000 | [diff] [blame] | 48 | : ${KZIP_NAME:=$(git rev-parse HEAD)} |
omarismail | d255c56 | 2024-11-08 15:48:53 +0000 | [diff] [blame] | 49 | |
Omar Ismail | 28b2e5d | 2024-11-15 17:05:23 +0000 | [diff] [blame] | 50 | # Fallback to a UUID if both the revision and Git commit hash are not there |
omarismail | d255c56 | 2024-11-08 15:48:53 +0000 | [diff] [blame] | 51 | : ${KZIP_NAME:=$(uuidgen)} |
| 52 | |
| 53 | |
| 54 | rm -rf $DIST_DIR/*.kzip |
| 55 | declare -r allkzip="$KZIP_NAME.kzip" |
| 56 | echo "Merging Kzips..." |
Omar Ismail | 1cae106 | 2024-11-14 15:04:36 +0000 | [diff] [blame] | 57 | |
| 58 | # Determine the directory based on OS |
| 59 | if [[ "$(uname)" == "Darwin" ]]; then |
| 60 | BUILD_TOOLS_DIR="$PREBUILTS_DIR/build-tools/darwin-x86/bin" |
| 61 | else |
| 62 | BUILD_TOOLS_DIR="$PREBUILTS_DIR/build-tools/linux-x86/bin" |
| 63 | fi |
| 64 | |
| 65 | "$BUILD_TOOLS_DIR/merge_zips" "$DIST_DIR/$allkzip" @<(find "$OUT_DIR/androidx" -name '*.kzip') |