Home | History | Annotate | Download | only in build
      1 # -*- coding: utf-8 -*-
      2 
      3 import os
      4 import shlex
      5 import subprocess
      6 
      7 SRC_BASE_DIR		= os.path.realpath(os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "..", "..")))
      8 DEQP_DIR			= os.path.join(SRC_BASE_DIR, "deqp")
      9 
     10 def die (msg):
     11 	print msg
     12 	exit(-1)
     13 
     14 def shellquote(s):
     15 	return '"%s"' % s.replace('\\', '\\\\').replace('"', '\"').replace('$', '\$').replace('`', '\`')
     16 
     17 g_workDirStack = []
     18 
     19 def pushWorkingDir (path):
     20 	oldDir = os.getcwd()
     21 	os.chdir(path)
     22 	g_workDirStack.append(oldDir)
     23 
     24 def popWorkingDir ():
     25 	assert len(g_workDirStack) > 0
     26 	newDir = g_workDirStack[-1]
     27 	g_workDirStack.pop()
     28 	os.chdir(newDir)
     29 
     30 def execute (args):
     31 	retcode	= subprocess.call(args)
     32 	if retcode != 0:
     33 		raise Exception("Failed to execute '%s', got %d" % (str(args), retcode))
     34 
     35 def readFile (filename):
     36 	f = open(filename, 'rb')
     37 	data = f.read()
     38 	f.close()
     39 	return data
     40 
     41 def writeFile (filename, data):
     42 	f = open(filename, 'wb')
     43 	f.write(data)
     44 	f.close()
     45 
     46 def which (binName):
     47 	for path in os.environ['PATH'].split(os.pathsep):
     48 		path = path.strip('"')
     49 		fullPath = os.path.join(path, binName)
     50 		if os.path.isfile(fullPath) and os.access(fullPath, os.X_OK):
     51 			return fullPath
     52 
     53 	return None
     54