summaryrefslogtreecommitdiff
path: root/buildstream
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-03-01 10:35:15 +0000
committerbst-marge-bot <marge-bot@buildstream.build>2019-03-01 20:58:29 +0000
commit5264b9093876a595d9c69892c5124f2fc55804e6 (patch)
tree41295665dfa216377f40baa93076ff6b58ef23ad /buildstream
parentd223c8f416aa5fe7fdf805baccf5a33e2a6c9992 (diff)
downloadbuildstream-5264b9093876a595d9c69892c5124f2fc55804e6.tar.gz
Let subprocess decode stdout based on localebschubert/no-subprocess-decode
Subprocesses can return decoded strings if we give them a "universal_newlines=True" argument. We can therefore offload that to them, and not explicitly decode output ourselves. This also fixes multiple bugs where we would not be respecting the locale used by the user, and in some cases force it to "ascii".
Diffstat (limited to 'buildstream')
-rw-r--r--buildstream/_platform/linux.py3
-rw-r--r--buildstream/utils.py6
2 files changed, 2 insertions, 7 deletions
diff --git a/buildstream/_platform/linux.py b/buildstream/_platform/linux.py
index 702059a5d..85e810c26 100644
--- a/buildstream/_platform/linux.py
+++ b/buildstream/_platform/linux.py
@@ -143,8 +143,7 @@ class Linux(Platform):
'--unshare-user',
'--uid', '0', '--gid', '0',
whoami,
- ])
- output = output.decode('UTF-8').strip()
+ ], universal_newlines=True).strip()
except subprocess.CalledProcessError:
output = ''
diff --git a/buildstream/utils.py b/buildstream/utils.py
index a4e161ed4..2960348e9 100644
--- a/buildstream/utils.py
+++ b/buildstream/utils.py
@@ -1122,14 +1122,10 @@ def _call(*popenargs, terminate=False, **kwargs):
with _signals.suspendable(suspend_proc, resume_proc), _signals.terminator(kill_proc):
process = subprocess.Popen( # pylint: disable=subprocess-popen-preexec-fn
- *popenargs, preexec_fn=preexec_fn, **kwargs)
+ *popenargs, preexec_fn=preexec_fn, universal_newlines=True, **kwargs)
output, _ = process.communicate()
exit_code = process.poll()
- # Program output is returned as bytes, we want utf8 strings
- if output is not None:
- output = output.decode('UTF-8')
-
return (exit_code, output)