Support importing codegen'd files in jinja templates
The resolver wasn't looking in the bazel-out/k8-opt/bin (or similar)
directory.
Change-Id: I762c62c691ab6efdc9afb55238e964d2475111a0
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 3575e99..82222c3 100644
--- a/tools/build_rules/jinja2_generator.py
+++ b/tools/build_rules/jinja2_generator.py
@@ -19,11 +19,15 @@
type=json.loads,
help="Dictionary of parameters to replace in the template.")
parser.add_argument("output", type=str, help="Output file to create.")
+ parser.add_argument(
+ "genfiles_dir",
+ type=str,
+ help="Directory where generated JSON files will be available.")
args = parser.parse_args(sys.argv[1:])
with open(args.template, 'r') as input_file:
- template = jinja2.Environment(
- loader=jinja2.FileSystemLoader(".")).from_string(input_file.read())
+ template = jinja2.Environment(loader=jinja2.FileSystemLoader(
+ [".", args.genfiles_dir])).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 1ad06d8..d3547d8 100644
--- a/tools/build_rules/template.bzl
+++ b/tools/build_rules/template.bzl
@@ -8,7 +8,8 @@
tools = [ctx.executable._jinja2],
progress_message = "Generating " + out.short_path,
outputs = [out],
- command = ctx.executable._jinja2.path + " " + ctx.files.src[0].path + " '" + str(parameters) + "' " + out.path,
+ # TODO(james): Is the genfiles_dir the correct thing?
+ command = ctx.executable._jinja2.path + " " + ctx.files.src[0].path + " '" + str(parameters) + "' " + out.path + " " + ctx.genfiles_dir.path,
)
return [DefaultInfo(files = depset([out])), OutputGroupInfo(out = depset([out]))]