[llvm-commits] [Review request] lit: cygming support on the function "which"

NAKAMURA Takumi geek4civic at gmail.com
Mon Oct 4 00:22:55 PDT 2010


Hello, Daniel.

Please take a look into my patch.
confirmed on cygwin-1.5, cygwin-1.7 and mingw.

* On Windows, os.path.exists(command) matches to directories, too.
(eg. at seeking "bugpoint", the directory "test/BugPoint" matched when
current directory is test/)

* On Windows, unexecutable file matches.
(eg. when "macho-dump" and "macho-dump.bat" exist, "macho-dump.bat" is not hit)

* On Cygwin, the environment variable PATHEXT meddles.
  (on cygwin, os.path.exists("/path/to/clang") matches to "/path/to/clang.exe")
  In contrast, on win32, which should not seek suffix-less files.
  (eg. "test/Scripts/macho-dump" should be ignored)

Thank you, ...Takumi
-------------- next part --------------
diff --git a/utils/lit/lit/Util.py b/utils/lit/lit/Util.py
index 414b714..5dbdd0b 100644
--- a/utils/lit/lit/Util.py
+++ b/utils/lit/lit/Util.py
@@ -56,7 +56,8 @@ def which(command, paths = None):
         paths = os.environ.get('PATH','')
 
     # Check for absolute match first.
-    if os.path.exists(command):
+    if (command != os.path.basename(command)
+        and os.path.isfile(command)):
         return command
 
     # Would be nice if Python had a lib function for this.
@@ -64,7 +65,11 @@ def which(command, paths = None):
         paths = os.defpath
 
     # Get suffixes to search.
-    pathext = os.environ.get('PATHEXT', '').split(os.pathsep)
+    # On Cygwin, 'PATHEXT' exists but it should not be used.
+    if os.pathsep == ';':
+        pathext = os.environ.get('PATHEXT', '').split(';')
+    else:
+        pathext = ['']
 
     # Search the paths...
     for path in paths.split(os.pathsep):


More information about the llvm-commits mailing list