tools/version.sh: Make it invokable from everywhere

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2020-06-23 06:33:43 +08:00 committed by Abdelatif Guettouche
parent 145205767d
commit bd12fb6b64

View file

@ -32,7 +32,7 @@
# POSSIBILITY OF SUCH DAMAGE. # POSSIBILITY OF SUCH DAMAGE.
# #
WD=`pwd` WD=$(dirname $0)
# Get command line parameters # Get command line parameters
@ -86,7 +86,7 @@ done
OUTFILE=$1 OUTFILE=$1
if [ -z ${VERSION} ] ; then if [ -z ${VERSION} ] ; then
VERSION=`git tag --sort=taggerdate | tail -1 | cut -d'-' -f2` VERSION=`git -C ${WD} tag --sort=taggerdate | tail -1 | cut -d'-' -f2`
# Earlier tags used the format "major.minor", append a "0" for a patch. # Earlier tags used the format "major.minor", append a "0" for a patch.
@ -133,12 +133,12 @@ PATCH=`echo ${VERSION} | cut -d'.' -f3`
# Get GIT information (if not provided on the command line) # Get GIT information (if not provided on the command line)
if [ -z "${BUILD}" ]; then if [ -z "${BUILD}" ]; then
BUILD=`git log --oneline -1 | cut -d' ' -f1 2>/dev/null` BUILD=`git -C ${WD} log --oneline -1 | cut -d' ' -f1 2>/dev/null`
if [ -z "${BUILD}" ]; then if [ -z "${BUILD}" ]; then
echo "GIT version information is not available" echo "GIT version information is not available"
exit 5 exit 5
fi fi
if [ -n "`git diff-index --name-only HEAD | head -1`" ]; then if [ -n "`git -C ${WD} diff-index --name-only HEAD | head -1`" ]; then
BUILD=${BUILD}-dirty BUILD=${BUILD}-dirty
fi fi
fi fi