Skip to content

Commit a09c660

Browse files
committed
build: Support for git archive stored tags
Attempt to solve problem with git archive generated tarballs (used for example by github when release is downloaded) which are no longer git tree and (in contrast to officially released tarballs) also doesn't contain .tarball-version file so git-version-gen script simply cannot obtain valid version info. Solution is based on using gitattributes which is instructs git to replace string in the .gitarchivever file by known ref names. git-version-gen is enhanced to support this file and tries to parse any string which looks like "tag: v[0-9]+.[0-9]+.[0-9]". If such string is found it's used as a version. This file is used as a last attempt and other methods (.tarball-version, git abbrev) have precedence. Based on idea stated by Jan Pokorný <jpokorny@redhat.com>. Signed-off-by: Jan Friesse <jfriesse@redhat.com> Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
1 parent 9186129 commit a09c660

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

.gitarchivever

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref names:$Format:%d$

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.gitarchivever export-subst

build-aux/git-version-gen

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/sh
22
# Print a version string.
3-
scriptversion=2010-10-13.20; # UTC
3+
scriptversion=2018-08-31.20; # UTC
44

5+
# Copyright (C) 2018 Red Hat, Inc.
56
# Copyright (C) 2007-2010 Free Software Foundation, Inc.
67
#
78
# This program is free software: you can redistribute it and/or modify
@@ -47,6 +48,17 @@ scriptversion=2010-10-13.20; # UTC
4748
# It is probably wise to add these two files to .gitignore, so that you
4849
# don't accidentally commit either generated file.
4950
#
51+
# In order to use git archive versions another two files has to be presented:
52+
#
53+
# .gitarchive-version - present in checked-out repository and git
54+
# archive tarball, but not in the distribution tarball. Used as a last
55+
# option for version. File must contain special string $Format:%d$,
56+
# which is substitued by git on archive operation.
57+
#
58+
# .gitattributes - present in checked-out repository and git archive
59+
# tarball, but not in the distribution tarball. Must set export-subst
60+
# attribute for .gitarchive-version file.
61+
#
5062
# Use the following line in your configure.ac, so that $(VERSION) will
5163
# automatically be up-to-date each time configure is run (and note that
5264
# since configure.ac no longer includes a version string, Makefile rules
@@ -67,14 +79,15 @@ scriptversion=2010-10-13.20; # UTC
6779
# echo $(VERSION) > $(distdir)/.tarball-version
6880

6981
case $# in
70-
1|2) ;;
82+
1|2|3) ;;
7183
*) echo 1>&2 "Usage: $0 \$srcdir/.tarball-version" \
72-
'[TAG-NORMALIZATION-SED-SCRIPT]'
84+
'[$srcdir/.gitarchive-version] [TAG-NORMALIZATION-SED-SCRIPT]'
7385
exit 1;;
7486
esac
7587

7688
tarball_version_file=$1
77-
tag_sed_script="${2:-s/x/x/}"
89+
gitarchive_version_file=$2
90+
tag_sed_script="${3:-s/x/x/}"
7891
nl='
7992
'
8093

@@ -131,7 +144,20 @@ then
131144
# Remove the "g" in git describe's output string, to save a byte.
132145
v=`echo "$v" | sed 's/-/./;s/\(.*\)-g/\1-/'`;
133146
else
134-
v=UNKNOWN
147+
if test -f $gitarchive_version_file
148+
then
149+
v=`sed 's/^.*tag: \(v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' $gitarchive_version_file` || exit 1
150+
case $v in
151+
*$nl*) v= ;; # reject multi-line output
152+
v[0-9]*) ;;
153+
*) v= ;;
154+
esac
155+
test -z "$v" \
156+
&& echo "$0: WARNING: $gitarchive_version_file doesn't contain valid version tag" 1>&2 \
157+
&& v=UNKNOWN
158+
else
159+
v=UNKNOWN
160+
fi
135161
fi
136162

137163
v=`echo "$v" |sed 's/^v//'`

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
AC_PREREQ([2.61])
66

77
AC_INIT([corosync-qdevice],
8-
m4_esyscmd([build-aux/git-version-gen .tarball-version]),
8+
m4_esyscmd([build-aux/git-version-gen .tarball-version .gitarchivever]),
99
[users@clusterlabs.org])
1010

1111
AC_USE_SYSTEM_EXTENSIONS

0 commit comments

Comments
 (0)