mirror of
https://github.com/ntop/n2n.git
synced 2024-09-19 16:41:11 +02:00
e7ad089d24
We aim to always build with the full version number from the git checkout, however if the current build is not being made from a git repository, we need to fallback to using the version number from the "VERSION" file. This patch changes the choice of the fallback path from just assuming that any git repo is our git repo to explicitly looking for a `.git` dir in the top of our checkout. Some integrated build systems end up doing a tar extract of the n2n source code inside their build-system git repo, and the old fallback check was failing in that case. We still need to identify these build systems and work out a way to provide them with the full and correct version number for their build, but this patch should make things more reliable until then.
56 lines
1.2 KiB
Bash
Executable File
56 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Output the current version number
|
|
#
|
|
|
|
usage() {
|
|
echo "Usage: $0 [short|hash]"
|
|
echo
|
|
echo "Determine the correct version number for the current build"
|
|
exit 0
|
|
}
|
|
|
|
# We assume this script is in the TOPDIR/scripts directory and use that
|
|
# to find any other files we need
|
|
TOPDIR=$(dirname "$0")/..
|
|
|
|
VER_FILE_SHORT=$(cat "${TOPDIR}/VERSION")
|
|
|
|
if [ -d "$TOPDIR/.git" ]; then
|
|
# If there is a .git directory in our TOPDIR, then this is assumed to be
|
|
# real git checkout
|
|
|
|
VER_GIT_SHORT=$(git describe --abbrev=0)
|
|
|
|
if [ "$VER_FILE_SHORT" != "$VER_GIT_SHORT" ]; then
|
|
echo "Error: VERSION file does not match tag version ($VER_FILE_SHORT != $VER_GIT_SHORT)"
|
|
exit 1
|
|
fi
|
|
|
|
VER_SHORT="$VER_GIT_SHORT"
|
|
VER_HASH=$(git rev-parse --short HEAD)
|
|
VER=$(git describe --abbrev=7 --dirty)
|
|
else
|
|
# If there is no .git directory in our TOPDIR, we fall back on relying on
|
|
# the VERSION file
|
|
|
|
VER_SHORT="$VER_FILE_SHORT"
|
|
VER_HASH="HEAD"
|
|
VER="$VER_FILE_SHORT"
|
|
fi
|
|
|
|
case "$1" in
|
|
hash)
|
|
echo "$VER_HASH"
|
|
;;
|
|
short)
|
|
echo "$VER_SHORT"
|
|
;;
|
|
"")
|
|
echo "$VER"
|
|
;;
|
|
*)
|
|
usage
|
|
;;
|
|
esac
|