-
Notifications
You must be signed in to change notification settings - Fork 3
/
version.SConscript
53 lines (37 loc) · 1.69 KB
/
version.SConscript
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Import("env")
Import("conf")
from git import Repo
import time
repo = Repo(".")
v = "0.0.0"
if str(repo.head.ref) == "develop":
# We are currently in the develop branch, find all dev tags (eg. 1.0.0-dev) and grab the last one
dev_tag = [str(tag) for tag in repo.tags if str(tag)[-3:] == "dev"][-1]
# In the develop branch the version is identical to the dev tag name and a count of
# commits from the dev tag to the HEAD in the "dev.x" format
commits_from_dev_tag = len(list(repo.iter_commits(dev_tag + "...develop")))
v = dev_tag + ".%d" % commits_from_dev_tag;
if str(repo.head.ref)[:8] == "feature/":
dev_branch = str(repo.head.ref)
dev_feature = dev_branch[8:]
dev_tag = [str(tag)[:-4] for tag in repo.tags if str(tag)[-3:] == "dev"][-1]
try:
commits_from_develop = len(list(repo.iter_commits("develop..." + dev_branch)))
except:
# local develop branch doesn't exist (most probably)
commits_from_develop = len(list(repo.iter_commits("origin/develop..." + dev_branch)))
v = dev_tag + "-" + dev_feature + ".%s" % commits_from_develop
if str(repo.head.ref) == "master":
v = str(next((tag for tag in repo.tags if tag.commit == repo.head.commit), "0.0.0"))
v += "+" + repo.head.commit.hexsha[:7]
v += "." + time.strftime("%Y%m%d")
env["VERSION"] = v
env["BUILD_DATE"] = time.strftime("%F %T %Z", time.localtime())
def make_ver(target, source, env):
for t in target:
with open(str(t), "w") as f:
f.write("#define UMESH_VERSION \"%s\"\n" % env["VERSION"])
f.write("#define UMESH_BUILD_DATE \"%s\"\n" % env["BUILD_DATE"])
return None
env.Append(BUILDERS = {"MakeVer": env.Builder(action = make_ver)})
version = env.MakeVer(target = "ports/%s/version.h" % conf["PORT_NAME"], source = None)