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 23set -e 24 25# Absolute path of the directory where this script lives 26SCRIPT_DIR="$(cd $(dirname $0) && pwd)" 27 28PREBUILTS_DIR=$SCRIPT_DIR/../../../../prebuilts 29 30cd "$SCRIPT_DIR/../.." 31if [ "$OUT_DIR" == "" ]; then 32 OUT_DIR="../../out" 33fi 34mkdir -p "$OUT_DIR" 35export OUT_DIR="$(cd $OUT_DIR && pwd)" 36if [ "$DIST_DIR" == "" ]; then 37 DIST_DIR="$OUT_DIR/dist" 38fi 39mkdir -p "$DIST_DIR" 40export DIST_DIR="$DIST_DIR" 41 42REVISION=$(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 48: ${KZIP_NAME:=$(git rev-parse HEAD)} 49 50# Fallback to a UUID if both the revision and Git commit hash are not there 51: ${KZIP_NAME:=$(uuidgen)} 52 53 54rm -rf $DIST_DIR/*.kzip 55declare -r allkzip="$KZIP_NAME.kzip" 56echo "Merging Kzips..." 57 58# Determine the directory based on OS 59if [[ "$(uname)" == "Darwin" ]]; then 60 BUILD_TOOLS_DIR="$PREBUILTS_DIR/build-tools/darwin-x86/bin" 61else 62 BUILD_TOOLS_DIR="$PREBUILTS_DIR/build-tools/linux-x86/bin" 63fi 64 65"$BUILD_TOOLS_DIR/merge_zips" "$DIST_DIR/$allkzip" @<(find "$OUT_DIR/androidx" -name '*.kzip') 66