[PATCH] D83894: [lit] Don't expand escapes until all substitutions have been applied

Sergej Jaskiewicz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 15 11:50:35 PDT 2020


broadwaylamb updated this revision to Diff 278265.
broadwaylamb added a comment.

Address the review comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83894/new/

https://reviews.llvm.org/D83894

Files:
  llvm/utils/lit/lit/TestRunner.py
  llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/escaping/lit.cfg
  llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/escaping/test.py
  llvm/utils/lit/tests/shtest-recursive-substitution.py


Index: llvm/utils/lit/tests/shtest-recursive-substitution.py
===================================================================
--- llvm/utils/lit/tests/shtest-recursive-substitution.py
+++ llvm/utils/lit/tests/shtest-recursive-substitution.py
@@ -21,3 +21,7 @@
 
 # RUN: %{lit} -j 1 %{inputs}/shtest-recursive-substitution/set-to-none --show-all | FileCheck --check-prefix=CHECK-TEST6 %s
 # CHECK-TEST6: PASS: set-to-none :: test.py
+
+# RUN: %{lit} -j 1 %{inputs}/shtest-recursive-substitution/escaping --show-all | FileCheck --check-prefix=CHECK-TEST7 %s
+# CHECK-TEST7: PASS: escaping :: test.py
+# CHECK-TEST7: $ "echo" "%s" "%%s"
Index: llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/escaping/test.py
===================================================================
--- /dev/null
+++ llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/escaping/test.py
@@ -0,0 +1 @@
+# RUN: echo %%s %%%%s
Index: llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/escaping/lit.cfg
===================================================================
--- /dev/null
+++ llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/escaping/lit.cfg
@@ -0,0 +1,8 @@
+import lit.formats
+config.name = 'escaping'
+config.suffixes = ['.py']
+config.test_format = lit.formats.ShTest()
+config.test_source_root = None
+config.test_exec_root = None
+
+config.recursiveExpansionLimit = 5
Index: llvm/utils/lit/lit/TestRunner.py
===================================================================
--- llvm/utils/lit/lit/TestRunner.py
+++ llvm/utils/lit/lit/TestRunner.py
@@ -1081,9 +1081,7 @@
         tmpDir = tmpDir.replace('\\', '/')
         tmpBase = tmpBase.replace('\\', '/')
 
-    # We use #_MARKER_# to hide %% while we do the other substitutions.
     substitutions = []
-    substitutions.extend([('%%', '#_MARKER_#')])
     substitutions.extend(test.config.substitutions)
     tmpName = tmpBase + '.tmp'
     baseName = os.path.basename(tmpBase)
@@ -1093,8 +1091,7 @@
                           ('%{pathsep}', os.pathsep),
                           ('%t', tmpName),
                           ('%basename_t', baseName),
-                          ('%T', tmpDir),
-                          ('#_MARKER_#', '%')])
+                          ('%T', tmpDir)])
 
     # "%/[STpst]" should be normalized.
     substitutions.extend([
@@ -1159,6 +1156,14 @@
     `recursion_limit` times, it is an error. If the `recursion_limit` is
     `None` (the default), no recursive substitution is performed at all.
     """
+
+    # We use #_MARKER_# to hide %% while we do the other substitutions.
+    def escape(ln):
+        return _caching_re_compile('%%').sub('#_MARKER_#', ln)
+
+    def unescape(ln):
+        return _caching_re_compile('#_MARKER_#').sub('%', ln)
+
     def processLine(ln):
         # Apply substitutions
         for a,b in substitutions:
@@ -1193,10 +1198,9 @@
 
         return processed
 
-    # Note Python 3 map() gives an iterator rather than a list so explicitly
-    # convert to list before returning.
     process = processLine if recursion_limit is None else processLineToFixedPoint
-    return list(map(process, script))
+    
+    return list([unescape(process(escape(ln))) for ln in script])
 
 
 class ParserKind(object):


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83894.278265.patch
Type: text/x-patch
Size: 3264 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200715/0ea72926/attachment.bin>


More information about the llvm-commits mailing list