summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build/env.py1
-rw-r--r--build/scons_tools/tool_jinja2.py27
2 files changed, 28 insertions, 0 deletions
diff --git a/build/env.py b/build/env.py
index c43bb60..6bc23e8 100644
--- a/build/env.py
+++ b/build/env.py
@@ -8,6 +8,7 @@ env = Environment(
'default',
'tool_selectmcu',
'tool_firmware',
+ 'tool_jinja2',
],
)
diff --git a/build/scons_tools/tool_jinja2.py b/build/scons_tools/tool_jinja2.py
new file mode 100644
index 0000000..a927285
--- /dev/null
+++ b/build/scons_tools/tool_jinja2.py
@@ -0,0 +1,27 @@
+from SCons.Script import *
+import jinja2
+
+def jinja2_build(target, source, env):
+ template = jinja2.Template(open(str(source[0])).read())
+
+ template_env = env.get('TEMPLATE_ENV', {})
+
+ output = template.render(**template_env) + '\n'
+
+ open(str(target[0]), 'w').write(output)
+
+jinja2_builder = Builder(action = Action(jinja2_build, '$J2COMSTR', varlist = ['TEMPLATE_ENV']))
+
+def Jinja2(env, target, source, **kwargs):
+ return env.Jinja2Build(target, source, TEMPLATE_ENV = kwargs)
+
+
+def exists():
+ return True
+
+def generate(env):
+ env.Append(
+ BUILDERS = {'Jinja2Build': jinja2_builder},
+ )
+
+ env.AddMethod(Jinja2) \ No newline at end of file