Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/expand_template_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A rule that performs template expansion.
<pre>
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")

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>)
expand_template(<a href="#expand_template-name">name</a>, <a href="#expand_template-out">out</a>, <a href="#expand_template-is_executable">is_executable</a>, <a href="#expand_template-substitutions">substitutions</a>, <a href="#expand_template-template">template</a>)
</pre>

Template expansion
Expand All @@ -27,6 +27,7 @@ explicitly add delimiters to the key strings, for example "{KEY}" or "@KEY@".
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="expand_template-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="expand_template-out"></a>out | The destination of the expanded file. | <a href="https://bazel.build/concepts/labels">Label</a>; <a href="https://bazel.build/reference/be/common-definitions#configurable-attributes">nonconfigurable</a> | required | |
| <a id="expand_template-is_executable"></a>is_executable | Whether the expanded file is executable | Boolean | optional | `False` |
| <a id="expand_template-substitutions"></a>substitutions | A dictionary mapping strings to their substitutions. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | required | |
| <a id="expand_template-template"></a>template | The template file to expand. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |

Expand Down
7 changes: 7 additions & 0 deletions rules/expand_template.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ def _expand_template_impl(ctx):
template = ctx.file.template,
output = ctx.outputs.out,
substitutions = ctx.attr.substitutions,
is_executable = ctx.attr.is_executable,
)
if ctx.attr.is_executable:
return [DefaultInfo(executable = ctx.outputs.out)]

expand_template = rule(
implementation = _expand_template_impl,
Expand All @@ -45,5 +48,9 @@ explicitly add delimiters to the key strings, for example "{KEY}" or "@KEY@"."""
mandatory = True,
doc = "The destination of the expanded file.",
),
"is_executable": attr.bool(
default = False,
doc = "Whether the expanded file is executable",
),
},
)