]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: Add git ref to the binary
authorDaniel Wagner <dwagner@suse.de>
Tue, 12 Apr 2022 11:52:59 +0000 (13:52 +0200)
committerDaniel Wagner <dwagner@suse.de>
Wed, 13 Apr 2022 19:50:12 +0000 (21:50 +0200)
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 <dwagner@suse.de>
meson-vcs-tag.sh [new file with mode: 0755]
meson.build
meson_options.txt
plugin.c

diff --git a/meson-vcs-tag.sh b/meson-vcs-tag.sh
new file mode 100755 (executable)
index 0000000..8ce6924
--- /dev/null
@@ -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"
index 6a7678ded032e1f1d28034b6bf401d8eee052c78..c1698f5d4eb8c6956efd2eb06c5d355962c1d504 100644 (file)
@@ -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'])
index 4259aaa50cbb60201e669e8397f01270872c60bd..4a1fbc1c1f80c41db1c7ad8aa8506a9948376f89 100644 (file)
@@ -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')
index fd8f67dd58680edca4c7d6d86e0d62d53d72fc63..b27b2cb2c90b11635943ac9dfc964e08b4968350 100644 (file)
--- 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;
 }