-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkversion.py
executable file
·48 lines (39 loc) · 1.28 KB
/
mkversion.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
import os
import subprocess
import datetime
def run_command(cmd):
pr = subprocess.Popen(cmd, stdout=subprocess.PIPE)
out, err = pr.communicate()
if pr.returncode:
raise RuntimeError('command %r failed with code %r' % (cmd, pr.returncode))
return out
date_str = datetime.datetime.now().strftime("%Y-%m-%d")
version_string = date_str
git_hash = None
if os.access('.git', os.F_OK):
# for my development versions
try:
git_hash = run_command(['git', 'rev-parse', 'HEAD']).strip()
git_diff = run_command(['git', 'diff', '--numstat']).strip()
git_hash = git_hash[:6]
if git_diff:
git_hash += '+'
version_string = '%s git %s' % (date_str, git_hash)
# write a file that is used by release versions
open("version.num", 'w').write(version_string)
except Exception, e:
print "Git failed or not installed: %s" % str(e)
else:
# for release versions
if os.access('version.num', os.R_OK):
version_string = open('version.num').read()
open("version.s", 'w').write(
"""; do not modify -- dynamically generated file
.module version
.globl _software_version_string
.area _CODE
_software_version_string:
.ascii "UNA CP/M (Will Sowerbutts, %s)"
.db 0
""" % version_string)