forked from sdlpal/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgengitrev
executable file
·33 lines (26 loc) · 907 Bytes
/
gengitrev
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
PWD="$(pwd)"
BASEDIR="$(dirname $0)"
date=date
stat=stat
if [ "x$(uname)" = xDarwin ]; then
date=gdate
stat=gstat
fi
PAL_GIT_REVISION=$(git describe --tags --dirty 2> /dev/null)
# Some environment like TravisCI won't fully clone so they may not get tag based describe correctly.
# Lets try another way that based on VCS logged info, which should be more accuracy.
if [ -z "$PAL_GIT_REVISION" ]; then
PAL_GIT_REVISION="v"$($date -d @$(git show -s --format=%ct) +"%F")"-g"$(git rev-parse --verify --short HEAD)
fi
if [ -z "$PAL_GIT_REVISION" ]; then
PAL_GIT_REVISION=$($date -d @$($stat -c %Y ${BASEDIR}/../.gitignore) +"%F %T")
fi
LINE="#define PAL_GIT_REVISION \"$PAL_GIT_REVISION\""
FILE="${BASEDIR}/../generated.h"
grep -F "$LINE" "$FILE" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo Generating Git revision header: $PAL_GIT_REVISION 1>&2
echo "$LINE" > "$FILE"
fi
echo -ne