Skip to content

Commit

Permalink
[lit] Add git usr bin to path automatically. (microsoft#5355)
Browse files Browse the repository at this point in the history
This will avoid test fail when forget to add git usr bin to PATH.

Port from
llvm/llvm-project@0f1f13f
  • Loading branch information
python3kgae authored Jun 29, 2023
1 parent d599cd9 commit 29b55d1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 34 additions & 1 deletion utils/lit/lit/TestingConfig.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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:
""""
Expand All @@ -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',
Expand Down

0 comments on commit 29b55d1

Please sign in to comment.