diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-05-25 20:46:13 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-05-25 20:54:53 (GMT) |
commit | 95a8998917591fdd77009f606bd55ece22f84950 (patch) | |
tree | cf6d1025c17599ecc2ec4bdabddf24b9719ce941 | |
parent | ee9eff16cd7024bdbd889bab7612c63bcfe3cbe9 (diff) | |
download | swift-contrib-95a8998917591fdd77009f606bd55ece22f84950.zip swift-contrib-95a8998917591fdd77009f606bd55ece22f84950.tar.bz2 |
Pick up build version from git tag (if present).
-rw-r--r-- | BuildTools/SCons/Tools/BuildVersion.py | 4 | ||||
-rw-r--r-- | BuildTools/SCons/Version.py | 25 | ||||
-rw-r--r-- | Slimber/Qt/SConscript | 2 | ||||
-rw-r--r-- | Swift/QtUI/SConscript | 4 | ||||
-rw-r--r-- | Swift/SConscript | 3 |
5 files changed, 24 insertions, 14 deletions
diff --git a/BuildTools/SCons/Tools/BuildVersion.py b/BuildTools/SCons/Tools/BuildVersion.py index 530ef8a..5edc79e 100644 --- a/BuildTools/SCons/Tools/BuildVersion.py +++ b/BuildTools/SCons/Tools/BuildVersion.py @@ -3,11 +3,11 @@ import SCons.Util import Version def generate(env) : - def createBuildVersion(env, target, version = None) : + def createBuildVersion(env, target, project) : buildVersion = """#pragma once static const char* buildVersion = \"%(buildVersion)s\";\n -""" % { "buildVersion" : Version.getBuildVersion(version) } +""" % { "buildVersion" : Version.getBuildVersion(project) } env.WriteVal(target, env.Value(buildVersion)) env.AddMethod(createBuildVersion, "BuildVersion") diff --git a/BuildTools/SCons/Version.py b/BuildTools/SCons/Version.py index 02edcc9..f4affd4 100644 --- a/BuildTools/SCons/Version.py +++ b/BuildTools/SCons/Version.py @@ -1,15 +1,26 @@ import subprocess, os, datetime -def getGitBuildVersion() : - p = subprocess.Popen("git rev-parse HEAD", shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=(os.name != "nt")) - gitVersion = p.stdout.read().rstrip()[0:7] +def getGitBuildVersion(project) : + headVersion = git("rev-parse HEAD") + if headVersion : + tags = git("tag --contains HEAD -l " + project + "-*") + if len(tags) > 0 : + for tag in tags.split("\n") : + tagVersion = git("rev-parse " + tag + "^{commit}") + if tagVersion == headVersion : + return tag + return None + +def git(cmd) : + p = subprocess.Popen("git " + cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=(os.name != "nt")) + gitVersion = p.stdout.read() p.stdin.close() return gitVersion if p.wait() == 0 else None -def getBuildVersion(version = None) : - if version : - return version - gitVersion = getGitBuildVersion() +def getBuildVersion(project) : + gitVersion = getGitBuildVersion(project) if gitVersion : return gitVersion + # TODO: Add the current branch + # TODO: Pick up a version number from a file (for distributing) return datetime.date.today().strftime("%Y%m%d") diff --git a/Slimber/Qt/SConscript b/Slimber/Qt/SConscript index 6fced8b..f59a0ba 100644 --- a/Slimber/Qt/SConscript +++ b/Slimber/Qt/SConscript @@ -22,7 +22,7 @@ if env["PLATFORM"] == "win32" : myenv.Append(LINKFLAGS = ["/SUBSYSTEM:WINDOWS"]) myenv.Append(LIBS = "qtmain") -myenv.BuildVersion("BuildVersion.h", version = env["SLIMBER_VERSION"]) +myenv.BuildVersion("BuildVersion.h", project = "slimber") sources = [ "main.cpp", diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript index d4acc50..b35668b 100644 --- a/Swift/QtUI/SConscript +++ b/Swift/QtUI/SConscript @@ -109,7 +109,9 @@ sources = [ ] -myenv.BuildVersion("BuildVersion.h", version = env["SWIFT_VERSION"]) +env["SWIFT_VERSION"] = Version.getBuildVersion("swift") +print env["SWIFT_VERSION"] +myenv.BuildVersion("BuildVersion.h", project = "swift") if env["PLATFORM"] == "win32" : myenv.RES("../resources/Windows/Swift.rc") diff --git a/Swift/SConscript b/Swift/SConscript index 8f1fa26..0064eee 100644 --- a/Swift/SConscript +++ b/Swift/SConscript @@ -9,8 +9,5 @@ if env["SCONS_STAGE"] == "build" : print "Error: Swift requires OpenSSL support, and OpenSSL was not found." Exit(1) - - env["SWIFT_VERSION"] = "0.9.9." + datetime.date.today().strftime("%Y%m%d") - if env["target"] == "native": SConscript("QtUI/SConscript") |