summaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2021-01-07 00:37:22 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2021-01-07 00:37:22 +0100
commitba807914e4f6afe9f95aad7aa4e634d47193ba5c (patch)
tree55b41a7d91ebd5e4c085ded4bb8c8f1ad32a2e69 /build
parentffe73df435efea8e6e78052a59361cba0e696189 (diff)
build: Add Jinja2 builder.
Diffstat (limited to 'build')
-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