[PATCH] D55024: [lit] Fix tool substitution when paths or arguments contain spaces

Zachary Turner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 28 13:35:06 PST 2018


zturner created this revision.
zturner added reviewers: rnk, stella.stamenova.
Herald added a subscriber: delcypher.

If you try to substitute a path or argument with spaces in it, this would lead to an invalid substitution.  This should fix it.


https://reviews.llvm.org/D55024

Files:
  llvm/utils/lit/lit/llvm/subst.py


Index: llvm/utils/lit/lit/llvm/subst.py
===================================================================
--- llvm/utils/lit/lit/llvm/subst.py
+++ llvm/utils/lit/lit/llvm/subst.py
@@ -1,5 +1,6 @@
 import os
 import re
+import sys
 
 import lit.util
 
@@ -118,8 +119,25 @@
             command_str = str(self.command)
 
         if command_str:
+            args = [command_str]
             if self.extra_args:
-                command_str = ' '.join([command_str] + self.extra_args)
+                args = args + self.extra_args
+
+            # This isn't intended to be perfect, as doing so is more trouble
+            # than it's worth.  We just want to catch strings with unquoted
+            # spaces, since that is the use case that comes up the most
+            # frequently.  However, as the user might explicitly quote them,
+            # we do try to avoid quoting already quoted strings.
+            def quote(x):
+                if ' ' not in x:
+                    return x
+                quote_ch = '"' if sys.platform == 'win32' else "'"
+                if x[0] != quote_ch:
+                    x = quote_ch + x
+                if x[-1] != quote_ch:
+                    x = x + quote_ch
+                return x
+            command_str = ' '.join(quote(x) for x in args)
         else:
             if self.unresolved == 'warn':
                 # Warn, but still provide a substitution.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55024.175760.patch
Type: text/x-patch
Size: 1423 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181128/7490f4c4/attachment.bin>


More information about the llvm-commits mailing list