From ffb7406ba9c12a58dd944574ab565f39aabb0dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 5 Apr 2022 10:51:21 +0200 Subject: [PATCH 1/7] tests: add a smoke test for --version option in binaries This is very similar to (and directly based on) the test for --help. I think it's nice to do this: the test is very quick, but it'll catch cases where we forgot to hook up the option, or forgot to exit after printing --version, and it'll also increase our test coverage a bit. --- meson.build | 7 +++++++ tools/check-help.sh | 8 ++++---- tools/check-version.sh | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100755 tools/check-version.sh diff --git a/meson.build b/meson.build index 0455d89b78..c54acd0d04 100644 --- a/meson.build +++ b/meson.build @@ -3891,6 +3891,7 @@ endif ############################################################ check_help = find_program('tools/check-help.sh') +check_version = find_program('tools/check-version.sh') foreach exec : public_programs name = exec.full_path().split('/')[-1] @@ -3899,6 +3900,12 @@ foreach exec : public_programs check_help, args : exec.full_path(), depends: exec) + + test('check-version-' + name, + check_version, + args : [exec.full_path(), + meson.project_version()], + depends: exec) endif endforeach diff --git a/tools/check-help.sh b/tools/check-help.sh index 76ac292675..19ec941469 100755 --- a/tools/check-help.sh +++ b/tools/check-help.sh @@ -3,8 +3,8 @@ set -eu set -o pipefail -# Note: `grep ... >/dev/null` instead of just `grep -q` is used intentionally -# here, since `grep -q` exits on the first match causing SIGPIPE being +# Note: 'grep ... >/dev/null' instead of just 'grep -q' is used intentionally +# here, since 'grep -q' exits on the first match causing SIGPIPE being # sent to the sender. BINARY="${1:?}" @@ -24,11 +24,11 @@ fi # --help prints something. Also catches case where args are ignored. if ! "$BINARY" --help | grep . >/dev/null; then - echo "$(basename "$BINARY") --help output is empty." + echo "$(basename "$BINARY") --help output is empty" exit 2 fi -# no --help output to stdout +# no --help output to stderr if "$BINARY" --help 2>&1 1>/dev/null | grep .; then echo "$(basename "$BINARY") --help prints to stderr" exit 3 diff --git a/tools/check-version.sh b/tools/check-version.sh new file mode 100755 index 0000000000..faefb46883 --- /dev/null +++ b/tools/check-version.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +set -eu +set -o pipefail + +# Note: 'grep ... >/dev/null' instead of just 'grep -q' is used intentionally +# here, since 'grep -q' exits on the first match causing SIGPIPE being +# sent to the sender. + +BINARY="${1:?}" +VERSION="${2:?}" +export SYSTEMD_LOG_LEVEL=info + +if [[ ! -x "$BINARY" ]]; then + echo "$BINARY is not an executable" + exit 1 +fi + +# --version prints something. Also catches case where args are ignored. +if ! "$BINARY" --version | grep . >/dev/null; then + echo "$(basename "$BINARY") --version output is empty" + exit 2 +fi + +# no --version output to stderr +if "$BINARY" --version 2>&1 1>/dev/null | grep .; then + echo "$(basename "$BINARY") --version prints to stderr" + exit 3 +fi + +# project version appears in version output +out="$("$BINARY" --version)" +if ! grep -F "$VERSION" >/dev/null <<<"$out"; then + echo "$(basename "$BINARY") --version output does not match '$VERSION': $out" + exit 4 +fi From 9f9be6ea28f09305f7ee796708f0fe8a871e7220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 5 Apr 2022 11:00:59 +0200 Subject: [PATCH 2/7] test/check-help: check that --help and -h are identical --- tools/check-help.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/check-help.sh b/tools/check-help.sh index 19ec941469..f97429364e 100755 --- a/tools/check-help.sh +++ b/tools/check-help.sh @@ -39,3 +39,9 @@ if ! ("$BINARY" --no-such-parameter 2>&1 1>/dev/null || :) | grep . >/dev/null; echo "$(basename "$BINARY") with an unknown parameter does not print to stderr" exit 4 fi + +# --help and -h are equivalent +if ! diff <("$BINARY" -h) <("$BINARY" --help); then + echo "$(basename "$BINARY") --help and -h are not identical" + exit 5 +fi From 03b3b55e117794701da47ec7d94b31aacb7eeb64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 5 Apr 2022 14:10:04 +0200 Subject: [PATCH 3/7] pid1: make --help output fit in 80 columns --- src/core/main.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/core/main.c b/src/core/main.c index 6567cdfb28..c6e9e9b034 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1075,9 +1075,8 @@ static int help(void) { " -h --help Show this help\n" " --version Show version\n" " --test Determine initial transaction, dump it and exit\n" - " --system In combination with --test: operate as system service manager\n" - " --user In combination with --test: operate as per-user service manager\n" - " --no-pager Do not pipe output into a pager\n" + " --system Combined with --test: operate in system mode\n" + " --user Combined with --test: operate in user mode\n" " --dump-configuration-items Dump understood unit configuration items\n" " --dump-bus-properties Dump exposed bus properties\n" " --bus-introspect=PATH Write XML introspection data\n" @@ -1087,14 +1086,17 @@ static int help(void) { " --crash-reboot[=BOOL] Reboot on crash\n" " --crash-shell[=BOOL] Run shell on crash\n" " --confirm-spawn[=BOOL] Ask for confirmation when spawning processes\n" - " --show-status[=BOOL] Show status updates on the console during bootup\n" - " --log-target=TARGET Set log target (console, journal, kmsg, journal-or-kmsg, null)\n" - " --log-level=LEVEL Set log level (debug, info, notice, warning, err, crit, alert, emerg)\n" + " --show-status[=BOOL] Show status updates on the console during boot\n" + " --log-target=TARGET Set log target (console, journal, kmsg,\n" + " journal-or-kmsg, null)\n" + " --log-level=LEVEL Set log level (debug, info, notice, warning,\n" + " err, crit, alert, emerg)\n" " --log-color[=BOOL] Highlight important log messages\n" " --log-location[=BOOL] Include code location in log messages\n" " --log-time[=BOOL] Prefix log messages with current time\n" " --default-standard-output= Set default standard output for services\n" " --default-standard-error= Set default standard error output for services\n" + " --no-pager Do not pipe output into a pager\n" "\nSee the %s for details.\n", program_invocation_short_name, ansi_highlight(), From e16793ee7e92908b1fbdf6493b7cc32b9116189e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 5 Apr 2022 14:11:42 +0200 Subject: [PATCH 4/7] firstboot: make --help output fit in 80 columns A long name of one parameter was making the whole thing very wide. I think that it's obvious from the context what the argument is, so a shorter name should be just as good. --- src/firstboot/firstboot.c | 62 +++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index d28a416e5d..39160182ef 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -984,37 +984,37 @@ static int help(void) { printf("%s [OPTIONS...]\n\n" "Configures basic settings of the system.\n\n" - " -h --help Show this help\n" - " --version Show package version\n" - " --root=PATH Operate on an alternate filesystem root\n" - " --image=PATH Operate on an alternate filesystem image\n" - " --locale=LOCALE Set primary locale (LANG=)\n" - " --locale-messages=LOCALE Set message locale (LC_MESSAGES=)\n" - " --keymap=KEYMAP Set keymap\n" - " --timezone=TIMEZONE Set timezone\n" - " --hostname=NAME Set hostname\n" - " --machine-ID=ID Set machine ID\n" - " --root-password=PASSWORD Set root password from plaintext password\n" - " --root-password-file=FILE Set root password from file\n" - " --root-password-hashed=HASHED_PASSWORD Set root password from hashed password\n" - " --root-shell=SHELL Set root shell\n" - " --prompt-locale Prompt the user for locale settings\n" - " --prompt-keymap Prompt the user for keymap settings\n" - " --prompt-timezone Prompt the user for timezone\n" - " --prompt-hostname Prompt the user for hostname\n" - " --prompt-root-password Prompt the user for root password\n" - " --prompt-root-shell Prompt the user for root shell\n" - " --prompt Prompt for all of the above\n" - " --copy-locale Copy locale from host\n" - " --copy-keymap Copy keymap from host\n" - " --copy-timezone Copy timezone from host\n" - " --copy-root-password Copy root password from host\n" - " --copy-root-shell Copy root shell from host\n" - " --copy Copy locale, keymap, timezone, root password\n" - " --setup-machine-id Generate a new random machine ID\n" - " --force Overwrite existing files\n" - " --delete-root-password Delete root password\n" - " --welcome=no Disable the welcome text\n" + " -h --help Show this help\n" + " --version Show package version\n" + " --root=PATH Operate on an alternate filesystem root\n" + " --image=PATH Operate on an alternate filesystem image\n" + " --locale=LOCALE Set primary locale (LANG=)\n" + " --locale-messages=LOCALE Set message locale (LC_MESSAGES=)\n" + " --keymap=KEYMAP Set keymap\n" + " --timezone=TIMEZONE Set timezone\n" + " --hostname=NAME Set hostname\n" + " --machine-ID=ID Set machine ID\n" + " --root-password=PASSWORD Set root password from plaintext password\n" + " --root-password-file=FILE Set root password from file\n" + " --root-password-hashed=HASH Set root password from hashed password\n" + " --root-shell=SHELL Set root shell\n" + " --prompt-locale Prompt the user for locale settings\n" + " --prompt-keymap Prompt the user for keymap settings\n" + " --prompt-timezone Prompt the user for timezone\n" + " --prompt-hostname Prompt the user for hostname\n" + " --prompt-root-password Prompt the user for root password\n" + " --prompt-root-shell Prompt the user for root shell\n" + " --prompt Prompt for all of the above\n" + " --copy-locale Copy locale from host\n" + " --copy-keymap Copy keymap from host\n" + " --copy-timezone Copy timezone from host\n" + " --copy-root-password Copy root password from host\n" + " --copy-root-shell Copy root shell from host\n" + " --copy Copy locale, keymap, timezone, root password\n" + " --setup-machine-id Generate a new random machine ID\n" + " --force Overwrite existing files\n" + " --delete-root-password Delete root password\n" + " --welcome=no Disable the welcome text\n" "\nSee the %s for details.\n", program_invocation_short_name, link); From 3761002eeaead8392a1c1517251c4f9be7c688aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 5 Apr 2022 14:12:52 +0200 Subject: [PATCH 5/7] test: do --help/--version checks for systemd, firstboot, cryptenroll, s-n-w-o I basically went by the list in systemd.directives for --help/-h. kernel-install is also listed there, but will be added in a later commit. --- meson.build | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index c54acd0d04..b43273262d 100644 --- a/meson.build +++ b/meson.build @@ -2113,7 +2113,7 @@ endforeach ############################################################ -dbus_programs += executable( +exe = executable( 'systemd', systemd_sources, include_directories : includes, @@ -2124,6 +2124,8 @@ dbus_programs += executable( install_rpath : rootlibexecdir, install : true, install_dir : rootlibexecdir) +dbus_programs += exe +public_programs += exe meson.add_install_script(meson_make_symlink, rootlibexecdir / 'systemd', @@ -2680,7 +2682,7 @@ if conf.get('HAVE_LIBCRYPTSETUP') == 1 install : true, install_dir : systemgeneratordir) - executable( + public_programs += executable( 'systemd-cryptenroll', systemd_cryptenroll_sources, include_directories : includes, @@ -3115,7 +3117,7 @@ if conf.get('ENABLE_RANDOMSEED') == 1 endif if conf.get('ENABLE_FIRSTBOOT') == 1 - executable( + public_programs += executable( 'systemd-firstboot', 'src/firstboot/firstboot.c', include_directories : includes, @@ -3605,7 +3607,7 @@ if conf.get('ENABLE_NETWORKD') == 1 install : true, install_dir : rootlibexecdir) - executable( + public_programs += executable( 'systemd-networkd-wait-online', systemd_networkd_wait_online_sources, include_directories : includes, From 8f04a1ca2bf973e5419c32adca1dcf888e0b263f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 5 Apr 2022 16:52:44 +0200 Subject: [PATCH 6/7] 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 cd3015ca4b..64476a5d76 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 821f176a74..ece2c644ff 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 83b368115b..d9c706b4ab 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 b43273262d..ce54b1045d 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 e6533e001a..f725e14d95 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 ae6a61e555..fb7314348a 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 bac531798c..b39f933ea4 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 f5e04b37ca..ee2f8774bf 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 4bbbc1431f..f81d906616 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 67b439a5dd..a86b8f896b 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 2d51ff7c58..a831391cc1 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 1a2d738e84..bd350569d5 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 b2da249c87..e11aefce7a 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 4bfeda8883..817665912a 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 8ecfbfab82..35467026a8 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 354b923291..79964a7d8e 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 eb22358c20..bb3c3c5a03 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 1745a13bfb..ecec903d1b 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 73d507f1f1..608c4b744a 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 b8d3919025..306e066f22 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 89735c70ed..fbaae596de 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 8a3bd0da51..e8f81f2230 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) From 99d8cbceffbae7ce58f47ed4c099bff574689ae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 5 Apr 2022 18:18:56 +0200 Subject: [PATCH 7/7] meson: make kernel-install a template file, add --version, add to tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In --help output, change "$0" → "kernel-install". We generally don't include the full path in --help output, and let's not do this here either. kernel-install is now in build/ directly, not in the subdirectory. --- man/kernel-install.xml | 1 + meson.build | 9 +++++++++ .../{kernel-install => kernel-install.in} | 16 ++++++++++++---- src/kernel-install/meson.build | 6 ++---- 4 files changed, 24 insertions(+), 8 deletions(-) rename src/kernel-install/{kernel-install => kernel-install.in} (95%) diff --git a/man/kernel-install.xml b/man/kernel-install.xml index 974d6984de..5ae86aca18 100644 --- a/man/kernel-install.xml +++ b/man/kernel-install.xml @@ -166,6 +166,7 @@ + diff --git a/meson.build b/meson.build index ce54b1045d..4a154850db 100644 --- a/meson.build +++ b/meson.build @@ -3655,6 +3655,15 @@ executable( install : true, install_dir : rootlibexecdir) +public_programs += custom_target( + 'kernel-install', + input : kernel_install_in, + output : 'kernel-install', + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], + install : want_kernel_install, + install_mode : 'rwxr-xr-x', + install_dir : bindir) + ############################################################ runtest_env = custom_target( diff --git a/src/kernel-install/kernel-install b/src/kernel-install/kernel-install.in similarity index 95% rename from src/kernel-install/kernel-install rename to src/kernel-install/kernel-install.in index a09b998362..f6d262f522 100755 --- a/src/kernel-install/kernel-install +++ b/src/kernel-install/kernel-install.in @@ -23,11 +23,12 @@ skip_remaining=77 usage() { echo "Usage:" - echo " $0 [OPTIONS...] add KERNEL-VERSION KERNEL-IMAGE [INITRD-FILE ...]" - echo " $0 [OPTIONS...] remove KERNEL-VERSION" - echo " $0 [OPTIONS...] inspect" + echo " kernel-install [OPTIONS...] add KERNEL-VERSION KERNEL-IMAGE [INITRD-FILE...]" + echo " kernel-install [OPTIONS...] remove KERNEL-VERSION" + echo " kernel-install [OPTIONS...] inspect" echo "Options:" - echo " -h, --help Print this help" + echo " -h, --help Print this help and exit" + echo " --version Print version string and exit" echo " -v, --verbose Increase verbosity" } @@ -59,6 +60,13 @@ for i; do fi done +for i; do + if [ "$i" = "--version" ]; then + echo "kernel-install {{PROJECT_VERSION}} ({{GIT_VERSION}})" + exit 0 + fi +done + export KERNEL_INSTALL_VERBOSE=0 if [ "$1" = "--verbose" ] || [ "$1" = "-v" ]; then shift diff --git a/src/kernel-install/meson.build b/src/kernel-install/meson.build index abc3520b62..06c1c3aafb 100644 --- a/src/kernel-install/meson.build +++ b/src/kernel-install/meson.build @@ -1,10 +1,8 @@ # SPDX-License-Identifier: LGPL-2.1-or-later -if want_kernel_install - install_data('kernel-install', - install_mode : 'rwxr-xr-x', - install_dir : bindir) +kernel_install_in = files('kernel-install.in') +if want_kernel_install install_data('50-depmod.install', '90-loaderentry.install', install_mode : 'rwxr-xr-x',