1 # This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2 # See https://llvm.org/LICENSE.txt for license information.
3 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 # Rule for simple expansion of template files. This performs a simple
6 # search over the template file for the keys in substitutions,
7 # and replaces them with the corresponding values.
10 # load("/tools/build_rules/template_rule", "expand_header_template")
12 # name = "ExpandMyTemplate",
13 # src = "my.template",
22 # name: The name of the rule.
23 # template: The template file to expand
24 # out: The destination of the expanded file
25 # substitutions: A dictionary mapping strings to their substitutions
27 def template_rule_impl(ctx):
28 ctx.actions.expand_template(
29 template = ctx.file.src,
30 output = ctx.outputs.out,
31 substitutions = ctx.attr.substitutions,
38 allow_single_file = True,
40 "substitutions": attr.string_dict(mandatory = True),
41 "out": attr.output(mandatory = True),
43 # output_to_genfiles is required for header files.
44 output_to_genfiles = True,
45 implementation = template_rule_impl,