Merge vk-gl-cts/opengl-es-cts-3.2.3 into vk-gl-cts/opengl-es-cts-3.2.4
[platform/upstream/VK-GL-CTS.git] / scripts / build / common.py
index 069905e..c1ea6de 100644 (file)
 #-------------------------------------------------------------------------
 
 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)
@@ -62,11 +98,26 @@ def writeFile (filename, data):
        f.write(data)
        f.close()
 
-def which (binName):
-       for path in os.environ['PATH'].split(os.pathsep):
-               path = path.strip('"')
-               fullPath = os.path.join(path, binName)
-               if os.path.isfile(fullPath) and os.access(fullPath, os.X_OK):
-                       return fullPath
+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