1#!/bin/bash -eu 2 3# Copyright 2020 Google Inc. All rights reserved. 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# 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. 31XREF_CORPUS="${corpus}" build/soong/soong_ui.bash --make-mode --skip-config --soong-only -k xref_java xref_cxx || echo Ignoring errors 32 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 43