[build] Convert output bytes to UTF-8 in gn_run_binary

The encoding parameter was not available on older versions of python.

Change-Id: I5ba56286d1ec1ac616daaac6006f5e9b0167d01d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195680
Auto-Submit: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
This commit is contained in:
Alexander Thomas 2021-04-16 18:03:06 +00:00 committed by commit-bot@chromium.org
parent 2ab4ef2a13
commit 30127ac12d

View file

@ -21,17 +21,18 @@ import subprocess
# Run a command, swallowing the output unless there is an error. # Run a command, swallowing the output unless there is an error.
def run_command(command): def run_command(command):
try: try:
subprocess.check_output(command, subprocess.check_output(command, stderr=subprocess.STDOUT)
encoding="UTF-8",
stderr=subprocess.STDOUT,
universal_newlines=True)
return 0 return 0
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
return ("Command failed: " + ' '.join(command) + "\n" + "output: " + return ("Command failed: " + ' '.join(command) + "\n" + "output: " +
e.output) _decode(e.output))
except OSError as e: except OSError as e:
return ("Command failed: " + ' '.join(command) + "\n" + "output: " + return ("Command failed: " + ' '.join(command) + "\n" + "output: " +
e.strerror) _decode(e.strerror))
def _decode(bytes):
return bytes.decode("utf-8")
def main(argv): def main(argv):