Home | History | Annotate | Download | only in build
      1 # -*- coding: utf-8 -*-
      2 
      3 #-------------------------------------------------------------------------
      4 # drawElements Quality Program utilities
      5 # --------------------------------------
      6 #
      7 # Copyright 2015 The Android Open Source Project
      8 #
      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
     12 #
     13 #      http://www.apache.org/licenses/LICENSE-2.0
     14 #
     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.
     20 #
     21 #-------------------------------------------------------------------------
     22 
     23 import os
     24 import shlex
     25 import subprocess
     26 
     27 DEQP_DIR = os.path.realpath(os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "..")))
     28 
     29 def die (msg):
     30 	print msg
     31 	exit(-1)
     32 
     33 def shellquote(s):
     34 	return '"%s"' % s.replace('\\', '\\\\').replace('"', '\"').replace('$', '\$').replace('`', '\`')
     35 
     36 g_workDirStack = []
     37 
     38 def pushWorkingDir (path):
     39 	oldDir = os.getcwd()
     40 	os.chdir(path)
     41 	g_workDirStack.append(oldDir)
     42 
     43 def popWorkingDir ():
     44 	assert len(g_workDirStack) > 0
     45 	newDir = g_workDirStack[-1]
     46 	g_workDirStack.pop()
     47 	os.chdir(newDir)
     48 
     49 def execute (args):
     50 	retcode	= subprocess.call(args)
     51 	if retcode != 0:
     52 		raise Exception("Failed to execute '%s', got %d" % (str(args), retcode))
     53 
     54 def readFile (filename):
     55 	f = open(filename, 'rb')
     56 	data = f.read()
     57 	f.close()
     58 	return data
     59 
     60 def writeFile (filename, data):
     61 	f = open(filename, 'wb')
     62 	f.write(data)
     63 	f.close()
     64 
     65 def which (binName):
     66 	for path in os.environ['PATH'].split(os.pathsep):
     67 		path = path.strip('"')
     68 		fullPath = os.path.join(path, binName)
     69 		if os.path.isfile(fullPath) and os.access(fullPath, os.X_OK):
     70 			return fullPath
     71 
     72 	return None
     73