lin
2025-07-30 fcd736bf35fd93b563e9bbf594f2aa7b62028cc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# -*- coding: utf-8 -*-
 
#-------------------------------------------------------------------------
# drawElements Quality Program utilities
# --------------------------------------
#
# Copyright 2015 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#-------------------------------------------------------------------------
 
import os
import sys
import shlex
import platform
import subprocess
 
DEQP_DIR = os.path.realpath(os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "..")))
 
# HostInfo describes properties of the host where these scripts
# are running on.
class HostInfo:
   OS_WINDOWS    = 0
   OS_LINUX    = 1
   OS_OSX        = 2
 
   @staticmethod
   def getOs ():
       if sys.platform == 'darwin':
           return HostInfo.OS_OSX
       elif sys.platform == 'win32':
           return HostInfo.OS_WINDOWS
       elif sys.platform.startswith('linux'):
           return HostInfo.OS_LINUX
       else:
           raise Exception("Unknown sys.platform '%s'" % sys.platform)
 
   @staticmethod
   def getArchBits ():
       MACHINE_BITS = {
           "i386":        32,
           "i686":        32,
           "x86":        32,
           "x86_64":    64,
           "AMD64":    64
       }
       machine = platform.machine()
 
       if not machine in MACHINE_BITS:
           raise Exception("Unknown platform.machine() '%s'" % machine)
 
       return MACHINE_BITS[machine]
 
def die (msg):
   print(msg)
   exit(-1)
 
def shellquote(s):
   return '"%s"' % s.replace('\\', '\\\\').replace('"', '\"').replace('$', '\$').replace('`', '\`')
 
g_workDirStack = []
 
def pushWorkingDir (path):
   oldDir = os.getcwd()
   os.chdir(path)
   g_workDirStack.append(oldDir)
 
def popWorkingDir ():
   assert len(g_workDirStack) > 0
   newDir = g_workDirStack[-1]
   g_workDirStack.pop()
   os.chdir(newDir)
 
def execute (args):
   retcode    = subprocess.call(args)
   if retcode != 0:
       raise Exception("Failed to execute '%s', got %d" % (str(args), retcode))
 
def readFile (filename):
   f = open(filename, 'rb')
   data = f.read()
   f.close()
   return data
 
def writeFile (filename, data):
   f = open(filename, 'wb')
   f.write(data)
   f.close()
 
def which (binName, paths = None):
   if paths == None:
       paths = os.environ['PATH'].split(os.pathsep)
 
   def whichImpl (binWithExt):
       for path in paths:
           path = path.strip('"')
           fullPath = os.path.join(path, binWithExt)
           if os.path.isfile(fullPath) and os.access(fullPath, os.X_OK):
               return fullPath
 
       return None
 
   extensions = [""]
   if HostInfo.getOs() == HostInfo.OS_WINDOWS:
       extensions += [".exe", ".bat"]
 
   for extension in extensions:
       extResult = whichImpl(binName + extension)
       if extResult != None:
           return extResult
 
   return None