Changeset - r23268:0183290253ce
[Not reviewed]
master
0 5 0
Niels Martin Hansen - 6 years ago 2019-01-27 13:04:49
nielsm@indvikleren.dk
Change: Include the full raw git revision hash in rev.cpp
5 files changed with 37 insertions and 20 deletions:
0 comments (0 inline, 0 general)
Makefile.src.in
Show inline comments
 
@@ -90,6 +90,7 @@ MODIFIED := $(shell echo "$(VERSIONS)" |
 
# 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:
 

	
findversion.sh
Show inline comments
 
@@ -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
projects/determineversion.vbs
Show inline comments
 
@@ -21,31 +21,34 @@ Sub FindReplaceInFile(filename, to_find,
 
	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
 
		Dim version, hashprefix
 
		If modified = 0 Then
 
			hashprefix = "-g"
 
		ElseIf modified = 2 Then
 
			hashprefix = "-m"
 
		Else
 
			hashprefix = "-u"
 
		End If
 

	
 
		If tag <> "" Then
 
			version = tag
 
		ElseIf branch = "master" Then
 
			version = isodate & "-g" & shorthash
 
		Else
 
			version = isodate & "-" & branch & "-g" & shorthash
 
		End If
 

	
 
		If modified = 2 Then
 
			version = version & "M"
 
			version = isodate & "-" & branch & hashprefix & shorthash
 
		End If
 

	
 
		DetermineVersion = version & Chr(9) & isodate & Chr(9) & modified & Chr(9) & hash
src/rev.cpp.in
Show inline comments
 
@@ -48,6 +48,11 @@ const char _openttd_revision[] = "!!VERS
 
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
 
 * --revision argument.
src/rev.h
Show inline comments
 
@@ -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;
 

	
0 comments (0 inline, 0 general)