Build: Rework git version detection
authorSimon Wilkinson <sxw@inf.ed.ac.uk>
Tue, 29 Jun 2010 20:45:36 +0000 (21:45 +0100)
committerDerrick Brashear <shadow@dementia.org>
Fri, 2 Jul 2010 16:48:46 +0000 (09:48 -0700)
Rework the git version detection script to handle some issues that
have been pointed out.

1/ Make it work properly with objdir builds
2/ Don't try to work out if the tree is dirty if git describe failed
3/ Use the configured VERSION as a fallback if we can't obtain proper
   version information during a make

Change-Id: I39494e1c18cf4eacbb55386334da7128fbe96310
Reviewed-on: http://gerrit.openafs.org/2283
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Tested-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

build-tools/git-version
configure-libafs.in
configure.in
src/config/Makefile.version-NOCML.in

index b8c6802..6bc9a50 100755 (executable)
@@ -1,20 +1,31 @@
 #!/bin/sh
 
-version_file=$1
+srcdir=$1
+fallback=$2
 
-if [ -f $version_file ] ; then
-  git_version=`cat $version_file`
+if [ "x$fallback" = "x" ]; then
+  fallback=UNKNOWN
+fi
+
+if [ -f $srcdir/.version ] ; then
+  git_version=`cat $srcdir/.version`
 else
   if which git > /dev/null; then
+    cd $srcdir
     git_version=`git describe --abbrev=4 HEAD 2>/dev/null`
-
-    # Is the working tree dirty?
-    if ! git diff-index --quiet --cached HEAD --ignore-submodules || \
-       ! git diff-files --quiet --ignore-submodules ; then
-      git_version="$git_version-dirty"
+    if [ $? = 0 ]; then
+      # Is the working tree dirty?
+      if git diff-index --quiet --cached HEAD --ignore-submodules && \
+         git diff-files --quiet --ignore-submodules ; then
+        :
+      else
+        git_version="$git_version-dirty"
+      fi
+    else
+      git_version=$fallback
     fi
   else
-    git_version=UNKNOWN
+    git_version=$fallback
   fi
 fi
 
index 77fb092..a8ba6f2 100644 (file)
@@ -1,5 +1,5 @@
 AC_PRERQ([2.60])
-AC_INIT([OpenAFS], m4_esyscmd([build-tools/git-version .version]))
+AC_INIT([OpenAFS], m4_esyscmd([build-tools/git-version .]))
 AC_CONFIG_SRCDIR(src/libafs/Makefile.common.in)
 AM_INIT_AUTOMAKE
 
index 039d8c7..5ebc1d4 100644 (file)
@@ -1,5 +1,5 @@
 AC_PREREQ([2.60])
-AC_INIT([OpenAFS], m4_esyscmd([build-tools/git-version .version]))
+AC_INIT([OpenAFS], m4_esyscmd([build-tools/git-version .]))
 AC_CONFIG_SRCDIR([src/config/stds.h])
 AM_INIT_AUTOMAKE
 
index e5baf5a..c5613ff 100644 (file)
@@ -10,12 +10,12 @@ PACKAGE=@PACKAGE@
 AFS_component_version_number.o: AFS_component_version_number.c
 
 AFS_component_version_number.c: @TOP_OBJDIR@/src/config/Makefile.version
-       VERSION=`@abs_top_srcdir@/build-tools/git-version @abs_top_srcdir@/.version` && \
+       VERSION=`@abs_top_srcdir@/build-tools/git-version @abs_top_srcdir@ "@VERSION@"` && \
        echo 'char cml_version_number[]="@(#) OpenAFS '$$VERSION' built ' `date +"%Y-%m-%d"` '";' >AFS_component_version_number.c && \
        echo 'char* AFSVersion = "${PACKAGE} '$$VERSION'";' >>AFS_component_version_number.c
 
 version.xml:
-       VERSION=`@abs_top_srcdir@/build-tools/git-version @abs_top_srcdir/.version` && \
+       VERSION=`@abs_top_srcdir@/build-tools/git-version @abs_top_srcdir@ "@VERSION@"` && \
        echo '<?xml version="1.0" encoding="UTF-8"?>' >version.xml && \
        echo '<revision>' >>version.xml && \
        echo '<revnumber>'$$VERSION'</revnumber>' >>version.xml && \