From 1f54f1536bbd1c21c74c826cea66f48287cb75db Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 12 Apr 2022 13:52:59 +0200 Subject: [PATCH] nvme: Add git ref to the binary In order to be able to figure out which binary is in use (for example in debugging situation) it's really helpful to have the 'git describe' ref added to the binary. $ .build/nvme --version nvme version 2.0 (git 2.0-2-gcbd3f8d+) $ .build/nvme wdc --version nvme wdc version 1.16.4 (git 2.0-2-gcbd3f8d+) Signed-off-by: Daniel Wagner --- meson-vcs-tag.sh | 17 +++++++++++++++++ meson.build | 11 +++++++++++ meson_options.txt | 1 + plugin.c | 11 +++++++---- 4 files changed, 36 insertions(+), 4 deletions(-) create mode 100755 meson-vcs-tag.sh diff --git a/meson-vcs-tag.sh b/meson-vcs-tag.sh new file mode 100755 index 00000000..8ce69249 --- /dev/null +++ b/meson-vcs-tag.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later + +set -eu +set -o pipefail + +dir="${1:?}" +fallback="${2:?}" + +# Apparently git describe has a bug where it always considers the work-tree +# dirty when invoked with --git-dir (even though 'git status' is happy). Work +# around this issue by cd-ing to the source directory. +cd "$dir" +# Check that we have either .git/ (a normal clone) or a .git file (a work-tree) +# and that we don't get confused if a tarball is extracted in a higher-level +# git repository. +[ -e .git ] && git describe --abbrev=7 --dirty=+ 2>/dev/null | sed 's/^v//' || echo "$fallback" diff --git a/meson.build b/meson.build index 6a7678de..c1698f5d 100644 --- a/meson.build +++ b/meson.build @@ -29,6 +29,17 @@ systemddir = join_paths(prefixdir, get_option('systemddir')) conf = configuration_data() requires = '' +version_tag = get_option('version-tag') +if version_tag != '' + conf.set('GIT_VERSION', '"@0@"'.format(version_tag)) +else + r = run_command('meson-vcs-tag.sh', + meson.current_source_dir(), + meson.project_version(), + check: true) + conf.set('GIT_VERSION', '"@0@"'.format(r.stdout().strip())) +endif + conf.set('SYSCONFDIR', '"@0@"'.format(sysconfdir)) libnvme_dep = dependency('libnvme', fallback : ['libnvme', 'libnvme_dep']) diff --git a/meson_options.txt b/meson_options.txt index 4259aaa5..4a1fbc1c 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,3 +1,4 @@ +option('version-tag', type : 'string', description : 'override the git version string') option('udevrulesdir', type : 'string', value : 'lib/udev/rules.d', description : 'directory for udev rules files') option('dracutrulesdir', type : 'string', value : 'lib/dracut/dracut.conf.d/', description : 'directory for dracut rules files') option('systemddir', type : 'string', value : 'lib/systemd/', description : 'directory for systemd files') diff --git a/plugin.c b/plugin.c index fd8f67dd..b27b2cb2 100644 --- a/plugin.c +++ b/plugin.c @@ -10,10 +10,13 @@ static int version(struct plugin *plugin) { struct program *prog = plugin->parent; - if (plugin->name) - printf("%s %s version %s\n", prog->name, plugin->name, plugin->version); - else - printf("%s version %s\n", prog->name, prog->version); + if (plugin->name) { + printf("%s %s version %s (git %s)\n", + prog->name, plugin->name, plugin->version, GIT_VERSION); + } else { + printf("%s version %s (git %s)\n", + prog->name, prog->version, GIT_VERSION); + } return 0; } -- 2.50.1