-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathgetversion.py
95 lines (84 loc) · 3.45 KB
/
getversion.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
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
# vim: set sw=2 ts=2 softtabstop=2 expandtab:
import os
import sys
import gvfindtools
import subprocess
""" This module is responsible for trying to determine the GPUVerify version"""
GPUVerifyDirectory = os.path.abspath( os.path.dirname(__file__))
GPUVerifyDeployVersionFile = os.path.join(GPUVerifyDirectory, '.gvdeployversion')
GPUVerifyRevisionErrorMessage = 'Error getting version information'
def getsha(path, showLocalRev=False):
oldpath = os.getcwd()
os.chdir(path)
if os.path.isdir(os.path.join(path,'.git')):
if showLocalRev:
sha = subprocess.check_output(['git','rev-list','HEAD', '--count'])
else:
sha = subprocess.check_output(['git','rev-parse','HEAD'])
elif os.path.isdir(os.path.join(path,'.svn')):
# The revision number is global for svn
sha = subprocess.check_output(['svnversion', '-c'])
elif path == getattr(gvfindtools, 'llvmSrcDir', None):
sha = subprocess.check_output([getattr(gvfindtools, 'llvmBinDir', None) + '/llvm-config', '--version'])
else:
sha = "Error [%s] path is not recognised as a git or svn repository" % path
os.chdir(oldpath)
return sha.decode().rstrip('\n\r')
def getVersionStringFromRepos():
try:
import gvfindtools
vs = []
# This method is used so if a member (e.g. libclcSrcDir)
# doesn't exist in gvfindtools then we just set None
# rather than raising an exception.
def repoTuple(toolName, **kargs ):
getLocalRev = ( 'getLocalRev' in kargs )
if 'gvft' in kargs:
return (toolName, getattr(gvfindtools, kargs['gvft'], None), getLocalRev)
elif 'path' in kargs:
return (toolName, kargs['path'], getLocalRev)
else:
raise Exception('Misuse of repoTuple')
for tool, path, localRev in [ repoTuple('llvm', gvft='llvmSrcDir'),
repoTuple('bugle', gvft='bugleSrcDir'),
repoTuple('libclc', gvft='libclcSrcDir'),
repoTuple('vcgen', path=GPUVerifyDirectory),
repoTuple('z3', gvft='z3SrcDir'),
repoTuple('cvc4', gvft='cvc4SrcDir'),
repoTuple('local-revision', path=GPUVerifyDirectory, getLocalRev=True) # GPUVerifyRise4Fun depends on this
]:
try:
vs.append(tool.ljust(15) + ": ")
revision = getsha(path, localRev)
except Exception as e:
revision = "No version information available ({0})".format(str(e))
vs[-1] += revision
return '\n'.join(vs) + '\n'
except Exception as e:
return GPUVerifyRevisionErrorMessage + " : " + str(e)
def getVersionString():
"""
This will first try to see if we are in a git repo. If so
version information is retrieved from there.
If not it will look for a file GPUVerifyDeployVersionFile and if
it is found it will use that.
"""
vs="GPUVerify:"
gitPath = os.path.join(GPUVerifyDirectory, '.git')
# Look for git
if os.path.isdir(gitPath):
vs += " Development version\n"
vs += getVersionStringFromRepos()
else:
vs +=" Deployment version\nBuilt from\n"
errorMessage = "Error Could not read version from file " + GPUVerifyDeployVersionFile + "\n"
#Try to open file
if os.path.isfile(GPUVerifyDeployVersionFile):
with open(GPUVerifyDeployVersionFile,'r') as f:
try:
vs += f.read()
except IOError:
vs = errorMessage
else:
vs = errorMessage
return vs