blob: 9477f8cd1ccffd60f2ba2607a90e01322f7aa9e9 [file] [log] [blame]
MarkDacekb98b3a42023-07-24 19:49:28 +00001#!/bin/bash -eu
2
3set -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
13source "$(dirname "$0")/lib.sh"
14
15function test_movable_top_bazel_build {
16 setup
17
18 mkdir -p a
19 touch a/g.txt
20 cat > a/Android.bp <<'EOF'
21filegroup {
22 name: "g",
23 srcs: ["g.txt"],
24 bazel_module: {bp2build_available: true},
25}
26EOF
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
40function test_movable_top_soong_build {
41 setup
42
43 mkdir -p a
44 touch a/g.txt
45 cat > a/Android.bp <<'EOF'
46filegroup {
47 name: "g",
48 srcs: ["g.txt"],
49}
50EOF
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
65function 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'
74filegroup {
75 name: "g",
76 srcs: ["g.txt"],
77}
78EOF
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
90scan_and_run_tests