20
20
import tempfile
21
21
from gyp .common import GypError
22
22
23
+ PY3 = bytes != str
24
+
23
25
# Populated lazily by XcodeVersion, for efficiency, and to fix an issue when
24
26
# "xcodebuild" is called too quickly (it has been found to return incorrect
25
27
# version number).
@@ -1407,7 +1409,7 @@ def XcodeVersion():
1407
1409
except :
1408
1410
version = CLTVersion ()
1409
1411
if version :
1410
- version = re . match ( r'(\d+\.\d+\.?\d*)' , version ). groups ()[ 0 ]
1412
+ version = "." . join ( version . split ( "." )[: 3 ])
1411
1413
else :
1412
1414
raise GypError ("No Xcode or CLT version detected!" )
1413
1415
# The CLT has no build information, so we return an empty string.
@@ -1453,6 +1455,8 @@ def GetStdoutQuiet(cmdlist):
1453
1455
job = subprocess .Popen (cmdlist , stdout = subprocess .PIPE ,
1454
1456
stderr = subprocess .PIPE )
1455
1457
out = job .communicate ()[0 ]
1458
+ if PY3 :
1459
+ out = out .decode ("utf-8" )
1456
1460
if job .returncode != 0 :
1457
1461
raise GypError ('Error %d running %s' % (job .returncode , cmdlist [0 ]))
1458
1462
return out .rstrip ('\n ' )
@@ -1463,6 +1467,8 @@ def GetStdout(cmdlist):
1463
1467
Raises |GypError| if the command return with a non-zero return code."""
1464
1468
job = subprocess .Popen (cmdlist , stdout = subprocess .PIPE )
1465
1469
out = job .communicate ()[0 ]
1470
+ if PY3 :
1471
+ out = out .decode ("utf-8" )
1466
1472
if job .returncode != 0 :
1467
1473
sys .stderr .write (out + '\n ' )
1468
1474
raise GypError ('Error %d running %s' % (job .returncode , cmdlist [0 ]))
0 commit comments