summaryrefslogtreecommitdiffstats
path: root/llvm/utils/lit
diff options
context:
space:
mode:
authorReid Kleckner <reid@kleckner.net>2015-07-20 19:42:08 +0000
committerReid Kleckner <reid@kleckner.net>2015-07-20 19:42:08 +0000
commitedd9b6ef36f8f9f480eb3e72d6eb9794ef0ef656 (patch)
treeba99779b6d529446603cd44aeab43a306f6a26b4 /llvm/utils/lit
parent1aa4567712ba897ce8aaf3573aa85f40fc375c44 (diff)
downloadbcm5719-llvm-edd9b6ef36f8f9f480eb3e72d6eb9794ef0ef656.tar.gz
bcm5719-llvm-edd9b6ef36f8f9f480eb3e72d6eb9794ef0ef656.zip
[lit] Implement 'env' in the internal shell
The MSys 2 version of 'env' cannot be used to set 'TZ' in the environment due to some portability hacks in the process spawning compatibility layer[1]. This affects test/Object/archive-toc.test, which tries to set TZ in the environment. Other than that, this saves a subprocess invocation of a small unix utility, which is makes the tests faster. The internal shell does not support shell variable expansion, so this idiom in the ASan tests isn't supported yet: RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:opt=1 ... [1] https://github.com/Alexpux/MSYS2-packages/issues/294 Differential Revision: http://reviews.llvm.org/D11350 llvm-svn: 242696
Diffstat (limited to 'llvm/utils/lit')
-rw-r--r--llvm/utils/lit/lit/TestRunner.py35
1 files changed, 28 insertions, 7 deletions
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 70382b472f5..dac06582e14 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -31,7 +31,7 @@ class ShellEnvironment(object):
def __init__(self, cwd, env):
self.cwd = cwd
- self.env = env
+ self.env = dict(env)
def executeShCmd(cmd, shenv, results):
if isinstance(cmd, ShUtil.Seq):
@@ -62,14 +62,18 @@ def executeShCmd(cmd, shenv, results):
# Handle shell builtins first.
if cmd.commands[0].args[0] == 'cd':
- # Update the cwd in the environment.
+ if len(cmd.commands) != 1:
+ raise ValueError("'cd' cannot be part of a pipeline")
if len(cmd.commands[0].args) != 2:
- raise ValueError('cd supports only one argument')
+ raise ValueError("'cd' supports only one argument")
newdir = cmd.commands[0].args[1]
+ # Update the cwd in the parent environment.
if os.path.isabs(newdir):
shenv.cwd = newdir
else:
shenv.cwd = os.path.join(shenv.cwd, newdir)
+ # The cd builtin always succeeds. If the directory does not exist, the
+ # following Popen calls will fail instead.
return 0
procs = []
@@ -81,6 +85,23 @@ def executeShCmd(cmd, shenv, results):
# output. This is null until we have seen some output using
# stderr.
for i,j in enumerate(cmd.commands):
+ # Reference the global environment by default.
+ cmd_shenv = shenv
+ if j.args[0] == 'env':
+ # Create a copy of the global environment and modify it for this one
+ # command. There might be multiple envs in a pipeline:
+ # env FOO=1 llc < %s | env BAR=2 llvm-mc | FileCheck %s
+ cmd_shenv = ShellEnvironment(shenv.cwd, shenv.env)
+ arg_idx = 1
+ for arg_idx, arg in enumerate(j.args[1:]):
+ # Partition the string into KEY=VALUE.
+ key, eq, val = arg.partition('=')
+ # Stop if there was no equals.
+ if eq == '':
+ break
+ cmd_shenv.env[key] = val
+ j.args = j.args[arg_idx+1:]
+
# Apply the redirections, we use (N,) as a sentinel to indicate stdin,
# stdout, stderr for N equal to 0, 1, or 2 respectively. Redirects to or
# from a file are represented with a list [file, mode, file-object]
@@ -126,7 +147,7 @@ def executeShCmd(cmd, shenv, results):
r[2] = tempfile.TemporaryFile(mode=r[1])
else:
# Make sure relative paths are relative to the cwd.
- redir_filename = os.path.join(shenv.cwd, r[0])
+ redir_filename = os.path.join(cmd_shenv.cwd, r[0])
r[2] = open(redir_filename, r[1])
# Workaround a Win32 and/or subprocess bug when appending.
#
@@ -157,7 +178,7 @@ def executeShCmd(cmd, shenv, results):
# Resolve the executable path ourselves.
args = list(j.args)
- executable = lit.util.which(args[0], shenv.env['PATH'])
+ executable = lit.util.which(args[0], cmd_shenv.env['PATH'])
if not executable:
raise InternalShellError(j, '%r: command not found' % j.args[0])
@@ -171,12 +192,12 @@ def executeShCmd(cmd, shenv, results):
args[i] = f.name
try:
- procs.append(subprocess.Popen(args, cwd=shenv.cwd,
+ procs.append(subprocess.Popen(args, cwd=cmd_shenv.cwd,
executable = executable,
stdin = stdin,
stdout = stdout,
stderr = stderr,
- env = shenv.env,
+ env = cmd_shenv.env,
close_fds = kUseCloseFDs))
except OSError as e:
raise InternalShellError(j, 'Could not create process due to {}'.format(e))
OpenPOWER on IntegriCloud