创建多个类似的基因并使用其输出
我有一个如下所示的正则。它基本上运行一个简单的 go 模板工具,获取资源名称、json 文件和模板并输出渲染的文件。我有一堆资源,所有这些资源都需要位于单独的文件中,并最终打包到一个容器中。
resources = ["foo", "bar"]
[genrule(
name = "generate_" + resource + "_config",
srcs = [
"//some:tool:config.tmpl",
"//some:json",
],
outs = [resource + ".hcl"],
cmd = "$(location //some/tool:template) -resource " + resource + " -json_path=$(location //some:json) -template=$(location //some/tool:config.tmpl) -out=$@",
tools = [
"/some/tool:template",
],
) for resource in resources]
上面将生成一些名为 generate_foo_config
和 generate_bar_config
的规则,并且文件输出正确。然而,如果不直接在文件组或 pkg_tar 规则中指定而不枚举每一项,我无法弄清楚如何使用每一项。我希望能够向 resources 变量添加新内容,并将其自动包含在文件组或 tar 中,以便稍后在构建规则中使用。这可能吗?
I have a genrule that looks like the below. It basically runs a simple go template tool that gets a resource name, a json file and template and outputs the rendered file. I have a bunch of resources that all need to be in separate files and ultimately packaged into a container.
resources = ["foo", "bar"]
[genrule(
name = "generate_" + resource + "_config",
srcs = [
"//some:tool:config.tmpl",
"//some:json",
],
outs = [resource + ".hcl"],
cmd = "$(location //some/tool:template) -resource " + resource + " -json_path=$(location //some:json) -template=$(location //some/tool:config.tmpl) -out=$@",
tools = [
"/some/tool:template",
],
) for resource in resources]
The above will generate a few rules named generate_foo_config
and generate_bar_config
and the files output correctly. I however cannot figure out how to use each one without specifying them directly in a filegroup or pkg_tar rule without enumerating each one. I would like to be able to add a new thing to the resources variable, and have it automatically included in the filegroup or tar for use in a build rule later. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 列表理解,就像您已经创建了属规则。像这样:
您还可以将列表放入 BUILD 文件中的变量中以多次使用它:
Use a list comprehension, like you've got creating the genrules. Something like this:
You can also put the list in a variable in the BUILD file to use it multiple times: