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
VERSION := $(shell echo "$(VERSIONS)" | cut -f 1 -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
ifeq ($(VERSION),)
@ -275,10 +276,10 @@ endif
# Revision files
$(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
$(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:

View File

@ -67,20 +67,25 @@ if [ -d "$ROOT_DIR/.git" ]; then
MODIFIED="2"
fi
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 }'`
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$@@'`"
if [ "$MODIFIED" -eq "0" ]; then
hashprefix="-g"
elif [ "$MODIFIED" -eq "2" ]; then
hashprefix="-m"
else
hashprefix="-u"
fi
if [ -n "$TAG" ]; then
VERSION="${TAG}"
else
VERSION="${ISODATE}-${BRANCH}-g${SHORTHASH}"
VERSION="${ISODATE}-${BRANCH}${hashprefix}${SHORTHASH}"
fi
if [ "$MODIFIED" -eq "2" ]; then
VERSION="${VERSION}M"
fi
elif [ -f "$ROOT_DIR/.ottdrev" ]; then
# We are an exported source bundle
cat $ROOT_DIR/.ottdrev

View File

@ -21,31 +21,34 @@ Sub FindReplaceInFile(filename, to_find, replacement)
file.Close
End Sub
Sub UpdateFile(modified, isodate, version, cur_date, filename)
Sub UpdateFile(modified, isodate, version, cur_date, githash, filename)
FSO.CopyFile filename & ".in", filename
FindReplaceInFile filename, "!!MODIFIED!!", modified
FindReplaceInFile filename, "!!ISODATE!!", isodate
FindReplaceInFile filename, "!!VERSION!!", version
FindReplaceInFile filename, "!!DATE!!", cur_date
FindReplaceInFile filename, "!!GITHASH!!", githash
End Sub
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)
If InStr(version, Chr(9)) Then
isodate = Mid(version, InStr(version, 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)
modified = Mid(modified, 1, InStr(modified, Chr(9)) - 1)
version = Mid(version, 1, InStr(version, Chr(9)) - 1)
Else
isodate = 0
modified = 1
githash = ""
End If
UpdateFile modified, isodate, version, cur_date, "../src/rev.cpp"
UpdateFile modified, isodate, version, cur_date, "../src/os/windows/ottdres.rc"
UpdateFile modified, isodate, version, cur_date, githash, "../src/rev.cpp"
UpdateFile modified, isodate, version, cur_date, githash, "../src/os/windows/ottdres.rc"
End Sub
Function DetermineVersion()
@ -71,7 +74,7 @@ Function DetermineVersion()
If oExec.ExitCode = 0 Then
hash = oExec.StdOut.ReadLine()
shorthash = Mid(hash, 1, 8)
shorthash = Mid(hash, 1, 10)
' Make sure index is in sync with disk
Set oExec = WshShell.Exec("git update-index --refresh")
If Err.Number = 0 Then
@ -133,17 +136,19 @@ Function DetermineVersion()
ElseIf hash = "" Then
DetermineVersion = "norev000"
Else
Dim version
If tag <> "" Then
version = tag
ElseIf branch = "master" Then
version = isodate & "-g" & shorthash
Dim version, hashprefix
If modified = 0 Then
hashprefix = "-g"
ElseIf modified = 2 Then
hashprefix = "-m"
Else
version = isodate & "-" & branch & "-g" & shorthash
hashprefix = "-u"
End If
If modified = 2 Then
version = version & "M"
If tag <> "" Then
version = tag
Else
version = isodate & "-" & branch & hashprefix & shorthash
End If
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__;
/**
* The git revision hash of this version.
*/
const char _openttd_revision_hash[] = "!!GITHASH!!";
/**
* Let us know if current build was modified. This detection
* 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_build_date[];
extern const char _openttd_revision_hash[];
extern const byte _openttd_revision_modified;
extern const uint32 _openttd_newgrf_version;