1 # -*- coding: utf-8 -*-
3 #-------------------------------------------------------------------------
4 # drawElements Quality Program utilities
5 # --------------------------------------
7 # Copyright 2015 The Android Open Source Project
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
21 #-------------------------------------------------------------------------
29 DEQP_DIR = os.path.realpath(os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "..")))
31 # HostInfo describes properties of the host where these scripts
40 if sys.platform == 'darwin':
41 return HostInfo.OS_OSX
42 elif sys.platform == 'win32':
43 return HostInfo.OS_WINDOWS
44 elif sys.platform.startswith('linux'):
45 return HostInfo.OS_LINUX
47 raise Exception("Unknown sys.platform '%s'" % sys.platform)
58 machine = platform.machine()
60 if not machine in MACHINE_BITS:
61 raise Exception("Unknown platform.machine() '%s'" % machine)
63 return MACHINE_BITS[machine]
70 return '"%s"' % s.replace('\\', '\\\\').replace('"', '\"').replace('$', '\$').replace('`', '\`')
74 def pushWorkingDir (path):
77 g_workDirStack.append(oldDir)
80 assert len(g_workDirStack) > 0
81 newDir = g_workDirStack[-1]
86 retcode = subprocess.call(args)
88 raise Exception("Failed to execute '%s', got %d" % (str(args), retcode))
90 def readFile (filename):
91 f = open(filename, 'rb')
96 def writeFile (filename, data):
97 f = open(filename, 'wb')
101 def which (binName, paths = None):
103 paths = os.environ['PATH'].split(os.pathsep)
105 def whichImpl (binWithExt):
107 path = path.strip('"')
108 fullPath = os.path.join(path, binWithExt)
109 if os.path.isfile(fullPath) and os.access(fullPath, os.X_OK):
115 if HostInfo.getOs() == HostInfo.OS_WINDOWS:
116 extensions += [".exe", ".bat"]
118 for extension in extensions:
119 extResult = whichImpl(binName + extension)
120 if extResult != None: