Bug 1259382 - Make mozbuild.shellutil.quote more useful for e.g. creating printable command lines. r?ted draft
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 05 Apr 2016 08:59:46 +0900
changeset 347602 b5696e24078bcd2f0efbcaac1721c28e541d3fc6
parent 347601 ea248721c757143814f6319be8572a2ed10588f3
child 347603 5375f070368e1244ae0450448a08a83a1b5e7b6a
push id14625
push userbmo:mh+mozilla@glandium.org
push dateTue, 05 Apr 2016 11:59:43 +0000
reviewersted
bugs1259382
milestone48.0a1
Bug 1259382 - Make mozbuild.shellutil.quote more useful for e.g. creating printable command lines. r?ted
build/moz.configure/init.configure
build/moz.configure/old.configure
python/mozbuild/mozbuild/shellutil.py
--- a/build/moz.configure/init.configure
+++ b/build/moz.configure/init.configure
@@ -138,17 +138,17 @@ def add_old_configure_assignment(var, va
         if value is None:
             return
         if value is True:
             assignments.append('%s=1' % var)
         elif value is False:
             assignments.append('%s=' % var)
         else:
             if isinstance(value, (list, tuple)):
-                value = ' '.join(quote(v) for v in value)
+                value = quote(*value)
             assignments.append('%s=%s' % (var, quote(value)))
 
 @template
 def add_old_configure_arg(arg):
     @depends(extra_old_configure_args, arg)
     def add_arg(args, arg):
         if arg:
             args.append(arg)
--- a/build/moz.configure/old.configure
+++ b/build/moz.configure/old.configure
@@ -390,17 +390,17 @@ def old_configure(prepare_configure, ext
     # We also pass it the options from js/moz.configure so that it can pass
     # them down to js/src/configure. Note this list is empty when running
     # js/src/configure, in which case we don't need to pass those options
     # to old-configure since old-configure doesn't handle them anyways.
     if extra_old_configure_args:
         cmd += extra_old_configure_args
 
     # For debugging purpose, in case it's not what we'd expect.
-    log.debug('Running %s', ' '.join(quote(a) for a in cmd))
+    log.debug('Running %s', quote(*cmd))
 
     # Our logging goes to config.log, the same file old.configure uses.
     # We can't share the handle on the file, so close it. We assume nothing
     # beyond this point is going to be interesting to log to config.log from
     # our end, so we don't make the effort to recreate a logging.FileHandler.
     logger = logging.getLogger('moz.configure')
     for handler in logger.handlers:
         if isinstance(handler, logging.FileHandler):
--- a/python/mozbuild/mozbuild/shellutil.py
+++ b/python/mozbuild/mozbuild/shellutil.py
@@ -168,17 +168,17 @@ class _ClineSplitter(object):
 def split(cline):
     '''
     Split the given command line string.
     '''
     s = ESCAPED_NEWLINES_RE.sub('', cline)
     return _ClineSplitter(s).result
 
 
-def quote(s):
+def _quote(s):
     '''Given a string, returns a version that can be used literally on a shell
     command line, enclosing it with single quotes if necessary.
 
     As a special case, if given an int, returns a string containing the int,
     not enclosed in quotes.
     '''
     if type(s) == int:
         return '%d' % s
@@ -189,9 +189,21 @@ def quote(s):
 
     # Single quoted strings can contain any characters unescaped except the
     # single quote itself, which can't even be escaped, so the string needs to
     # be closed, an escaped single quote added, and reopened.
     t = type(s)
     return t("'%s'") % s.replace(t("'"), t("'\\''"))
 
 
+def quote(*strings):
+    '''Given one or more strings, returns a quoted string that can be used
+    literally on a shell command line.
+
+        >>> quote('a', 'b')
+        "a b"
+        >>> quote('a b', 'c')
+        "'a b' c"
+    '''
+    return ' '.join(_quote(s) for s in strings)
+
+
 __all__ = ['MetaCharacterException', 'split', 'quote']