[PATCH] D76178: [lit] Recursively apply substitutions
Louis Dionne via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 14 09:39:02 PDT 2020
ldionne created this revision.
Herald added subscribers: llvm-commits, dexonsmith, jkorous, delcypher.
Herald added a project: LLVM.
This allows defining substitutions in terms of other substitutions. For
example, a %build substitution could be defined in terms of a %cxx
substitution as '%cxx %s -o %t.exe' and the script would be properly
expanded.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D76178
Files:
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
@@ -1148,9 +1148,14 @@
return re.compile(r)
def applySubstitutions(script, substitutions):
- """Apply substitutions to the script. Allow full regular expression syntax.
+ """
+ Apply substitutions to the script. Allow full regular expression syntax.
Replace each matching occurrence of regular expression pattern a with
- substitution b in line ln."""
+ substitution b in line ln.
+
+ If a substitution expands into another substitution, it is expanded
+ recursively until the line has no more expandable substitutions.
+ """
def processLine(ln):
# Apply substitutions
for a,b in substitutions:
@@ -1167,9 +1172,17 @@
# Strip the trailing newline and any extra whitespace.
return ln.strip()
+
+ def fullyProcessLine(ln):
+ processed = processLine(ln)
+ while processed != ln:
+ ln = processed
+ processed = processLine(ln)
+ return processed
+
# Note Python 3 map() gives an iterator rather than a list so explicitly
# convert to list before returning.
- return list(map(processLine, script))
+ return list(map(fullyProcessLine, script))
class ParserKind(object):
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76178.250362.patch
Type: text/x-patch
Size: 1395 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200314/245f5e85/attachment.bin>
More information about the llvm-commits
mailing list