Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
30 lines (25 sloc) 754 Bytes
"""Generate a file using a template.
It is much more memory-efficient to use a template file than creating the whole
content during the analysis phase.
"""
# Label of the template file to use.
_TEMPLATE = "//expand_template:hello.cc"
def _hello_impl(ctx):
ctx.actions.expand_template(
template = ctx.file._template,
output = ctx.outputs.source_file,
substitutions = {
"{FIRSTNAME}": ctx.attr.firstname,
},
)
hello = rule(
implementation = _hello_impl,
attrs = {
"firstname": attr.string(mandatory = True),
"_template": attr.label(
default = Label(_TEMPLATE),
allow_single_file = True,
),
},
outputs = {"source_file": "%{name}.cc"},
)
You can’t perform that action at this time.