forked from diffpy/libdiffpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSConscript.version
More file actions
54 lines (43 loc) · 1.72 KB
/
SConscript.version
File metadata and controls
54 lines (43 loc) · 1.72 KB
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
54
import os
from subprocess import Popen, PIPE
Import('env')
def parsemajorminor(hcode):
'Extract major and minor version from a C++ header file.'
import re
mx = re.search(r'(?m)^#define *DIFFPY_VERSION_MAJOR *(\d+)', hcode)
major = int(mx.group(1))
mx = re.search(r'(?m)^#define *DIFFPY_VERSION_MINOR *(\d+)', hcode)
minor = int(mx.group(1))
return (major, minor)
def build_VersionCode(target, source, env):
import string
tplcode = source[0].get_contents()
major, minor = parsemajorminor(tplcode)
gsha, gepoch, gisodate = gitlog.split(None, 2)
daydate = int(gepoch) // 86400
flds = {
'DIFFPY_VERSION' : 10000000 * major + 100000 * minor + daydate,
'DIFFPY_VERSION_STR' : "%i.%i-t%i" % (major, minor, daydate),
'DIFFPY_VERSION_DATE' : gisodate,
'DIFFPY_GIT_SHA' : gsha,
}
versiontemplate = string.Template(tplcode)
versioncode = versiontemplate.safe_substitute(flds)
open(target[0].path, 'w').write(versioncode)
return None
env.Append(BUILDERS={'BuildVersionCode' :
Builder(action=build_VersionCode, suffix='.hpp', src_suffix='.tpl')})
# Targets --------------------------------------------------------------------
vhpp = File('version.hpp')
# If version.hpp exists do not use git
if os.path.isfile(str(vhpp.srcnode())):
majorminor = parsemajorminor(vhpp.srcnode().get_contents())
else:
vtpl = File('version.tpl')
proc = Popen(['git', 'log', '-1', '--format=%h %at %ai'], stdout=PIPE)
gitlog = proc.stdout.read().strip()
vhpp, = env.BuildVersionCode(['version.hpp'], vtpl)
env.Depends(vhpp, env.Value(gitlog))
majorminor = parsemajorminor(vtpl.get_contents())
env['majorminor'] = majorminor
# vim: ft=python