summaryrefslogtreecommitdiffstats
blob: 091d998b7df1302e322c64b6a7c42fa14aac17a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import subprocess, os, datetime, re

def getGitBuildVersion(project) :
  tag = git("describe --tags --exact --match \"" + project + "-*\"")
  if tag :
    return tag.rstrip()[len(project)+1:]
  tag = git("describe --tags --match \"" + project + "-*\"")
  if tag :
    m = re.match(project + "-(.*)-(.*)-(.*)", tag)
    if m :
      return m.group(1) + "-dev" + m.group(2)
  log = git("log --oneline")
  if log :
    return project + "-0.1-dev" + str(len(log.split("\n")))
  else :
    return project + "-0.0-dev"
    
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(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")