Index: pylib/gyp/xcode_emulation.py |
=================================================================== |
--- pylib/gyp/xcode_emulation.py (revision 1825) |
+++ pylib/gyp/xcode_emulation.py (working copy) |
@@ -876,6 +876,27 @@ |
def _BuildMachineOSBuild(self): |
return self._GetStdout(['sw_vers', '-buildVersion']) |
+ # This method ported from the logic in Homebrew's CLT version check |
+ def _CLTVersion(self): |
+ # pkgutil output looks like |
+ # package-id: com.apple.pkg.CLTools_Executables |
+ # version: 5.0.1.0.1.1382131676 |
+ # volume: / |
+ # location: / |
+ # install-time: 1382544035 |
+ # groups: com.apple.FindSystemFiles.pkg-group com.apple.DevToolsBoth.pkg-group com.apple.DevToolsNonRelocatableShared.pkg-group |
+ STANDALONE_PKG_ID = "com.apple.pkg.DeveloperToolsCLILeo" |
+ FROM_XCODE_PKG_ID = "com.apple.pkg.DeveloperToolsCLI" |
+ MAVERICKS_PKG_ID = "com.apple.pkg.CLTools_Executables" |
+ |
+ regex = re.compile('version: (?P<version>.+)') |
+ for key in [MAVERICKS_PKG_ID, STANDALONE_PKG_ID, FROM_XCODE_PKG_ID]: |
+ try: |
+ output = self._GetStdout(['/usr/sbin/pkgutil', '--pkg-info', key]) |
+ return re.search(regex, output).groupdict()['version'] |
+ except: |
+ continue |
+ |
def _XcodeVersion(self): |
# `xcodebuild -version` output looks like |
# Xcode 4.6.3 |
@@ -886,13 +907,30 @@ |
# BuildVersion: 10M2518 |
# Convert that to '0463', '4H1503'. |
if len(XcodeSettings._xcode_version_cache) == 0: |
- version_list = self._GetStdout(['xcodebuild', '-version']).splitlines() |
+ try: |
+ version_list = self._GetStdout(['xcodebuild', '-version']).splitlines() |
+ # In some circumstances xcodebuild exits 0 but doesn't return |
+ # the right results; for example, a user on 10.7 or 10.8 with |
+ # a bogus path set via xcode-select |
+ # In that case this may be a CLT-only install so fall back to |
+ # checking that version. |
+ if len(version_list) < 2: |
+ raise GypError, "xcodebuild returned unexpected results" |
+ except: |
+ version = self._CLTVersion() |
+ if version: |
+ version = re.match('(\d\.\d\.?\d*)', version).groups()[0] |
+ else: |
+ 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) |
- build = build.split()[-1] |
+ if build: |
+ build = build.split()[-1] |
XcodeSettings._xcode_version_cache = (version, build) |
return XcodeSettings._xcode_version_cache |
@@ -950,7 +988,11 @@ |
default_sdk_root = XcodeSettings._sdk_root_cache.get(default_sdk_path) |
if default_sdk_root: |
return default_sdk_root |
- all_sdks = self._GetStdout(['xcodebuild', '-showsdks']) |
+ try: |
+ all_sdks = self._GetStdout(['xcodebuild', '-showsdks']) |
+ except: |
+ # If xcodebuild fails, there will be no valid SDKs |
+ return '' |
for line in all_sdks.splitlines(): |
items = line.split() |
if len(items) >= 3 and items[-2] == '-sdk': |