Change: Include the full raw git revision hash in rev.cpp

This commit is contained in:
Niels Martin Hansen 2019-01-27 14:04:49 +01:00
parent cca952d94b
commit 67c6f945fb
5 changed files with 37 additions and 20 deletions

View File

@ -90,6 +90,7 @@ MODIFIED := $(shell echo "$(VERSIONS)" | cut -f 3 -d' ')
# Use autodetected revisions # Use autodetected revisions
VERSION := $(shell echo "$(VERSIONS)" | cut -f 1 -d' ') VERSION := $(shell echo "$(VERSIONS)" | cut -f 1 -d' ')
ISODATE := $(shell echo "$(VERSIONS)" | cut -f 2 -d' ') ISODATE := $(shell echo "$(VERSIONS)" | cut -f 2 -d' ')
GITHASH := $(shell echo "$(VERSIONS)" | cut -f 3 -d' ')
# Make sure we have something in VERSION and ISODATE # Make sure we have something in VERSION and ISODATE
ifeq ($(VERSION),) ifeq ($(VERSION),)
@ -275,10 +276,10 @@ endif
# Revision files # Revision files
$(SRC_DIR)/rev.cpp: $(CONFIG_CACHE_VERSION) $(SRC_DIR)/rev.cpp.in $(SRC_DIR)/rev.cpp: $(CONFIG_CACHE_VERSION) $(SRC_DIR)/rev.cpp.in
$(Q)cat $(SRC_DIR)/rev.cpp.in | sed "s@\!\!ISODATE\!\!@$(ISODATE)@g;s@!!VERSION!!@$(VERSION)@g;s@!!MODIFIED!!@$(MODIFIED)@g;s@!!DATE!!@`date +%d.%m.%y`@g" > $(SRC_DIR)/rev.cpp $(Q)cat $(SRC_DIR)/rev.cpp.in | sed "s@\!\!ISODATE\!\!@$(ISODATE)@g;s@!!VERSION!!@$(VERSION)@g;s@!!MODIFIED!!@$(MODIFIED)@g;s@!!DATE!!@`date +%d.%m.%y`@g;s@!!GITHASH!!@$(GITHASH)@g" > $(SRC_DIR)/rev.cpp
$(SRC_DIR)/os/windows/ottdres.rc: $(CONFIG_CACHE_VERSION) $(SRC_DIR)/os/windows/ottdres.rc.in $(SRC_DIR)/os/windows/ottdres.rc: $(CONFIG_CACHE_VERSION) $(SRC_DIR)/os/windows/ottdres.rc.in
$(Q)cat $(SRC_DIR)/os/windows/ottdres.rc.in | sed "s@\!\!ISODATE\!\!@$(ISODATE)@g;s@!!VERSION!!@$(VERSION)@g;s@!!DATE!!@`date +%d.%m.%y`@g" > $(SRC_DIR)/os/windows/ottdres.rc $(Q)cat $(SRC_DIR)/os/windows/ottdres.rc.in | sed "s@\!\!ISODATE\!\!@$(ISODATE)@g;s@!!VERSION!!@$(VERSION)@g;s@!!DATE!!@`date +%d.%m.%y`@g;s@!!GITHASH!!@$(GITHASH)@g" > $(SRC_DIR)/os/windows/ottdres.rc
FORCE: FORCE:

View File

@ -67,20 +67,25 @@ if [ -d "$ROOT_DIR/.git" ]; then
MODIFIED="2" MODIFIED="2"
fi fi
HASH=`LC_ALL=C git rev-parse --verify HEAD 2>/dev/null` HASH=`LC_ALL=C git rev-parse --verify HEAD 2>/dev/null`
SHORTHASH=`echo ${HASH} | cut -c1-8` SHORTHASH=`echo ${HASH} | cut -c1-10`
ISODATE=`LC_ALL=C git show -s --pretty='format:%ci' HEAD | "$AWK" '{ gsub("-", "", $1); print $1 }'` ISODATE=`LC_ALL=C git show -s --pretty='format:%ci' HEAD | "$AWK" '{ gsub("-", "", $1); print $1 }'`
BRANCH="`git symbolic-ref -q HEAD 2>/dev/null | sed 's@.*/@@'`" BRANCH="`git symbolic-ref -q HEAD 2>/dev/null | sed 's@.*/@@'`"
TAG="`git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null | sed 's@\^0$@@'`" TAG="`git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null | sed 's@\^0$@@'`"
if [ "$MODIFIED" -eq "0" ]; then
hashprefix="-g"
elif [ "$MODIFIED" -eq "2" ]; then
hashprefix="-m"
else
hashprefix="-u"
fi
if [ -n "$TAG" ]; then if [ -n "$TAG" ]; then
VERSION="${TAG}" VERSION="${TAG}"
else else
VERSION="${ISODATE}-${BRANCH}-g${SHORTHASH}" VERSION="${ISODATE}-${BRANCH}${hashprefix}${SHORTHASH}"
fi fi
if [ "$MODIFIED" -eq "2" ]; then
VERSION="${VERSION}M"
fi
elif [ -f "$ROOT_DIR/.ottdrev" ]; then elif [ -f "$ROOT_DIR/.ottdrev" ]; then
# We are an exported source bundle # We are an exported source bundle
cat $ROOT_DIR/.ottdrev cat $ROOT_DIR/.ottdrev

