[lit] Fix bug where ``lit.util.which()`` would return a directory
authorDan Liew <dan@su-root.co.uk>
Fri, 13 Nov 2015 11:37:25 +0000 (11:37 +0000)
committerDan Liew <dan@su-root.co.uk>
Fri, 13 Nov 2015 11:37:25 +0000 (11:37 +0000)
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
```

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253031 91177308-0d34-0410-b5e6-96231b3b80d8

utils/lit/lit/util.py

index a4233bac7aa5bc43a1e777dcd8495297da335b31..224509ab840b610bf773b4f85eca8911f6f97720 100644 (file)
@@ -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