diff options
author | 2023-10-05 13:29:20 +0000 | |
---|---|---|
committer | 2023-10-05 13:29:20 +0000 | |
commit | a90225096218bc6aaef9440945d1f2f8e48b6dce (patch) | |
tree | ab44a69829fc5edc5f2d28096085f46529caa3f3 /tests | |
parent | f2fd12d97c511a92d4a1ebb582a04e3ac06da03d (diff) | |
parent | ca390b2f007c8c7a64f4938ebf466b843728593c (diff) |
Merge "Update symlinks in output directory when TOP dir changes" into main
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib.sh | 13 | ||||
-rwxr-xr-x | tests/run_integration_tests.sh | 2 | ||||
-rwxr-xr-x | tests/symlinks_path_test.sh | 51 |
3 files changed, 65 insertions, 1 deletions
diff --git a/tests/lib.sh b/tests/lib.sh index dbb10b72c..fb3b374d9 100644 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -8,6 +8,11 @@ HARDWIRED_MOCK_TOP= REAL_TOP="$(readlink -f "$(dirname "$0")"/../../..)" +function make_mock_top { + mock=$(mktemp -t -d st.XXXXX) + echo "$mock" +} + if [[ -n "$HARDWIRED_MOCK_TOP" ]]; then MOCK_TOP="$HARDWIRED_MOCK_TOP" else @@ -198,3 +203,11 @@ function scan_and_run_tests { info "Completed test case \e[96;1m$f\e[0m" done } + +function move_mock_top { + MOCK_TOP2=$(make_mock_top) + rm -rf $MOCK_TOP2 + mv $MOCK_TOP $MOCK_TOP2 + MOCK_TOP=$MOCK_TOP2 + trap cleanup_mock_top EXIT +} diff --git a/tests/run_integration_tests.sh b/tests/run_integration_tests.sh index 6b9ff8b93..223baa4ac 100755 --- a/tests/run_integration_tests.sh +++ b/tests/run_integration_tests.sh @@ -23,4 +23,4 @@ TEST_BAZEL=true extra_build_params=--bazel-mode-staging "$TOP/build/soong/tests/ "$TOP/build/soong/tests/apex_cc_module_arch_variant_tests.sh" "aosp_cf_arm64_phone" "armv8-a" "cortex-a53" "$TOP/build/bazel/ci/b_test.sh" - +"$TOP/build/soong/tests/symlinks_path_test.sh" diff --git a/tests/symlinks_path_test.sh b/tests/symlinks_path_test.sh new file mode 100755 index 000000000..ed429119c --- /dev/null +++ b/tests/symlinks_path_test.sh @@ -0,0 +1,51 @@ +#!/bin/bash -eu + +set -o pipefail + +# Test that relative symlinks work by recreating the bug in b/259191764 +# In some cases, developers prefer to move their checkouts. This causes +# issues in that symlinked files (namely, the bazel wrapper script) +# cannot be found. As such, we implemented relative symlinks so that a +# moved checkout doesn't need a full clean before rebuilding. +# The bazel output base will still need to be removed, as Starlark +# doesn't seem to support relative symlinks yet. + +source "$(dirname "$0")/lib.sh" + +function check_link_has_mock_top_prefix { + input_link=$1 + link_target=`readlink $input_link` + if [[ $link_target != "$MOCK_TOP"* ]]; then + echo "Symlink for file $input_link -> $link_target doesn't start with $MOCK_TOP" + exit 1 + fi +} + +function test_symlinks_updated_when_top_dir_changed { + setup + + mkdir -p a + touch a/g.txt + cat > a/Android.bp <<'EOF' +filegroup { + name: "g", + srcs: ["g.txt"], + bazel_module: {bp2build_available: true}, +} +EOF + # A directory under $MOCK_TOP + outdir=out2 + + # Modify OUT_DIR in a subshell so it doesn't affect the top level one. + (export OUT_DIR=$MOCK_TOP/$outdir; run_soong bp2build && run_bazel build --config=bp2build --config=ci //a:g) + + g_txt="out2/soong/workspace/a/g.txt" + check_link_has_mock_top_prefix "$g_txt" + + move_mock_top + + (export OUT_DIR=$MOCK_TOP/$outdir; run_soong bp2build && run_bazel build --config=bp2build --config=ci //a:g) + check_link_has_mock_top_prefix "$g_txt" +} + +scan_and_run_tests
\ No newline at end of file |