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,16 @@ +RUN: echo No%[[Foo*]]Match | 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 Left%[[%T/Test?.txt]]Right | FileCheck -check-prefix=MATCH %s +RUN: echo Left%[[%S/Inputs/glob-input]]Right | FileCheck -check-prefix=MATCH2 %s +RUN: echo Left%[[%T/Test1.*]]%[[%T/Test2.*]]%[[%T/Test1.*]]Right | FileCheck -check-prefix=MATCH3 %s + +NOMATCH: NoMatch + +MATCH-NOT: Test12.txt +MATCH: Left{{.*}}Test1.txt{{.*}}Test2.txtRight + +MATCH2: Left{{.*}}glob-inputRight + +MATCH3: Left{{.*}}Test1.txt{{.*}}Test2.txt{{.*}}Test1.txtRight \ No newline at end of file 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 @@ -734,6 +735,14 @@ b = b.replace("\\","\\\\") ln = re.sub(a, b, ln) + while True: + # First expand any glob expressions. + m = re.search(r"%\[\[(.*?)]]", ln) + if m is None: + break + result = [os.path.normpath(x) for x in glob.glob(m.groups()[0])] + ln = ln.replace(m.group(), " ".join(result)) + # Strip the trailing newline and any extra whitespace. return ln.strip() # Note Python 3 map() gives an iterator rather than a list so explicitly