From 29b55d138cb4bb72f8d403b9a0f84b288acc2da8 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Thu, 29 Jun 2023 17:20:35 -0400 Subject: [PATCH] [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 --- README.md | 2 +- utils/lit/lit/TestingConfig.py | 35 +++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c8a5c45e1f..8134e0de2e 100644 --- a/README.md +++ b/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 diff --git a/utils/lit/lit/TestingConfig.py b/utils/lit/lit/TestingConfig.py index 68d4f68133..24d7c448a6 100644 --- a/utils/lit/lit/TestingConfig.py +++ b/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 @@ def fromdefaults(litConfig): [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',