Skip to content

Commit d12ae04

Browse files
committed
[lit] Fix Python 2/3 compat in new winreg search code
This should fix the test failures on the clang win64 bot: http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/18830 It has been red since Sept 23-ish. This was subtle to debug. Windows has 'find' and 'sort' utilities in C:\Windows\system32, but they don't support all the same flags as the coreutils programs. I configured the buildbot above with Python 2.7 64-bit (hey, it was set up in 2016). When I installed git for Windows, I opted to add all the Unix utilities that come with git to the system PATH. This is *almost* enough to make the LLVM tests pass, but not quite, because if you use the system PATH, the Windows version of find and sort come first, but the tests that use diff, cmp, etc, will all pass. So only a handful of tests will fail, and with cryptic error messages. The code changed in this CL doesn't work with Python 2. Before Python 3.2, the winreg.OpenKey function did not accept the `access=` keyword argument, the caller was required to pass an unused `reserved` positional argument of 0. The try/except/pass around the OpenKey operation masked this usage error in Python 2. Further, the result of the registry operation has to be converted from unicode to add it to the environment, but that was incidental.
1 parent 5d46d7e commit d12ae04

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ def _find_git_windows_unix_tools(self, tools_needed):
133133
hives = [winreg.HKEY_LOCAL_MACHINE, winreg.HKEY_CURRENT_USER]
134134
for mask, hive in itertools.product(masks, hives):
135135
try:
136-
with winreg.OpenKey(hive, r"SOFTWARE\GitForWindows", access=winreg.KEY_READ | mask) as key:
136+
with winreg.OpenKey(hive, r"SOFTWARE\GitForWindows", 0,
137+
winreg.KEY_READ | mask) as key:
137138
install_root, _ = winreg.QueryValueEx(key, 'InstallPath')
138139

139140
if not install_root:
@@ -143,7 +144,7 @@ def _find_git_windows_unix_tools(self, tools_needed):
143144
continue
144145

145146
# We found it, stop enumerating.
146-
return candidate_path
147+
return lit.util.to_string(candidate_path)
147148
except:
148149
continue
149150

@@ -168,7 +169,7 @@ def norm(x):
168169
paths = []
169170

170171
# If we are passed a list [a b c], then iterating this list forwards
171-
# and adding each to the beginning would result in b c a. So we
172+
# and adding each to the beginning would result in c b a. So we
172173
# need to iterate in reverse to end up with the original ordering.
173174
for p in reversed(paths_to_add):
174175
# Move it to the front if it already exists, otherwise insert it at the

0 commit comments

Comments
 (0)