MarkDacek | b98b3a4 | 2023-07-24 19:49:28 +0000 | [diff] [blame^] | 1 | #!/bin/bash -eu |
| 2 | |
| 3 | set -o pipefail |
| 4 | |
| 5 | # Test that relative symlinks work by recreating the bug in b/259191764 |
| 6 | # In some cases, developers prefer to move their checkouts. This causes |
| 7 | # issues in that symlinked files (namely, the bazel wrapper script) |
| 8 | # cannot be found. As such, we implemented relative symlinks so that a |
| 9 | # moved checkout doesn't need a full clean before rebuilding. |
| 10 | # The bazel output base will still need to be removed, as Starlark |
| 11 | # doesn't seem to support relative symlinks yet. |
| 12 | |
| 13 | source "$(dirname "$0")/lib.sh" |
| 14 | |
| 15 | function test_movable_top_bazel_build { |
| 16 | setup |
| 17 | |
| 18 | mkdir -p a |
| 19 | touch a/g.txt |
| 20 | cat > a/Android.bp <<'EOF' |
| 21 | filegroup { |
| 22 | name: "g", |
| 23 | srcs: ["g.txt"], |
| 24 | bazel_module: {bp2build_available: true}, |
| 25 | } |
| 26 | EOF |
| 27 | # A directory under $MOCK_TOP |
| 28 | outdir=out2 |
| 29 | |
| 30 | # Modify OUT_DIR in a subshell so it doesn't affect the top level one. |
| 31 | (export OUT_DIR=$MOCK_TOP/$outdir; run_soong bp2build && run_bazel build --config=bp2build --config=ci //a:g) |
| 32 | |
| 33 | move_mock_top |
| 34 | |
| 35 | # remove the bazel output base |
| 36 | rm -rf $outdir/bazel/output_user_root |
| 37 | (export OUT_DIR=$MOCK_TOP/$outdir; run_soong bp2build && run_bazel build --config=bp2build --config=ci //a:g) |
| 38 | } |
| 39 | |
| 40 | function test_movable_top_soong_build { |
| 41 | setup |
| 42 | |
| 43 | mkdir -p a |
| 44 | touch a/g.txt |
| 45 | cat > a/Android.bp <<'EOF' |
| 46 | filegroup { |
| 47 | name: "g", |
| 48 | srcs: ["g.txt"], |
| 49 | } |
| 50 | EOF |
| 51 | |
| 52 | # A directory under $MOCK_TOP |
| 53 | outdir=out2 |
| 54 | |
| 55 | # Modify OUT_DIR in a subshell so it doesn't affect the top level one. |
| 56 | (export OUT_DIR=$MOCK_TOP/$outdir; run_soong g) |
| 57 | |
| 58 | move_mock_top |
| 59 | |
| 60 | # remove the bazel output base |
| 61 | rm -rf $outdir/bazel/output |
| 62 | (export OUT_DIR=$MOCK_TOP/$outdir; run_soong g) |
| 63 | } |
| 64 | |
| 65 | function test_remove_output_base_and_ninja_file { |
| 66 | # If the bazel output base is removed without the ninja file, the build will fail |
| 67 | # This tests that removing both the bazel output base and ninja file will succeed |
| 68 | # without a clean |
| 69 | setup |
| 70 | |
| 71 | mkdir -p a |
| 72 | touch a/g.txt |
| 73 | cat > a/Android.bp <<'EOF' |
| 74 | filegroup { |
| 75 | name: "g", |
| 76 | srcs: ["g.txt"], |
| 77 | } |
| 78 | EOF |
| 79 | outdir=out2 |
| 80 | |
| 81 | # Modify OUT_DIR in a subshell so it doesn't affect the top level one. |
| 82 | (export OUT_DIR=$MOCK_TOP/$outdir; run_soong g) |
| 83 | # remove the bazel output base |
| 84 | rm -rf $outdir/bazel/output |
| 85 | rm $outdir/soong/build*ninja |
| 86 | |
| 87 | (export OUT_DIR=$MOCK_TOP/$outdir; run_soong g) |
| 88 | } |
| 89 | |
| 90 | scan_and_run_tests |