From a09c6604ce50204003b0313e99cd5d493be992aa Mon Sep 17 00:00:00 2001 From: Jan Friesse Date: Mon, 3 Sep 2018 17:01:21 +0200 Subject: [PATCH] build: Support for git archive stored tags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ý . Signed-off-by: Jan Friesse Reviewed-by: Christine Caulfield --- .gitarchivever | 1 + .gitattributes | 1 + build-aux/git-version-gen | 36 +++++++++++++++++++++++++++++++----- configure.ac | 2 +- 4 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 .gitarchivever create mode 100644 .gitattributes diff --git a/.gitarchivever b/.gitarchivever new file mode 100644 index 0000000..37b24fb --- /dev/null +++ b/.gitarchivever @@ -0,0 +1 @@ +ref names:$Format:%d$ diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..2e36fe7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +.gitarchivever export-subst diff --git a/build-aux/git-version-gen b/build-aux/git-version-gen index 795a98b..3ceb717 100755 --- a/build-aux/git-version-gen +++ b/build-aux/git-version-gen @@ -1,7 +1,8 @@ #!/bin/sh # Print a version string. -scriptversion=2010-10-13.20; # UTC +scriptversion=2018-08-31.20; # UTC +# Copyright (C) 2018 Red Hat, Inc. # Copyright (C) 2007-2010 Free Software Foundation, Inc. # # This program is free software: you can redistribute it and/or modify @@ -47,6 +48,17 @@ scriptversion=2010-10-13.20; # UTC # It is probably wise to add these two files to .gitignore, so that you # don't accidentally commit either generated file. # +# In order to use git archive versions another two files has to be presented: +# +# .gitarchive-version - present in checked-out repository and git +# archive tarball, but not in the distribution tarball. Used as a last +# option for version. File must contain special string $Format:%d$, +# which is substitued by git on archive operation. +# +# .gitattributes - present in checked-out repository and git archive +# tarball, but not in the distribution tarball. Must set export-subst +# attribute for .gitarchive-version file. +# # Use the following line in your configure.ac, so that $(VERSION) will # automatically be up-to-date each time configure is run (and note that # since configure.ac no longer includes a version string, Makefile rules @@ -67,14 +79,15 @@ scriptversion=2010-10-13.20; # UTC # echo $(VERSION) > $(distdir)/.tarball-version case $# in - 1|2) ;; + 1|2|3) ;; *) echo 1>&2 "Usage: $0 \$srcdir/.tarball-version" \ - '[TAG-NORMALIZATION-SED-SCRIPT]' + '[$srcdir/.gitarchive-version] [TAG-NORMALIZATION-SED-SCRIPT]' exit 1;; esac tarball_version_file=$1 -tag_sed_script="${2:-s/x/x/}" +gitarchive_version_file=$2 +tag_sed_script="${3:-s/x/x/}" nl=' ' @@ -131,7 +144,20 @@ then # Remove the "g" in git describe's output string, to save a byte. v=`echo "$v" | sed 's/-/./;s/\(.*\)-g/\1-/'`; else - v=UNKNOWN + if test -f $gitarchive_version_file + then + v=`sed 's/^.*tag: \(v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' $gitarchive_version_file` || exit 1 + case $v in + *$nl*) v= ;; # reject multi-line output + v[0-9]*) ;; + *) v= ;; + esac + test -z "$v" \ + && echo "$0: WARNING: $gitarchive_version_file doesn't contain valid version tag" 1>&2 \ + && v=UNKNOWN + else + v=UNKNOWN + fi fi v=`echo "$v" |sed 's/^v//'` diff --git a/configure.ac b/configure.ac index dc19ddf..e6954df 100644 --- a/configure.ac +++ b/configure.ac @@ -5,7 +5,7 @@ AC_PREREQ([2.61]) AC_INIT([corosync-qdevice], - m4_esyscmd([build-aux/git-version-gen .tarball-version]), + m4_esyscmd([build-aux/git-version-gen .tarball-version .gitarchivever]), [users@clusterlabs.org]) AC_USE_SYSTEM_EXTENSIONS