summaryrefslogtreecommitdiff
path: root/tools/meson-render-jinja2.py
Commit message (Collapse)AuthorAgeFilesLines
* meson: adjust whitespace handling in jinja2 renderingZbigniew Jędrzejewski-Szmek2023-02-211-2/+5
| | | | | | | | | | | | | | | | | 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.
* meson: also allow setting GIT_VERSION via templatesZbigniew Jędrzejewski-Szmek2022-04-051-4/+5
| | | | | | | | | GIT_VERSION is not available as a config.h variable, because it's rendered into version.h during builds. Let's rework jinja2 rendering to also parse version.h. No functional change, the new variable is so far unused. I guess this will make partial rebuilds a bit slower, but it's useful to be able to use the full version string.
* meson: add missing final newline in jinja2 outputsZbigniew Jędrzejewski-Szmek2021-12-091-0/+1
| | | | | I think this might be caused by trim_blocks=True. We were missing the final newline everywhere.
* build: preserve correct mode when generating files via jinja2Christian Brauner2021-11-081-1/+6
| | | | | | | | | When using "capture : true" in custom_target()s the mode of the source file is not preserved when the generated file is not installed and so needs to be tweaked manually. Switch from output capture to creating the target file and copy the permissions from the input file. Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
* meson-render-jinja2: use ast.literal_eval()Zbigniew Jędrzejewski-Szmek2021-11-051-2/+4
| | | | | | | | | | | Imports are sorted in the usual fashion: stdlib first. literal_eval() parses string/numbers/lists/sets/dicts, and nothing else, while eval will execute any python code. Using literal_eval() is generally more correct, because it avoids the risk of side effects from the parsed expression. In this case, we generate the parsed strings ourselves, so it's very unlikely to have anything unexpected in the expressions. But let's do the correct thing anyway.
* tree-wide: fix SPDX short identifier for LGPL-2.1-or-laterLuca Boccassi2021-10-011-1/+1
| | | | | https://spdx.dev/ids/#:~:text=Allowing%20later%20versions%20of%20a%20license https://spdx.org/licenses/LGPL-2.1-or-later.html
* meson: replace some m4 templates with jinja2Zbigniew Jędrzejewski-Szmek2021-05-191-0/+28
m4 was nice in '85, but the syntax feels a bit dated. Since we use python for meson, let's use a popular python templating engine to replace some m4 usage. A little nicety is that typos are caught: FAILED: sysusers.d/systemd-remote.conf /usr/bin/meson --internal exe --capture sysusers.d/systemd-remote.conf -- /home/zbyszek/src/systemd/tools/meson-render-jinja2.py config.h ../sysusers.d/systemd-remote.conf.j2 Traceback (most recent call last): File "/home/zbyszek/src/systemd/tools/meson-render-jinja2.py", line 28, in <module> print(render(sys.argv[2], defines)) File "/home/zbyszek/src/systemd/tools/meson-render-jinja2.py", line 24, in render return template.render(defines) File "/usr/lib/python3.9/site-packages/jinja2/environment.py", line 1090, in render self.environment.handle_exception() File "/usr/lib/python3.9/site-packages/jinja2/environment.py", line 832, in handle_exception reraise(*rewrite_traceback_stack(source=source)) File "/usr/lib/python3.9/site-packages/jinja2/_compat.py", line 28, in reraise raise value.with_traceback(tb) File "<template>", line 8, in top-level template code jinja2.exceptions.UndefinedError: 'HAVE_MICROHTTP' is undefined This checking mirrors what 349cc4a507c4d84fcadf61f42159ea6412717896 did for C defines.