1*cda5da8dSAndroid Build Coastguard Worker#!/bin/bash -eu 2*cda5da8dSAndroid Build Coastguard Worker 3*cda5da8dSAndroid Build Coastguard Worker# Copyright 2020 Google Inc. All rights reserved. 4*cda5da8dSAndroid Build Coastguard Worker# 5*cda5da8dSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 6*cda5da8dSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 7*cda5da8dSAndroid Build Coastguard Worker# You may obtain a copy of the License at 8*cda5da8dSAndroid Build Coastguard Worker# 9*cda5da8dSAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 10*cda5da8dSAndroid Build Coastguard Worker# 11*cda5da8dSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 12*cda5da8dSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 13*cda5da8dSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*cda5da8dSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 15*cda5da8dSAndroid Build Coastguard Worker# limitations under the License. 16*cda5da8dSAndroid Build Coastguard Worker 17*cda5da8dSAndroid Build Coastguard Worker# Builds cumulative cross-reference extraction file (.kzip) for all the 18*cda5da8dSAndroid Build Coastguard Worker# modules defined and buildable in this repository. 19*cda5da8dSAndroid Build Coastguard Worker# Usage: 20*cda5da8dSAndroid Build Coastguard Worker# cd <repository top> && OUT_DIR=<output dir> prebuilts/build-tools-kzip.sh 21*cda5da8dSAndroid Build Coastguard Worker# Generates $OUT_DIR/all.zkip 22*cda5da8dSAndroid Build Coastguard Worker 23*cda5da8dSAndroid Build Coastguard Workerdeclare -r corpus=android.googlesource.com/platform/superproject 24*cda5da8dSAndroid Build Coastguard Workermkdir -p "${OUT_DIR:?Specify output directory}/soong" 25*cda5da8dSAndroid Build Coastguard Worker 26*cda5da8dSAndroid Build Coastguard Worker# Build for x86, ignore missing references. 27*cda5da8dSAndroid Build Coastguard Workerprintf '{"Allow_missing_dependencies": true, "HostArch":"x86_64" }\n' >"${OUT_DIR}/soong/soong.variables" 28*cda5da8dSAndroid Build Coastguard Worker 29*cda5da8dSAndroid Build Coastguard Worker# Some of targets will fail because of the missing references, but there 30*cda5da8dSAndroid Build Coastguard Worker# will be sufficient number of successfully compiled modules. 31*cda5da8dSAndroid Build Coastguard WorkerXREF_CORPUS="${corpus}" build/soong/soong_ui.bash --make-mode --skip-config --soong-only -k xref_java xref_cxx || echo Ignoring errors 32*cda5da8dSAndroid Build Coastguard Worker 33*cda5da8dSAndroid Build Coastguard Worker# Package it all into a single .kzip, ignoring duplicates. 34*cda5da8dSAndroid Build Coastguard Workerallkzip=$(realpath "${OUT_DIR}/all.kzip") 35*cda5da8dSAndroid Build Coastguard Workerrm -f "${allkzip}" 36*cda5da8dSAndroid Build Coastguard Workertempdir=$(mktemp -d) 37*cda5da8dSAndroid Build Coastguard Workerfor zip in $(find "${OUT_DIR}" -name '*.kzip'); do 38*cda5da8dSAndroid Build Coastguard Worker unzip -qn "${zip}" -d "${tempdir}" 39*cda5da8dSAndroid Build Coastguard Workerdone 40*cda5da8dSAndroid Build Coastguard Worker(cd "${tempdir}" && zip -9rmq "${allkzip}" . && rmdir "${tempdir}") 41*cda5da8dSAndroid Build Coastguard Workerprintf "Created %s with %d compilation units\n" "${allkzip}" $(zipinfo "${allkzip}" 'root/units/?*' | wc -l) 42*cda5da8dSAndroid Build Coastguard Worker 43