小编zhu*_*nyi的帖子

如何在 Bazel 中使用 genrule 输出作为字符串来 Expand_template 替换?

看来genrule只能输出一个Target,而expand_template替换只接受string_dict,如何使用genrule输出来expand_template?

gen.bzl

def _expand_impl(ctx):
    ctx.actions.expand_template(
        template = ctx.file._template,
        output = ctx.outputs.source_file,
        substitutions = {
            "{version}": ctx.attr.version,
        }
    )

expand = rule(
    implementation = _expand_impl,
    attrs = {
        "version": attr.string(mandatory = True),
        "_template": attr.label(
            default = Label("//version:local.go.in"),
            allow_single_file = True,
        ),
    },
    outputs = {"source_file": "local.go"},
)
Run Code Online (Sandbox Code Playgroud)

建造

load("@io_bazel_rules_go//go:def.bzl", "go_library")

filegroup(
    name = "templates",
    srcs = ["local.go.in"],
)

genrule(
    name = "inject",
    outs = ["VERSION"],
    local = 1,
    cmd = "git rev-parse HEAD",
)

load(":gen.bzl", "expand")

expand(
    name = "expand",
    version …
Run Code Online (Sandbox Code Playgroud)

bazel

5
推荐指数
1
解决办法
2360
查看次数

标签 统计

bazel ×1