-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathSConscript.version
More file actions
96 lines (79 loc) · 3.1 KB
/
SConscript.version
File metadata and controls
96 lines (79 loc) · 3.1 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os
import re
import string
Import('env')
def get_version_or_die():
from libdiffpybuildutils import getversion
try:
rv = getversion()
except RuntimeError as e:
print(e)
Exit(1)
return rv
def parsemajorminor(hcode):
'Extract major and minor version from a C++ header file.'
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):
tplcode = source[0].get_text_contents()
numversion = gver['major']
numversion = 1000 * numversion + gver['minor']
numversion = 1000 * numversion + gver['micro']
numversion = 1000 * numversion + gver['patchnumber']
# verify that formulas in version.tpl work as advertised
emsg = "Inconsistent value of DIFFPY_VERSION = %i" % numversion
assert numversion // 1000000000 == gver['major'], emsg
assert numversion // 1000000 % 1000 == gver['minor'], emsg
assert numversion // 1000 % 1000 == gver['micro'], emsg
assert numversion % 500 == gver['patchnumber'], emsg
libversion = str(numversion) + "LL"
if gver['prerelease']:
libversion = "(-500 + %s)" % libversion
flds = {
'DIFFPY_VERSION' : libversion,
'DIFFPY_VERSION_MAJOR' : gver['major'],
'DIFFPY_VERSION_MINOR' : gver['minor'],
'DIFFPY_VERSION_MICRO' : gver['micro'],
'DIFFPY_VERSION_PATCH' : gver['patchnumber'],
'DIFFPY_VERSION_STR' : gver['version'],
'DIFFPY_VERSION_DATE' : gver['date'],
'DIFFPY_GIT_SHA' : gver['commit'],
}
versiontemplate = string.Template(tplcode)
versioncode = versiontemplate.safe_substitute(flds)
with open(target[0].path, 'w') as fp:
fp.write(versioncode)
return None
env.Append(BUILDERS={'BuildVersionCode' :
Builder(action=build_VersionCode, suffix='.hpp', src_suffix='.tpl')})
def build_FeaturesCode(target, source, env):
tplcode = source[0].get_text_contents()
flds = {
'DIFFPY_HAS_OBJCRYST' : int(env['has_objcryst']),
}
codetemplate = string.Template(tplcode)
codetext = codetemplate.safe_substitute(flds)
with open(target[0].path, 'w') as fp:
fp.write(codetext)
return None
env.Append(BUILDERS={'BuildFeaturesCode' :
Builder(action=build_FeaturesCode, 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_text_contents())
else:
vtpl = File('version.tpl')
gver = get_version_or_die()
vhpp, = env.BuildVersionCode(['version.hpp'], vtpl)
env.Depends(vhpp, env.Value(gver['version'] + gver['commit']))
majorminor = (gver['major'], gver['minor'])
fhpp, = env.BuildFeaturesCode(['features.tpl'])
env.Depends(fhpp, env.Value(env['has_objcryst']))
env['lib_includes'] += [vhpp, fhpp]
env['majorminor'] = majorminor
# vim: ft=python