From c0b92530e90586f0ed3378f2cc4948e98c5d829d Mon Sep 17 00:00:00 2001 From: Christian Moritz Date: Tue, 5 Nov 2019 20:18:33 +0100 Subject: [PATCH] tools: port Python 3 compat patch 19398a4 from node-gyp to gyp original commit: https://github.com/nodejs/node-gyp/commit/19398a4 Refs: https://github.com/nodejs/node-gyp/pull/1890 Co-Authored-By: Christian Clauss --- tools/gyp/pylib/gyp/xcode_emulation.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/gyp/pylib/gyp/xcode_emulation.py b/tools/gyp/pylib/gyp/xcode_emulation.py index 9a58df4782af7e..610f90de21f7c9 100644 --- a/tools/gyp/pylib/gyp/xcode_emulation.py +++ b/tools/gyp/pylib/gyp/xcode_emulation.py @@ -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). @@ -1407,7 +1409,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. @@ -1453,6 +1455,8 @@ def GetStdoutQuiet(cmdlist): 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') @@ -1463,6 +1467,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]))