From 601be74a64585172bd487caa267623bf7b00253c Mon Sep 17 00:00:00 2001 From: Philipp Wollermann Date: Fri, 28 Aug 2015 14:45:44 +0000 Subject: Fixes #400: Linux sandboxing and relative symbolic links. Symlink resolution did not work in all cases and broke ./compile.sh on certain Linux distros. -- MOS_MIGRATED_REVID=101775459 --- src/test/shell/bazel/bazel_sandboxing_test.sh | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/test/shell') diff --git a/src/test/shell/bazel/bazel_sandboxing_test.sh b/src/test/shell/bazel/bazel_sandboxing_test.sh index 24f6baa8f1..14f110a26e 100755 --- a/src/test/shell/bazel/bazel_sandboxing_test.sh +++ b/src/test/shell/bazel/bazel_sandboxing_test.sh @@ -73,6 +73,12 @@ EOF ln -sf cyclic2 examples/genrule/cyclic1 ln -sf cyclic1 examples/genrule/cyclic2 + # Create relative symlinks. + mkdir -p examples/genrule/symlinks/{a,ok/sub} + echo OK > examples/genrule/symlinks/ok/x.txt + ln -s $PWD/examples/genrule/symlinks/ok/sub examples/genrule/symlinks/a/b + ln -s ../x.txt examples/genrule/symlinks/a/b/x.txt + cat << 'EOF' > examples/genrule/BUILD genrule( name = "works", @@ -102,6 +108,13 @@ genrule( cmd = "ls -l tools/genrule | tee $@ >&2; cat tools/genrule/genrule-setup.sh >&2", ) +genrule( + name = "relative_symlinks", + srcs = [ "symlinks/a/b/x.txt" ], + outs = [ "relative_symlinks.txt" ], + cmd = "cat $(location :symlinks/a/b/x.txt) > $@", +) + genrule( name = "breaks1", srcs = [ "a.txt" ], @@ -169,6 +182,23 @@ function test_sandboxed_genrule_with_tools() { || fail "Genrule didn't produce output: examples/genrule:tools_work" } +# Test for #400: Linux sandboxing and relative symbolic links. +# +# let A = examples/genrule/symlinks/a/b/x.txt -> ../x.txt +# where examples/genrule/symlinks/a/b -> examples/genrule/symlinks/ok/sub +# thus the realpath of A is example/genrule/symlinks/ok/x.txt +# but if the code doesn't correctly resolve intermediate symlinks and instead +# uses string operations to handle ".." parts, it will arrive at: +# examples/genrule/symlinks/a/x.txt, which is wrong. +# +function test_sandbox_relative_symlink_in_inputs() { + bazel build --genrule_strategy=sandboxed \ + examples/genrule:relative_symlinks \ + || fail "Hermetic genrule failed: examples/genrule:relative_symlinks" + [ -f "${BAZEL_GENFILES_DIR}/examples/genrule/relative_symlinks.txt" ] \ + || fail "Genrule didn't produce output: examples/genrule:relative_symlinks" +} + function test_sandbox_undeclared_deps() { bazel build --genrule_strategy=sandboxed \ examples/genrule:breaks1 \ -- cgit v1.2.3