[llvm] r253031 - [lit] Fix bug where ``lit.util.which()`` would return a directory

Dan Liew via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 13 03:37:28 PST 2015


Author: delcypher
Date: Fri Nov 13 05:37:25 2015
New Revision: 253031

URL: http://llvm.org/viewvc/llvm-project?rev=253031&view=rev
Log:
[lit] Fix bug where ``lit.util.which()`` would return a directory
instead of executable if the argument was found inside a directory
contained in PATH.

An example where this could cause a problem is if there was a RUN line
that ran the ``test`` command and if the user had a directory in their
PATH that contained a directory called ``test/`` (that occured before
``/usr/bin/``). Lit would try to use the directory as the executable
which would fail with the rather cryptic message.

```
Could not create process due to [Errno 13] Permission denied
```

Modified:
    llvm/trunk/utils/lit/lit/util.py

Modified: llvm/trunk/utils/lit/lit/util.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/util.py?rev=253031&r1=253030&r2=253031&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/util.py (original)
+++ llvm/trunk/utils/lit/lit/util.py Fri Nov 13 05:37:25 2015
@@ -94,7 +94,7 @@ def which(command, paths = None):
     for path in paths.split(os.pathsep):
         for ext in pathext:
             p = os.path.join(path, command + ext)
-            if os.path.exists(p):
+            if os.path.exists(p) and not os.path.isdir(p):
                 return p
 
     return None




More information about the llvm-commits mailing list