From 1503223f835444e2c8911eb848eab0b8c29f15bc Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 12 Apr 2022 13:24:27 +0200 Subject: [PATCH] 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 --- meson-vcs-tag.sh | 17 +++++++++++++++++ meson.build | 11 +++++++++++ meson_options.txt | 1 + src/nvme/util.c | 3 +++ 4 files changed, 32 insertions(+) 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 da7d05e0..a9bc49ca 100644 --- a/meson.build +++ b/meson.build @@ -36,6 +36,17 @@ pkgconfiglibdir = get_option('pkgconfiglibdir') == '' ? join_paths(libdir, 'pkgc ################################################################################ conf = configuration_data() +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)) # Check for libuuid availability diff --git a/meson_options.txt b/meson_options.txt index f5cac6eb..1843ac0e 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,4 +1,5 @@ # -*- mode: meson -*- +option('version-tag', type : 'string', description : 'override the git version string') option('pkgconfiglibdir', type : 'string', value : '', description : 'directory for standard pkg-config files') option('htmldir', type : 'string', value : '', description : 'directory for HTML documentation') diff --git a/src/nvme/util.c b/src/nvme/util.c index 799c0cf6..2899144f 100644 --- a/src/nvme/util.c +++ b/src/nvme/util.c @@ -23,6 +23,9 @@ #include "util.h" #include "log.h" +/* Source Code Control System, query version of binary with 'what' */ +const char sccsid[] = "@(#)libnvme " GIT_VERSION; + static inline __u8 nvme_generic_status_to_errno(__u16 status) { switch (status) { -- 2.50.1