Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix CLT/xcode version detection exception #413

Merged
merged 1 commit into from
Jun 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions worker/deps/gyp/pylib/gyp/xcode_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,8 @@ def XcodeVersion():
global XCODE_VERSION_CACHE
if XCODE_VERSION_CACHE:
return XCODE_VERSION_CACHE
version = ""
build = ""
try:
version_list = GetStdout(['xcodebuild', '-version']).splitlines()
# In some circumstances xcodebuild exits 0 but doesn't return
Expand All @@ -1405,21 +1407,16 @@ def XcodeVersion():
# checking that version.
if len(version_list) < 2:
raise GypError("xcodebuild returned unexpected results")
except:
version = CLTVersion()
if version:
version = re.match(r'(\d\.\d\.?\d*)', version).groups()[0]
else:
version = version_list[0].split()[-1] # Last word on first line
build = version_list[-1].split()[-1] # Last word on last line
except GypError: # Xcode not installed so look for CLT
version = CLTVersion() # OS X 10.15 may returns 11.0.0.0.xxx or 11.5
if not version:
raise GypError("No Xcode or CLT version detected!")
# The CLT has no build information, so we return an empty string.
version_list = [version, '']
version = version_list[0]
build = version_list[-1]
# Be careful to convert "4.2" to "0420":
version = version.split()[-1].replace('.', '')
version = (version + '0' * (3 - len(version))).zfill(4)
if build:
build = build.split()[-1]
# Be careful to convert "4.2" to "0420" and "11.0.0" to "1100":
version = version.split(".")[:3] # Just major, minor, micro
version[0] = version[0].zfill(2) # Add a leading zero if major is one digit
version = ("".join(version) + "00")[:4] # Limit to exactly four characters
XCODE_VERSION_CACHE = (version, build)
return XCODE_VERSION_CACHE

Expand All @@ -1446,6 +1443,12 @@ def CLTVersion():
except:
continue

regex = re.compile('Command Line Tools for Xcode\s+(?P<version>\S+)')
try:
output = GetStdout(['/usr/sbin/softwareupdate', '--history'])
return re.search(regex, output).groupdict()['version']
except (GypError, OSError):
return None

def GetStdout(cmdlist):
"""Returns the content of standard output returned by invoking |cmdlist|.
Expand Down