From 46cc7df98a4dbc84fb2fceff5e590e1ab5a9d11b Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 31 Mar 2017 12:46:39 +0000 Subject: [PATCH] Use the current working directory in the glob expansion This fixes tests that do things like mkdir cd .. *.foo llvm-svn: 299209 --- llvm/utils/lit/lit/ShCommands.py | 9 +++++++-- llvm/utils/lit/lit/TestRunner.py | 12 ++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/llvm/utils/lit/lit/ShCommands.py b/llvm/utils/lit/lit/ShCommands.py index 0c4c205..01e91c5 100644 --- a/llvm/utils/lit/lit/ShCommands.py +++ b/llvm/utils/lit/lit/ShCommands.py @@ -48,9 +48,14 @@ class GlobItem: return (self.pattern == other.pattern) - def resolve(self): + def resolve(self, cwd): import glob - results = glob.glob(self.pattern) + import os + if os.path.isabs(self.pattern): + abspath = self.pattern + else: + abspath = os.path.join(cwd, self.pattern) + results = glob.glob(abspath) return [self.pattern] if len(results) == 0 else results class Pipeline: diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py index 2e6c37c..d3f1c2a 100644 --- a/llvm/utils/lit/lit/TestRunner.py +++ b/llvm/utils/lit/lit/TestRunner.py @@ -142,15 +142,15 @@ def executeShCmd(cmd, shenv, results, timeout=0): return (finalExitCode, timeoutInfo) -def expand_glob(arg): +def expand_glob(arg, cwd): if isinstance(arg, GlobItem): - return arg.resolve() + return arg.resolve(cwd) return [arg] -def expand_glob_expressions(args): +def expand_glob_expressions(args, cwd): result = [args[0]] for arg in args[1:]: - result.extend(expand_glob(arg)) + result.extend(expand_glob(arg, cwd)) return result def quote_windows_command(seq): @@ -325,7 +325,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper): else: if r[2] is None: redir_filename = None - name = expand_glob(r[0]) + name = expand_glob(r[0], cmd_shenv.cwd) if len(name) != 1: raise InternalShellError(j,"Unsupported: glob in redirect expanded to multiple files") name = name[0] @@ -389,7 +389,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper): args[i] = f.name # Expand all glob expressions - args = expand_glob_expressions(args) + args = expand_glob_expressions(args, cmd_shenv.cwd) # On Windows, do our own command line quoting for better compatibility # with some core utility distributions. -- 2.7.4