Remove unnecessary wrapper macro for expand_template rule (#365)

Followup to #330: remove the wrapper macro and export the rule directly; the macro
does not serve any useful function. As a side effect, this fixes the inability to
set tags etc., since the macro did not support **kwargs.
This commit is contained in:
Alexandre Rostovtsev 2022-04-06 15:21:13 -04:00 committed by GitHub
parent de3035d605
commit d54e8a70ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 40 deletions

View File

@ -8,26 +8,25 @@ A rule that performes template expansion.
## expand_template ## expand_template
<pre> <pre>
expand_template(<a href="#expand_template-name">name</a>, <a href="#expand_template-template">template</a>, <a href="#expand_template-substitutions">substitutions</a>, <a href="#expand_template-out">out</a>) expand_template(<a href="#expand_template-name">name</a>, <a href="#expand_template-out">out</a>, <a href="#expand_template-substitutions">substitutions</a>, <a href="#expand_template-template">template</a>)
</pre> </pre>
Template expansion Template expansion
This performs a simple search over the template file for the keys in substitutions, This performs a simple search over the template file for the keys in
and replaces them with the corresponding values. substitutions, and replaces them with the corresponding values.
There is no special syntax for the keys. There is no special syntax for the keys. To avoid conflicts, you would need to
To avoid conflicts, you would need to explicitly add delimiters to the key strings, for example "{KEY}" or "@KEY@". explicitly add delimiters to the key strings, for example "{KEY}" or "@KEY@".
**ATTRIBUTES**
**PARAMETERS** | Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="expand_template-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| Name | Description | Default Value | | <a id="expand_template-out"></a>out | The destination of the expanded file. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
| :------------- | :------------- | :------------- | | <a id="expand_template-substitutions"></a>substitutions | A dictionary mapping strings to their substitutions. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | required | |
| <a id="expand_template-name"></a>name | The name of the rule. | none | | <a id="expand_template-template"></a>template | The template file to expand. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
| <a id="expand_template-template"></a>template | The template file to expand | none |
| <a id="expand_template-substitutions"></a>substitutions | A dictionary mapping strings to their substitutions | none |
| <a id="expand_template-out"></a>out | The destination of the expanded file | none |

View File

@ -22,34 +22,29 @@ def _expand_template_impl(ctx):
substitutions = ctx.attr.substitutions, substitutions = ctx.attr.substitutions,
) )
_expand_template = rule( expand_template = rule(
implementation = _expand_template_impl, implementation = _expand_template_impl,
doc = """Template expansion
This performs a simple search over the template file for the keys in
substitutions, and replaces them with the corresponding values.
There is no special syntax for the keys. To avoid conflicts, you would need to
explicitly add delimiters to the key strings, for example "{KEY}" or "@KEY@".""",
attrs = { attrs = {
"template": attr.label(mandatory = True, allow_single_file = True), "template": attr.label(
"substitutions": attr.string_dict(mandatory = True), mandatory = True,
"out": attr.output(mandatory = True), allow_single_file = True,
doc = "The template file to expand.",
),
"substitutions": attr.string_dict(
mandatory = True,
doc = "A dictionary mapping strings to their substitutions.",
),
"out": attr.output(
mandatory = True,
doc = "The destination of the expanded file.",
),
}, },
output_to_genfiles = True, output_to_genfiles = True,
) )
def expand_template(name, template, substitutions, out):
"""Template expansion
This performs a simple search over the template file for the keys in substitutions,
and replaces them with the corresponding values.
There is no special syntax for the keys.
To avoid conflicts, you would need to explicitly add delimiters to the key strings, for example "{KEY}" or "@KEY@".
Args:
name: The name of the rule.
template: The template file to expand
out: The destination of the expanded file
substitutions: A dictionary mapping strings to their substitutions
"""
_expand_template(
name = name,
template = template,
substitutions = substitutions,
out = out,
)