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 readBinaryFile (filename):
91 f = open(filename, 'rb')
96 def readFile (filename):
97 f = open(filename, 'rt')
102 def writeBinaryFile (filename, data):
103 f = open(filename, 'wb')
107 def writeFile (filename, data):
108 if (sys.version_info < (3, 0)):
109 f = open(filename, 'wt')
111 f = open(filename, 'wt', newline='\n')
115 def which (binName, paths = None):
117 paths = os.environ['PATH'].split(os.pathsep)
119 def whichImpl (binWithExt):
121 path = path.strip('"')
122 fullPath = os.path.join(path, binWithExt)
123 if os.path.isfile(fullPath) and os.access(fullPath, os.X_OK):
129 if HostInfo.getOs() == HostInfo.OS_WINDOWS:
130 extensions += [".exe", ".bat"]
132 for extension in extensions:
133 extResult = whichImpl(binName + extension)
134 if extResult != None: