Skip to content

Commit 1503223

Browse files
committed
build: 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. The simplest way to expose the it via good old Source Code Control System string id. No need to come up with something complicated else as there is no agreement on how to do this. So let's add this simple magic string to library. You can either query with 'what' or just $strings .build/src/libnvme.so | grep '@(#)' @(#)libnvme 1.0-1-g5ff5d22+ The idea how to extract the version string is shamelessly copied from the systemd project. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 033449f commit 1503223

4 files changed

Lines changed: 32 additions & 0 deletions

File tree

meson-vcs-tag.sh

Lines changed: 17 additions & 0 deletions
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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ pkgconfiglibdir = get_option('pkgconfiglibdir') == '' ? join_paths(libdir, 'pkgc
3636
################################################################################
3737
conf = configuration_data()
3838

39+
version_tag = get_option('version-tag')
40+
if version_tag != ''
41+
conf.set('GIT_VERSION', '"@0@"'.format(version_tag))
42+
else
43+
r = run_command('meson-vcs-tag.sh',
44+
meson.current_source_dir(),
45+
meson.project_version(),
46+
check: true)
47+
conf.set('GIT_VERSION', '"@0@"'.format(r.stdout().strip()))
48+
endif
49+
3950
conf.set('SYSCONFDIR', '"@0@"'.format(sysconfdir))
4051

4152
# Check for libuuid availability

meson_options.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- mode: meson -*-
2+
option('version-tag', type : 'string', description : 'override the git version string')
23
option('pkgconfiglibdir', type : 'string', value : '', description : 'directory for standard pkg-config files')
34
option('htmldir', type : 'string', value : '', description : 'directory for HTML documentation')
45

src/nvme/util.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include "util.h"
2424
#include "log.h"
2525

26+
/* Source Code Control System, query version of binary with 'what' */
27+
const char sccsid[] = "@(#)libnvme " GIT_VERSION;
28+
2629
static inline __u8 nvme_generic_status_to_errno(__u16 status)
2730
{
2831
switch (status) {

0 commit comments

Comments
 (0)