I have looked at your suggested adjustments to make_versioncpp.py (btw, patch was based on a commit by Geoff to the github mirror repo that he hasn't applied to SVN, so I could not cleanly apply it to my SVN working copy, did that manually), and played around with the possibilities offered by the various git commands a bit. I came up with the following changes:
- Instead of using "git describe --always" to acquire the commit hash of HEAD, use "git show -s --format=%h HEAD". The output of the former can vary and is therefore more difficult to parse.
- Take the branch out of the "build number" you compile, and set it between the major version "0.4.4+" and the "build number".
- To shorten things a bit, compile the "build number" as follows: <2-digit-year-number><2-digit-month-number><2-digit-day-number>.<commit-hash>
- Most important: Don't get the date from datetime.utcnow(), as that would give you the current date and time of the system. The version string (and therefore any build number constructed using a date/time) must be identical for builds based on the same commit. So fetch the date of the commit instead, and make sure to convert it to UTC.
So the final version string will be something like this: "v0.4.4+ branch [build 150320.831f1b0] Xcode 0511".
Here is what my version of make_versioncpp.py looks like now, with all adjustments:
Code: Select all
#!/usr/bin/python
import sys
import os
from string import Template
from subprocess import check_output
from datetime import datetime
if 3 != len(sys.argv):
print "ERROR: invalid parameters."
print "make_versioncpp.py <project rootdir> <build system name>"
quit()
os.chdir(sys.argv[1])
build_sys = sys.argv[2]
infile = 'util/Version.cpp.in'
outfile = 'util/Version.cpp'
version = "0.4.4+"
build_no = "???"
try:
branch = check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip()
if branch == "master":
branch = ""
commit = check_output(["git", "show", "-s", "--format=%h", "HEAD"]).strip()
timestamp = float(check_output(["git", "show", "-s", "--format=%ct", "HEAD"]).strip())
build_no = ".".join([datetime.utcfromtimestamp(timestamp).strftime("%y%m%d"), commit])
except:
print "WARNING: git not installed"
if build_no == "???" and os.path.exists(outfile):
print "WARNING: Can't determine git commit, %s not updated!" % outfile
quit()
try:
template_file = open(infile)
template = Template(template_file.read())
template_file.close()
except:
print "WARNING: Can't access %s, %s not updated!" % (infile, outfile)
quit()
print "Writing file: %s" % outfile
version_cpp = open(outfile, "w")
version_cpp.write(template.substitute(
FreeOrion_VERSION=version,
FreeOrion_BRANCH=branch,
FreeOrion_BUILD_NO=build_no,
FreeOrion_BUILDSYS=build_sys))
version_cpp.close()
print "Building v%s build %s" %(version, build_no)
And here is the accordingly adjusted Version.cpp.in template file:
Code: Select all
#include "util/Version.h"
namespace {
static const std::string retval = "v${FreeOrion_VERSION} ${FreeOrion_BRANCH} [build ${FreeOrion_BUILD_NO}] ${FreeOrion_BUILDSYS}";
}
const std::string& FreeOrionVersionString()
{
return retval;
}
Cjkjvfnby wrote:In file name I suggest next schema: FreeOrion-<year>-<month(number)>-<day>-<branch>-<commit>-Test-Win32-Setup.exe
Sort by name will be same as sort by date.
Hm, I'd rather sort by branch first, then by date, and use the build number as constructed above: "FreeOrion-<branch>-<build-number>-Test-Win32-Setup.exe". Using the example above: "FreeOrion-branch-150320.831f1b0-Test-Win32-Setup.exe". When branch is master, omit the branch part.
@Everyone: comments, opinions, other suggestions?