We also need to catch OSError here.
[oota-llvm.git] / test / Bindings / Go / lit.local.cfg
index 5053e2c3952491f18a3de275fad0f0e96275428a..c41ff16b287e944a99048731f8d1310ae3f7d525 100644 (file)
@@ -1,11 +1,29 @@
-import distutils.spawn
 import os
 import pipes
 import shlex
 import os
 import pipes
 import shlex
+import sys
 
 if not 'go' in config.root.llvm_bindings:
     config.unsupported = True
 
 
 if not 'go' in config.root.llvm_bindings:
     config.unsupported = True
 
+def find_executable(executable, path=None):
+    if path is None:
+        path = os.environ['PATH']
+    paths = path.split(os.pathsep)
+    base, ext = os.path.splitext(executable)
+
+    if (sys.platform == 'win32' or os.name == 'os2') and (ext != '.exe'):
+        executable = executable + '.exe'
+
+    if not os.path.isfile(executable):
+        for p in paths:
+            f = os.path.join(p, executable)
+            if os.path.isfile(f):
+                return f
+        return None
+    else:
+        return executable
+
 # Resolve certain symlinks in the first word of compiler.
 #
 # This is a Go-specific hack. cgo and other Go tools check $CC and $CXX for the
 # Resolve certain symlinks in the first word of compiler.
 #
 # This is a Go-specific hack. cgo and other Go tools check $CC and $CXX for the
@@ -13,19 +31,19 @@ if not 'go' in config.root.llvm_bindings:
 # $CC is cc and cc is a symlink pointing to clang, as it is on Darwin.
 def fixup_compiler_path(compiler):
     args = shlex.split(compiler)
 # $CC is cc and cc is a symlink pointing to clang, as it is on Darwin.
 def fixup_compiler_path(compiler):
     args = shlex.split(compiler)
-    path = distutils.spawn.find_executable(args[0])
+    path = find_executable(args[0])
 
     try:
         if path.endswith('/cc') and os.readlink(path) == 'clang':
             args[0] = path[:len(path)-2] + 'clang'
 
     try:
         if path.endswith('/cc') and os.readlink(path) == 'clang':
             args[0] = path[:len(path)-2] + 'clang'
-    except OSError:
-        skip
+    except (AttributeError, OSError):
+        pass
 
     try:
         if path.endswith('/c++') and os.readlink(path) == 'clang++':
             args[0] = path[:len(path)-3] + 'clang++'
 
     try:
         if path.endswith('/c++') and os.readlink(path) == 'clang++':
             args[0] = path[:len(path)-3] + 'clang++'
-    except OSError:
-        skip
+    except (AttributeError, OSError):
+        pass
 
     return ' '.join([pipes.quote(arg) for arg in args])
 
 
     return ' '.join([pipes.quote(arg) for arg in args])