Build: Rework git version detection

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>
This commit is contained in:
Simon Wilkinson 2010-06-29 21:45:36 +01:00 committed by Derrick Brashear
parent a155d71914
commit 417d2c8f95
4 changed files with 24 additions and 13 deletions

View File

@ -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

View 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

View 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

View 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 && \