[llvm-branch-commits] [llvm] ee5ed9d - Allow lit.util.which() to find executables with extension.

2020-08-03 Thread Zachary Turner via llvm-branch-commits

Author: Zachary Turner
Date: 2020-08-03T13:47:27-07:00
New Revision: ee5ed9d11e77f02631ed782f4ed8f6e872047b02

URL: 
https://github.com/llvm/llvm-project/commit/ee5ed9d11e77f02631ed782f4ed8f6e872047b02
DIFF: 
https://github.com/llvm/llvm-project/commit/ee5ed9d11e77f02631ed782f4ed8f6e872047b02.diff

LOG: Allow lit.util.which() to find executables with extension.

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.

Added: 


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

Removed: 




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
 



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] dd18fa1 - [lit] Support running tests on Windows without GnuWin32.

2020-08-03 Thread Zachary Turner via llvm-branch-commits

Author: Zachary Turner
Date: 2020-08-03T13:47:27-07:00
New Revision: dd18fa1d7e71e7bc546251a3a68dac114c5c7526

URL: 
https://github.com/llvm/llvm-project/commit/dd18fa1d7e71e7bc546251a3a68dac114c5c7526
DIFF: 
https://github.com/llvm/llvm-project/commit/dd18fa1d7e71e7bc546251a3a68dac114c5c7526.diff

LOG: [lit] Support running tests on Windows without GnuWin32.

Historically, we have told contributors that GnuWin32 is a pre-requisite
because our tests depend on utilities such as sed, grep, diff, and more.
However, Git on Windows includes versions of these utilities in its
installation.  Furthermore, GnuWin32 has not been updated in many years.
For these reasons, it makes sense to have the ability to run llvm tests
in a way that is both:
  a) Easier on the user (less stuff to install)
  b) More up-to-date (The verions that ship with git are at least as
 new, if not newer, than the versions in GnuWin32.

We add support for this here by attempting to detect where Git is
installed using the Windows registry, confirming the existence of
several common Unix tools, and then adding this location to lit's PATH
environment.

Added: 


Modified: 
llvm/utils/lit/lit/llvm/config.py

Removed: 




diff  --git a/llvm/utils/lit/lit/llvm/config.py 
b/llvm/utils/lit/lit/llvm/config.py
index db557a7b1fef..af79fb5dddb5 100644
--- a/llvm/utils/lit/lit/llvm/config.py
+++ b/llvm/utils/lit/lit/llvm/config.py
@@ -1,3 +1,4 @@
+import itertools
 import os
 import platform
 import re
@@ -20,13 +21,16 @@ def __init__(self, lit_config, config):
 self.use_lit_shell = False
 # Tweak PATH for Win32 to decide to use bash.exe or not.
 if sys.platform == 'win32':
-# For tests that require Windows to run.
-features.add('system-windows')
-
-# Seek sane tools in directories and set to $PATH.
-path = self.lit_config.getToolsPath(config.lit_tools_dir,
-config.environment['PATH'],
-['cmp.exe', 'grep.exe', 
'sed.exe'])
+# Seek necessary tools in directories and set to $PATH.
+path = None
+lit_tools_dir = getattr(config, 'lit_tools_dir', None)
+required_tools = ['cmp.exe', 'grep.exe', 'sed.exe', '
diff .exe', 'echo.exe']
+if lit_tools_dir:
+path = self.lit_config.getToolsPath(lit_tools_dir,
+config.environment['PATH'],
+required_tools)
+if path is None:
+path = self._find_git_windows_unix_tools(required_tools)
 if path is not None:
 self.with_environment('PATH', path, append_path=True)
 # Many tools behave strangely if these environment variables 
aren't set.
@@ -115,6 +119,34 @@ def __init__(self, lit_config, config):
 self.with_environment(
 'DYLD_INSERT_LIBRARIES', gmalloc_path_str)
 
+def _find_git_windows_unix_tools(self, tools_needed):
+assert(sys.platform == 'win32')
+if sys.version_info.major >= 3:
+import winreg
+else:
+import _winreg as winreg
+
+# Search both the 64-bit hives, as well as HKLM + HKCU
+masks = [0, winreg.KEY_WOW64_64KEY]
+hives = [winreg.HKEY_CURRENT_USER, winreg.HKEY_LOCAL_MACHINE]
+for mask, hive in itertools.product(masks, hives):
+try:
+with winreg.OpenKey(hive, r"SOFTWARE\GitForWindows", 
access=winreg.KEY_READ | mask) as key:
+install_root, _ = winreg.QueryValueEx(key, 'InstallPath')
+
+if not install_root:
+continue
+candidate_path = os.path.join(install_root, 'usr', 'bin')
+if not lit.util.checkToolsPath(candidate_path, 
tools_needed):
+continue
+
+# We found it, stop enumerating.
+return candidate_path
+except:
+continue
+
+return None
+
 def with_environment(self, variable, value, append_path=False):
 if append_path:
 # For paths, we should be able to take a list of them and process 
all



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits