|
| 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" |
0 commit comments