Skip to content

Commit

Permalink
Decode stdout on Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Sep 25, 2019
1 parent 0a4d8c8 commit 19398a4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion gyp/pylib/gyp/xcode_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import tempfile
from gyp.common import GypError

PY3 = bytes != str

# Populated lazily by XcodeVersion, for efficiency, and to fix an issue when
# "xcodebuild" is called too quickly (it has been found to return incorrect
# version number).
Expand Down Expand Up @@ -1277,7 +1279,7 @@ def XcodeVersion():
except:
version = CLTVersion()
if version:
version = re.match(r'(\d+\.\d+\.?\d*)', version).groups()[0]
version = ".".join(version.split(".")[:3])
else:
raise GypError("No Xcode or CLT version detected!")
# The CLT has no build information, so we return an empty string.
Expand Down Expand Up @@ -1322,6 +1324,8 @@ def GetStdoutQuiet(cmdlist):
Raises |GypError| if the command return with a non-zero return code."""
job = subprocess.Popen(cmdlist, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out = job.communicate()[0]
if PY3:
out = out.decode("utf-8")
if job.returncode != 0:
raise GypError('Error %d running %s' % (job.returncode, cmdlist[0]))
return out.rstrip('\n')
Expand All @@ -1332,6 +1336,8 @@ def GetStdout(cmdlist):
Raises |GypError| if the command return with a non-zero return code."""
job = subprocess.Popen(cmdlist, stdout=subprocess.PIPE)
out = job.communicate()[0]
if PY3:
out = out.decode("utf-8")
if job.returncode != 0:
sys.stderr.write(out + '\n')
raise GypError('Error %d running %s' % (job.returncode, cmdlist[0]))
Expand Down

0 comments on commit 19398a4

Please sign in to comment.