blob: 69ad2013d28845a7635e5f72333b8ce2e106518b [file] [log] [blame]
Lukacs T. Berki3b730c42021-04-08 13:21:13 +02001#!/bin/bash -eu
2
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -04003set -o pipefail
4
Lukacs T. Berki3b730c42021-04-08 13:21:13 +02005HARDWIRED_MOCK_TOP=
6# Uncomment this to be able to view the source tree after a test is run
7# HARDWIRED_MOCK_TOP=/tmp/td
8
9REAL_TOP="$(readlink -f "$(dirname "$0")"/../../..)"
10
Usta Shrestha2c9a5e32022-06-09 12:22:36 -040011if [[ -n "$HARDWIRED_MOCK_TOP" ]]; then
Lukacs T. Berki686965b2021-04-14 16:40:03 +020012 MOCK_TOP="$HARDWIRED_MOCK_TOP"
13else
14 MOCK_TOP=$(mktemp -t -d st.XXXXX)
15 trap cleanup_mock_top EXIT
16fi
17
18WARMED_UP_MOCK_TOP=$(mktemp -t soong_integration_tests_warmup.XXXXXX.tar.gz)
19trap 'rm -f "$WARMED_UP_MOCK_TOP"' EXIT
20
21function warmup_mock_top {
22 info "Warming up mock top ..."
23 info "Mock top warmup archive: $WARMED_UP_MOCK_TOP"
24 cleanup_mock_top
25 mkdir -p "$MOCK_TOP"
26 cd "$MOCK_TOP"
27
28 create_mock_soong
29 run_soong
30 tar czf "$WARMED_UP_MOCK_TOP" *
31}
32
33function cleanup_mock_top {
34 cd /
35 rm -fr "$MOCK_TOP"
36}
37
38function info {
Usta Shrestha2c9a5e32022-06-09 12:22:36 -040039 echo -e "\e[92;1m[TEST HARNESS INFO]\e[0m" "$*"
Lukacs T. Berki686965b2021-04-14 16:40:03 +020040}
41
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020042function fail {
Usta Shrestha2c9a5e32022-06-09 12:22:36 -040043 echo -e "\e[91;1mFAILED:\e[0m" "$*"
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020044 exit 1
45}
46
Usta Shrestha2c9a5e32022-06-09 12:22:36 -040047function copy_directory {
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020048 local dir="$1"
Usta Shrestha2c9a5e32022-06-09 12:22:36 -040049 local -r parent="$(dirname "$dir")"
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020050
51 mkdir -p "$MOCK_TOP/$parent"
52 cp -R "$REAL_TOP/$dir" "$MOCK_TOP/$parent"
53}
54
Usta Shrestha2c9a5e32022-06-09 12:22:36 -040055function symlink_file {
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020056 local file="$1"
57
58 mkdir -p "$MOCK_TOP/$(dirname "$file")"
59 ln -s "$REAL_TOP/$file" "$MOCK_TOP/$file"
60}
61
Usta Shrestha2c9a5e32022-06-09 12:22:36 -040062function symlink_directory {
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020063 local dir="$1"
64
65 mkdir -p "$MOCK_TOP/$dir"
66 # We need to symlink the contents of the directory individually instead of
67 # using one symlink for the whole directory because finder.go doesn't follow
68 # symlinks when looking for Android.bp files
Usta Shrestha2c9a5e32022-06-09 12:22:36 -040069 for i in "$REAL_TOP/$dir"/*; do
70 i=$(basename "$i")
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020071 local target="$MOCK_TOP/$dir/$i"
72 local source="$REAL_TOP/$dir/$i"
73
74 if [[ -e "$target" ]]; then
75 if [[ ! -d "$source" || ! -d "$target" ]]; then
76 fail "Trying to symlink $dir twice"
77 fi
78 else
79 ln -s "$REAL_TOP/$dir/$i" "$MOCK_TOP/$dir/$i";
80 fi
81 done
82}
83
Lukacs T. Berki686965b2021-04-14 16:40:03 +020084function create_mock_soong {
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020085 copy_directory build/blueprint
86 copy_directory build/soong
Cole Faustd9932ad2022-03-24 17:27:41 -070087 copy_directory build/make/tools/rbcrun
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020088
Lukacs T. Berkie3487c82022-05-02 10:13:19 +020089 symlink_directory prebuilts/sdk
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020090 symlink_directory prebuilts/go
91 symlink_directory prebuilts/build-tools
Liz Kammer0940b892022-03-18 15:55:04 -040092 symlink_directory prebuilts/clang/host
Dan Willemsen4591b642021-05-24 14:24:12 -070093 symlink_directory external/go-cmp
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020094 symlink_directory external/golang-protobuf
Cole Faustd9932ad2022-03-24 17:27:41 -070095 symlink_directory external/starlark-go
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020096
97 touch "$MOCK_TOP/Android.bp"
Lukacs T. Berki686965b2021-04-14 16:40:03 +020098}
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020099
Usta Shrestha2c9a5e32022-06-09 12:22:36 -0400100function setup {
Lukacs T. Berki686965b2021-04-14 16:40:03 +0200101 cleanup_mock_top
102 mkdir -p "$MOCK_TOP"
Lukacs T. Berki3b730c42021-04-08 13:21:13 +0200103
Lukacs T. Berki686965b2021-04-14 16:40:03 +0200104 echo
105 echo ----------------------------------------------------------------------------
Lukacs T. Berki7a519072021-04-15 18:18:45 +0200106 info "Running test case \e[96;1m${FUNCNAME[1]}\e[0m"
Lukacs T. Berki686965b2021-04-14 16:40:03 +0200107 cd "$MOCK_TOP"
108
109 tar xzf "$WARMED_UP_MOCK_TOP"
Lukacs T. Berki3b730c42021-04-08 13:21:13 +0200110}
111
Usta Shrestha2c9a5e32022-06-09 12:22:36 -0400112# shellcheck disable=SC2120
113function run_soong {
Colin Cross34d60c92021-10-28 16:19:40 -0700114 build/soong/soong_ui.bash --make-mode --skip-ninja --skip-config --soong-only --skip-soong-tests "$@"
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400115}
116
Usta Shrestha2c9a5e32022-06-09 12:22:36 -0400117function create_mock_bazel {
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400118 copy_directory build/bazel
Yifan Hong82799f22022-06-28 16:25:56 -0700119 copy_directory build/bazel_common_rules
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400120
121 symlink_directory prebuilts/bazel
Lukacs T. Berkie3487c82022-05-02 10:13:19 +0200122 symlink_directory prebuilts/clang
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400123 symlink_directory prebuilts/jdk
Jingwen Chen91632252021-08-10 13:00:33 +0000124 symlink_directory external/bazel-skylib
Lukacs T. Berkie3487c82022-05-02 10:13:19 +0200125 symlink_directory external/bazelbuild-rules_android
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400126
127 symlink_file WORKSPACE
Liz Kammer09f947d2021-05-12 14:51:49 -0400128 symlink_file BUILD
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400129 symlink_file tools/bazel
130}
131
Usta Shrestha2c9a5e32022-06-09 12:22:36 -0400132function run_bazel {
Jingwen Chend4b1dc82022-05-12 11:08:03 +0000133 # Remove the ninja_build output marker file to communicate to buildbot that this is not a regular Ninja build, and its
134 # output should not be parsed as such.
135 rm -rf out/ninja_build
136
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400137 tools/bazel "$@"
138}
139
Usta Shrestha2c9a5e32022-06-09 12:22:36 -0400140function run_ninja {
Colin Cross34d60c92021-10-28 16:19:40 -0700141 build/soong/soong_ui.bash --make-mode --skip-config --soong-only --skip-soong-tests "$@"
Spandan Das05063612021-06-25 01:39:04 +0000142}
143
Usta Shrestha2c9a5e32022-06-09 12:22:36 -0400144info "Starting Soong integration test suite $(basename "$0")"
Lukacs T. Berki686965b2021-04-14 16:40:03 +0200145info "Mock top: $MOCK_TOP"
146
147
148export ALLOW_MISSING_DEPENDENCIES=true
Lukacs T. Berkie3487c82022-05-02 10:13:19 +0200149export ALLOW_BP_UNDER_SYMLINKS=true
Lukacs T. Berki686965b2021-04-14 16:40:03 +0200150warmup_mock_top