]> git.proxmox.com Git - mirror_corosync-qdevice.git/commitdiff
build: Support for git archive stored tags
authorJan Friesse <jfriesse@redhat.com>
Mon, 3 Sep 2018 15:01:21 +0000 (17:01 +0200)
committerJan Friesse <jfriesse@redhat.com>
Mon, 3 Sep 2018 15:01:21 +0000 (17:01 +0200)
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>
.gitarchivever [new file with mode: 0644]
.gitattributes [new file with mode: 0644]
build-aux/git-version-gen
configure.ac

diff --git a/.gitarchivever b/.gitarchivever
new file mode 100644 (file)
index 0000000..37b24fb
--- /dev/null
@@ -0,0 +1 @@
+ref names:$Format:%d$
diff --git a/.gitattributes b/.gitattributes
new file mode 100644 (file)
index 0000000..2e36fe7
--- /dev/null
@@ -0,0 +1 @@
+.gitarchivever export-subst
index 795a98b32364ca1fbf8a8f131ee6c12daa46fcf3..3ceb71735233617c1bbf26e37d3e8e46072ee9bb 100755 (executable)
@@ -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//'`
index dc19ddf338c56ecea46228ff4f56baaaef637bea..e6954df45d42fc2a1d73337d7697bfdf2e57ca39 100644 (file)
@@ -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