From d54e8a70ce90a24b921381cbe84fa0b88b22dc46 Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Wed, 6 Apr 2022 15:21:13 -0400 Subject: [PATCH] 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. --- docs/expand_template_doc.md | 27 ++++++++++----------- rules/expand_template.bzl | 47 +++++++++++++++++-------------------- 2 files changed, 34 insertions(+), 40 deletions(-) diff --git a/docs/expand_template_doc.md b/docs/expand_template_doc.md index b086829..b370135 100755 --- a/docs/expand_template_doc.md +++ b/docs/expand_template_doc.md @@ -8,26 +8,25 @@ A rule that performes template expansion. ## expand_template
-expand_template(name, template, substitutions, out)
+expand_template(name, out, substitutions, template)
 
Template expansion -This performs a simple search over the template file for the keys in substitutions, -and replaces them with the corresponding values. +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@". +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@". + +**ATTRIBUTES** -**PARAMETERS** - - -| Name | Description | Default Value | -| :------------- | :------------- | :------------- | -| name | The name of the rule. | none | -| template | The template file to expand | none | -| substitutions | A dictionary mapping strings to their substitutions | none | -| out | The destination of the expanded file | none | +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| out | The destination of the expanded file. | Label | required | | +| substitutions | A dictionary mapping strings to their substitutions. | Dictionary: String -> String | required | | +| template | The template file to expand. | Label | required | | diff --git a/rules/expand_template.bzl b/rules/expand_template.bzl index 58f1920..96bff44 100644 --- a/rules/expand_template.bzl +++ b/rules/expand_template.bzl @@ -22,34 +22,29 @@ def _expand_template_impl(ctx): substitutions = ctx.attr.substitutions, ) -_expand_template = rule( +expand_template = rule( 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 = { - "template": attr.label(mandatory = True, allow_single_file = True), - "substitutions": attr.string_dict(mandatory = True), - "out": attr.output(mandatory = True), + "template": attr.label( + 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, ) - -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, - )