View File

@ -21,31 +21,34 @@ Sub FindReplaceInFile(filename, to_find, replacement)
file.Close file.Close
End Sub End Sub
Sub UpdateFile(modified, isodate, version, cur_date, filename) Sub UpdateFile(modified, isodate, version, cur_date, githash, filename)
FSO.CopyFile filename & ".in", filename FSO.CopyFile filename & ".in", filename
FindReplaceInFile filename, "!!MODIFIED!!", modified FindReplaceInFile filename, "!!MODIFIED!!", modified
FindReplaceInFile filename, "!!ISODATE!!", isodate FindReplaceInFile filename, "!!ISODATE!!", isodate
FindReplaceInFile filename, "!!VERSION!!", version FindReplaceInFile filename, "!!VERSION!!", version
FindReplaceInFile filename, "!!DATE!!", cur_date FindReplaceInFile filename, "!!DATE!!", cur_date
FindReplaceInFile filename, "!!GITHASH!!", githash
End Sub End Sub
Sub UpdateFiles(version) Sub UpdateFiles(version)
Dim modified, isodate, cur_date Dim modified, isodate, cur_date, githash
cur_date = DatePart("D", Date) & "." & DatePart("M", Date) & "." & DatePart("YYYY", Date) cur_date = DatePart("D", Date) & "." & DatePart("M", Date) & "." & DatePart("YYYY", Date)
If InStr(version, Chr(9)) Then If InStr(version, Chr(9)) Then
isodate = Mid(version, InStr(version, Chr(9)) + 1) isodate = Mid(version, InStr(version, Chr(9)) + 1)
modified = Mid(isodate, InStr(isodate, Chr(9)) + 1) modified = Mid(isodate, InStr(isodate, Chr(9)) + 1)
githash = Mid(modified, InStr(modified, Chr(9)) + 1)
isodate = Mid(isodate, 1, InStr(isodate, Chr(9)) - 1) isodate = Mid(isodate, 1, InStr(isodate, Chr(9)) - 1)
modified = Mid(modified, 1, InStr(modified, Chr(9)) - 1) modified = Mid(modified, 1, InStr(modified, Chr(9)) - 1)
version = Mid(version, 1, InStr(version, Chr(9)) - 1) version = Mid(version, 1, InStr(version, Chr(9)) - 1)
Else Else
isodate = 0 isodate = 0
modified = 1 modified = 1
githash = ""
End If End If
UpdateFile modified, isodate, version, cur_date, "../src/rev.cpp" UpdateFile modified, isodate, version, cur_date, githash, "../src/rev.cpp"
UpdateFile modified, isodate, version, cur_date, "../src/os/windows/ottdres.rc" UpdateFile modified, isodate, version, cur_date, githash, "../src/os/windows/ottdres.rc"
End Sub End Sub
Function DetermineVersion() Function DetermineVersion()
@ -71,7 +74,7 @@ Function DetermineVersion()
If oExec.ExitCode = 0 Then If oExec.ExitCode = 0 Then
hash = oExec.StdOut.ReadLine() hash = oExec.StdOut.ReadLine()
shorthash = Mid(hash, 1, 8) shorthash = Mid(hash, 1, 10)
' Make sure index is in sync with disk ' Make sure index is in sync with disk
Set oExec = WshShell.Exec("git update-index --refresh") Set oExec = WshShell.Exec("git update-index --refresh")
If Err.Number = 0 Then If Err.Number = 0 Then
@ -133,17 +136,19 @@ Function DetermineVersion()
ElseIf hash = "" Then ElseIf hash = "" Then
DetermineVersion = "norev000" DetermineVersion = "norev000"
Else Else
Dim version Dim version, hashprefix
If tag <> "" Then If modified = 0 Then
version = tag hashprefix = "-g"
ElseIf branch = "master" Then ElseIf modified = 2 Then
version = isodate & "-g" & shorthash hashprefix = "-m"
Else Else
version = isodate & "-" & branch & "-g" & shorthash hashprefix = "-u"
End If End If
If modified = 2 Then If tag <> "" Then
version = version & "M" version = tag
Else
version = isodate & "-" & branch & hashprefix & shorthash
End If End If
DetermineVersion = version & Chr(9) & isodate & Chr(9) & modified & Chr(9) & hash DetermineVersion = version & Chr(9) & isodate & Chr(9) & modified & Chr(9) & hash

View File

@ -47,6 +47,11 @@ const char _openttd_revision[] = "!!VERSION!!";
*/ */
const char _openttd_build_date[] = __DATE__ " " __TIME__; const char _openttd_build_date[] = __DATE__ " " __TIME__;
/**
* The git revision hash of this version.
*/
const char _openttd_revision_hash[] = "!!GITHASH!!";
/** /**
* Let us know if current build was modified. This detection * Let us know if current build was modified. This detection
* works even in the case when revision string is overridden by * works even in the case when revision string is overridden by

View File

@ -14,6 +14,7 @@
extern const char _openttd_revision[]; extern const char _openttd_revision[];
extern const char _openttd_build_date[]; extern const char _openttd_build_date[];
extern const char _openttd_revision_hash[];
extern const byte _openttd_revision_modified; extern const byte _openttd_revision_modified;
extern const uint32 _openttd_newgrf_version; extern const uint32 _openttd_newgrf_version;