aos: Support custom filters in jinja2_template

I've been wanting to do this a few times now and I decided it was
finally time to do it.

I'm looking to render some jinja2 templates where I want to turn an
array of numbers (RGB colors) into an object initialization. That's a
little cumbersome for the existing filters. It's much easier to do in
a custom filter. This patch enables custom filters.

Change-Id: I09317cba7ec916cbbf076924c2d33509c20a5889
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/tools/build_rules/template.bzl b/tools/build_rules/template.bzl
index 7174969..b8b513b 100644
--- a/tools/build_rules/template.bzl
+++ b/tools/build_rules/template.bzl
@@ -19,9 +19,10 @@
     args.add_all(include_dirs, before_each = "--include_dir")
     if ctx.file.parameters_file:
         args.add("--replacements_file", ctx.file.parameters_file)
+    args.add_all(ctx.files.filter_srcs, before_each = "--filter_file")
 
     ctx.actions.run(
-        inputs = ctx.files.src + ctx.files.includes + ctx.files.parameters_file,
+        inputs = ctx.files.src + ctx.files.includes + ctx.files.parameters_file + ctx.files.filter_srcs,
         tools = [ctx.executable._jinja2],
         progress_message = "Generating " + out.short_path,
         outputs = [out],
@@ -60,6 +61,11 @@
             allow_files = True,
             doc = """Files which are included by the template.""",
         ),
+        "filter_srcs": attr.label_list(
+            allow_files = [".py"],
+            doc = """Files that are sourced for filters.
+Needs to have a register_filters function defined.""",
+        ),
         "_jinja2": attr.label(
             default = "//tools/build_rules:jinja2_generator",
             cfg = "exec",