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

--HG--
extra : rebase_source : 6f7c5784230bd37b3496b9bb1781e8d342f741b4
This commit is contained in:
Gregory Szorc 2017-07-18 18:06:03 -07:00
Родитель 22586623b5
Коммит c29efbaf05
1 изменённых файлов: 18 добавлений и 1 удалений

Просмотреть файл

@ -22,6 +22,7 @@ def configure_error(message):
# 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')
@ -29,10 +30,26 @@ def configure_error(message):
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: