blob: 3c97e141c515bbd9e35c3e9d6cdb98e2dea559bf [file] [log] [blame]
Lukacs T. Berki3b730c42021-04-08 13:21:13 +02001#!/bin/bash -eu
2
3HARDWIRED_MOCK_TOP=
4# Uncomment this to be able to view the source tree after a test is run
5# HARDWIRED_MOCK_TOP=/tmp/td
6
7REAL_TOP="$(readlink -f "$(dirname "$0")"/../../..)"
8
9function fail {
10 echo ERROR: $1
11 exit 1
12}
13
14function copy_directory() {
15 local dir="$1"
16 local parent="$(dirname "$dir")"
17
18 mkdir -p "$MOCK_TOP/$parent"
19 cp -R "$REAL_TOP/$dir" "$MOCK_TOP/$parent"
20}
21
22function symlink_file() {
23 local file="$1"
24
25 mkdir -p "$MOCK_TOP/$(dirname "$file")"
26 ln -s "$REAL_TOP/$file" "$MOCK_TOP/$file"
27}
28
29function symlink_directory() {
30 local dir="$1"
31
32 mkdir -p "$MOCK_TOP/$dir"
33 # We need to symlink the contents of the directory individually instead of
34 # using one symlink for the whole directory because finder.go doesn't follow
35 # symlinks when looking for Android.bp files
36 for i in $(ls "$REAL_TOP/$dir"); do
37 local target="$MOCK_TOP/$dir/$i"
38 local source="$REAL_TOP/$dir/$i"
39
40 if [[ -e "$target" ]]; then
41 if [[ ! -d "$source" || ! -d "$target" ]]; then
42 fail "Trying to symlink $dir twice"
43 fi
44 else
45 ln -s "$REAL_TOP/$dir/$i" "$MOCK_TOP/$dir/$i";
46 fi
47 done
48}
49
50function setup() {
51 if [[ ! -z "$HARDWIRED_MOCK_TOP" ]]; then
52 MOCK_TOP="$HARDWIRED_MOCK_TOP"
53 rm -fr "$MOCK_TOP"
54 mkdir -p "$MOCK_TOP"
55 else
56 MOCK_TOP=$(mktemp -t -d st.XXXXX)
57 trap 'echo cd / && echo rm -fr "$MOCK_TOP"' EXIT
58 fi
59
60 echo "Test case: ${FUNCNAME[1]}, mock top path: $MOCK_TOP"
61 cd "$MOCK_TOP"
62
63 copy_directory build/blueprint
64 copy_directory build/soong
65
66 symlink_directory prebuilts/go
67 symlink_directory prebuilts/build-tools
68 symlink_directory external/golang-protobuf
69
70 touch "$MOCK_TOP/Android.bp"
71
72 export ALLOW_MISSING_DEPENDENCIES=true
73
74 mkdir -p out/soong
75}
76
77function run_soong() {
78 build/soong/soong_ui.bash --make-mode --skip-ninja --skip-make --skip-soong-tests
79}