Skip to content

Commit d2a973e

Browse files
committed
Generate the XrdVersion.hh header on compile time basing on the information retrieved from git
* when compiling in git repository version is determined using git-describe utility * when compiling a package created with git-archive version is derived from VERSION_INFO file
1 parent 48f1cbb commit d2a973e

8 files changed

+112
-7
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VERSION_INFO export-subst

Makefile.am

+6-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if NEED_MACOS_DEPLOYMENT_TARGET
3131
export MACOSX_DEPLOYMENT_TARGET = 10.3
3232
endif
3333

34-
.PHONY: doc silent
34+
.PHONY: doc silent version
3535

3636
silent:
3737
@cd src; $(MAKE) | sed -n -e '/libtool/d' \
@@ -55,7 +55,7 @@ doc: Doxyfile
5555
fi
5656
endif
5757

58-
58+
BUILT_SOURCES = version
5959

6060
################################################################
6161
## Here we define general includes (not specific to any module)
@@ -122,3 +122,7 @@ TESTS = test/test1.sh test/test2.sh
122122
rpm: dist
123123
cp $(DIST_ARCHIVES) /usr/src/redhat/SOURCES/
124124
rpmbuild -bb xrootd.spec
125+
126+
version:
127+
@echo "Generating version header"
128+
@./genversion.sh

VERSION_INFO

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$Format:RefNames: %d%nShortHash: %h%n$

bootstrap.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Author: Derek Feichtinger, 19 Oct 2005
44

5-
if test ! -e src/XrdVersion.hh; then
5+
if test ! -e src/XrdVersion.hh.in; then
66
echo "Sanity check. Could not find src/XrdVersion.hh. You need to bootstrap from the xrootd main directory" >&2
77
exit 1
88
fi

config/GNUmakefile.in

+6-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export INCPATH = @inst_incdir@
4949
# R u l e s #
5050
#------------------------------------------------------------------------------#
5151

52-
all:
52+
all: version
5353
@$(MAKE) $(TARGETS) MAKEXEQ=all XMSG=Making XDBG=@dbgmsg@ --no-print-directory
5454
@if [ "x$(ARCHDIR)" != "x" ]; then \
5555
$(RM) -fr bin/arch@dbgsfx@ lib/arch@dbgsfx@ obj/arch@dbgsfx@;\
@@ -250,4 +250,9 @@ XrdXrootd: FORCE
250250
$(ECHO)cd src/XrdXrootd;\
251251
$(MAKE) $(MAKEXEQ) ARCH=$(ARCH) --no-print-directory
252252

253+
version: FORCE
254+
@echo Creatiing version header...
255+
@./genversion.sh
256+
257+
253258
FORCE: ;

configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
AC_PREREQ(2.57)
2424
AC_INIT(xrootd,v20100805-1700,xrootd-l@slac.stanford.edu)
25-
AC_CONFIG_SRCDIR([src/XrdVersion.hh])
25+
AC_CONFIG_SRCDIR([src/XrdVersion.hh.in])
2626

2727
# use C++ for the compilation of tests
2828
dnl currently commented out, since older versions of libtool (<1.5) contain

genversion.sh

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
3+
#-------------------------------------------------------------------------------
4+
# Process the git decoration expansion and try to derive version number
5+
#-------------------------------------------------------------------------------
6+
function getVersionFromRefs()
7+
{
8+
REFS=${1/RefNames:/}
9+
REFS=${REFS//,/}
10+
REFS=${REFS/(/}
11+
REFS=${REFS/)/}
12+
REFS=($REFS)
13+
if test ${#REFS[@]} -eq 3; then
14+
echo "${REFS[1]}"
15+
else
16+
echo "unknown"
17+
fi
18+
}
19+
20+
#-------------------------------------------------------------------------------
21+
# We're not inside a git repo
22+
#-------------------------------------------------------------------------------
23+
if test ! -d .git; then
24+
#-----------------------------------------------------------------------------
25+
# We cannot figure out what version we are
26+
#----------------------------------------------------------------------------
27+
echo "[I] No git repository info found. Trying to interpret VERSION_INFO"
28+
if test ! -r VERSION_INFO; then
29+
echo "[!] VERSION_INFO file absent. Unable to determine the version. Using \"unknown\""
30+
VERSION="unknown"
31+
elif test x"`grep Format VERSION_INFO`" != x; then
32+
echo "[!] VERSION_INFO file invalid. Unable to determine the version. Using \"unknown\""
33+
VERSION="unknown"
34+
35+
#-----------------------------------------------------------------------------
36+
# The version file exists and seems to be valid so we know the version
37+
#----------------------------------------------------------------------------
38+
else
39+
REFNAMES="`grep RefNames VERSION_INFO`"
40+
VERSION="`getVersionFromRefs "$REFNAMES"`"
41+
if test x$VERSION == xunknown; then
42+
SHORTHASH="`grep ShortHash VERSION_INFO`"
43+
SHORTHASH=${SHORTHASH/ShortHash:/}
44+
SHORTHASH=${SHORTHASH// /}
45+
VERSION="untagged-$SHORTHASH"
46+
fi
47+
fi
48+
49+
#-------------------------------------------------------------------------------
50+
# We're in a git repo so we can try to determine the version using that
51+
#-------------------------------------------------------------------------------
52+
else
53+
echo "[I] Determining version from git"
54+
GIT=`which git 2>/dev/null`
55+
if test ! -x ${GIT}; then
56+
echo "[!] Unable to find git in the path: setting the version tag to unknown"
57+
VERSION="unknown"
58+
fi
59+
60+
git describe --tags --abbrev=0 --exact-match >/dev/null 2>&1
61+
62+
if test ${?} -eq 0; then
63+
VERSION="`git describe --tags --abbrev=0 --exact-match`"
64+
else
65+
VERSION="`git describe --tags --abbrev=0`+more"
66+
fi
67+
fi
68+
69+
#-------------------------------------------------------------------------------
70+
# Create XrdVersion.hh
71+
#-------------------------------------------------------------------------------
72+
if test ! -r src/XrdVersion.hh.in; then
73+
echo "[!] Unable to find src/XrdVersion.hh.in"
74+
exit 1
75+
fi
76+
77+
sed -e "s/#define XrdVERSION \"unknown\"/#define XrdVERSION \"$VERSION\"/" src/XrdVersion.hh.in > src/XrdVersion.hh.new
78+
79+
if test $? -ne 0; then
80+
echo "[!] Error while generating src/XrdVersion.hh from the input template"
81+
exit 1
82+
fi
83+
84+
if test ! -e src/XrdVersion.hh; then
85+
mv src/XrdVersion.hh.new src/XrdVersion.hh
86+
elif test x"`diff src/XrdVersion.hh.new src/XrdVersion.hh`" != x; then
87+
mv src/XrdVersion.hh.new src/XrdVersion.hh
88+
fi
89+
echo "[I] src/XrdVersion.hh successfuly generated"
+7-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
// $Id$
1+
// this file is automatically updated by the genversion.sh script
2+
// if you touch anything make sure that it still works
3+
24
#ifndef __XRD_VERSION_H__
35
#define __XRD_VERSION_H__
4-
#define XrdVERSION "Unknown"
6+
7+
#define XrdVERSION "unknown"
8+
59
#if XrdDEBUG
610
#define XrdVSTRING XrdVERSION "_dbg"
711
#else
812
#define XrdVSTRING XrdVERSION
913
#endif
1014

1115
#define XrdDEFAULTPORT 1094;
16+
1217
#endif

0 commit comments

Comments
 (0)