Index: pylib/gyp/xcode_emulation.py |
diff --git a/pylib/gyp/xcode_emulation.py b/pylib/gyp/xcode_emulation.py |
index 30f27d5832d99bd02ede773af5e59ed7c513b127..abeffcc172b4998b3e2a72607cba0237505a625e 100644 |
--- a/pylib/gyp/xcode_emulation.py |
+++ b/pylib/gyp/xcode_emulation.py |
@@ -271,21 +271,13 @@ class XcodeSettings(object): |
# CURRENT_ARCH / NATIVE_ARCH env vars? |
return self.xcode_settings[configname].get('ARCHS', [self._DefaultArch()]) |
- def _GetStdout(self, cmdlist): |
- job = subprocess.Popen(cmdlist, stdout=subprocess.PIPE) |
- out = job.communicate()[0] |
- if job.returncode != 0: |
- sys.stderr.write(out + '\n') |
- raise GypError('Error %d running %s' % (job.returncode, cmdlist[0])) |
- return out.rstrip('\n') |
- |
def _GetSdkVersionInfoItem(self, sdk, infoitem): |
# xcodebuild requires Xcode and can't run on Command Line Tools-only |
# systems from 10.7 onward. |
# Since the CLT has no SDK paths anyway, returning None is the |
# most sensible route and should still do the right thing. |
try: |
- return self._GetStdout(['xcodebuild', '-version', '-sdk', sdk, infoitem]) |
+ return GetStdout(['xcodebuild', '-version', '-sdk', sdk, infoitem]) |
except: |
pass |
@@ -874,64 +866,11 @@ class XcodeSettings(object): |
return libraries |
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 |
+ return GetStdout(['sw_vers', '-buildVersion']) |
def _XcodeVersion(self): |
- # `xcodebuild -version` output looks like |
- # Xcode 4.6.3 |
- # Build version 4H1503 |
- # or like |
- # Xcode 3.2.6 |
- # Component versions: DevToolsCore-1809.0; DevToolsSupport-1806.0 |
- # BuildVersion: 10M2518 |
- # Convert that to '0463', '4H1503'. |
if len(XcodeSettings._xcode_version_cache) == 0: |
- 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) |
- if build: |
- build = build.split()[-1] |
- XcodeSettings._xcode_version_cache = (version, build) |
+ XcodeSettings._xcode_version_cache = XcodeVersion() |
return XcodeSettings._xcode_version_cache |
def _XcodeIOSDeviceFamily(self, configname): |
@@ -989,7 +928,7 @@ class XcodeSettings(object): |
if default_sdk_root: |
return default_sdk_root |
try: |
- all_sdks = self._GetStdout(['xcodebuild', '-showsdks']) |
+ all_sdks = GetStdout(['xcodebuild', '-showsdks']) |
except: |
# If xcodebuild fails, there will be no valid SDKs |
return '' |
@@ -1131,6 +1070,77 @@ class MacPrefixHeader(object): |
] |
+def XcodeVersion(): |
+ """Returns a tuple of version and build version of installed Xcode.""" |
+ # `xcodebuild -version` output looks like |
+ # Xcode 4.6.3 |
+ # Build version 4H1503 |
+ # or like |
+ # Xcode 3.2.6 |
+ # Component versions: DevToolsCore-1809.0; DevToolsSupport-1806.0 |
+ # BuildVersion: 10M2518 |
+ # Convert that to '0463', '4H1503'. |
+ try: |
+ version_list = 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 = 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) |
+ if build: |
+ build = build.split()[-1] |
+ return version, build |
+ |
+ |
+# This function ported from the logic in Homebrew's CLT version check |
+def CLTVersion(): |
+ """Returns the version of command-line tools from pkgutil.""" |
+ # 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 = GetStdout(['/usr/sbin/pkgutil', '--pkg-info', key]) |
+ return re.search(regex, output).groupdict()['version'] |
+ except: |
+ continue |
+ |
+ |
+def GetStdout(cmdlist): |
+ """Returns the content of standard output returned by invoking |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 job.returncode != 0: |
+ sys.stderr.write(out + '\n') |
+ raise GypError('Error %d running %s' % (job.returncode, cmdlist[0])) |
+ return out.rstrip('\n') |
+ |
+ |
def MergeGlobalXcodeSettingsToSpec(global_dict, spec): |
"""Merges the global xcode_settings dictionary into each configuration of the |
target represented by spec. For keys that are both in the global and the local |