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
--- 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')):