Skip to content

Commit

Permalink
Handle symlinks and root_symlinks in Runfiles
Browse files Browse the repository at this point in the history
Fixes #18249.

Closes #18399.

PiperOrigin-RevId: 532767884
Change-Id: I7c50b2bea7b93072e601a192031c14d2c22a5713
  • Loading branch information
coeuvre authored and copybara-github committed May 17, 2023
1 parent 4b9505f commit fb76e6e
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,27 @@ private void addRunfiles(ProviderCollection buildTarget) {
if (runfilesSupport == null) {
return;
}
for (Artifact runfile : runfilesSupport.getRunfiles().getArtifacts().toList()) {
var runfiles = runfilesSupport.getRunfiles();
for (Artifact runfile : runfiles.getArtifacts().toList()) {
if (runfile.isSourceArtifact()) {
continue;
}
toplevelArtifactsToDownload.add(runfile);
}
for (var symlink : runfiles.getSymlinks().toList()) {
var artifact = symlink.getArtifact();
if (artifact.isSourceArtifact()) {
continue;
}
toplevelArtifactsToDownload.add(artifact);
}
for (var symlink : runfiles.getRootSymlinks().toList()) {
var artifact = symlink.getArtifact();
if (artifact.isSourceArtifact()) {
continue;
}
toplevelArtifactsToDownload.add(artifact);
}
}

public void addInputToDownload(ActionInput file) {
Expand Down
92 changes: 92 additions & 0 deletions src/test/shell/bazel/remote/build_without_the_bytes_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1778,4 +1778,96 @@ EOF
expect_log "Found remote cache eviction error, retrying the build..."
}

function test_download_toplevel_symlinks_runfiles() {
cat > rules.bzl <<EOF
def _symlink_rule_impl(ctx):
file = ctx.actions.declare_file("file.txt")
executable = ctx.actions.declare_file("executable")
ctx.actions.run_shell(
outputs = [file],
command = "echo 'Hello World!' > " + file.path,
)
ctx.actions.write(executable, "[[ -L symlink.txt ]] && cat symlink.txt")
return [DefaultInfo(
runfiles = ctx.runfiles(
symlinks = {"symlink.txt": file},
),
executable = executable,
)]
symlink_rule = rule(
implementation = _symlink_rule_impl,
executable = True,
attrs = {},
)
EOF
cat > BUILD <<EOF
load(":rules.bzl", "symlink_rule")
symlink_rule(name = "symlink")
EOF

bazel run \
--remote_executor=grpc://localhost:${worker_port} \
--remote_download_toplevel \
//:symlink >& $TEST_log || fail "Failed to run //:symlink"

expect_log "Hello World"

rm bazel-bin/file.txt

bazel run \
--remote_executor=grpc://localhost:${worker_port} \
--remote_download_toplevel \
//:symlink >& $TEST_log || fail "Failed to run //:symlink"

expect_log "Hello World"
}

function test_download_toplevel_root_symlinks_runfiles() {
cat > rules.bzl <<EOF
def _symlink_rule_impl(ctx):
file = ctx.actions.declare_file("file.txt")
executable = ctx.actions.declare_file("executable")
ctx.actions.run_shell(
outputs = [file],
command = "echo 'Hello World!' > " + file.path,
)
ctx.actions.write(executable, "[[ -L ../symlink.txt ]] && cat ../symlink.txt")
return [DefaultInfo(
runfiles = ctx.runfiles(
root_symlinks = {"symlink.txt": file},
),
executable = executable,
)]
symlink_rule = rule(
implementation = _symlink_rule_impl,
executable = True,
attrs = {},
)
EOF
cat > BUILD <<EOF
load(":rules.bzl", "symlink_rule")
symlink_rule(name = "symlink")
EOF

bazel run \
--remote_executor=grpc://localhost:${worker_port} \
--remote_download_toplevel \
//:symlink >& $TEST_log || fail "Failed to run //:symlink"

expect_log "Hello World"

rm bazel-bin/file.txt

bazel run \
--remote_executor=grpc://localhost:${worker_port} \
--remote_download_toplevel \
//:symlink >& $TEST_log || fail "Failed to run //:symlink"

expect_log "Hello World"
}

run_suite "Build without the Bytes tests"

0 comments on commit fb76e6e

Please sign in to comment.