Chromium Code Reviews| Index: pylib/gyp/xcode_emulation.py |
| =================================================================== |
| --- pylib/gyp/xcode_emulation.py (revision 1733) |
| +++ pylib/gyp/xcode_emulation.py (working copy) |
| @@ -22,6 +22,10 @@ |
| # at class-level for efficiency. |
| _sdk_path_cache = {} |
| + # Populated lazily by GetExtraPlistItems(). Shared by all XcodeSettings, so |
| + # cached at class-level for efficiency. |
| + _plist_cache = {} |
| + |
| def __init__(self, spec): |
| self.spec = spec |
| @@ -246,17 +250,22 @@ |
| # CURRENT_ARCH / NATIVE_ARCH env vars? |
| return self.xcode_settings[configname].get('ARCHS', ['i386']) |
| - def _GetSdkVersionInfoItem(self, sdk, infoitem): |
| - job = subprocess.Popen(['xcodebuild', '-version', '-sdk', sdk, infoitem], |
| - stdout=subprocess.PIPE) |
| + 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 xcodebuild' % job.returncode) |
| + raise GypError('Error %d running %s' % (job.returncode, cmdlist[0])) |
| return out.rstrip('\n') |
| + def _GetSdkVersionInfoItem(self, sdk, infoitem): |
| + return self._GetStdout(['xcodebuild', '-version', '-sdk', sdk, infoitem]) |
| + |
| + def _SdkRoot(self): |
| + return self.GetPerTargetSetting('SDKROOT', default='') |
| + |
| def _SdkPath(self): |
| - sdk_root = self.GetPerTargetSetting('SDKROOT', default='macosx') |
|
Nico
2013/09/17 22:03:49
Turns out the correct default is just '' apparentl
|
| + sdk_root = self._SdkRoot() |
| if sdk_root.startswith('/'): |
| return sdk_root |
| if sdk_root not in XcodeSettings._sdk_path_cache: |
| @@ -659,12 +668,12 @@ |
| def GetPerTargetSetting(self, setting, default=None): |
| """Tries to get xcode_settings.setting from spec. Assumes that the setting |
| has the same value in all configurations and throws otherwise.""" |
| - first_pass = True |
| + is_first_pass = True |
| result = None |
| for configname in sorted(self.xcode_settings.keys()): |
| - if first_pass: |
| + if is_first_pass: |
| result = self.xcode_settings[configname].get(setting, None) |
| - first_pass = False |
| + is_first_pass = False |
| else: |
| assert result == self.xcode_settings[configname].get(setting, None), ( |
| "Expected per-target setting for '%s', got per-config setting " |
| @@ -752,7 +761,37 @@ |
| libraries = [ self._AdjustLibrary(library) for library in libraries] |
| return libraries |
| + def _BuildMachineOSBuild(self): |
| + return self._GetStdout(['sw_vers', '-buildVersion']) |
| + def _XcodeVersion(self): |
| + # `xcodebuild -version` output looks like |
| + # Xcode 4.6.3 |
| + # Build version 4H1503 |
| + # Convert that to '0463', '4H1503'. |
| + version, build = self._GetStdout(['xcodebuild', '-version']).splitlines() |
| + version = version.split()[-1].replace('.', '').zfill(4) |
| + build = build.split()[-1] |
| + return version, build |
| + |
| + def GetExtraPlistItems(self): |
| + """Returns a dictionary with extra items to insert into Info.plist.""" |
| + if not XcodeSettings._plist_cache: |
| + cache = XcodeSettings._plist_cache |
| + cache['BuildMachineOSBuild'] = self._BuildMachineOSBuild() |
| + |
| + sdk_root = self._SdkRoot() |
| + cache['DTSDKName'] = sdk_root |
| + cache['DTSDKBuild'] = self._GetSdkVersionInfoItem( |
| + sdk_root, 'ProductBuildVersion') |
| + |
| + xcode, xcode_build = self._XcodeVersion() |
| + cache['DTXcode'] = xcode |
| + cache['DTXcodeBuild'] = xcode_build |
| + |
| + return XcodeSettings._plist_cache |
| + |
| + |
| class MacPrefixHeader(object): |
| """A class that helps with emulating Xcode's GCC_PREFIX_HEADER feature. |