有哪些不同类型的runfiles

abe*_*ier 6 bazel

DefaultInfo的文档中,我们现在可以返回3种不同的"类型"的runfiles:

runfiles
data_runfiles
default_runfiles
Run Code Online (Sandbox Code Playgroud)

我找不到任何文件,这些文件之间的分离和何时使用哪个.任何人都可以详细说明吗?

Ada*_*dam 6

data_runfiles是添加到二进制文件的运行文件中的文件,它依赖于通过data属性的规则.default_runfiles是添加到二进制文件的运行文件中的文件,它依赖于除了data属性之外的任何内容的规则.runfiles是一个简写,用于创建一个DefaultInfo具有相同的文件集作为data_runfilesdefault_runfiles.

请考虑以下涉及filegroup规则的示例.(我不完全确定为什么要filegroup关心它是否通过data属性引用,但确实如此,它就是一个简单的例子.)

# BUILD
filegroup(
    name = "a",
    srcs = ["b"],
    data = ["c"],
)
sh_binary(
    name = "bin1",
    srcs = ["bin.sh"],
    deps = [":a"],
)
sh_binary(
    name = "bin2",
    srcs = ["bin.sh"],
    data = [":a"],
)

# bin.sh
ls
Run Code Online (Sandbox Code Playgroud)

我们发现该文件b位于runfile中,:bin2但不是:bin1.

$ bazel run //:bin1
bin1
bin.sh
c

$ bazel run //:bin2
b
bin2
bin.sh
c
Run Code Online (Sandbox Code Playgroud)

现在让我们看看在default_runfilesdata_runfiles直接.

# my_rule.bzl
def _impl(ctx):
  print(ctx.attr.dep.default_runfiles.files)
  print(ctx.attr.dep.data_runfiles.files)
my_rule = rule(
    implementation = _impl,
    attrs = {"dep": attr.label()},
)

# BUILD
load("//:my_rule.bzl", "my_rule")
my_rule(name = "foo", dep = ":a")


$ bazel build //:foo
WARNING: /usr/local/google/home/ajmichael/playgrounds/runfiles/my_rule.bzl:2:3: depset([File:[/usr/local/google/home/ajmichael/playgrounds/runfiles[source]]c]).
WARNING: /usr/local/google/home/ajmichael/playgrounds/runfiles/my_rule.bzl:3:3: depset([File:[/usr/local/google/home/ajmichael/playgrounds/runfiles[source]]b, File:[/usr/local/google/home/ajmichael/playgrounds/runfiles[source]]c]).
INFO: Found 1 target...
Target //:foo up-to-date (nothing to build)
INFO: Elapsed time: 0.194s, Critical Path: 0.00s
Run Code Online (Sandbox Code Playgroud)

如您所见,default_runfiles仅包含cwhile 和.data_runfilesbc