Allow depending on files in jinja2_template
This lets us use the {% include %} directive in jinja2 to more cleanly
compose JSON files.
Change-Id: Ifdeb6f890c05ae1c20f4ffdd1540c64eb8e24be0
Signed-off-by: James Kuszmaul <jabukuszmaul+collab@gmail.com>
diff --git a/tools/build_rules/jinja2_generator.py b/tools/build_rules/jinja2_generator.py
index e5f6fa3..3575e99 100644
--- a/tools/build_rules/jinja2_generator.py
+++ b/tools/build_rules/jinja2_generator.py
@@ -22,7 +22,8 @@
args = parser.parse_args(sys.argv[1:])
with open(args.template, 'r') as input_file:
- template = jinja2.Template(input_file.read())
+ template = jinja2.Environment(
+ loader=jinja2.FileSystemLoader(".")).from_string(input_file.read())
output = template.render(args.replacements)
with open(args.output, 'w') as config_file:
diff --git a/tools/build_rules/template.bzl b/tools/build_rules/template.bzl
index d4807e8..0b9167e 100644
--- a/tools/build_rules/template.bzl
+++ b/tools/build_rules/template.bzl
@@ -2,7 +2,7 @@
out = ctx.actions.declare_file(ctx.attr.name)
ctx.actions.run_shell(
- inputs = ctx.files.src,
+ inputs = ctx.files.src + ctx.files.includes,
tools = [ctx.executable._jinja2],
progress_message = "Generating " + out.short_path,
outputs = [out],
@@ -22,6 +22,10 @@
mandatory = True,
doc = """The parameters to supply to Jinja2.""",
),
+ "includes": attr.label_list(
+ allow_files = True,
+ doc = """Files which are included by the template.""",
+ ),
"_jinja2": attr.label(
default = "//tools/build_rules:jinja2_generator",
cfg = "host",