In the documentation of DefaultInfo, we now can return 3 different "types" of runfiles:
runfiles
data_runfiles
default_runfiles
I could not find any documentation where the separation between these is and when to use which. Could anyone elaborate in detail?
A container of information regarding a set of files required at runtime execution.
Targets. A package is a container. The elements of a package are called targets.
data_runfiles
are the files that are added to the runfiles of a binary that depends on the rule via the data
attribute. default_runfiles
are the files that are added to the runfiles of a binary that depends on the rule via anything but the data
attribute. runfiles
are a shorthand for creating a DefaultInfo
that has the same set of files acting as both the data_runfiles
and default_runfiles
.
Consider the following example involving the filegroup
rule. (I'm not entirely sure why filegroup
cares whether or not it is referenced via the data
attribute, but it does and it makes a simple example.)
# 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
We find that file b
is in the runfiles of :bin2
but not :bin1
.
$ bazel run //:bin1
bin1
bin.sh
c
$ bazel run //:bin2
b
bin2
bin.sh
c
Now lets have a look at the default_runfiles
and data_runfiles
directly.
# 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
As you can see, default_runfiles
contains only c
while data_runfiles
contains both b
and c
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With