blob: 387447ba34ad7f9f54693802a23e30758feedd1d [file] [log] [blame]
Sasha Smundak0d7c5212019-11-11 10:42:19 -08001#!/bin/bash -eu
Colin Cross9297fad2020-08-10 12:18:51 -07002
3# Copyright 2020 Google Inc. All rights reserved.
Sasha Smundak0d7c5212019-11-11 10:42:19 -08004#
Colin Cross9297fad2020-08-10 12:18:51 -07005# 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
Sasha Smundak0d7c5212019-11-11 10:42:19 -080017# Builds cumulative cross-reference extraction file (.kzip) for all the
18# modules defined and buildable in this repository.
19# Usage:
20# cd <repository top> && OUT_DIR=<output dir> prebuilts/build-tools-kzip.sh
21# Generates $OUT_DIR/all.zkip
22
23declare -r corpus=android.googlesource.com/platform/superproject
24mkdir -p "${OUT_DIR:?Specify output directory}/soong"
25
26# Build for x86, ignore missing references.
27printf '{"Allow_missing_dependencies": true, "HostArch":"x86_64" }\n' >"${OUT_DIR}/soong/soong.variables"
28
29# Some of targets will fail because of the missing references, but there
30# will be sufficient number of successfully compiled modules.
Colin Cross27b1e622021-10-28 16:32:22 -070031XREF_CORPUS="${corpus}" build/soong/soong_ui.bash --make-mode --skip-config --soong-only -k xref_java xref_cxx || echo Ignoring errors
Sasha Smundak0d7c5212019-11-11 10:42:19 -080032
33# Package it all into a single .kzip, ignoring duplicates.
34allkzip=$(realpath "${OUT_DIR}/all.kzip")
35rm -f "${allkzip}"
36tempdir=$(mktemp -d)
37for zip in $(find "${OUT_DIR}" -name '*.kzip'); do
38 unzip -qn "${zip}" -d "${tempdir}"
39done
40(cd "${tempdir}" && zip -9rmq "${allkzip}" . && rmdir "${tempdir}")
41printf "Created %s with %d compilation units\n" "${allkzip}" $(zipinfo "${allkzip}" 'root/units/?*' | wc -l)
42