Let build-prebuilts.sh compile unit tests

build-prebuilts.sh compiles header-checker-unittests by default. The
continuous builds ensure that the tests are compilable. The developers
can use the script to build the tests locally.

Test: OUT_DIR=out BUILD_BROKEN_DISABLE_BAZEL=1 \
      development/vndk/tools/header-checker/android/build-prebuilts.sh \
      header-checker-unittests
Test: OUT_DIR=out BUILD_BROKEN_DISABLE_BAZEL=1 DIST_DIR=/tmp/distdir \
      development/vndk/tools/header-checker/android/build-prebuilts.sh
Bug: 280008249
Change-Id: I32d6ade3c527785d68802c1737c94f963ead5b3c
This commit is contained in:
Hsin-Yi Chen
2023-03-02 01:32:01 +08:00
parent 6ca8712996
commit 9beee3bf06

View File

@@ -18,19 +18,39 @@ usage() {
echo "Usage: $(basename "$0") [build_target]..."
echo " Build all targets if build_target is not specified."
echo " Supported build targets for macOS: ${MACOS_SOONG_BINARIES[*]}"
echo " Supported build targets for Linux: ${LINUX_SOONG_BINARIES[*]}"
echo " Supported build targets for Linux:" \
"${LINUX_SOONG_BINARIES[@]}" "${LINUX_SOONG_TESTS[@]}"
}
valid_build_target () {
for i in "${VALID_SOONG_BINARIES[@]}"; do
if [ "$i" = "$1" ]; then
return 0
fi
in_array () {
value="$1"
shift
for i in "$@"; do
[ "$i" = "${value}" ] && return 0
done
return 1
}
SOONG_BINARIES=()
LINUX_SOONG_BINARIES=(
"bindgen"
"cxx_extractor"
"header-abi-linker"
"header-abi-dumper"
"header-abi-diff"
"proto_metadata_plugin"
"protoc_extractor"
"versioner"
)
LINUX_SOONG_TESTS=(
"header-checker-unittests"
)
MACOS_SOONG_BINARIES=(
"versioner"
)
BUILD_TARGETS=()
while [ $# -gt 0 ]; do
case $1 in
@@ -38,8 +58,8 @@ while [ $# -gt 0 ]; do
usage
exit 0
;;
*) # Add specified build targets into SOONG_BINARIES
SOONG_BINARIES+=("$1")
*) # Add specified build targets into BUILD_TARGETS
BUILD_TARGETS+=("$1")
;;
esac
shift
@@ -63,42 +83,37 @@ Darwin)
;;
esac
LINUX_SOONG_BINARIES=(
"bindgen"
"cxx_extractor"
"header-abi-linker"
"header-abi-dumper"
"header-abi-diff"
"proto_metadata_plugin"
"protoc_extractor"
"versioner"
)
MACOS_SOONG_BINARIES=(
"versioner"
)
# Targets to be built
if [ "${OS}" = "darwin" ]; then
VALID_SOONG_BINARIES=("${MACOS_SOONG_BINARIES[@]}")
VALID_SOONG_TESTS=()
else
VALID_SOONG_BINARIES=("${LINUX_SOONG_BINARIES[@]}")
VALID_SOONG_TESTS=("${LINUX_SOONG_TESTS[@]}")
fi
if [ "${#SOONG_BINARIES[@]}" -eq 0 ]; then
# SOONG_BINARIES is empty, so there must be no commandline argument, thus we
# build everything.
SOONG_BINARIES=("${VALID_SOONG_BINARIES[@]}")
fi
SOONG_BINARIES=()
SOONG_TESTS=()
# Check if all specified targets are valid
for name in "${SOONG_BINARIES[@]}"; do
if ! valid_build_target "${name}"; then
echo "build_target ${name} is not one of the supported targets: ${VALID_SOONG_BINARIES[*]}"
exit 1
fi
for name in "${BUILD_TARGETS[@]}"; do
if in_array "${name}" "${VALID_SOONG_BINARIES[@]}"; then
SOONG_BINARIES+=("${name}")
elif in_array "${name}" "${VALID_SOONG_TESTS[@]}"; then
SOONG_TESTS+=("${name}")
else
echo "build_target ${name} is not one of the supported targets:" \
"${VALID_SOONG_BINARIES[@]}" "${VALID_SOONG_TESTS[@]}"
exit 1
fi
done
if [ "${#BUILD_TARGETS[@]}" -eq 0 ]; then
# Build everything by default.
SOONG_BINARIES=("${VALID_SOONG_BINARIES[@]}")
SOONG_TESTS=("${VALID_SOONG_TESTS[@]}")
fi
if [ -z "${OUT_DIR}" ]; then
echo "error: Must set OUT_DIR"
exit 1
@@ -133,12 +148,15 @@ if [ "${OS}" = "darwin" ]; then
fi
# Build binaries and shared libs
build/soong/soong_ui.bash --make-mode --skip-config --soong-only "${binaries[@]}" "${libs[@]}"
build/soong/soong_ui.bash --make-mode --skip-config --soong-only \
"${binaries[@]}" "${libs[@]}" "${SOONG_TESTS[@]}"
# Copy binaries and shared libs
SOONG_DIST="${SOONG_OUT}/dist"
mkdir -p "${SOONG_DIST}/bin"
cp "${binaries[@]}" "${SOONG_DIST}/bin"
if [ -n "${binaries}" ]; then
cp "${binaries[@]}" "${SOONG_DIST}/bin"
fi
cp -R "${SOONG_HOST_OUT}/lib64" "${SOONG_DIST}"
# create symlink lib -> lib64 as toolchain libraries have a RUNPATH pointing to
# $ORIGIN/../lib instead of lib64
@@ -180,12 +198,12 @@ for file in "${SOONG_OUT}/dist/lib"*"/"*; do
done
# Package binaries and shared libs
(
cd "${SOONG_OUT}/dist"
if [ -z "${DIST_DIR}" ]; then
echo "DIST_DIR is empty. Skip zipping binaries."
else
pushd "${SOONG_OUT}/dist"
zip -qryX build-prebuilts.zip *
)
if [ -n "${DIST_DIR}" ]; then
popd
mkdir -p "${DIST_DIR}" || true
cp "${SOONG_OUT}/dist/build-prebuilts.zip" "${DIST_DIR}/"
fi