Skip to content

Commit c0b9253

Browse files
chrmoritzcclauss
andcommitted
tools: port Python 3 compat patch 19398a4 from node-gyp to gyp
original commit: nodejs/node-gyp@19398a4 Refs: nodejs/node-gyp#1890 Co-Authored-By: Christian Clauss <[email protected]>
1 parent d855904 commit c0b9253

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tools/gyp/pylib/gyp/xcode_emulation.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import tempfile
2121
from gyp.common import GypError
2222

23+
PY3 = bytes != str
24+
2325
# Populated lazily by XcodeVersion, for efficiency, and to fix an issue when
2426
# "xcodebuild" is called too quickly (it has been found to return incorrect
2527
# version number).
@@ -1407,7 +1409,7 @@ def XcodeVersion():
14071409
except:
14081410
version = CLTVersion()
14091411
if version:
1410-
version = re.match(r'(\d+\.\d+\.?\d*)', version).groups()[0]
1412+
version = ".".join(version.split(".")[:3])
14111413
else:
14121414
raise GypError("No Xcode or CLT version detected!")
14131415
# The CLT has no build information, so we return an empty string.
@@ -1453,6 +1455,8 @@ def GetStdoutQuiet(cmdlist):
14531455
job = subprocess.Popen(cmdlist, stdout=subprocess.PIPE,
14541456
stderr=subprocess.PIPE)
14551457
out = job.communicate()[0]
1458+
if PY3:
1459+
out = out.decode("utf-8")
14561460
if job.returncode != 0:
14571461
raise GypError('Error %d running %s' % (job.returncode, cmdlist[0]))
14581462
return out.rstrip('\n')
@@ -1463,6 +1467,8 @@ def GetStdout(cmdlist):
14631467
Raises |GypError| if the command return with a non-zero return code."""
14641468
job = subprocess.Popen(cmdlist, stdout=subprocess.PIPE)
14651469
out = job.communicate()[0]
1470+
if PY3:
1471+
out = out.decode("utf-8")
14661472
if job.returncode != 0:
14671473
sys.stderr.write(out + '\n')
14681474
raise GypError('Error %d running %s' % (job.returncode, cmdlist[0]))

0 commit comments

Comments
 (0)