在DefaultInfo的文档中,我们现在可以返回3种不同的"类型"的runfiles:
runfiles
data_runfiles
default_runfiles
Run Code Online (Sandbox Code Playgroud)
我找不到任何文件,这些文件之间的分离和何时使用哪个.任何人都可以详细说明吗?
data_runfiles
是添加到二进制文件的运行文件中的文件,它依赖于通过data
属性的规则.default_runfiles
是添加到二进制文件的运行文件中的文件,它依赖于除了data
属性之外的任何内容的规则.runfiles
是一个简写,用于创建一个DefaultInfo
具有相同的文件集作为data_runfiles
和default_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_runfiles
和data_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
仅包含c
while 和.data_runfiles
b
c
归档时间: |
|
查看次数: |
1329 次 |
最近记录: |