2017-05-12 47 views
5

DefaultInfo的文件,我們現在可以返回3不同的「類型」 runfiles的:有哪些不同類型的runfiles

runfiles 
data_runfiles 
default_runfiles 

我找不到任何文檔,其中它們之間的分離以及何時使用哪個。任何人都可以詳細說明嗎?

回答

4

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 

我們發現,文件b是在:bin2的runfiles但不是:bin1

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

$ bazel run //:bin2 
b 
bin2 
bin.sh 
c 

現在讓我們來看看直接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 

正如你所看到的,default_runfiles只包含cdata_runfiles同時包含bc

相關問題