I read the following bazel manual about make variables (or custom variables):
https://bazel.build/reference/be/make-variables#custom_variables
“Attributes marked as “Subject to ‘Make variable’ substitution” can reference the “Make” variable FOO as follows:”
my_attr = "prefix $(FOO) suffix"
My question is: how to mark attribute as “Subject to ‘Make variable’ substitution” ?
There is nothing about this in the documentation about rule attributes:
https://bazel.build/rules/lib/toplevel/attr
Please help
In my example
### BUILD.bazel
load("version.bzl", "version_rule")
load("file.bzl", "file")
version_rule(
name = "version_provider",
varname = "VERSION",
)
file(
name = "hello",
version = ":version_provider",
output_name = "hello",
content = "Hello world $(VERSION)n",
)
### version.bzl
def _version_rule_impl(ctx):
print("n------------------- _version_rule_impln")
return [
platform_common.TemplateVariableInfo({
'VERSION': '1-2-3-4',
}),
]
version_rule = rule(
implementation = _version_rule_impl,
attrs = {
"varname": attr.string(mandatory = True),
},
)
### file.bzl
def file(**kwargs):
_file(out = "{output_name}.txt".format(**kwargs), **kwargs)
def _impl(ctx):
output = ctx.outputs.out
ctx.actions.write(output = output, content = ctx.attr.content)
_file = rule(
implementation = _impl,
attrs = {
"version": attr.label(providers=[platform_common.TemplateVariableInfo]),
"output_name": attr.string(mandatory=True),
"content": attr.string(),
"out": attr.output()
},
)
I expect that generated file contents will be “Hello world 1-2-3-4n” but it is “Hello world $(VERSION)n”