Skip to content

Commit e610838

Browse files
committed
Fix TypeError in XcodeVersion()
1 parent e6aca7d commit e610838

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

gyp/pylib/gyp/xcode_emulation.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,10 +1263,12 @@ def XcodeVersion():
12631263
# Xcode 3.2.6
12641264
# Component versions: DevToolsCore-1809.0; DevToolsSupport-1806.0
12651265
# BuildVersion: 10M2518
1266-
# Convert that to '0463', '4H1503'.
1266+
# Convert that to ('0463', '4H1503') or ('0326', '10M2518').
12671267
global XCODE_VERSION_CACHE
12681268
if XCODE_VERSION_CACHE:
12691269
return XCODE_VERSION_CACHE
1270+
version = ""
1271+
build = ""
12701272
try:
12711273
version_list = GetStdoutQuiet(['xcodebuild', '-version']).splitlines()
12721274
# In some circumstances xcodebuild exits 0 but doesn't return
@@ -1276,21 +1278,16 @@ def XcodeVersion():
12761278
# checking that version.
12771279
if len(version_list) < 2:
12781280
raise GypError("xcodebuild returned unexpected results")
1279-
except GypError:
1280-
version = CLTVersion()
1281-
if version:
1282-
version = ".".join(version.split(".")[:3])
1283-
else:
1281+
version = version_list[0].split()[-1] # Last word on first line
1282+
build = version_list[-1].split()[-1] # Last word on last line
1283+
except GypError: # Xcode not installed so look for XCode Command Line Tools
1284+
version = CLTVersion() # macOS Catalina returns 11.0.0.0.1.1567737322
1285+
if not version:
12841286
raise GypError("No Xcode or CLT version detected!")
1285-
# The CLT has no build information, so we return an empty string.
1286-
version_list = [version, '']
1287-
version = version_list[0]
1288-
build = version_list[-1]
1289-
# Be careful to convert "4.2" to "0420" and "10.0" to "1000":
1290-
version = format(''.join((version.split()[-1].split('.') + ['0', '0'])[:3]),
1291-
'>04s')
1292-
if build:
1293-
build = build.split()[-1]
1287+
# Be careful to convert "4.2.3" to "0423" and "11.0.0" to "1100":
1288+
version = version.split(".")[:3] # Just major, minor, micro
1289+
version[0] = version[0].zfill(2) # Add a leading zero if major is one digit
1290+
version = ("".join(version) + "00")[:4] # Limit to exactly four characters
12941291
XCODE_VERSION_CACHE = (version, build)
12951292
return XCODE_VERSION_CACHE
12961293

0 commit comments

Comments
 (0)