Merge "Let build-prebuilts.sh compile unit tests" into main

This commit is contained in:
Hsin-Yi Chen
2023-09-12 07:00:36 +00:00
committed by Gerrit Code Review

View File

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