From ba807914e4f6afe9f95aad7aa4e634d47193ba5c Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Thu, 7 Jan 2021 00:37:22 +0100 Subject: build: Add Jinja2 builder. --- build/env.py | 1 + build/scons_tools/tool_jinja2.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 build/scons_tools/tool_jinja2.py 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 -- cgit v1.2.3