blob: ed429119c941893ae08e121951f829a1ff0f0efb [file] [log] [blame]
Kousik Kumarca390b22023-10-04 04:14: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 check_link_has_mock_top_prefix {
16 input_link=$1
17 link_target=`readlink $input_link`
18 if [[ $link_target != "$MOCK_TOP"* ]]; then
19 echo "Symlink for file $input_link -> $link_target doesn't start with $MOCK_TOP"
20 exit 1
21 fi
22}
23
24function test_symlinks_updated_when_top_dir_changed {
25 setup
26
27 mkdir -p a
28 touch a/g.txt
29 cat > a/Android.bp <<'EOF'
30filegroup {
31 name: "g",
32 srcs: ["g.txt"],
33 bazel_module: {bp2build_available: true},
34}
35EOF
36 # A directory under $MOCK_TOP
37 outdir=out2
38
39 # Modify OUT_DIR in a subshell so it doesn't affect the top level one.
40 (export OUT_DIR=$MOCK_TOP/$outdir; run_soong bp2build && run_bazel build --config=bp2build --config=ci //a:g)
41
42 g_txt="out2/soong/workspace/a/g.txt"
43 check_link_has_mock_top_prefix "$g_txt"
44
45 move_mock_top
46
47 (export OUT_DIR=$MOCK_TOP/$outdir; run_soong bp2build && run_bazel build --config=bp2build --config=ci //a:g)
48 check_link_has_mock_top_prefix "$g_txt"
49}
50
51scan_and_run_tests