Skip to content

Commit b3418cb

Browse files
zturnerbxaganea
authored andcommitted
[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. Differential Revision: https://reviews.llvm.org/D84380
1 parent 24f5105 commit b3418cb

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

llvm/utils/lit/lit/llvm/config.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import itertools
12
import os
23
import platform
34
import re
@@ -20,13 +21,16 @@ def __init__(self, lit_config, config):
2021
self.use_lit_shell = False
2122
# Tweak PATH for Win32 to decide to use bash.exe or not.
2223
if sys.platform == 'win32':
23-
# For tests that require Windows to run.
24-
features.add('system-windows')
25-
26-
# Seek sane tools in directories and set to $PATH.
27-
path = self.lit_config.getToolsPath(config.lit_tools_dir,
28-
config.environment['PATH'],
29-
['cmp.exe', 'grep.exe', 'sed.exe'])
24+
# Seek necessary tools in directories and set to $PATH.
25+
path = None
26+
lit_tools_dir = getattr(config, 'lit_tools_dir', None)
27+
required_tools = ['cmp.exe', 'grep.exe', 'sed.exe', 'diff.exe', 'echo.exe']
28+
if lit_tools_dir:
29+
path = self.lit_config.getToolsPath(lit_tools_dir,
30+
config.environment['PATH'],
31+
required_tools)
32+
if path is None:
33+
path = self._find_git_windows_unix_tools(required_tools)
3034
if path is not None:
3135
self.with_environment('PATH', path, append_path=True)
3236
# Many tools behave strangely if these environment variables aren't set.
@@ -117,6 +121,34 @@ def __init__(self, lit_config, config):
117121
self.with_environment(
118122
'DYLD_INSERT_LIBRARIES', gmalloc_path_str)
119123

124+
def _find_git_windows_unix_tools(self, tools_needed):
125+
assert(sys.platform == 'win32')
126+
if sys.version_info.major >= 3:
127+
import winreg
128+
else:
129+
import _winreg as winreg
130+
131+
# Search both the 64 and 32-bit hives, as well as HKLM + HKCU
132+
masks = [0, winreg.KEY_WOW64_64KEY]
133+
hives = [winreg.HKEY_LOCAL_MACHINE, winreg.HKEY_CURRENT_USER]
134+
for mask, hive in itertools.product(masks, hives):
135+
try:
136+
with winreg.OpenKey(hive, r"SOFTWARE\GitForWindows", access=winreg.KEY_READ | mask) as key:
137+
install_root, _ = winreg.QueryValueEx(key, 'InstallPath')
138+
139+
if not install_root:
140+
continue
141+
candidate_path = os.path.join(install_root, 'usr', 'bin')
142+
if not lit.util.checkToolsPath(candidate_path, tools_needed):
143+
continue
144+
145+
# We found it, stop enumerating.
146+
return candidate_path
147+
except:
148+
continue
149+
150+
return None
151+
120152
def with_environment(self, variable, value, append_path=False):
121153
if append_path:
122154
# For paths, we should be able to take a list of them and process all

0 commit comments

Comments
 (0)