summaryrefslogtreecommitdiff
path: root/build/scons_tools/tool_jinja2.py
blob: a9272857e91a8ff968fd33ca0c4d6fca8fc456a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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)