Lukacs T. Berki | 3b730c4 | 2021-04-08 13:21:13 +0200 | [diff] [blame^] | 1 | #!/bin/bash -eu |
| 2 | |
| 3 | HARDWIRED_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 | |
| 7 | REAL_TOP="$(readlink -f "$(dirname "$0")"/../../..)" |
| 8 | |
| 9 | function fail { |
| 10 | echo ERROR: $1 |
| 11 | exit 1 |
| 12 | } |
| 13 | |
| 14 | function 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 | |
| 22 | function 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 | |
| 29 | function 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 | |
| 50 | function 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 | |
| 77 | function run_soong() { |
| 78 | build/soong/soong_ui.bash --make-mode --skip-ninja --skip-make --skip-soong-tests |
| 79 | } |