[PATCH] D84423: [lit] Allow lit.which() to find executables which already have an extension

Zachary Turner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 23 09:08:24 PDT 2020


zturner created this revision.
zturner added reviewers: amccarth, akhuang.
zturner added a project: LLVM.
Herald added subscribers: llvm-commits, delcypher.

  LLVM usually specifies executable names without extension so that
  they work portably across platforms.  Occasionally, if you're writing
  something platform specific, you might want to specify the extension.
  For example, you might want to write a test that invokes a batch file.
  It's awkward to say `foo` when the file is really called `foo.bat`, but
  in this case `lit.util.which()` currently won't find it because it will
  construct the filename `foo.bat.bat`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84423

Files:
  llvm/utils/lit/lit/util.py


Index: llvm/utils/lit/lit/util.py
===================================================================
--- llvm/utils/lit/lit/util.py
+++ llvm/utils/lit/lit/util.py
@@ -232,16 +232,24 @@
     # Get suffixes to search.
     # On Cygwin, 'PATHEXT' may exist but it should not be used.
     if os.pathsep == ';':
-        pathext = os.environ.get('PATHEXT', '').split(';')
+        # Since this branch implies windows, it's safe to convert all extensions to lowercase.
+        assert(sys.platform == 'win32')
+        pathext = [x.lower() for x in os.environ.get('PATHEXT', '').split(';')]
+
+        # If the path was given to us with an extension already, ignore PATHEXT
+        _, current_ext = os.path.splitext(command)
+        if current_ext.lower() in pathext:
+            pathext = ['']
     else:
         pathext = ['']
 
     # Search the paths...
     for path in paths.split(os.pathsep):
+        p = os.path.join(path, command)
         for ext in pathext:
-            p = os.path.join(path, command + ext)
-            if os.path.exists(p) and not os.path.isdir(p):
-                return os.path.normcase(os.path.normpath(p))
+            p_with_ext = p + ext
+            if os.access(p_with_ext, os.X_OK):
+                return os.path.normcase(os.path.normpath(p_with_ext))
 
     return None
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84423.280156.patch
Type: text/x-patch
Size: 1317 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200723/b4047ac3/attachment.bin>


More information about the llvm-commits mailing list