Skip to content

--remote_download_toplevel does not download symlink targets of runfiles #18249

@eric-skydio

Description

@eric-skydio

Description of the bug:

--remote_download_toplevel downloads the runfiles associated with any outputs explicitly listed on the command line, and (on Linux) constructs a runfiles tree of symlinks for them.
Unfortunately, if the runfiles is constructed with symlinks= or root_symlinks= that refer to File objects not in the files= depset of the runfiles, this process fails and the target of the symlink is not downloaded, which results in a broken symlink in the resulting runfiles tree.

This is important for us because we use root_symlinks to relocate files to keep our PYTHONPATH smaller. This works file when not using --remote_download_toplevel.

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

rules.bzl

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, "cat symlink.txt")
    return [DefaultInfo(
        runfiles = ctx.runfiles(
            symlinks = {"symlink.txt": file},
        ),
        executable = executable,
    )]

symlink_rule = rule(
    implementation = _symlink_rule_impl,
    executable = True,
    attrs = {},
)

BUILD

load(":rules.bzl", "symlink_rule")

symlink_rule(name = "symlink")

Reproduction steps:

  1. bazel run //:symlink --remote_download_toplevel --disk_cache /tmp/cache
  2. bazel clean
  3. bazel run //:symlink --remote_download_toplevel --disk_cache /tmp/cache

Which operating system are you running Bazel on?

Ubuntu 18.04

What is the output of bazel info release?

release 6.1.2

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

This seems to reproduce both on Bazel 5.x and the latest 7.0.0-pre*

Metadata

Metadata

Assignees

Labels

P1I'll work on this now. (Assignee required)team-Remote-ExecIssues and PRs for the Execution (Remote) teamtype: bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions