From fa6ebffd342c9e5728433c0b0e327675e8148222 Mon Sep 17 00:00:00 2001 From: Matt Stark Date: Mon, 3 Jun 2024 13:19:15 +1000 Subject: [PATCH] expand_template: Add an is_executable flag --- docs/expand_template_doc.md | 3 ++- rules/expand_template.bzl | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/expand_template_doc.md b/docs/expand_template_doc.md index d40649c6..9d732472 100755 --- a/docs/expand_template_doc.md +++ b/docs/expand_template_doc.md @@ -9,7 +9,7 @@ A rule that performs template expansion.
 load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
 
-expand_template(name, out, substitutions, template)
+expand_template(name, out, is_executable, substitutions, template)
 
Template expansion @@ -27,6 +27,7 @@ explicitly add delimiters to the key strings, for example "{KEY}" or "@KEY@". | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | | out | The destination of the expanded file. | Label; nonconfigurable | required | | +| is_executable | Whether the expanded file is executable | Boolean | optional | `False` | | 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 f95507ec..2cf5b086 100644 --- a/rules/expand_template.bzl +++ b/rules/expand_template.bzl @@ -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, @@ -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", + ), }, )