Index: llvm/utils/lit/lit/ShCommands.py =================================================================== --- llvm/utils/lit/lit/ShCommands.py +++ llvm/utils/lit/lit/ShCommands.py @@ -48,14 +48,9 @@ return (self.pattern == other.pattern) - def resolve(self, cwd): + def resolve(self): import glob - import os - if os.path.isabs(self.pattern): - abspath = self.pattern - else: - abspath = os.path.join(cwd, self.pattern) - results = glob.glob(abspath) + results = glob.glob(self.pattern) return [self.pattern] if len(results) == 0 else results class Pipeline: Index: llvm/utils/lit/lit/TestRunner.py =================================================================== --- llvm/utils/lit/lit/TestRunner.py +++ llvm/utils/lit/lit/TestRunner.py @@ -32,8 +32,7 @@ Environment variables are not implemented, but cwd tracking is. """ - def __init__(self, cwd, env): - self.cwd = cwd + def __init__(self, env): self.env = dict(env) class TimeoutHelper(object): @@ -142,15 +141,15 @@ return (finalExitCode, timeoutInfo) -def expand_glob(arg, cwd): +def expand_glob(arg): if isinstance(arg, GlobItem): - return arg.resolve(cwd) + return arg.resolve() return [arg] -def expand_glob_expressions(args, cwd): +def expand_glob_expressions(args): result = [args[0]] for arg in args[1:]: - result.extend(expand_glob(arg, cwd)) + result.extend(expand_glob(arg)) return result def quote_windows_command(seq): @@ -248,11 +247,7 @@ if len(cmd.commands[0].args) != 2: 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.realpath(os.path.join(shenv.cwd, newdir)) + os.chdir(newdir) # The cd builtin always succeeds. If the directory does not exist, the # following Popen calls will fail instead. return 0 @@ -272,7 +267,7 @@ # 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) + cmd_shenv = ShellEnvironment(shenv.env) arg_idx = 1 for arg_idx, arg in enumerate(j.args[1:]): # Partition the string into KEY=VALUE. @@ -324,8 +319,7 @@ result = subprocess.PIPE else: if r[2] is None: - redir_filename = None - name = expand_glob(r[0], cmd_shenv.cwd) + name = expand_glob(r[0]) if len(name) != 1: raise InternalShellError(j,"Unsupported: glob in redirect expanded to multiple files") name = name[0] @@ -336,15 +330,13 @@ # "CON" is a special filename for the console. r[2] = open("CON", r[1]) else: - # Make sure relative paths are relative to the cwd. - redir_filename = os.path.join(cmd_shenv.cwd, name) - r[2] = open(redir_filename, r[1]) + r[2] = open(name, r[1]) # Workaround a Win32 and/or subprocess bug when appending. # # FIXME: Actually, this is probably an instance of PR6753. if r[1] == 'a': r[2].seek(0, 2) - opened_files.append(tuple(r) + (redir_filename,)) + opened_files.append(tuple(r) + (name,)) result = r[2] final_redirects.append(result) @@ -371,9 +363,7 @@ executable = None # For paths relative to cwd, use the cwd of the shell environment. if args[0].startswith('.'): - exe_in_cwd = os.path.join(cmd_shenv.cwd, args[0]) - if os.path.isfile(exe_in_cwd): - executable = exe_in_cwd + excutable = args[0] if not executable: executable = lit.util.which(args[0], cmd_shenv.env['PATH']) if not executable: @@ -389,7 +379,7 @@ args[i] = f.name # Expand all glob expressions - args = expand_glob_expressions(args, cmd_shenv.cwd) + args = expand_glob_expressions(args) # On Windows, do our own command line quoting for better compatibility # with some core utility distributions. @@ -397,7 +387,7 @@ args = quote_windows_command(args) try: - procs.append(subprocess.Popen(args, cwd=cmd_shenv.cwd, + procs.append(subprocess.Popen(args, executable = executable, stdin = stdin, stdout = stdout, @@ -517,6 +507,7 @@ return exitCode def executeScriptInternal(test, litConfig, tmpBase, commands, cwd): + os.chdir(cwd) cmds = [] for ln in commands: try: @@ -532,7 +523,7 @@ results = [] timeoutInfo = None try: - shenv = ShellEnvironment(cwd, test.config.environment) + shenv = ShellEnvironment(test.config.environment) exitCode, timeoutInfo = executeShCmd(cmd, shenv, results, timeout=litConfig.maxIndividualTestTime) except InternalShellError: e = sys.exc_info()[1]