Bug 1377216 - Accept environment variables to check_cmd_output; r=glandium
authorGregory Szorc <gps@mozilla.com>
Tue, 18 Jul 2017 18:06:03 -0700
changeset 418766 e9dfbaff0283af804bfdef17cf9140be0c06b940
parent 418765 2582a92759c4f299ed9d7a5b6c99f1ffe13cda99
child 418767 ce73e01ddacb18603453c356e336084da3a61137
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1377216
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1377216 - Accept environment variables to check_cmd_output; r=glandium And include code to work around a bug on older Python versions. MozReview-Commit-ID: 4pBnMQQJOGB
build/moz.configure/util.configure
--- a/build/moz.configure/util.configure
+++ b/build/moz.configure/util.configure
@@ -17,27 +17,44 @@ def configure_error(message):
     Primarily for use in moz.configure templates to sanity check
     their inputs from moz.configure usage.'''
     raise ConfigureError(message)
 
 # A wrapper to obtain a process' output that returns the output generated
 # by running the given command if it exits normally, and streams that
 # output to log.debug and calls die or the given error callback if it
 # does not.
+@imports(_from='__builtin__', _import='unicode')
 @imports('subprocess')
 @imports('sys')
 @imports(_from='mozbuild.configure.util', _import='LineIO')
 @imports(_from='mozbuild.shellutil', _import='quote')
 def check_cmd_output(*args, **kwargs):
     onerror = kwargs.pop('onerror', None)
 
+    # subprocess on older Pythons can't handle unicode keys or values in
+    # environment dicts. Normalize automagically so callers don't have to
+    # deal with this.
+    if 'env' in kwargs:
+        normalized_env = {}
+        for k, v in kwargs['env'].items():
+            if isinstance(k, unicode):
+                k = k.encode('utf-8', 'strict')
+
+            if isinstance(v, unicode):
+                v = v.encode('utf-8', 'strict')
+
+            normalized_env[k] = v
+
+        kwargs['env'] = normalized_env
+
     with log.queue_debug():
         log.debug('Executing: `%s`', quote(*args))
         proc = subprocess.Popen(args, stdout=subprocess.PIPE,
-                                stderr=subprocess.PIPE)
+                                stderr=subprocess.PIPE, **kwargs)
         stdout, stderr = proc.communicate()
         retcode = proc.wait()
         if retcode == 0:
             return stdout
 
         log.debug('The command returned non-zero exit status %d.',
                   retcode)
         for out, desc in ((stdout, 'output'), (stderr, 'error output')):