ソースを参照

[lit] Add git usr bin to path automatically. (#5355)

This will avoid test fail when forget to add git usr bin to PATH.

Port from
https://github.com/llvm/llvm-project/commit/0f1f13fcb17fbc8c93d505da989a04ab5cbd9ed3
Xiang Li 2 年 前
コミット
29b55d138c
2 ファイル変更35 行追加2 行削除
  1. 1 1
      README.md
  2. 34 1
      utils/lit/lit/TestingConfig.py

+ 1 - 1
README.md

@@ -65,7 +65,7 @@ Building on windows additionally requires:
 
 Before you build, you will need to have some additional software installed. This is the most straightforward path - see [Building Sources](https://github.com/microsoft/DirectXShaderCompiler/wiki/Building-Sources) on the Wiki for more options, including Visual Studio 2015 and Ninja support.
 
-* [Git](http://git-scm.com/downloads) - On Windows the Git command line tools must be added to the PATH in order to successfully build and test DXC.
+* [Git](http://git-scm.com/downloads).
 * [Python](https://www.python.org/downloads/) - version 3.x is required
 * [Visual Studio 2019](https://www.visualstudio.com/downloads) - select the following workloads: 
     * Universal Windows Platform Development

+ 34 - 1
utils/lit/lit/TestingConfig.py

@@ -1,6 +1,8 @@
 import os
 import sys
 import platform
+import itertools
+import lit.util
 
 OldPy = sys.version_info[0] == 2 and sys.version_info[1] < 7
 
@@ -11,6 +13,33 @@ def strip_dxil_validator_path(env_path):
         if not os.path.isfile(os.path.join(p, dxil_name))
         ])
 
+def _find_git_windows_unix_tools(tools_needed):
+    assert(sys.platform == 'win32')
+    if sys.version_info.major >= 3:
+        import winreg
+    else:
+        import _winreg as winreg
+
+    # Search both the 64 and 32-bit hives, as well as HKLM + HKCU
+    masks = [0, winreg.KEY_WOW64_64KEY]
+    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", 0,
+                                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 lit.util.to_string(candidate_path)
+        except:
+            continue
+    raise(f"fail to find {tools_needed} which are required for DXC tests")
 
 class TestingConfig:
     """"
@@ -32,7 +61,11 @@ class TestingConfig:
                                      [os.environ.get('PATH','')])
 
         all_path = strip_dxil_validator_path(all_path)
-
+        if sys.platform == 'win32':
+            required_tools = [
+                'cmp.exe', 'grep.exe', 'sed.exe', 'diff.exe', 'echo.exe', 'ls.exe']
+            path = _find_git_windows_unix_tools(required_tools)
+            all_path = f"{path};{all_path}"
         environment = {
             'PATH' : all_path,
             'LLVM_DISABLE_CRASH_REPORT' : '1',