blob: 55f9ab4641bc0ff0b7ca5b5eacb6740153a316e0 [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
Lukacs T. Berki686965b2021-04-14 16:40:03 +020011if [[ ! -z "$HARDWIRED_MOCK_TOP" ]]; then
12 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 {
39 echo -e "\e[92;1m[TEST HARNESS INFO]\e[0m" $*
40}
41
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020042function fail {
Lukacs T. Berki686965b2021-04-14 16:40:03 +020043 echo -e "\e[91;1mFAILED:\e[0m" $*
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020044 exit 1
45}
46
47function copy_directory() {
48 local dir="$1"
49 local parent="$(dirname "$dir")"
50
51 mkdir -p "$MOCK_TOP/$parent"
52 cp -R "$REAL_TOP/$dir" "$MOCK_TOP/$parent"
53}
54
55function symlink_file() {
56 local file="$1"
57
58 mkdir -p "$MOCK_TOP/$(dirname "$file")"
59 ln -s "$REAL_TOP/$file" "$MOCK_TOP/$file"
60}
61
62function symlink_directory() {
63 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
69 for i in $(ls "$REAL_TOP/$dir"); do
70 local target="$MOCK_TOP/$dir/$i"
71 local source="$REAL_TOP/$dir/$i"
72
73 if [[ -e "$target" ]]; then
74 if [[ ! -d "$source" || ! -d "$target" ]]; then
75 fail "Trying to symlink $dir twice"
76 fi
77 else
78 ln -s "$REAL_TOP/$dir/$i" "$MOCK_TOP/$dir/$i";
79 fi
80 done
81}
82
Lukacs T. Berki686965b2021-04-14 16:40:03 +020083function create_mock_soong {
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020084 copy_directory build/blueprint
85 copy_directory build/soong
86
87 symlink_directory prebuilts/go
88 symlink_directory prebuilts/build-tools
Liz Kammer0940b892022-03-18 15:55:04 -040089 symlink_directory prebuilts/clang/host
Dan Willemsen4591b642021-05-24 14:24:12 -070090 symlink_directory external/go-cmp
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020091 symlink_directory external/golang-protobuf
92
93 touch "$MOCK_TOP/Android.bp"
Lukacs T. Berki686965b2021-04-14 16:40:03 +020094}
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020095
Lukacs T. Berki686965b2021-04-14 16:40:03 +020096function setup() {
97 cleanup_mock_top
98 mkdir -p "$MOCK_TOP"
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020099
Lukacs T. Berki686965b2021-04-14 16:40:03 +0200100 echo
101 echo ----------------------------------------------------------------------------
Lukacs T. Berki7a519072021-04-15 18:18:45 +0200102 info "Running test case \e[96;1m${FUNCNAME[1]}\e[0m"
Lukacs T. Berki686965b2021-04-14 16:40:03 +0200103 cd "$MOCK_TOP"
104
105 tar xzf "$WARMED_UP_MOCK_TOP"
Lukacs T. Berki3b730c42021-04-08 13:21:13 +0200106}
107
108function run_soong() {
Colin Cross34d60c92021-10-28 16:19:40 -0700109 build/soong/soong_ui.bash --make-mode --skip-ninja --skip-config --soong-only --skip-soong-tests "$@"
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400110}
111
112function create_mock_bazel() {
113 copy_directory build/bazel
114
115 symlink_directory prebuilts/bazel
116 symlink_directory prebuilts/jdk
Jingwen Chen91632252021-08-10 13:00:33 +0000117 symlink_directory external/bazel-skylib
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400118
119 symlink_file WORKSPACE
Liz Kammer09f947d2021-05-12 14:51:49 -0400120 symlink_file BUILD
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400121 symlink_file tools/bazel
122}
123
124run_bazel() {
125 tools/bazel "$@"
126}
127
Spandan Das05063612021-06-25 01:39:04 +0000128run_ninja() {
Colin Cross34d60c92021-10-28 16:19:40 -0700129 build/soong/soong_ui.bash --make-mode --skip-config --soong-only --skip-soong-tests "$@"
Spandan Das05063612021-06-25 01:39:04 +0000130}
131
Lukacs T. Berki686965b2021-04-14 16:40:03 +0200132info "Starting Soong integration test suite $(basename $0)"
133info "Mock top: $MOCK_TOP"
134
135
136export ALLOW_MISSING_DEPENDENCIES=true
137warmup_mock_top