diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 15:35:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 15:35:18 +0000 |
commit | b750101eb236130cf056c675997decbac904cc49 (patch) | |
tree | a5df1a06754bdd014cb975c051c83b01c9a97532 /tools/meson-render-jinja2.py | |
parent | Initial commit. (diff) | |
download | systemd-b750101eb236130cf056c675997decbac904cc49.tar.xz systemd-b750101eb236130cf056c675997decbac904cc49.zip |
Adding upstream version 252.22.upstream/252.22
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/meson-render-jinja2.py')
-rwxr-xr-x | tools/meson-render-jinja2.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tools/meson-render-jinja2.py b/tools/meson-render-jinja2.py new file mode 100755 index 0000000..fbaae59 --- /dev/null +++ b/tools/meson-render-jinja2.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-2.1-or-later + +import ast +import os +import re +import sys + +import jinja2 + +def parse_config_h(filename): + # Parse config.h file generated by meson. + ans = {} + for line in open(filename): + m = re.match(r'#define\s+(\w+)\s+(.*)', line) + if not m: + continue + a, b = m.groups() + if b and b[0] in '0123456789"': + b = ast.literal_eval(b) + ans[a] = b + return ans + +def render(filename, defines): + text = open(filename).read() + template = jinja2.Template(text, trim_blocks=True, undefined=jinja2.StrictUndefined) + return template.render(defines) + +if __name__ == '__main__': + defines = parse_config_h(sys.argv[1]) + defines.update(parse_config_h(sys.argv[2])) + 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) |