2021-04-08 13:21:13 +02:00
|
|
|
#!/bin/bash -eu
|
|
|
|
|
2021-04-21 13:10:09 +02:00
|
|
|
set -o pipefail
|
|
|
|
|
2021-04-08 13:21:13 +02:00
|
|
|
HARDWIRED_MOCK_TOP=
|
|
|
|
# Uncomment this to be able to view the source tree after a test is run
|
|
|
|
# HARDWIRED_MOCK_TOP=/tmp/td
|
|
|
|
|
|
|
|
REAL_TOP="$(readlink -f "$(dirname "$0")"/../../..)"
|
|
|
|
|
2023-10-04 06:14:28 +02:00
|
|
|
function make_mock_top {
|
|
|
|
mock=$(mktemp -t -d st.XXXXX)
|
|
|
|
echo "$mock"
|
|
|
|
}
|
|
|
|
|
2022-06-09 18:22:36 +02:00
|
|
|
if [[ -n "$HARDWIRED_MOCK_TOP" ]]; then
|
2021-04-14 16:40:03 +02:00
|
|
|
MOCK_TOP="$HARDWIRED_MOCK_TOP"
|
|
|
|
else
|
2023-10-05 15:06:09 +02:00
|
|
|
MOCK_TOP=$(make_mock_top)
|
2021-04-14 16:40:03 +02:00
|
|
|
trap cleanup_mock_top EXIT
|
|
|
|
fi
|
|
|
|
|
|
|
|
WARMED_UP_MOCK_TOP=$(mktemp -t soong_integration_tests_warmup.XXXXXX.tar.gz)
|
|
|
|
trap 'rm -f "$WARMED_UP_MOCK_TOP"' EXIT
|
|
|
|
|
|
|
|
function warmup_mock_top {
|
|
|
|
info "Warming up mock top ..."
|
|
|
|
info "Mock top warmup archive: $WARMED_UP_MOCK_TOP"
|
|
|
|
cleanup_mock_top
|
|
|
|
mkdir -p "$MOCK_TOP"
|
|
|
|
cd "$MOCK_TOP"
|
|
|
|
|
|
|
|
create_mock_soong
|
|
|
|
run_soong
|
|
|
|
tar czf "$WARMED_UP_MOCK_TOP" *
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanup_mock_top {
|
|
|
|
cd /
|
|
|
|
rm -fr "$MOCK_TOP"
|
|
|
|
}
|
|
|
|
|
|
|
|
function info {
|
2022-06-09 18:22:36 +02:00
|
|
|
echo -e "\e[92;1m[TEST HARNESS INFO]\e[0m" "$*"
|
2021-04-14 16:40:03 +02:00
|
|
|
}
|
|
|
|
|
2021-04-08 13:21:13 +02:00
|
|
|
function fail {
|
2022-06-09 18:22:36 +02:00
|
|
|
echo -e "\e[91;1mFAILED:\e[0m" "$*"
|
2021-04-08 13:21:13 +02:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2022-06-09 18:22:36 +02:00
|
|
|
function copy_directory {
|
2021-04-08 13:21:13 +02:00
|
|
|
local dir="$1"
|
2022-06-09 18:22:36 +02:00
|
|
|
local -r parent="$(dirname "$dir")"
|
2021-04-08 13:21:13 +02:00
|
|
|
|
|
|
|
mkdir -p "$MOCK_TOP/$parent"
|
|
|
|
cp -R "$REAL_TOP/$dir" "$MOCK_TOP/$parent"
|
|
|
|
}
|
|
|
|
|
2023-08-02 20:45:43 +02:00
|
|
|
function delete_directory {
|
|
|
|
rm -rf "$MOCK_TOP/$1"
|
|
|
|
}
|
|
|
|
|
2022-06-09 18:22:36 +02:00
|
|
|
function symlink_file {
|
2021-04-08 13:21:13 +02:00
|
|
|
local file="$1"
|
|
|
|
|
|
|
|
mkdir -p "$MOCK_TOP/$(dirname "$file")"
|
|
|
|
ln -s "$REAL_TOP/$file" "$MOCK_TOP/$file"
|
|
|
|
}
|
|
|
|
|
2022-06-09 18:22:36 +02:00
|
|
|
function symlink_directory {
|
2021-04-08 13:21:13 +02:00
|
|
|
local dir="$1"
|
|
|
|
|
|
|
|
mkdir -p "$MOCK_TOP/$dir"
|
|
|
|
# We need to symlink the contents of the directory individually instead of
|
|
|
|
# using one symlink for the whole directory because finder.go doesn't follow
|
|
|
|
# symlinks when looking for Android.bp files
|
2022-06-09 18:22:36 +02:00
|
|
|
for i in "$REAL_TOP/$dir"/*; do
|
|
|
|
i=$(basename "$i")
|
2021-04-08 13:21:13 +02:00
|
|
|
local target="$MOCK_TOP/$dir/$i"
|
|
|
|
local source="$REAL_TOP/$dir/$i"
|
|
|
|
|
|
|
|
if [[ -e "$target" ]]; then
|
|
|
|
if [[ ! -d "$source" || ! -d "$target" ]]; then
|
|
|
|
fail "Trying to symlink $dir twice"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
ln -s "$REAL_TOP/$dir/$i" "$MOCK_TOP/$dir/$i";
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2021-04-14 16:40:03 +02:00
|
|
|
function create_mock_soong {
|
2022-11-01 01:08:45 +01:00
|
|
|
create_mock_bazel
|
2021-04-08 13:21:13 +02:00
|
|
|
copy_directory build/blueprint
|
|
|
|
copy_directory build/soong
|
2022-12-06 00:02:29 +01:00
|
|
|
copy_directory build/make
|
2021-04-08 13:21:13 +02:00
|
|
|
|
2022-05-02 10:13:19 +02:00
|
|
|
symlink_directory prebuilts/sdk
|
2021-04-08 13:21:13 +02:00
|
|
|
symlink_directory prebuilts/go
|
|
|
|
symlink_directory prebuilts/build-tools
|
2022-03-18 20:55:04 +01:00
|
|
|
symlink_directory prebuilts/clang/host
|
2023-03-22 21:22:27 +01:00
|
|
|
symlink_directory external/compiler-rt
|
2021-05-24 23:24:12 +02:00
|
|
|
symlink_directory external/go-cmp
|
2021-04-08 13:21:13 +02:00
|
|
|
symlink_directory external/golang-protobuf
|
2023-03-31 18:31:34 +02:00
|
|
|
symlink_directory external/licenseclassifier
|
2022-03-25 01:27:41 +01:00
|
|
|
symlink_directory external/starlark-go
|
2023-01-24 20:48:08 +01:00
|
|
|
symlink_directory external/python
|
|
|
|
symlink_directory external/sqlite
|
2023-03-31 18:31:34 +02:00
|
|
|
symlink_directory external/spdx-tools
|
2023-05-23 08:57:38 +02:00
|
|
|
symlink_directory libcore
|
2021-04-08 13:21:13 +02:00
|
|
|
|
2023-06-12 21:18:28 +02:00
|
|
|
# TODO: b/286872909 - Remove these when the blocking bug is completed
|
|
|
|
symlink_directory external/libavc
|
|
|
|
symlink_directory external/libaom
|
|
|
|
symlink_directory external/libvpx
|
|
|
|
symlink_directory frameworks/base/libs/androidfw
|
|
|
|
symlink_directory external/libhevc
|
|
|
|
symlink_directory external/libexif
|
|
|
|
symlink_directory external/libopus
|
|
|
|
symlink_directory external/libmpeg2
|
|
|
|
symlink_directory external/expat
|
|
|
|
symlink_directory external/flac
|
|
|
|
symlink_directory system/extras/toolchain-extras
|
|
|
|
|
2021-04-08 13:21:13 +02:00
|
|
|
touch "$MOCK_TOP/Android.bp"
|
2021-04-14 16:40:03 +02:00
|
|
|
}
|
2021-04-08 13:21:13 +02:00
|
|
|
|
2022-06-09 18:22:36 +02:00
|
|
|
function setup {
|
2021-04-14 16:40:03 +02:00
|
|
|
cleanup_mock_top
|
|
|
|
mkdir -p "$MOCK_TOP"
|
2021-04-08 13:21:13 +02:00
|
|
|
|
2021-04-14 16:40:03 +02:00
|
|
|
echo
|
|
|
|
echo ----------------------------------------------------------------------------
|
2021-04-15 18:18:45 +02:00
|
|
|
info "Running test case \e[96;1m${FUNCNAME[1]}\e[0m"
|
2021-04-14 16:40:03 +02:00
|
|
|
cd "$MOCK_TOP"
|
|
|
|
|
2022-11-09 03:14:01 +01:00
|
|
|
tar xzf "$WARMED_UP_MOCK_TOP" --warning=no-timestamp
|
2021-04-08 13:21:13 +02:00
|
|
|
}
|
|
|
|
|
2022-06-09 18:22:36 +02:00
|
|
|
# shellcheck disable=SC2120
|
|
|
|
function run_soong {
|
2024-04-01 22:40:58 +02:00
|
|
|
USE_RBE=false TARGET_PRODUCT=aosp_arm TARGET_RELEASE=trunk_staging TARGET_BUILD_VARIANT=userdebug build/soong/soong_ui.bash --make-mode --skip-ninja --skip-config --soong-only --skip-soong-tests "$@"
|
2021-04-21 13:10:09 +02:00
|
|
|
}
|
|
|
|
|
2022-06-09 18:22:36 +02:00
|
|
|
function create_mock_bazel {
|
2021-04-21 13:10:09 +02:00
|
|
|
copy_directory build/bazel
|
2022-06-29 01:25:56 +02:00
|
|
|
copy_directory build/bazel_common_rules
|
2021-04-21 13:10:09 +02:00
|
|
|
|
2023-08-02 20:45:43 +02:00
|
|
|
# This requires pulling more tools into the mock top to build partitions
|
|
|
|
delete_directory build/bazel/examples/partitions
|
|
|
|
|
2022-12-02 23:31:58 +01:00
|
|
|
symlink_directory packages/modules/common/build
|
2021-04-21 13:10:09 +02:00
|
|
|
symlink_directory prebuilts/bazel
|
2022-05-02 10:13:19 +02:00
|
|
|
symlink_directory prebuilts/clang
|
2021-04-21 13:10:09 +02:00
|
|
|
symlink_directory prebuilts/jdk
|
2021-08-10 15:00:33 +02:00
|
|
|
symlink_directory external/bazel-skylib
|
2022-05-02 10:13:19 +02:00
|
|
|
symlink_directory external/bazelbuild-rules_android
|
2023-06-26 05:44:04 +02:00
|
|
|
symlink_directory external/bazelbuild-rules_go
|
2022-08-04 22:31:14 +02:00
|
|
|
symlink_directory external/bazelbuild-rules_license
|
2022-09-06 22:20:09 +02:00
|
|
|
symlink_directory external/bazelbuild-kotlin-rules
|
2023-08-21 19:25:49 +02:00
|
|
|
symlink_directory external/bazelbuild-rules_cc
|
2023-08-05 04:12:19 +02:00
|
|
|
symlink_directory external/bazelbuild-rules_python
|
2023-07-20 15:41:29 +02:00
|
|
|
symlink_directory external/bazelbuild-rules_java
|
2023-08-21 19:29:51 +02:00
|
|
|
symlink_directory external/bazelbuild-rules_rust
|
2023-10-03 23:49:50 +02:00
|
|
|
symlink_directory external/bazelbuild-rules_testing
|
2023-08-21 19:29:51 +02:00
|
|
|
symlink_directory external/rust/crates/tinyjson
|
2021-04-21 13:10:09 +02:00
|
|
|
|
|
|
|
symlink_file WORKSPACE
|
2021-05-12 20:51:49 +02:00
|
|
|
symlink_file BUILD
|
2021-04-21 13:10:09 +02:00
|
|
|
}
|
|
|
|
|
2022-06-09 18:22:36 +02:00
|
|
|
function run_bazel {
|
2022-05-12 13:08:03 +02:00
|
|
|
# Remove the ninja_build output marker file to communicate to buildbot that this is not a regular Ninja build, and its
|
|
|
|
# output should not be parsed as such.
|
|
|
|
rm -rf out/ninja_build
|
|
|
|
|
2022-10-24 15:38:11 +02:00
|
|
|
build/bazel/bin/bazel "$@"
|
2021-04-21 13:10:09 +02:00
|
|
|
}
|
|
|
|
|
2022-06-09 18:22:36 +02:00
|
|
|
function run_ninja {
|
2021-10-29 01:19:40 +02:00
|
|
|
build/soong/soong_ui.bash --make-mode --skip-config --soong-only --skip-soong-tests "$@"
|
2021-06-25 03:39:04 +02:00
|
|
|
}
|
|
|
|
|
2022-06-09 18:22:36 +02:00
|
|
|
info "Starting Soong integration test suite $(basename "$0")"
|
2021-04-14 16:40:03 +02:00
|
|
|
info "Mock top: $MOCK_TOP"
|
|
|
|
|
|
|
|
|
|
|
|
export ALLOW_MISSING_DEPENDENCIES=true
|
2022-05-02 10:13:19 +02:00
|
|
|
export ALLOW_BP_UNDER_SYMLINKS=true
|
2021-04-14 16:40:03 +02:00
|
|
|
warmup_mock_top
|
2022-12-08 07:29:21 +01:00
|
|
|
|
|
|
|
function scan_and_run_tests {
|
|
|
|
# find all test_ functions
|
|
|
|
# NB "declare -F" output is sorted, hence test order is deterministic
|
|
|
|
readarray -t test_fns < <(declare -F | sed -n -e 's/^declare -f \(test_.*\)$/\1/p')
|
|
|
|
info "Found ${#test_fns[*]} tests"
|
|
|
|
if [[ ${#test_fns[*]} -eq 0 ]]; then
|
|
|
|
fail "No tests found"
|
|
|
|
fi
|
|
|
|
for f in ${test_fns[*]}; do
|
|
|
|
$f
|
2023-03-15 00:56:12 +01:00
|
|
|
info "Completed test case \e[96;1m$f\e[0m"
|
2022-12-08 07:29:21 +01:00
|
|
|
done
|
2022-12-06 00:02:29 +01:00
|
|
|
}
|
2023-10-04 06:14:28 +02:00
|
|
|
|
|
|
|
function move_mock_top {
|
|
|
|
MOCK_TOP2=$(make_mock_top)
|
|
|
|
rm -rf $MOCK_TOP2
|
|
|
|
mv $MOCK_TOP $MOCK_TOP2
|
|
|
|
MOCK_TOP=$MOCK_TOP2
|
|
|
|
trap cleanup_mock_top EXIT
|
|
|
|
}
|