Skip to content

Commit

Permalink
Add tests for unresolved symlinks + remote execution.
Browse files Browse the repository at this point in the history
The tests don't currently pass due to bazelbuild#16290 and bazelbuild#16289. Making them pass might
be considered a blocker for bazelbuild#10298 (declaring unresolved symlinks stable).
  • Loading branch information
tjgq committed Sep 16, 2022
1 parent d834905 commit 3313be9
Showing 1 changed file with 50 additions and 16 deletions.
66 changes: 50 additions & 16 deletions src/test/shell/bazel/remote/remote_execution_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2986,33 +2986,49 @@ function test_external_cc_test_sibling_repository_layout() {
@other_repo//test >& $TEST_log || fail "Test should pass"
}

function test_unresolved_symlink_input() {
function do_test_unresolved_symlink() {
local -r strategy=$1
local -r link_target=$2

mkdir -p symlink
touch symlink/BUILD
cat > symlink/symlink.bzl <<EOF
def _dangling_symlink_impl(ctx):
symlink = ctx.actions.declare_symlink(ctx.label.name)
cat > symlink/symlink.bzl <<'EOF'
def _unresolved_symlink_impl(ctx):
symlink = ctx.actions.declare_symlink(ctx.label.name)
if ctx.attr.strategy == "internal":
ctx.actions.symlink(
output = symlink,
target_path = ctx.attr.link_target,
output = symlink,
target_path = ctx.attr.link_target,
)
if ctx.attr.strategy == "spawn":
ctx.actions.run_shell(
outputs = [symlink],
command = "ln -s $1 $2",
arguments = [ctx.attr.link_target, symlink.path],
)
return DefaultInfo(files = depset([symlink]))
dangling_symlink = rule(
implementation = _dangling_symlink_impl,
attrs = {"link_target": attr.string()},
return DefaultInfo(files = depset([symlink]))
unresolved_symlink = rule(
implementation = _unresolved_symlink_impl,
attrs = {
"link_target": attr.string(mandatory = True),
"strategy": attr.string(values = ["internal", "spawn"], mandatory = True),
},
)
EOF

mkdir -p pkg
cat > pkg/BUILD <<'EOF'
load("//symlink:symlink.bzl", "dangling_symlink")
dangling_symlink(name="a", link_target="non/existent")
cat > pkg/BUILD <<EOF
load("//symlink:symlink.bzl", "unresolved_symlink")
unresolved_symlink(name="a", link_target="$link_target", strategy="$strategy")
genrule(
name = "b",
srcs = [":a"],
outs = ["b.txt"],
cmd = "readlink $(location :a) > $@",
cmd = "readlink \$(location :a) > \$@",
)
EOF

Expand All @@ -3023,7 +3039,7 @@ EOF
--spawn_strategy=remote \
--remote_executor=grpc://localhost:${worker_port} \
//pkg:b &>$TEST_log || fail "expected build to succeed"
[[ $(cat bazel-bin/pkg/b.txt) == non/existent ]] || fail "expected symlink target to be non/existent"
[[ "$(cat bazel-bin/pkg/b.txt)" == "$link_target" ]] || fail "expected symlink target to be $link_target"

bazel clean --expunge
bazel \
Expand All @@ -3034,7 +3050,25 @@ EOF
--remote_executor=grpc://localhost:${worker_port} \
--experimental_remote_merkle_tree_cache \
//pkg:b &>$TEST_log || fail "expected build to succeed with Merkle tree cache"
[[ $(cat bazel-bin/pkg/b.txt) == non/existent ]] || fail "expected symlink target to be non/existent"
[[ "$(cat bazel-bin/pkg/b.txt)" == "$link_target" ]] || fail "expected symlink target to be $link_target"
}

function test_unresolved_symlink_internal_relative() {
do_test_unresolved_symlink internal non/existent
}

function test_unresolved_symlink_internal_absolute() {
do_test_unresolved_symlink internal /non/existent
}

function test_unresolved_symlink_spawn_relative() {
do_test_unresolved_symlink spawn non/existent
}

function test_unresolved_symlink_spawn_absolute() {
do_test_unresolved_symlink spawn /non/existent
}

run_suite "Remote execution and remote cache tests"

}

0 comments on commit 3313be9

Please sign in to comment.