Skip to content

Commit 1f54f15

Browse files
committed
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 <[email protected]>
1 parent 3034c34 commit 1f54f15

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

meson-vcs-tag.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
# SPDX-License-Identifier: LGPL-2.1-or-later
3+
4+
set -eu
5+
set -o pipefail
6+
7+
dir="${1:?}"
8+
fallback="${2:?}"
9+
10+
# Apparently git describe has a bug where it always considers the work-tree
11+
# dirty when invoked with --git-dir (even though 'git status' is happy). Work
12+
# around this issue by cd-ing to the source directory.
13+
cd "$dir"
14+
# Check that we have either .git/ (a normal clone) or a .git file (a work-tree)
15+
# and that we don't get confused if a tarball is extracted in a higher-level
16+
# git repository.
17+
[ -e .git ] && git describe --abbrev=7 --dirty=+ 2>/dev/null | sed 's/^v//' || echo "$fallback"

meson.build

+11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ systemddir = join_paths(prefixdir, get_option('systemddir'))
2929
conf = configuration_data()
3030
requires = ''
3131

32+
version_tag = get_option('version-tag')
33+
if version_tag != ''
34+
conf.set('GIT_VERSION', '"@0@"'.format(version_tag))
35+
else
36+
r = run_command('meson-vcs-tag.sh',
37+
meson.current_source_dir(),
38+
meson.project_version(),
39+
check: true)
40+
conf.set('GIT_VERSION', '"@0@"'.format(r.stdout().strip()))
41+
endif
42+
3243
conf.set('SYSCONFDIR', '"@0@"'.format(sysconfdir))
3344

3445
libnvme_dep = dependency('libnvme', fallback : ['libnvme', 'libnvme_dep'])

meson_options.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
option('version-tag', type : 'string', description : 'override the git version string')
12
option('udevrulesdir', type : 'string', value : 'lib/udev/rules.d', description : 'directory for udev rules files')
23
option('dracutrulesdir', type : 'string', value : 'lib/dracut/dracut.conf.d/', description : 'directory for dracut rules files')
34
option('systemddir', type : 'string', value : 'lib/systemd/', description : 'directory for systemd files')

plugin.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ static int version(struct plugin *plugin)
1010
{
1111
struct program *prog = plugin->parent;
1212

13-
if (plugin->name)
14-
printf("%s %s version %s\n", prog->name, plugin->name, plugin->version);
15-
else
16-
printf("%s version %s\n", prog->name, prog->version);
13+
if (plugin->name) {
14+
printf("%s %s version %s (git %s)\n",
15+
prog->name, plugin->name, plugin->version, GIT_VERSION);
16+
} else {
17+
printf("%s version %s (git %s)\n",
18+
prog->name, prog->version, GIT_VERSION);
19+
}
1720
return 0;
1821
}
1922

0 commit comments

Comments
 (0)