diff options
author | Zachary Turner <zturner@roblox.com> | 2020-07-23 08:40:48 -0700 |
---|---|---|
committer | Zachary Turner <zturner@roblox.com> | 2020-08-03 13:47:27 -0700 |
commit | ee5ed9d11e77f02631ed782f4ed8f6e872047b02 (patch) | |
tree | 49e83dbd1292bdff3ca93357a79c206990be3518 | |
parent | dd18fa1d7e71e7bc546251a3a68dac114c5c7526 (diff) | |
download | llvm-LitFixes.tar.gz |
Allow lit.util.which() to find executables with extension.LitFixes
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.
-rw-r--r-- | llvm/utils/lit/lit/util.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/llvm/utils/lit/lit/util.py b/llvm/utils/lit/lit/util.py index d7afbdabcff9..40a16122b4fb 100644 --- a/llvm/utils/lit/lit/util.py +++ b/llvm/utils/lit/lit/util.py @@ -232,16 +232,24 @@ def which(command, paths=None): # 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 |