diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py --- a/llvm/utils/lit/lit/TestRunner.py +++ b/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):