-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathupdate_version_string.py
More file actions
31 lines (26 loc) Β· 987 Bytes
/
update_version_string.py
File metadata and controls
31 lines (26 loc) Β· 987 Bytes
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
import re
import subprocess
import sys
def main():
version_string = subprocess.check_output(['git', 'describe', '--dirty', '--always', '--tags'])
file_name = sys.argv[1]
all_lines = []
with open(file_name, "r", encoding='utf-8') as f:
for line in f.readlines():
m = re.search(r'^const char \*(\w+)::Version\(\)\s*(const)?\s*\{ return ".*"; \}', line)
if m:
NS = str(m[1])
line = 'const char *' + NS + '::Version() ';
if m[2] != None:
line += 'const '
line += '{ return "'
line += version_string.decode('UTF-8')[0:-1]
line += '"; }\n'
print('Writing version: ', version_string.decode('UTF-8')[0:-1])
all_lines.append(line)
# rewrite file
with open(file_name, "w", encoding='utf-8') as f:
for line in all_lines:
f.write(line)
if __name__ == "__main__":
main()