forked from uncrustify/uncrustify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_version.py
executable file
·48 lines (41 loc) · 1.32 KB
/
make_version.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
#!/usr/bin/env python
#
# Rebuilds the version using git describe
#
import sys
import os
import subprocess
def main (argv):
root = os.path.abspath(os.path.dirname(__file__))
git_path = os.path.join(root, '.git')
if not os.path.exists(git_path):
return
try:
txt = subprocess.check_output(['git', 'describe', '--long', '--always', '--dirty']).strip()
except:
return
# convert the git describe text to a version
pts = txt.split('-', 2)
full_vers = '%s.%s' % (pts[1], pts[2])
tag_vers = pts[1]
print 'full version:', full_vers
print ' tag version:', tag_vers
# rebuild uncrustify_version.h
fn = os.path.join(root, 'src', 'uncrustify_version.h.in')
with open(fn, 'rb') as fh:
data = fh.read()
with open(fn[:-3], 'wb') as fh:
fh.write(data.replace('@PACKAGE_VERSION@', full_vers))
# rebuild configure.in
fn = os.path.join(root, 'configure.ac')
with open(fn, 'rb') as fh:
data = fh.read()
with open(fn, 'wb') as fh:
for line in data.splitlines():
if line.startswith('AC_INIT(uncrustify'):
pts = line.split(',', 2)
line = '%s,%s,%s' % (pts[0], tag_vers, pts[2])
fh.write(line)
fh.write('\n')
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))