Unverified 提交 68103bd1 authored 作者: Rocky LUO's avatar Rocky LUO 提交者: GitHub

fix CLT version detect exception (#410)

上级 40b089cb
...@@ -1394,6 +1394,8 @@ def XcodeVersion(): ...@@ -1394,6 +1394,8 @@ def XcodeVersion():
global XCODE_VERSION_CACHE global XCODE_VERSION_CACHE
if XCODE_VERSION_CACHE: if XCODE_VERSION_CACHE:
return XCODE_VERSION_CACHE return XCODE_VERSION_CACHE
version = ""
build = ""
try: try:
version_list = GetStdout(['xcodebuild', '-version']).splitlines() version_list = GetStdout(['xcodebuild', '-version']).splitlines()
# In some circumstances xcodebuild exits 0 but doesn't return # In some circumstances xcodebuild exits 0 but doesn't return
...@@ -1403,21 +1405,16 @@ def XcodeVersion(): ...@@ -1403,21 +1405,16 @@ def XcodeVersion():
# checking that version. # checking that version.
if len(version_list) < 2: if len(version_list) < 2:
raise GypError("xcodebuild returned unexpected results") raise GypError("xcodebuild returned unexpected results")
except: version = version_list[0].split()[-1] # Last word on first line
version = CLTVersion() build = version_list[-1].split()[-1] # Last word on last line
if version: except GypError: # Xcode not installed so look for XCode Command Line Tools
version = re.match(r'(\d\.\d\.?\d*)', version).groups()[0] version = CLTVersion() # macOS Catalina returns 11.0.0.0.xxx or 11.5
else: if not version:
raise GypError("No Xcode or CLT version detected!") raise GypError("No Xcode or CLT version detected!")
# The CLT has no build information, so we return an empty string. # Be careful to convert "4.2" to "0420" and "11.0.0" to "1100":
version_list = [version, ''] version = version.split(".")[:3] # Just major, minor, micro
version = version_list[0] version[0] = version[0].zfill(2) # Add a leading zero if major is one digit
build = version_list[-1] version = ("".join(version) + "00")[:4] # Limit to exactly four characters
# 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]
XCODE_VERSION_CACHE = (version, build) XCODE_VERSION_CACHE = (version, build)
return XCODE_VERSION_CACHE return XCODE_VERSION_CACHE
...@@ -1444,6 +1441,12 @@ def CLTVersion(): ...@@ -1444,6 +1441,12 @@ def CLTVersion():
except: except:
continue 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): def GetStdout(cmdlist):
"""Returns the content of standard output returned by invoking |cmdlist|. """Returns the content of standard output returned by invoking |cmdlist|.
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论