From 8f04a1ca2bf973e5419c32adca1dcf888e0b263f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 5 Apr 2022 16:52:44 +0200 Subject: [PATCH] meson: also allow setting GIT_VERSION via templates 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. --- docs/sysvinit/meson.build | 2 +- factory/templates/meson.build | 2 +- man/meson.build | 2 +- meson.build | 2 ++ rules.d/meson.build | 2 +- shell-completion/bash/meson.build | 2 +- shell-completion/zsh/meson.build | 2 +- src/core/meson.build | 4 ++-- src/journal-remote/meson.build | 2 +- src/libsystemd/meson.build | 2 +- src/libudev/meson.build | 2 +- src/login/meson.build | 2 +- src/resolve/meson.build | 2 +- src/rpm/meson.build | 2 +- src/timesync/meson.build | 2 +- src/udev/meson.build | 2 +- src/vconsole/meson.build | 2 +- sysctl.d/meson.build | 2 +- sysusers.d/meson.build | 2 +- tmpfiles.d/meson.build | 2 +- tools/meson-render-jinja2.py | 9 +++++---- units/meson.build | 2 +- 22 files changed, 28 insertions(+), 25 deletions(-) diff --git a/docs/sysvinit/meson.build b/docs/sysvinit/meson.build index cd3015ca4b4..64476a5d76f 100644 --- a/docs/sysvinit/meson.build +++ b/docs/sysvinit/meson.build @@ -4,6 +4,6 @@ custom_target( 'README', input : 'README.in', output : 'README', - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@'], + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : conf.get('HAVE_SYSV_COMPAT') == 1, install_dir : sysvinit_path) diff --git a/factory/templates/meson.build b/factory/templates/meson.build index 821f176a747..ece2c644ff2 100644 --- a/factory/templates/meson.build +++ b/factory/templates/meson.build @@ -6,6 +6,6 @@ custom_target( 'locale.conf', input : 'locale.conf.in', output : 'locale.conf', - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@'], + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : true, install_dir : factory_etc_dir) diff --git a/man/meson.build b/man/meson.build index 83b368115b4..d9c706b4aba 100644 --- a/man/meson.build +++ b/man/meson.build @@ -30,7 +30,7 @@ custom_entities_ent = custom_target( 'custom-entities.ent', input : 'custom-entities.ent.in', output : 'custom-entities.ent', - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@']) + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@']) man_pages = [] html_pages = [] diff --git a/meson.build b/meson.build index b43273262d0..ce54b1045db 100644 --- a/meson.build +++ b/meson.build @@ -1826,6 +1826,8 @@ config_h = configure_file( add_project_arguments('-include', 'config.h', language : 'c') +jinja2_cmdline = [meson_render_jinja2, config_h, version_h] + ############################################################ # binaries that have --help and are intended for use by humans, diff --git a/rules.d/meson.build b/rules.d/meson.build index e6533e001a5..f725e14d95d 100644 --- a/rules.d/meson.build +++ b/rules.d/meson.build @@ -51,7 +51,7 @@ foreach file : rules_in file, input : file + '.in', output: file, - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@'], + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : true, install_dir : udevrulesdir) endforeach diff --git a/shell-completion/bash/meson.build b/shell-completion/bash/meson.build index ae6a61e5554..fb7314348a4 100644 --- a/shell-completion/bash/meson.build +++ b/shell-completion/bash/meson.build @@ -14,7 +14,7 @@ custom_target( 'systemctl', input : 'systemctl.in', output : 'systemctl', - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@'], + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : bashcompletiondir != 'no', install_dir : bashcompletiondir) diff --git a/shell-completion/zsh/meson.build b/shell-completion/zsh/meson.build index bac531798cc..b39f933ea4c 100644 --- a/shell-completion/zsh/meson.build +++ b/shell-completion/zsh/meson.build @@ -9,7 +9,7 @@ custom_target( '_systemctl', input : '_systemctl.in', output : '_systemctl', - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@'], + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : zshcompletiondir != 'no', install_dir : zshcompletiondir) diff --git a/src/core/meson.build b/src/core/meson.build index f5e04b37ca2..ee2f8774bf3 100644 --- a/src/core/meson.build +++ b/src/core/meson.build @@ -151,7 +151,7 @@ load_fragment_gperf_gperf = custom_target( 'load-fragment-gperf.gperf', input : 'load-fragment-gperf.gperf.in', output: 'load-fragment-gperf.gperf', - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@']) + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@']) load_fragment_gperf_c = custom_target( 'load-fragment-gperf.c', @@ -217,7 +217,7 @@ foreach item : in_files file, input : file + '.in', output: file, - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@'], + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : (dir == pkgsysconfdir) ? install_sysconfdir_samples : (dir != 'no'), install_dir : dir) endforeach diff --git a/src/journal-remote/meson.build b/src/journal-remote/meson.build index 4bbbc1431fd..f81d906616d 100644 --- a/src/journal-remote/meson.build +++ b/src/journal-remote/meson.build @@ -54,7 +54,7 @@ foreach tuple : in_files file, input : file + '.in', output: file, - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@'], + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : tuple[1], install_dir : pkgsysconfdir) endforeach diff --git a/src/libsystemd/meson.build b/src/libsystemd/meson.build index 67b439a5dd5..a86b8f896b6 100644 --- a/src/libsystemd/meson.build +++ b/src/libsystemd/meson.build @@ -186,7 +186,7 @@ custom_target( 'libsystemd.pc', input : 'libsystemd.pc.in', output : 'libsystemd.pc', - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@'], + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : pkgconfiglibdir != 'no', install_dir : pkgconfiglibdir) diff --git a/src/libudev/meson.build b/src/libudev/meson.build index 2d51ff7c583..a831391cc1f 100644 --- a/src/libudev/meson.build +++ b/src/libudev/meson.build @@ -38,7 +38,7 @@ custom_target( 'libudev.pc', input : 'libudev.pc.in', output : 'libudev.pc', - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@'], + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : pkgconfiglibdir != 'no', install_dir : pkgconfiglibdir) diff --git a/src/login/meson.build b/src/login/meson.build index 1a2d738e840..bd350569d56 100644 --- a/src/login/meson.build +++ b/src/login/meson.build @@ -80,7 +80,7 @@ foreach tuple : in_files file, input : file + '.in', output: file, - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@'], + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : tuple[2] and install, install_dir : dir) endforeach diff --git a/src/resolve/meson.build b/src/resolve/meson.build index b2da249c87d..e11aefce7ac 100644 --- a/src/resolve/meson.build +++ b/src/resolve/meson.build @@ -168,7 +168,7 @@ custom_target( 'resolved.conf', input : 'resolved.conf.in', output : 'resolved.conf', - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@'], + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : conf.get('ENABLE_RESOLVE') == 1 and install_sysconfdir_samples, install_dir : pkgsysconfdir) diff --git a/src/rpm/meson.build b/src/rpm/meson.build index 4bfeda8883c..817665912a9 100644 --- a/src/rpm/meson.build +++ b/src/rpm/meson.build @@ -18,7 +18,7 @@ foreach tuple : in_files file, input : file + '.in', output : file, - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@'], + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : tuple[1], install_dir : tuple.length() > 2 ? tuple[2] : '', build_by_default : true) diff --git a/src/timesync/meson.build b/src/timesync/meson.build index 8ecfbfab828..35467026a84 100644 --- a/src/timesync/meson.build +++ b/src/timesync/meson.build @@ -39,7 +39,7 @@ custom_target( 'timesyncd.conf', input : 'timesyncd.conf.in', output : 'timesyncd.conf', - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@'], + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : conf.get('ENABLE_TIMESYNCD') == 1 and install_sysconfdir_samples, install_dir : pkgsysconfdir) diff --git a/src/udev/meson.build b/src/udev/meson.build index 354b9232914..79964a7d8e9 100644 --- a/src/udev/meson.build +++ b/src/udev/meson.build @@ -166,7 +166,7 @@ custom_target( 'udev.pc', input : 'udev.pc.in', output : 'udev.pc', - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@'], + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : pkgconfigdatadir != 'no', install_dir : pkgconfigdatadir) diff --git a/src/vconsole/meson.build b/src/vconsole/meson.build index eb22358c205..bb3c3c5a03b 100644 --- a/src/vconsole/meson.build +++ b/src/vconsole/meson.build @@ -4,6 +4,6 @@ custom_target( '90-vconsole.rules', input : '90-vconsole.rules.in', output : '90-vconsole.rules', - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@'], + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : conf.get('ENABLE_VCONSOLE') == 1, install_dir : udevrulesdir) diff --git a/sysctl.d/meson.build b/sysctl.d/meson.build index 1745a13bfbd..ecec903d1bf 100644 --- a/sysctl.d/meson.build +++ b/sysctl.d/meson.build @@ -16,7 +16,7 @@ custom_target( '50-coredump.conf', input : '50-coredump.conf.in', output : '50-coredump.conf', - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@'], + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : conf.get('ENABLE_COREDUMP') == 1, install_dir : sysctldir) diff --git a/sysusers.d/meson.build b/sysusers.d/meson.build index 73d507f1f15..608c4b744a5 100644 --- a/sysusers.d/meson.build +++ b/sysusers.d/meson.build @@ -33,7 +33,7 @@ foreach tuple : in_files file, input : file + '.in', output: file, - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@'], + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : tuple[1], install_dir : sysusersdir) endforeach diff --git a/tmpfiles.d/meson.build b/tmpfiles.d/meson.build index b8d39190259..306e066f226 100644 --- a/tmpfiles.d/meson.build +++ b/tmpfiles.d/meson.build @@ -41,7 +41,7 @@ foreach pair : in_files pair[0], input : pair[0] + '.in', output: pair[0], - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@'], + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : enable_tmpfiles, install_dir : tmpfilesdir) else diff --git a/tools/meson-render-jinja2.py b/tools/meson-render-jinja2.py index 89735c70ed2..fbaae596de6 100755 --- a/tools/meson-render-jinja2.py +++ b/tools/meson-render-jinja2.py @@ -28,9 +28,10 @@ def render(filename, defines): if __name__ == '__main__': defines = parse_config_h(sys.argv[1]) - output = render(sys.argv[2], defines) - with open(sys.argv[3], 'w') as f: + 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[2]) - os.chmod(sys.argv[3], info.st_mode) + info = os.stat(sys.argv[3]) + os.chmod(sys.argv[4], info.st_mode) diff --git a/units/meson.build b/units/meson.build index 8a3bd0da512..e8f81f22302 100644 --- a/units/meson.build +++ b/units/meson.build @@ -276,7 +276,7 @@ foreach tuple : in_units file, input : file + '.in', output : file, - command : [meson_render_jinja2, config_h, '@INPUT@', '@OUTPUT@'], + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : install, install_dir : systemunitdir) -- 2.39.5