[llvm] d12ae04 - [lit] Fix Python 2/3 compat in new winreg search code

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 12:22:37 PDT 2020


Author: Reid Kleckner
Date: 2020-10-01T12:22:28-07:00
New Revision: d12ae042e17b27ebc8d2b5ae3d8dd5f88384d093

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

LOG: [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.

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 1dbed8e70537..c8013945e3f9 100644
--- a/llvm/utils/lit/lit/llvm/config.py
+++ b/llvm/utils/lit/lit/llvm/config.py
@@ -133,7 +133,8 @@ def _find_git_windows_unix_tools(self, tools_needed):
         hives = [winreg.HKEY_LOCAL_MACHINE, winreg.HKEY_CURRENT_USER]
         for mask, hive in itertools.product(masks, hives):
             try:
-                with winreg.OpenKey(hive, r"SOFTWARE\GitForWindows", access=winreg.KEY_READ | mask) as key:
+                with winreg.OpenKey(hive, r"SOFTWARE\GitForWindows", 0,
+                                    winreg.KEY_READ | mask) as key:
                     install_root, _ = winreg.QueryValueEx(key, 'InstallPath')
 
                     if not install_root:
@@ -143,7 +144,7 @@ def _find_git_windows_unix_tools(self, tools_needed):
                         continue
 
                     # We found it, stop enumerating.
-                    return candidate_path
+                    return lit.util.to_string(candidate_path)
             except:
                 continue
 
@@ -168,7 +169,7 @@ def norm(x):
                 paths = []
 
             # If we are passed a list [a b c], then iterating this list forwards
-            # and adding each to the beginning would result in b c a.  So we
+            # and adding each to the beginning would result in c b a.  So we
             # need to iterate in reverse to end up with the original ordering.
             for p in reversed(paths_to_add):
                 # Move it to the front if it already exists, otherwise insert it at the


        


More information about the llvm-commits mailing list