Skip to content

Commit 7f76c0b

Browse files
authored
Merge pull request #340 from igaw/add-git-version
build: Add git ref to the binary
2 parents 5f412d9 + fb628fe commit 7f76c0b

6 files changed

Lines changed: 69 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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ 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+
conf.set('PROJECT_VERSION', '"@0@"'.format(meson.project_version()))
50+
3951
conf.set('SYSCONFDIR', '"@0@"'.format(sysconfdir))
4052

4153
# 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
option('rstdir', type : 'string', value : '', description : 'directory for ReST documentation')

src/libnvme.map

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
LIBNVME_1_1 {
2+
global:
3+
nvme_get_version;
4+
};
5+
16
LIBNVME_1_0 {
27
global:
38
nvme_admin_passthru64;

src/nvme/util.c

Lines changed: 15 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) {
@@ -775,3 +778,15 @@ struct nvmf_ext_attr *nvmf_exat_ptr_next(struct nvmf_ext_attr *p)
775778
return (struct nvmf_ext_attr *)
776779
((uintptr_t)p + (ptrdiff_t)nvmf_exat_size(le16_to_cpu(p->exatlen)));
777780
}
781+
782+
const char *nvme_get_version(enum nvme_version type)
783+
{
784+
switch(type) {
785+
case NVME_VERSION_PROJECT:
786+
return PROJECT_VERSION;
787+
case NVME_VERSION_GIT:
788+
return GIT_VERSION;
789+
default:
790+
return "n/a";
791+
}
792+
}

src/nvme/util.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,4 +532,23 @@ static inline __u16 nvmf_exat_size(size_t val_len)
532532
*/
533533
struct nvmf_ext_attr *nvmf_exat_ptr_next(struct nvmf_ext_attr *p);
534534

535+
/**
536+
* enum nvme_version - Selector for version to be returned by @nvme_get_version
537+
*
538+
* NVME_VERSION_PROJECT: Project release version
539+
* NVME_VERSION_GIT: Git reference
540+
*/
541+
enum nvme_version {
542+
NVME_VERSION_PROJECT = 0,
543+
NVME_VERSION_GIT = 1,
544+
};
545+
546+
/**
547+
* nvme_get_version - Return version libnvme string
548+
* @type: Selects which version type (see @struct nvme_version)
549+
*
550+
* Return: Returns version string for known types or else "n/a"
551+
*/
552+
const char *nvme_get_version(enum nvme_version type);
553+
535554
#endif /* _LIBNVME_UTIL_H */

0 commit comments

Comments
 (0)