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")"/../../..)"
|
|
|
|
|
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
|
|
|
|
MOCK_TOP=$(mktemp -t -d st.XXXXX)
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
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 {
|
2021-04-08 13:21:13 +02:00
|
|
|
copy_directory build/blueprint
|
|
|
|
copy_directory build/soong
|
2022-03-25 01:27:41 +01:00
|
|
|
copy_directory build/make/tools/rbcrun
|
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
|
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
|
2022-03-25 01:27:41 +01:00
|
|
|
symlink_directory external/starlark-go
|
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"
|
|
|
|
|
|
|
|
tar xzf "$WARMED_UP_MOCK_TOP"
|
2021-04-08 13:21:13 +02:00
|
|
|
}
|
|
|
|
|
2022-06-09 18:22:36 +02:00
|
|
|
# shellcheck disable=SC2120
|
|
|
|
function run_soong {
|
2021-10-29 01:19:40 +02:00
|
|
|
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
|
|
|
|
|
|
|
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
|
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
|
|
|
symlink_file tools/bazel
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2021-04-21 13:10:09 +02:00
|
|
|
tools/bazel "$@"
|
|
|
|
}
|
|
|
|
|
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
|