diff options
author | Gunhan Gulsoy <gunan@google.com> | 2016-12-22 18:44:21 -0800 |
---|---|---|
committer | Gunhan Gulsoy <gunan@google.com> | 2016-12-22 18:44:21 -0800 |
commit | 1e9ed820139f489e17fee294d72a42522e6297bf (patch) | |
tree | 442c1c7e8fe973a8da8a6ffe172ce2ec15e496d6 /third_party/common.bzl | |
parent | afeb7cd3ac69b0028d1b3ce75d006509f95f4d88 (diff) |
Move expand_header_template macro to a common skylark file to be shared.
Diffstat (limited to 'third_party/common.bzl')
-rw-r--r-- | third_party/common.bzl | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/third_party/common.bzl b/third_party/common.bzl new file mode 100644 index 0000000000..18e3798c5a --- /dev/null +++ b/third_party/common.bzl @@ -0,0 +1,39 @@ +# Rule for simple expansion of template files. This performs a simple +# search over the template file for the keys in substitutions, +# and replaces them with the corresponding values. +# +# Typical usage: +# load("/tools/build_rules/expand_header_template", "expand_header_template") +# expand_header_template( +# name = "ExpandMyTemplate", +# template = "my.template", +# out = "my.txt", +# substitutions = { +# "$VAR1": "foo", +# "$VAR2": "bar", +# } +# ) +# +# 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 + +def expand_header_template_impl(ctx): + ctx.template_action( + template = ctx.file.template, + output = ctx.outputs.out, + substitutions = ctx.attr.substitutions, + ) + +expand_header_template = rule( + implementation = expand_header_template_impl, + attrs = { + "template": attr.label(mandatory=True, allow_files=True, single_file=True), + "substitutions": attr.string_dict(mandatory=True), + "out": attr.output(mandatory=True), + }, + # output_to_genfiles is required for header files. + output_to_genfiles = True, +) |