Add git support to run.py

This commit is contained in:
Andrey Kamaev 2012-08-07 11:35:13 +04:00
parent bd33e166d0
commit a3527fc4d8

View File

@ -56,6 +56,7 @@ parse_patterns = (
{'name': "tests_dir", 'default': None, 'pattern': re.compile("^EXECUTABLE_OUTPUT_PATH:PATH=(.+)$")}, {'name': "tests_dir", 'default': None, 'pattern': re.compile("^EXECUTABLE_OUTPUT_PATH:PATH=(.+)$")},
{'name': "build_type", 'default': "Release", 'pattern': re.compile("^CMAKE_BUILD_TYPE:STRING=(.*)$")}, {'name': "build_type", 'default': "Release", 'pattern': re.compile("^CMAKE_BUILD_TYPE:STRING=(.*)$")},
{'name': "svnversion_path", 'default': None, 'pattern': re.compile("^SVNVERSION_PATH:FILEPATH=(.*)$")}, {'name': "svnversion_path", 'default': None, 'pattern': re.compile("^SVNVERSION_PATH:FILEPATH=(.*)$")},
{'name': "git_executable", 'default': None, 'pattern': re.compile("^GIT_EXECUTABLE:FILEPATH=(.*)$")},
{'name': "cxx_flags", 'default': "", 'pattern': re.compile("^CMAKE_CXX_FLAGS:STRING=(.*)$")}, {'name': "cxx_flags", 'default': "", 'pattern': re.compile("^CMAKE_CXX_FLAGS:STRING=(.*)$")},
{'name': "cxx_flags_debug", 'default': "", 'pattern': re.compile("^CMAKE_CXX_FLAGS_DEBUG:STRING=(.*)$")}, {'name': "cxx_flags_debug", 'default': "", 'pattern': re.compile("^CMAKE_CXX_FLAGS_DEBUG:STRING=(.*)$")},
{'name': "cxx_flags_release", 'default': "", 'pattern': re.compile("^CMAKE_CXX_FLAGS_RELEASE:STRING=(.*)$")}, {'name': "cxx_flags_release", 'default': "", 'pattern': re.compile("^CMAKE_CXX_FLAGS_RELEASE:STRING=(.*)$")},
@ -303,13 +304,15 @@ class RunInfo(object):
# detect target arch # detect target arch
if self.targetos == "android": if self.targetos == "android":
if "armeabi-v7a" in self.android_abi: if "armeabi-v7a" in self.android_abi:
self.targetarch = "ARMv7a" self.targetarch = "armv7a"
elif "armeabi-v6" in self.android_abi: elif "armeabi-v6" in self.android_abi:
self.targetarch = "ARMv6" self.targetarch = "armv6"
elif "armeabi" in self.android_abi: elif "armeabi" in self.android_abi:
self.targetarch = "ARMv5te" self.targetarch = "armv5te"
elif "x86" in self.android_abi: elif "x86" in self.android_abi:
self.targetarch = "x86" self.targetarch = "x86"
elif "mips" in self.android_abi:
self.targetarch = "mips"
else: else:
self.targetarch = "ARM" self.targetarch = "ARM"
elif self.is_x64 and hostmachine in ["AMD64", "x86_64"]: elif self.is_x64 and hostmachine in ["AMD64", "x86_64"]:
@ -327,19 +330,38 @@ class RunInfo(object):
self.hardware = None self.hardware = None
self.getSvnVersion(self.cmake_home, "cmake_home_svn") self.cmake_home_vcver = self.getVCVersion(self.cmake_home)
if self.opencv_home == self.cmake_home: if self.opencv_home == self.cmake_home:
self.opencv_home_svn = self.cmake_home_svn self.opencv_home_vcver = self.cmake_home_vcver
else: else:
self.getSvnVersion(self.opencv_home, "opencv_home_svn") self.opencv_home_vcver = self.getVCVersion(self.opencv_home)
self.tests = self.getAvailableTestApps() self.tests = self.getAvailableTestApps()
def getSvnVersion(self, path, name): def getVCVersion(self, root_path):
if os.path.isdir(os.path.join(root_path, ".svn")):
return self.getSvnVersion(root_path)
elif os.path.isdir(os.path.join(root_path, ".git")):
return self.getGitHash(root_path)
return None
def getGitHash(self, path):
if not path or not self.git_executable:
return None
try:
output = Popen([self.git_executable, "rev-parse", "--short", "HEAD"], stdout=PIPE, stderr=PIPE, cwd = path).communicate()
if not output[1]:
return output[0].strip()
else:
return None
except OSError:
return None
def getSvnVersion(self, path):
if not path: if not path:
val = None val = None
elif not self.svnversion_path and hostos == 'nt': elif not self.svnversion_path and hostos == 'nt':
val = self.tryGetSvnVersionWithTortoise(path, name) val = self.tryGetSvnVersionWithTortoise(path)
else: else:
svnversion = self.svnversion_path svnversion = self.svnversion_path
if not svnversion: if not svnversion:
@ -354,9 +376,9 @@ class RunInfo(object):
val = None val = None
if val: if val:
val = val.replace(" ", "_") val = val.replace(" ", "_")
setattr(self, name, val) return val
def tryGetSvnVersionWithTortoise(self, path, name): def tryGetSvnVersionWithTortoise(self, path):
try: try:
wcrev = "SubWCRev.exe" wcrev = "SubWCRev.exe"
dir = tempfile.mkdtemp() dir = tempfile.mkdtemp()
@ -408,13 +430,13 @@ class RunInfo(object):
if app.startswith(self.nameprefix): if app.startswith(self.nameprefix):
app = app[len(self.nameprefix):] app = app[len(self.nameprefix):]
if self.cmake_home_svn: if self.cmake_home_vcver:
if self.cmake_home_svn == self.opencv_home_svn: if self.cmake_home_vcver == self.opencv_home_vcver:
rev = self.cmake_home_svn rev = self.cmake_home_vcver
elif self.opencv_home_svn: elif self.opencv_home_vcver:
rev = self.cmake_home_svn + "-" + self.opencv_home_svn rev = self.cmake_home_vcver + "-" + self.opencv_home_vcver
else: else:
rev = self.cmake_home_svn rev = self.cmake_home_vcver
else: else:
rev = None rev = None
if rev: if rev:
@ -486,7 +508,6 @@ class RunInfo(object):
else: else:
prev_option = prev_option + " " + opt prev_option = prev_option + " " + opt
options.append(tmpfile[1]) options.append(tmpfile[1])
print options
output = Popen(options, stdout=PIPE, stderr=PIPE).communicate() output = Popen(options, stdout=PIPE, stderr=PIPE).communicate()
compiler_output = output[1] compiler_output = output[1]
os.remove(tmpfile[1]) os.remove(tmpfile[1])
@ -508,7 +529,7 @@ class RunInfo(object):
hw = "CUDA_" hw = "CUDA_"
else: else:
hw = "" hw = ""
tstamp = timestamp.strftime("%Y-%m-%d--%H-%M-%S") tstamp = timestamp.strftime("%Y%m%d-%H%M%S")
return "%s_%s_%s_%s%s%s.xml" % (app, self.targetos, self.targetarch, hw, rev, tstamp) return "%s_%s_%s_%s%s%s.xml" % (app, self.targetos, self.targetarch, hw, rev, tstamp)
def getTest(self, name): def getTest(self, name):