Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions llvm/utils/lit/lit/LitConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ def _write_message(self, kind, message):
# Step out of _write_message, and then out of wrapper.
f = f.f_back.f_back
file = os.path.abspath(inspect.getsourcefile(f))
if lit.util.pythonize_bool(self.params.get("use_normalized_slashes")):
file = file.replace("\\", "/")
line = inspect.getlineno(f)
sys.stderr.write(
"%s: %s:%d: %s: %s\n" % (self.progname, file, line, kind, message)
Expand Down
49 changes: 40 additions & 9 deletions llvm/utils/lit/lit/TestRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ class ShellEnvironment(object):
we maintain a dir stack for pushd/popd.
"""

def __init__(self, cwd, env, umask=-1, ulimit=None):
def __init__(self, cwd, env, umask=-1, ulimit=None, normalize_slashes=False):
self.cwd = cwd
self.env = dict(env)
self.umask = umask
self.dirStack = []
self.ulimit = ulimit if ulimit else {}
self.normalize_slashes = normalize_slashes

def change_dir(self, newdir):
if os.path.isabs(newdir):
Expand Down Expand Up @@ -725,7 +726,7 @@ def processRedirects(cmd, stdin_source, cmd_shenv, opened_files):
return std_fds


def _expandLateSubstitutions(cmd, arguments, cwd):
def _expandLateSubstitutions(cmd, arguments, cwd, normalize_slashes=False):
for i, arg in enumerate(arguments):
if not isinstance(arg, str):
continue
Expand All @@ -734,6 +735,8 @@ def _replaceReadFile(match):
filePath = match.group(1)
if not os.path.isabs(filePath):
filePath = os.path.join(cwd, filePath)
if normalize_slashes:
filePath = filePath.replace("\\", "/")
try:
with open(filePath) as fileHandle:
return fileHandle.read()
Expand Down Expand Up @@ -817,7 +820,9 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
not_crash = False

# Expand all late substitutions.
args = _expandLateSubstitutions(j, args, cmd_shenv.cwd)
args = _expandLateSubstitutions(
j, args, cmd_shenv.cwd, cmd_shenv.normalize_slashes
)

while True:
if args[0] == "env":
Expand All @@ -828,7 +833,12 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
# env FOO=1 llc < %s | env BAR=2 llvm-mc | FileCheck %s
# env FOO=1 %{another_env_plus_cmd} | FileCheck %s
if cmd_shenv is shenv:
cmd_shenv = ShellEnvironment(shenv.cwd, shenv.env, shenv.umask)
cmd_shenv = ShellEnvironment(
shenv.cwd,
shenv.env,
shenv.umask,
normalize_slashes=shenv.normalize_slashes,
)
args = updateEnv(cmd_shenv, args)
if not args:
# Return the environment variables if no argument is provided.
Expand Down Expand Up @@ -1227,7 +1237,10 @@ def executeScriptInternal(

results = []
timeoutInfo = None
shenv = ShellEnvironment(cwd, test.config.environment)
normalize_slashes = litConfig.params.get("use_normalized_slashes", False)
shenv = ShellEnvironment(
cwd, test.config.environment, normalize_slashes=normalize_slashes
)
shenv.env["LIT_CURRENT_TESTCASE"] = test.getFullName()

exitCode, timeoutInfo = executeShCmd(
Expand Down Expand Up @@ -1526,11 +1539,25 @@ def getDefaultSubstitutions(test, tmpDir, tmpBase, normalize_slashes=False):
substitutions.append(("%{s:basename}", sourceBaseName))
substitutions.append(("%{t:stem}", tmpBaseName))

fs_sep = os.path.sep
if normalize_slashes:
fs_sep = "/"

substitutions.extend(
[
("%{fs-src-root}", pathlib.Path(sourcedir).anchor),
("%{fs-tmp-root}", pathlib.Path(tmpBase).anchor),
("%{fs-sep}", os.path.sep),
(
"%{fs-src-root}",
pathlib.Path(sourcedir).anchor.replace("\\", "/")
if normalize_slashes
else pathlib.Path(sourcedir).anchor,
),
(
"%{fs-tmp-root}",
pathlib.Path(tmpBase).anchor.replace("\\", "/")
if normalize_slashes
else pathlib.Path(tmpBase).anchor,
),
("%{fs-sep}", fs_sep),
]
)

Expand Down Expand Up @@ -2467,7 +2494,11 @@ def executeShTest(
tmpDir, tmpBase = getTempPaths(test)
substitutions = list(extra_substitutions)
substitutions += getDefaultSubstitutions(
test, tmpDir, tmpBase, normalize_slashes=useExternalSh
test,
tmpDir,
tmpBase,
normalize_slashes=useExternalSh
or litConfig.params.get("use_normalized_slashes", False),
)
conditions = {feature: True for feature in test.config.available_features}
script = applySubstitutions(
Expand Down
8 changes: 8 additions & 0 deletions llvm/utils/lit/lit/llvm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def __init__(self, lit_config, config):
self.lit_config.diagnostic_level_enabled("note")
and lit_path_displayed is False
):
if lit.util.pythonize_bool(
self.lit_config.params.get("use_normalized_slashes")
):
path = path.replace("\\", "/")
self.lit_config.note("using lit tools: {}".format(path))
lit_path_displayed = True

Expand Down Expand Up @@ -557,6 +561,10 @@ def use_llvm_tool(

if tool:
tool = os.path.normpath(tool)
if lit.util.pythonize_bool(
self.lit_config.params.get("use_normalized_slashes")
):
tool = tool.replace("\\", "/")
if not quiet:
self.lit_config.note("using {}: {}".format(name, tool))
return tool
Expand Down
13 changes: 10 additions & 3 deletions llvm/utils/lit/tests/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,21 @@ for attribute in ("llvm_tools_dir", "lit_tools_dir"):
# within %{inputs}'s test suites. Thus, %{lit} clears environment variables
# that can affect FileCheck's output. It also includes "--order=lexical -j1"
# to ensure predictable test order, as it is often required for FileCheck
# matches.
# matches. It also specifies "-D use_normalized_slashes={0,1}" to be aligned
# with the slashes in the substitutions (e.g, %t, %p) for Windows since it
# switches between forward slashes and backslashes based on
# LLVM_WINDOWS_PREFER_FORWARD_SLASH build config.
config.substitutions.append(("%{inputs}", "Inputs"))
config.substitutions.append(("%{lit}", "%{lit-no-order-opt} --order=lexical"))
use_normalized_slashes = "0"
if lit.util.pythonize_bool(lit_config.params.get("use_normalized_slashes")):
use_normalized_slashes = "1"
config.substitutions.append(
(
"%{lit-no-order-opt}",
"{env} %{{python}} {lit} -j1".format(
env="env -u FILECHECK_OPTS", lit=os.path.join(lit_path, "lit.py")
"{env} %{{python}} {lit} -j1 -D use_normalized_slashes={use_normalized_slashes}".format(
env="env -u FILECHECK_OPTS", lit=os.path.join(lit_path, "lit.py"),
use_normalized_slashes=use_normalized_slashes,
),
)
)
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/lit/tests/shtest-readfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# TODO(boomanaiden154): This sometimes fails, possibly due to buffers not being flushed.
# ALLOW_RETRIES: 2

# RUN: env LIT_USE_INTERNAL_SHELL=1 not %{lit} -v %{inputs}/shtest-readfile | FileCheck -match-full-lines -DTEMP_PATH=%S%{fs-sep}Inputs%{fs-sep}shtest-readfile%{fs-sep}Output %s
# RUN: env LIT_USE_INTERNAL_SHELL=1 not %{lit} -v %{inputs}/shtest-readfile | FileCheck -match-full-lines -DTEMP_PATH=%/S/Inputs/shtest-readfile/Output %s

# CHECK: -- Testing: 5 tests{{.*}}

Expand Down
5 changes: 5 additions & 0 deletions llvm/utils/llvm-lit/llvm-lit.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ builtin_parameters['config_map'] = config_map
llvm_source_root = path(r'@LLVM_SOURCE_DIR@')
sys.path.insert(0, os.path.join(llvm_source_root, 'utils', 'lit'))

import lit.util

if lit.util.pythonize_bool('@LLVM_WINDOWS_PREFER_FORWARD_SLASH@'):
builtin_parameters['use_normalized_slashes'] = True

if __name__=='__main__':
from lit.main import main
main(builtin_parameters)