1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-29 21:55:36 +03:00

Merge pull request #22980 from keszybz/test-help-and-version-output

Test --help and --version output in more cases
This commit is contained in:
Yu Watanabe 2022-04-06 13:42:12 +09:00 committed by GitHub
commit bab34bc12e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 150 additions and 78 deletions

View File

@ -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)

View File

@ -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)

View File

@ -166,6 +166,7 @@
</varlistentry>
<xi:include href="standard-options.xml" xpointer="help" />
<xi:include href="standard-options.xml" xpointer="version" />
</variablelist>
</refsect1>

View File

@ -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 = []

View File

@ -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,
@ -2113,7 +2115,7 @@ endforeach
############################################################
dbus_programs += executable(
exe = executable(
'systemd',
systemd_sources,
include_directories : includes,
@ -2124,6 +2126,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 +2684,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 +3119,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 +3609,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,
@ -3651,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(
@ -3891,6 +3904,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 +3913,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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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(),

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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',

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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
@ -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

36
tools/check-version.sh Executable file
View File

@ -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

View File

@ -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)

View File

@ -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)