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).
@@ -1277,7 +1279,7 @@ def XcodeVersion():
1277
1279
except :
1278
1280
version = CLTVersion ()
1279
1281
if version :
1280
- version = re . match ( r'(\d+\.\d+\.?\d*)' , version ). groups ()[ 0 ]
1282
+ version = "." . join ( version . split ( "." )[: 3 ])
1281
1283
else :
1282
1284
raise GypError ("No Xcode or CLT version detected!" )
1283
1285
# The CLT has no build information, so we return an empty string.
@@ -1322,6 +1324,8 @@ def GetStdoutQuiet(cmdlist):
1322
1324
Raises |GypError| if the command return with a non-zero return code."""
1323
1325
job = subprocess .Popen (cmdlist , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
1324
1326
out = job .communicate ()[0 ]
1327
+ if PY3 :
1328
+ out = out .decode ("utf-8" )
1325
1329
if job .returncode != 0 :
1326
1330
raise GypError ('Error %d running %s' % (job .returncode , cmdlist [0 ]))
1327
1331
return out .rstrip ('\n ' )
@@ -1332,6 +1336,8 @@ def GetStdout(cmdlist):
1332
1336
Raises |GypError| if the command return with a non-zero return code."""
1333
1337
job = subprocess .Popen (cmdlist , stdout = subprocess .PIPE )
1334
1338
out = job .communicate ()[0 ]
1339
+ if PY3 :
1340
+ out = out .decode ("utf-8" )
1335
1341
if job .returncode != 0 :
1336
1342
sys .stderr .write (out + '\n ' )
1337
1343
raise GypError ('Error %d running %s' % (job .returncode , cmdlist [0 ]))
0 commit comments