[英]Is there any way to generate the deps list for particular rules?
I have a program that can look at my language's source file, and derive the correct value for the deps=[]
value of its build rule. 我有一个程序可以查看我的语言的源文件,并为其构建规则的
deps=[]
值派生正确的值。
I'm looking for a way to replace all my existing rules (that look like this): 我正在寻找一种方法来替换我现有的所有规则(看起来像这样):
build_lib(name = "foo", deps = [...])
build_lib(name = "bar", deps = [...])
build_lib(name = "baz", deps = [...])
To instead be: 相反是:
build_lib_new(name = "foo")
build_lib_new(name = "bar")
build_lib_new(name = "baz")
with the same specified deps resolved internally in the rule by calling my program. 通过调用我的程序在规则内部解析相同的指定deps。
Ideally, build_lib_new
would just be a wrapper rule around build_lib
: 理想情况下,
build_lib_new
也只是围绕一个包装规则build_lib
:
def derive_deps(name):
deps = []
# call my tool somehow?
return deps
def build_lib_new(name):
deps = derive_deps(name)
build_lib(name,deps)
Now I'm stuck. 现在我被卡住了。 Unfortunately, I think bazel wants to know all the dependencies up front as part of the analysis phase.
不幸的是,我认为bazel希望在分析阶段预先了解所有依赖关系。 I see that their are actions to run shell commands, but I believe those happen after the dependency graph is made.
我看到他们是运行shell命令的动作,但我相信这些是在创建依赖图之后发生的。
Do I have to run the external tool outside of bazel to rewrite BUILD
files? 我是否必须在bazel之外运行外部工具来重写
BUILD
文件?
Do I have to run the external tool outside of bazel to rewrite BUILD files?
我是否必须在bazel之外运行外部工具来重写BUILD文件?
In short, yes. 简而言之,是的。 This is why tools like Gazelle and Jadep exist.
这就是为什么像Gazelle和Jadep这样的工具存在的原因。
If your tool runs as actions during execution phase, then the deps would be non-existent during loading and analysis phase. 如果您的工具在执行阶段作为操作运行,那么在加载和分析阶段,deps将不存在。 You'll need to run the tool before loading/analysis, maybe as a repository rule ?
您需要在加载/分析之前运行该工具,可能作为存储库规则 ?
I see that their are actions to run shell commands, but I believe those happen after the dependency graph is made.
我看到他们是运行shell命令的动作,但我相信这些是在创建依赖图之后发生的。
Correct. 正确。 The analysis phase creates the configured target graph, and reifies it into the action (shell commands, artifacts, etc) graph for the execution phase.
分析阶段创建配置的目标图,并将其强制执行到执行阶段的操作(shell命令,工件等)图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.