Skip to content

Commit 5b252c9

Browse files
committed
Allow for macros and error checks in SUIT manifests templates
Ref: NCSDK-NONE Signed-off-by: Artur Hadasz <artur.hadasz@nordicsemi.no>
1 parent 0a8712a commit 5b252c9

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

ncs/build.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
import logging
1414
import yaml
1515

16-
from jinja2 import Template
16+
from jinja2 import FileSystemLoader, Environment
17+
from jinja2.exceptions import TemplateRuntimeError
1718
from argparse import ArgumentParser
1819
from configparser import ConfigParser
1920

@@ -158,10 +159,21 @@ def read_version_file(version_file):
158159
return {}
159160

160161

162+
def raise_helper(msg):
163+
"""Raise an error as a result of the raise_err directive the template."""
164+
raise TemplateRuntimeError(msg)
165+
166+
161167
def render_template(template_location, data):
162168
"""Render template using passed data."""
163-
with open(template_location) as template_file:
164-
template = Template(template_file.read())
169+
macros_path = pathlib.Path(dir_path.parent.parent.parent.parent / "nrf" / "config" / "suit" / "macros").absolute()
170+
template_location = pathlib.Path(template_location)
171+
env = Environment(
172+
loader=FileSystemLoader([macros_path, template_location.parent]), trim_blocks=False, lstrip_blocks=False
173+
)
174+
env.globals["raise_err"] = raise_helper
175+
176+
template = env.get_template(template_location.name)
165177
return template.render(data)
166178

167179

0 commit comments

Comments
 (0)