2
0
Fork 0
mirror of https://github.com/bazel-contrib/bazel-lib synced 2024-11-25 11:32:33 +00:00
bazel-lib/lib/expand_template.bzl
Alex Eagle 882bc95615
feat: expand_template allows inline template content (#533)
Co-authored-by: thesayyn <thesayyn@gmail.com>
2023-09-20 18:32:05 -07:00

32 lines
970 B
Python

"Public API for expand template"
load("@bazel_skylib//lib:types.bzl", "types")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("//lib/private:expand_template.bzl", _expand_template = "expand_template")
expand_template_rule = _expand_template
def expand_template(name, template, **kwargs):
"""Wrapper macro for `expand_template_rule`.
Args:
name: name of resulting rule
template: the label of a template file, or a list of strings
which are lines representing the content of the template.
**kwargs: other named parameters to `expand_template_rule`.
"""
if types.is_list(template):
write_target = "_{}.tmpl".format(name)
write_file(
name = write_target,
out = "{}.txt".format(write_target),
content = template,
)
template = write_target
_expand_template(
name = name,
template = template,
**kwargs
)