Index: llvm/docs/CommandGuide/lit.rst =================================================================== --- llvm/docs/CommandGuide/lit.rst +++ llvm/docs/CommandGuide/lit.rst @@ -388,6 +388,7 @@ %S source dir (directory of the file currently being run) %p same as %S %{pathsep} path separator + %[[glob]] A list of all files matching the glob expression, separated by spaces. %t temporary file name unique to the test %T temporary directory unique to the test %% % Index: llvm/test/Other/lit-globbing.ll =================================================================== --- /dev/null +++ llvm/test/Other/lit-globbing.ll @@ -0,0 +1,17 @@ +RUN: echo %[[Foo*]] Bar | FileCheck -check-prefix=NOMATCH %s +RUN: echo Test1 > %T/Test1.txt +RUN: echo Test2 > %T/Test2.txt +RUN: echo Test12 > %T/Test12.txt +RUN: echo %[[%T/Test?.txt]] | FileCheck -check-prefix=MATCH %s +RUN: echo %[[%S/Inputs/glob-input]] | FileCheck -check-prefix=MATCH2 %s +RUN: echo %[[%T/Test1.*]] %[[%T/Test2.*]] %[[%T/Test1.*]] | FileCheck -check-prefix=MATCH3 %s + +NOMATCH-NOT: Foo +NOMATCH: Bar + +MATCH-NOT: Test12.txt +MATCH: {{(Test1.txt.*Test2.txt|Test2.txt.*Test1.txt)}} + +MATCH2: {{.*}}glob-input + +MATCH3: {{.*}}Test1.txt{{.*}}Test2.txt{{.*}}Test1.txt Index: llvm/utils/lit/lit/TestRunner.py =================================================================== --- llvm/utils/lit/lit/TestRunner.py +++ llvm/utils/lit/lit/TestRunner.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +import glob import os, signal, subprocess, sys import re import platform @@ -141,6 +142,24 @@ return (finalExitCode, timeoutInfo) +def expand_glob_expressions(cmd, args): + result = [args[0]] + expr = re.compile(r"%\[\[(.*?)]]") + for arg in args[1:]: + # Search for a glob expression anywhere in the string, but fail if it + # occurs at a non-zero offset or does not constitute the entire + # argument. + m = expr.search(arg) + if m is None: + result.append(arg) + else: + if m.span(0) != (0, len(arg)): + raise InternalShellError(cmd, "Only entire arguments can be globbed") + glob_expr = m.group(1) + matches = glob.glob(glob_expr) + result.extend(matches) + return result + def quote_windows_command(seq): """ Reimplement Python's private subprocess.list2cmdline for MSys compatibility @@ -372,6 +391,9 @@ named_temp_files.append(f.name) args[i] = f.name + # Expand all glob expressions + args = expand_glob_expressions(j, args) + # On Windows, do our own command line quoting for better compatibility # with some core utility distributions. if kIsWindows: