diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2021-01-07 12:25:05 +0100 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2021-01-07 12:25:05 +0100 |
commit | 082db0c6b5b70df45ef16b7124a982df3054e3c8 (patch) | |
tree | bea0b623d6a5856e2fa286a173ef7e9c7a9952b1 | |
parent | cf79d8f57747cb41fa9756263fe14470197c5c86 (diff) |
build: Added hex and size_prefix filters for Jinja2.
-rw-r--r-- | build/scons_tools/tool_jinja2.py | 11 | ||||
-rw-r--r-- | ld_scripts/generated.ld.j2 | 2 |
2 files changed, 11 insertions, 2 deletions
diff --git a/build/scons_tools/tool_jinja2.py b/build/scons_tools/tool_jinja2.py index a927285..c85c559 100644 --- a/build/scons_tools/tool_jinja2.py +++ b/build/scons_tools/tool_jinja2.py @@ -1,8 +1,17 @@ from SCons.Script import * import jinja2 +loader = jinja2.FileSystemLoader('.') + +jinja2_env = jinja2.Environment( + loader = loader, +) + +jinja2_env.filters['hex'] = lambda value: '%#x' % value +jinja2_env.filters['size_prefix'] = lambda value: '%d%s' % next((value / 1024**i, c) for i, c in [(2, 'M'), (1, 'k'), (0, '')] if value % 1024**i == 0) + def jinja2_build(target, source, env): - template = jinja2.Template(open(str(source[0])).read()) + template = jinja2_env.get_template(str(source[0])) template_env = env.get('TEMPLATE_ENV', {}) diff --git a/ld_scripts/generated.ld.j2 b/ld_scripts/generated.ld.j2 index 40a198a..bc088d5 100644 --- a/ld_scripts/generated.ld.j2 +++ b/ld_scripts/generated.ld.j2 @@ -1,6 +1,6 @@ MEMORY { {% for name, m in mem.items() %} - {{ name }} ({{ 'rx' if name == 'flash' else 'rwx' }}) : org = {{ m.origin }}, len = {{ m.size }} + {{ name }} ({{ 'rx' if name == 'flash' else 'rwx' }}) : org = {{ m.origin | hex }}, len = {{ m.size | size_prefix }} {% endfor %} } |