bazel-skylib icon indicating copy to clipboard operation
bazel-skylib copied to clipboard

Make common_settings flags return platform_common.TemplateVariableInfo

Open steeve opened this issue 5 years ago • 0 comments

This would allows for genrule and friends to consume args as templates, for instance:

load("@bazel_skylib//rules:common_settings.bzl", "string_flag")

string_flag(
    name = "myflag",
)

genrule(
    name = "myrule",
    outs = ["value.txt"],
    cmd = """echo $(@myrepo//mypkg:myflag) > $@""",
    toolchains = [":myflags"],
)

I have a working prototype that just forward flags as templates, and it works well:

load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")

def _flags_supplier_impl(ctx):
    flags = {}
    for flag in ctx.attr.flags:
        flags[str(flag.label)] = flag[BuildSettingInfo].value
    return [
        platform_common.TemplateVariableInfo(flags),
    ]

flags_supplier = rule(
    implementation = _flags_supplier_impl,
    attrs = {
        "flags": attr.label_list(),
    },
)

steeve avatar Aug 24 '20 13:08 steeve