summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-05-25 20:46:13 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-05-25 20:54:53 (GMT)
commit95a8998917591fdd77009f606bd55ece22f84950 (patch)
treecf6d1025c17599ecc2ec4bdabddf24b9719ce941 /BuildTools/SCons/Version.py
parentee9eff16cd7024bdbd889bab7612c63bcfe3cbe9 (diff)
downloadswift-95a8998917591fdd77009f606bd55ece22f84950.zip
swift-95a8998917591fdd77009f606bd55ece22f84950.tar.bz2
Pick up build version from git tag (if present).
Diffstat (limited to 'BuildTools/SCons/Version.py')
-rw-r--r--BuildTools/SCons/Version.py25
1 files changed, 18 insertions, 7 deletions
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")