summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-02-20 15:07:44 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-02-21 06:41:19 +0900
commita324a8958b06b577f1a82a3a3d5f696add2b1fb4 (patch)
tree58bcbafb348d08cdbfae69654cf94059e6d6c8ed /tools
parente814f8b24661ef89cd84fb4c3f64f5be2d53061e (diff)
downloadsystemd-a324a8958b06b577f1a82a3a3d5f696add2b1fb4.tar.gz
meson: adjust whitespace handling in jinja2 rendering
In 6abe882bae1bb12827ef395c60f21ab8bb1bc61b the renderer was made to unconditionally append a newline to output. This works, but is ugly. A nicer solution is to tell jinja2 to not strip the newline in the first place, via keep_trailing_newline=True. It seems that the result is unchanged because all our source files have exactly one trailing newline. Also, enable lstrip_blocks=True. This would cause whitespace on the line before an {%if block to be automatically stripped. It seems reasonable to enable that if trim_blocks=True. Overall, no change is expected, though I didn't test combinations of configurations, so there might be a change in some cases. But now the rules of rendering are more logical, e.g. we should be able to indent nested conditional statements without getting unexpected whitespace in the output.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/meson-render-jinja2.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/tools/meson-render-jinja2.py b/tools/meson-render-jinja2.py
index fbaae596de..6ccb1fbe0c 100755
--- a/tools/meson-render-jinja2.py
+++ b/tools/meson-render-jinja2.py
@@ -23,7 +23,11 @@ def parse_config_h(filename):
def render(filename, defines):
text = open(filename).read()
- template = jinja2.Template(text, trim_blocks=True, undefined=jinja2.StrictUndefined)
+ template = jinja2.Template(text,
+ trim_blocks=True,
+ lstrip_blocks=True,
+ keep_trailing_newline=True,
+ undefined=jinja2.StrictUndefined)
return template.render(defines)
if __name__ == '__main__':
@@ -32,6 +36,5 @@ if __name__ == '__main__':
output = render(sys.argv[3], defines)
with open(sys.argv[4], 'w') as f:
f.write(output)
- f.write('\n')
info = os.stat(sys.argv[3])
os.chmod(sys.argv[4], info.st_mode)