[PATCH] D30380: Teach lit to expand glob expressions

Zachary Turner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 1 10:50:46 PST 2017


zturner updated this revision to Diff 90208.
zturner added a comment.

Move the globbing closer to the invocation of `subprocess.Popen`.


https://reviews.llvm.org/D30380

Files:
  llvm/docs/CommandGuide/lit.rst
  llvm/test/Other/Inputs/glob-input
  llvm/test/Other/lit-globbing.ll
  llvm/utils/lit/lit/TestRunner.py


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:
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/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
  %%         %


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30380.90208.patch
Type: text/x-patch
Size: 2834 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170301/0ae3899c/attachment.bin>


More information about the llvm-commits mailing list