diff --git a/meson.build b/meson.build index 5dc083f47f..9dbdf34080 100644 --- a/meson.build +++ b/meson.build @@ -1647,6 +1647,7 @@ make_autosuspend_rules_py = find_program('tools/make-autosuspend-rules.py') make_directive_index_py = find_program('tools/make-directive-index.py') make_man_index_py = find_program('tools/make-man-index.py') meson_apply_m4 = find_program('tools/meson-apply-m4.sh') +meson_render_jinja2 = find_program('tools/meson-render-jinja2.py') update_dbus_docs_py = find_program('tools/update-dbus-docs.py') update_hwdb_sh = find_program('tools/update-hwdb.sh') update_hwdb_autosuspend_sh = find_program('tools/update-hwdb-autosuspend.sh') diff --git a/sysusers.d/basic.conf.in b/sysusers.d/basic.conf.in index 4be0bd869e..9da0251421 100644 --- a/sysusers.d/basic.conf.in +++ b/sysusers.d/basic.conf.in @@ -9,7 +9,7 @@ u root 0 "Super User" /root # The nobody user for NFS file systems -u @NOBODY_USER_NAME@ 65534 "Nobody" - +u {{NOBODY_USER_NAME}} 65534 "Nobody" - # Administrator group: can *see* more than normal users g adm - - - @@ -19,7 +19,7 @@ g wheel - - - # Access to certain kernel and userspace facilities g kmem - - - -g tty @TTY_GID@ - - +g tty {{TTY_GID}} - - g utmp - - - # Hardware access groups @@ -36,4 +36,4 @@ g tape - - - g video - - - # Default group for normal users -g users @USERS_GID@ - - +g users {{USERS_GID}} - - diff --git a/sysusers.d/meson.build b/sysusers.d/meson.build index ef809a4f44..894d1840bc 100644 --- a/sysusers.d/meson.build +++ b/sysusers.d/meson.build @@ -4,32 +4,19 @@ if enable_sysusers install_data('README', install_dir : sysusersdir) endif -in_files = ['basic.conf'] +in_files = [['basic.conf', enable_sysusers], + ['systemd.conf', enable_sysusers], + ['systemd-remote.conf', enable_sysusers and + conf.get('ENABLE_REMOTE') == 1 and conf.get('HAVE_MICROHTTPD') == 1]] -foreach file : in_files - gen = configure_file( - input : file + '.in', - output : file, - configuration : substs) - if enable_sysusers - install_data(gen, - install_dir : sysusersdir) - endif -endforeach - -m4_files = ['systemd.conf'] - -if conf.get('ENABLE_REMOTE') == 1 and conf.get('HAVE_MICROHTTPD') == 1 - m4_files += ['systemd-remote.conf'] -endif - -foreach file : m4_files +foreach tuple : in_files + file = tuple[0] custom_target( - 'sysusers.d_' + file, - input : file + '.m4', + file, + input : file + '.in', output: file, - command : [meson_apply_m4, config_h, '@INPUT@'], + command : [meson_render_jinja2, config_h, '@INPUT@'], capture : true, - install : enable_sysusers, + install : tuple[1], install_dir : sysusersdir) endforeach diff --git a/sysusers.d/systemd-remote.conf.m4 b/sysusers.d/systemd-remote.conf.in similarity index 90% rename from sysusers.d/systemd-remote.conf.m4 rename to sysusers.d/systemd-remote.conf.in index 988917672b..dae1077225 100644 --- a/sysusers.d/systemd-remote.conf.m4 +++ b/sysusers.d/systemd-remote.conf.in @@ -5,6 +5,6 @@ # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. -m4_ifdef(`HAVE_MICROHTTPD', +{% if HAVE_MICROHTTPD %} u systemd-journal-remote - "systemd Journal Remote" -)m4_dnl +{% endif %} diff --git a/sysusers.d/systemd.conf.m4 b/sysusers.d/systemd.conf.in similarity index 75% rename from sysusers.d/systemd.conf.m4 rename to sysusers.d/systemd.conf.in index fdfdcf553c..9905eb596c 100644 --- a/sysusers.d/systemd.conf.m4 +++ b/sysusers.d/systemd.conf.in @@ -6,18 +6,18 @@ # (at your option) any later version. g systemd-journal - - -m4_ifdef(`ENABLE_NETWORKD', +{% if ENABLE_NETWORKD %} u systemd-network - "systemd Network Management" -)m4_dnl -m4_ifdef(`ENABLE_OOMD', +{% endif %} +{% if ENABLE_OOMD %} u systemd-oom - "systemd Userspace OOM Killer" -)m4_dnl -m4_ifdef(`ENABLE_RESOLVE', +{% endif %} +{% if ENABLE_RESOLVE %} u systemd-resolve - "systemd Resolver" -)m4_dnl -m4_ifdef(`ENABLE_TIMESYNCD', +{% endif %} +{% if ENABLE_TIMESYNCD %} u systemd-timesync - "systemd Time Synchronization" -)m4_dnl -m4_ifdef(`ENABLE_COREDUMP', +{% endif %} +{% if ENABLE_COREDUMP %} u systemd-coredump - "systemd Core Dumper" -)m4_dnl +{% endif %} diff --git a/tools/meson-render-jinja2.py b/tools/meson-render-jinja2.py new file mode 100755 index 0000000000..063cb0eb27 --- /dev/null +++ b/tools/meson-render-jinja2.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-2.1+ + +import jinja2 +import re +import sys + +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 = 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]) + print(render(sys.argv[2], defines))