-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgitversion.py
executable file
·56 lines (50 loc) · 1.94 KB
/
gitversion.py
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
#!/usr/bin/python3
from fusesoc.capi2.generator import Generator
import subprocess
class VersionGenerator(Generator):
def run(self):
verlist = subprocess.check_output(['git',
'describe',
'--tags',
'--dirty',
'--abbrev=8',
'--long'],
cwd=self.files_root).decode().rstrip().split('-')
dirty = verlist[-1] == 'dirty'
if dirty:
verlist.pop()
sha = verlist.pop()[1:9]
rev = verlist.pop()
#Sanity checks on version
if len(verlist) > 1:
print("'-' is not allowed in version tag")
exit(1)
if not verlist[0][0] == 'v':
print("Version tag must start with 'v'")
exit(1)
ver = verlist[0][1:].split('.')
major = ver.pop(0)
minor = ver.pop(0)
patch = ver[0] if ver else 0
params = {'VERSION_MAJOR' : major,
'VERSION_MINOR' : minor,
'VERSION_PATCH' : patch,
'VERSION_REV' : rev,
}
for k,v in params.items():
self.add_parameter(k,
{'datatype' : 'int',
'default' : int(v),
'paramtype' : 'vlogdefine',
})
self.add_parameter('VERSION_DIRTY',
{'datatype' : 'bool',
'default' : dirty,
'paramtype' : 'vlogdefine'})
self.add_parameter('VERSION_SHA',
{'datatype' : 'str',
'default' : str(sha),
'paramtype' : 'vlogdefine'})
vg = VersionGenerator()
vg.run()
vg.write()