diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py --- a/llvm/utils/lit/lit/TestRunner.py +++ b/llvm/utils/lit/lit/TestRunner.py @@ -11,6 +11,7 @@ import shutil import tempfile import threading +from pathlib import Path import io @@ -2066,7 +2067,18 @@ return out, err, exitCode, timeoutInfo, status # Create the output directory if it does not already exist. - lit.util.mkdir_p(os.path.dirname(tmpBase)) + outputDir = os.path.dirname(tmpBase) + lit.util.mkdir_p(outputDir) + + # On Windows, copy the required DLLs from PATH into the test directory + # This avoids the loader finding DLLs in C:\Windows\System32 + if litConfig.isWindows: + toolsetDirectory = Path(lit.util.which("cl.exe")).parent + for dllToCopy in itertools.chain(\ + toolsetDirectory.glob('msvcp*.dll'),\ + toolsetDirectory.glob('vcruntime*.dll'),\ + toolsetDirectory.glob('ucrtbase*.dll')): + shutil.copyfile(dllToCopy, os.path.join(outputDir, dllToCopy.name)) # Re-run failed tests up to test.allowed_retries times. execdir = os.path.dirname(test.getExecPath()) diff --git a/llvm/utils/lit/lit/util.py b/llvm/utils/lit/lit/util.py --- a/llvm/utils/lit/lit/util.py +++ b/llvm/utils/lit/lit/util.py @@ -241,10 +241,10 @@ # Get suffixes to search. # On Cygwin, 'PATHEXT' may exist but it should not be used. - if os.pathsep == ";": - pathext = os.environ.get("PATHEXT", "").split(";") + if os.path.splitext(command)[-1] != '' or os.pathsep != ';': + pathext = [''] else: - pathext = [""] + pathext = os.environ.get('PATHEXT', '').split(';') # Search the paths... for path in paths.split(os.pathsep):