Skip to content

litsupport changes for windows support #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 17, 2024
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
31 changes: 18 additions & 13 deletions litsupport/modules/timeit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def _mutateCommandLine(context, commandline):
timefile = context.tmpBase + ".time"
timefile = os.path.normpath(context.tmpBase + ".time")
config = context.config
cmd = shellcommand.parse(commandline)

Expand All @@ -16,24 +16,28 @@ def _mutateCommandLine(context, commandline):
timeit_name = "timeit"
else:
timeit_name = "timeit-target"
timeit = "%s/tools/%s" % (config.test_source_root, timeit_name)
args = ["--limit-core", "0"]
args += ["--limit-cpu", "7200"]
args += ["--timeout", "7200"]
args += ["--limit-file-size", "209715200"]
args += ["--limit-rss-size", "838860800"]
workdir = cmd.workdir

timeit = os.path.normpath("%s/tools/%s" % (config.test_source_root, timeit_name))
args = ["--timeout", "7200"]
if os.name != 'nt':
args += ["--limit-core", "0"]
args += ["--limit-cpu", "7200"]
args += ["--limit-file-size", "209715200"]
args += ["--limit-rss-size", "838860800"]

workdir = os.path.normpath(cmd.workdir) if cmd.workdir is not None else None

if not config.traditional_output:
stdout = cmd.stdout
if cmd.stdout is not None:
if not os.path.isabs(stdout) and workdir is not None:
stdout = os.path.join(workdir, stdout)
stdout = os.path.join(workdir, os.path.normpath(stdout))
args += ["--redirect-stdout", stdout]
cmd.stdout = None
stderr = cmd.stderr
if stderr is not None:
if not os.path.isabs(stderr) and workdir is not None:
stderr = os.path.join(workdir, stderr)
stderr = os.path.join(workdir, os.path.normpath(stderr))
args += ["--redirect-stderr", stderr]
cmd.stderr = None
else:
Expand All @@ -42,17 +46,18 @@ def _mutateCommandLine(context, commandline):
"Separate stdout/stderr redirection not "
+ "possible with traditional output"
)
outfile = context.tmpBase + ".out"
outfile = os.path.normpath(context.tmpBase + ".out")
args += ["--append-exitstatus"]
args += ["--redirect-output", outfile]
stdin = cmd.stdin
if stdin is not None:
if not os.path.isabs(stdin) and workdir is not None:
stdin = os.path.join(workdir, stdin)
stdin = os.path.join(workdir, os.path.normpath(stdin))
args += ["--redirect-input", stdin]
cmd.stdin = None
else:
args += ["--redirect-input", "/dev/null"]
if os.name != 'nt':
args += ["--redirect-input", "/dev/null"]
if workdir is not None:
args += ["--chdir", workdir]
cmd.workdir = None
Expand Down
2 changes: 2 additions & 0 deletions litsupport/shellcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def parse(commandline):
and will throw an exception if the commandline uses unsupported features.
"""
result = ShellCommand()
if os.name == 'nt':
commandline = commandline.replace("\\", "/")
tokens = shlex.split(commandline)
i = 0
first_word = True
Expand Down
14 changes: 14 additions & 0 deletions litsupport/testfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from litsupport import shellcommand
import logging

import os
import shlex

def _parseShellCommand(script, ln):
# Trim trailing whitespace.
Expand All @@ -18,6 +20,15 @@ def _parseShellCommand(script, ln):
else:
script.append(ln)

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

def parse(context, filename):
"""Parse a .test file as used in the llvm test-suite.
Expand Down Expand Up @@ -77,6 +88,9 @@ def parse(context, filename):
preparescript = applySubstitutions(preparescript, substitutions)
runscript = applySubstitutions(runscript, substitutions)
verifyscript = applySubstitutions(verifyscript, substitutions)
if os.name == 'nt':
verifyscript = [clean_verify_command_for_windows(cmd) for cmd in verifyscript]

metricscripts = {
k: applySubstitutions(v, substitutions) for k, v in metricscripts.items()
}
Expand Down