Skip to content

Commit a3107ed

Browse files
committed
litsupport changes for windows support
This patch makes changes required in litsupport/* to support running llvm testsuite on windows platform.
1 parent 77418e0 commit a3107ed

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

litsupport/modules/timeit.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
def _mutateCommandLine(context, commandline):
8-
timefile = context.tmpBase + ".time"
8+
timefile = os.path.normpath(context.tmpBase + ".time")
99
config = context.config
1010
cmd = shellcommand.parse(commandline)
1111

@@ -16,24 +16,28 @@ def _mutateCommandLine(context, commandline):
1616
timeit_name = "timeit"
1717
else:
1818
timeit_name = "timeit-target"
19-
timeit = "%s/tools/%s" % (config.test_source_root, timeit_name)
20-
args = ["--limit-core", "0"]
21-
args += ["--limit-cpu", "7200"]
22-
args += ["--timeout", "7200"]
23-
args += ["--limit-file-size", "209715200"]
24-
args += ["--limit-rss-size", "838860800"]
25-
workdir = cmd.workdir
19+
20+
timeit = os.path.normpath("%s/tools/%s" % (config.test_source_root, timeit_name))
21+
args = ["--timeout", "7200"]
22+
if os.name != 'nt':
23+
args += ["--limit-core", "0"]
24+
args += ["--limit-cpu", "7200"]
25+
args += ["--limit-file-size", "209715200"]
26+
args += ["--limit-rss-size", "838860800"]
27+
28+
workdir = os.path.normpath(cmd.workdir) if cmd.workdir is not None else None
29+
2630
if not config.traditional_output:
2731
stdout = cmd.stdout
2832
if cmd.stdout is not None:
2933
if not os.path.isabs(stdout) and workdir is not None:
30-
stdout = os.path.join(workdir, stdout)
34+
stdout = os.path.join(workdir, os.path.normpath(stdout))
3135
args += ["--redirect-stdout", stdout]
3236
cmd.stdout = None
3337
stderr = cmd.stderr
3438
if stderr is not None:
3539
if not os.path.isabs(stderr) and workdir is not None:
36-
stderr = os.path.join(workdir, stderr)
40+
stderr = os.path.join(workdir, os.path.normpath(stderr))
3741
args += ["--redirect-stderr", stderr]
3842
cmd.stderr = None
3943
else:
@@ -42,17 +46,17 @@ def _mutateCommandLine(context, commandline):
4246
"Separate stdout/stderr redirection not "
4347
+ "possible with traditional output"
4448
)
45-
outfile = context.tmpBase + ".out"
49+
outfile = os.path.normpath(context.tmpBase + ".out")
4650
args += ["--append-exitstatus"]
4751
args += ["--redirect-output", outfile]
4852
stdin = cmd.stdin
4953
if stdin is not None:
5054
if not os.path.isabs(stdin) and workdir is not None:
51-
stdin = os.path.join(workdir, stdin)
55+
stdin = os.path.join(workdir, os.path.normpath(stdin))
5256
args += ["--redirect-input", stdin]
5357
cmd.stdin = None
5458
else:
55-
args += ["--redirect-input", "/dev/null"]
59+
args += ["--redirect-input", "/dev/null"] if os.name != 'nt' else []
5660
if workdir is not None:
5761
args += ["--chdir", workdir]
5862
cmd.workdir = None

litsupport/shellcommand.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def parse(commandline):
8888
and will throw an exception if the commandline uses unsupported features.
8989
"""
9090
result = ShellCommand()
91+
commandline = commandline.replace("\\", "/") if os.name == 'nt' else commandline
9192
tokens = shlex.split(commandline)
9293
i = 0
9394
first_word = True

litsupport/testfile.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from litsupport import shellcommand
88
import logging
99

10+
import os
11+
import shlex
1012

1113
def _parseShellCommand(script, ln):
1214
# Trim trailing whitespace.
@@ -18,6 +20,15 @@ def _parseShellCommand(script, ln):
1820
else:
1921
script.append(ln)
2022

23+
def clean_verify_command_for_windows(command_str):
24+
"""Prepares a command string for execution in Windows command line by
25+
formatting paths and arguments."""
26+
# Replace backslashes with forward slashes and split into tokens
27+
tokens = shlex.split(command_str.replace("\\", "/"))
28+
# Enclose each token in double quotes and convert slashes back
29+
tokens_quoted = ['"{}"'.format(token.replace('/', '\\')) for token in tokens]
30+
# Join the tokens into a single command string and return
31+
return ' '.join(tokens_quoted)
2132

2233
def parse(context, filename):
2334
"""Parse a .test file as used in the llvm test-suite.
@@ -77,6 +88,9 @@ def parse(context, filename):
7788
preparescript = applySubstitutions(preparescript, substitutions)
7889
runscript = applySubstitutions(runscript, substitutions)
7990
verifyscript = applySubstitutions(verifyscript, substitutions)
91+
if os.name == 'nt':
92+
verifyscript = [clean_verify_command_for_windows(cmd) for cmd in verifyscript]
93+
8094
metricscripts = {
8195
k: applySubstitutions(v, substitutions) for k, v in metricscripts.items()
8296
}

0 commit comments

Comments
 (0)