blob: 36825097b7f2d381c50a7569b6f1e4955f3c9c3b [file] [log] [blame]
omarismaild255c562024-11-08 15:48:53 +00001#!/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
Omar Ismail28b2e5d2024-11-15 17:05:23 +000042REVISION=$(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 Ismail3b9a0572024-11-15 12:21:32 +000048: ${KZIP_NAME:=$(git rev-parse HEAD)}
omarismaild255c562024-11-08 15:48:53 +000049
Omar Ismail28b2e5d2024-11-15 17:05:23 +000050# Fallback to a UUID if both the revision and Git commit hash are not there
omarismaild255c562024-11-08 15:48:53 +000051: ${KZIP_NAME:=$(uuidgen)}
52
53
54rm -rf $DIST_DIR/*.kzip
55declare -r allkzip="$KZIP_NAME.kzip"
56echo "Merging Kzips..."
Omar Ismail1cae1062024-11-14 15:04:36 +000057
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')