blob: 0766d85bd4f8ec1112cfb255bbe13b1ab1c5bc0d [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
Cole Faust16d10942023-08-02 11:45:43 -070055function delete_directory {
56 rm -rf "$MOCK_TOP/$1"
57}
58
Usta Shrestha2c9a5e32022-06-09 12:22:36 -040059function symlink_file {
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020060 local file="$1"
61
62 mkdir -p "$MOCK_TOP/$(dirname "$file")"
63 ln -s "$REAL_TOP/$file" "$MOCK_TOP/$file"
64}
65
Usta Shrestha2c9a5e32022-06-09 12:22:36 -040066function symlink_directory {
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020067 local dir="$1"
68
69 mkdir -p "$MOCK_TOP/$dir"
70 # We need to symlink the contents of the directory individually instead of
71 # using one symlink for the whole directory because finder.go doesn't follow
72 # symlinks when looking for Android.bp files
Usta Shrestha2c9a5e32022-06-09 12:22:36 -040073 for i in "$REAL_TOP/$dir"/*; do
74 i=$(basename "$i")
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020075 local target="$MOCK_TOP/$dir/$i"
76 local source="$REAL_TOP/$dir/$i"
77
78 if [[ -e "$target" ]]; then
79 if [[ ! -d "$source" || ! -d "$target" ]]; then
80 fail "Trying to symlink $dir twice"
81 fi
82 else
83 ln -s "$REAL_TOP/$dir/$i" "$MOCK_TOP/$dir/$i";
84 fi
85 done
86}
87
Lukacs T. Berki686965b2021-04-14 16:40:03 +020088function create_mock_soong {
Chris Parsonsb6e96902022-10-31 20:08:45 -040089 create_mock_bazel
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020090 copy_directory build/blueprint
91 copy_directory build/soong
Joe Onoratofa5fc262022-12-05 15:02:29 -080092 copy_directory build/make
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020093
Lukacs T. Berkie3487c82022-05-02 10:13:19 +020094 symlink_directory prebuilts/sdk
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020095 symlink_directory prebuilts/go
96 symlink_directory prebuilts/build-tools
Liz Kammer0940b892022-03-18 15:55:04 -040097 symlink_directory prebuilts/clang/host
Trevor Radcliffe391a25d2023-03-22 20:22:27 +000098 symlink_directory external/compiler-rt
Dan Willemsen4591b642021-05-24 14:24:12 -070099 symlink_directory external/go-cmp
Lukacs T. Berki3b730c42021-04-08 13:21:13 +0200100 symlink_directory external/golang-protobuf
Ibrahim Kanouche7c1de512023-03-31 16:31:34 +0000101 symlink_directory external/licenseclassifier
Cole Faustd9932ad2022-03-24 17:27:41 -0700102 symlink_directory external/starlark-go
Cole Faust5c503d12023-01-24 11:48:08 -0800103 symlink_directory external/python
104 symlink_directory external/sqlite
Ibrahim Kanouche7c1de512023-03-31 16:31:34 +0000105 symlink_directory external/spdx-tools
Jihoon Kangf5306962023-05-23 06:57:38 +0000106 symlink_directory libcore
Lukacs T. Berki3b730c42021-04-08 13:21:13 +0200107
Trevor Radcliffeded095c2023-06-12 19:18:28 +0000108 # TODO: b/286872909 - Remove these when the blocking bug is completed
109 symlink_directory external/libavc
110 symlink_directory external/libaom
111 symlink_directory external/libvpx
112 symlink_directory frameworks/base/libs/androidfw
113 symlink_directory external/libhevc
114 symlink_directory external/libexif
115 symlink_directory external/libopus
116 symlink_directory external/libmpeg2
117 symlink_directory external/expat
118 symlink_directory external/flac
119 symlink_directory system/extras/toolchain-extras
120
Lukacs T. Berki3b730c42021-04-08 13:21:13 +0200121 touch "$MOCK_TOP/Android.bp"
Lukacs T. Berki686965b2021-04-14 16:40:03 +0200122}
Lukacs T. Berki3b730c42021-04-08 13:21:13 +0200123
Usta Shrestha2c9a5e32022-06-09 12:22:36 -0400124function setup {
Lukacs T. Berki686965b2021-04-14 16:40:03 +0200125 cleanup_mock_top
126 mkdir -p "$MOCK_TOP"
Lukacs T. Berki3b730c42021-04-08 13:21:13 +0200127
Lukacs T. Berki686965b2021-04-14 16:40:03 +0200128 echo
129 echo ----------------------------------------------------------------------------
Lukacs T. Berki7a519072021-04-15 18:18:45 +0200130 info "Running test case \e[96;1m${FUNCNAME[1]}\e[0m"
Lukacs T. Berki686965b2021-04-14 16:40:03 +0200131 cd "$MOCK_TOP"
132
Cole Faustb85d1a12022-11-08 18:14:01 -0800133 tar xzf "$WARMED_UP_MOCK_TOP" --warning=no-timestamp
Lukacs T. Berki3b730c42021-04-08 13:21:13 +0200134}
135
Usta Shrestha2c9a5e32022-06-09 12:22:36 -0400136# shellcheck disable=SC2120
137function run_soong {
Sam Delmerico970b96d2022-08-04 14:00:08 -0400138 USE_RBE=false build/soong/soong_ui.bash --make-mode --skip-ninja --skip-config --soong-only --skip-soong-tests "$@"
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400139}
140
Usta Shrestha2c9a5e32022-06-09 12:22:36 -0400141function create_mock_bazel {
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400142 copy_directory build/bazel
Yifan Hong82799f22022-06-28 16:25:56 -0700143 copy_directory build/bazel_common_rules
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400144
Cole Faust16d10942023-08-02 11:45:43 -0700145 # This requires pulling more tools into the mock top to build partitions
146 delete_directory build/bazel/examples/partitions
147
Sam Delmericoeddd3c02022-12-02 17:31:58 -0500148 symlink_directory packages/modules/common/build
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400149 symlink_directory prebuilts/bazel
Lukacs T. Berkie3487c82022-05-02 10:13:19 +0200150 symlink_directory prebuilts/clang
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400151 symlink_directory prebuilts/jdk
Jingwen Chen91632252021-08-10 13:00:33 +0000152 symlink_directory external/bazel-skylib
Lukacs T. Berkie3487c82022-05-02 10:13:19 +0200153 symlink_directory external/bazelbuild-rules_android
Spandan Dasf7373e62023-06-26 03:44:04 +0000154 symlink_directory external/bazelbuild-rules_go
Sasha Smundak8bea2672022-08-04 13:31:14 -0700155 symlink_directory external/bazelbuild-rules_license
Romain Jobredeaux0dfe8d32022-09-06 16:20:09 -0400156 symlink_directory external/bazelbuild-kotlin-rules
Vinh Tran4f793592023-08-21 13:25:49 -0400157 symlink_directory external/bazelbuild-rules_cc
usta36249c72023-08-04 22:12:19 -0400158 symlink_directory external/bazelbuild-rules_python
Romain Jobredeauxca4706b2023-07-20 09:41:29 -0400159 symlink_directory external/bazelbuild-rules_java
Vinh Trand007cea2023-08-21 13:29:51 -0400160 symlink_directory external/bazelbuild-rules_rust
161 symlink_directory external/rust/crates/tinyjson
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400162
163 symlink_file WORKSPACE
Liz Kammer09f947d2021-05-12 14:51:49 -0400164 symlink_file BUILD
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400165}
166
Usta Shrestha2c9a5e32022-06-09 12:22:36 -0400167function run_bazel {
Jingwen Chend4b1dc82022-05-12 11:08:03 +0000168 # Remove the ninja_build output marker file to communicate to buildbot that this is not a regular Ninja build, and its
169 # output should not be parsed as such.
170 rm -rf out/ninja_build
171
Joe Onoratoba29f382022-10-24 06:38:11 -0700172 build/bazel/bin/bazel "$@"
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400173}
174
Usta Shrestha2c9a5e32022-06-09 12:22:36 -0400175function run_ninja {
Colin Cross34d60c92021-10-28 16:19:40 -0700176 build/soong/soong_ui.bash --make-mode --skip-config --soong-only --skip-soong-tests "$@"
Spandan Das05063612021-06-25 01:39:04 +0000177}
178
Usta Shrestha2c9a5e32022-06-09 12:22:36 -0400179info "Starting Soong integration test suite $(basename "$0")"
Lukacs T. Berki686965b2021-04-14 16:40:03 +0200180info "Mock top: $MOCK_TOP"
181
182
183export ALLOW_MISSING_DEPENDENCIES=true
Lukacs T. Berkie3487c82022-05-02 10:13:19 +0200184export ALLOW_BP_UNDER_SYMLINKS=true
Lukacs T. Berki686965b2021-04-14 16:40:03 +0200185warmup_mock_top
Usta Shrestha572ecec2022-12-08 01:29:21 -0500186
187function scan_and_run_tests {
188 # find all test_ functions
189 # NB "declare -F" output is sorted, hence test order is deterministic
190 readarray -t test_fns < <(declare -F | sed -n -e 's/^declare -f \(test_.*\)$/\1/p')
191 info "Found ${#test_fns[*]} tests"
192 if [[ ${#test_fns[*]} -eq 0 ]]; then
193 fail "No tests found"
194 fi
195 for f in ${test_fns[*]}; do
196 $f
usta94e89a42023-03-14 19:56:12 -0400197 info "Completed test case \e[96;1m$f\e[0m"
Usta Shrestha572ecec2022-12-08 01:29:21 -0500198 done
Joe Onoratofa5fc262022-12-05 15:02:29 -0800199}