OLD | NEW |
---|---|
1 # Copyright (c) 2012 Google Inc. All rights reserved. | 1 # Copyright (c) 2012 Google Inc. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
baxley
2015/11/18 16:46:57
I also got a presubmit warning about not having a
| |
4 | 4 |
5 """ | 5 """ |
6 This module contains classes that help to emulate xcodebuild behavior on top of | 6 This module contains classes that help to emulate xcodebuild behavior on top of |
7 other build systems, such as make and ninja. | 7 other build systems, such as make and ninja. |
8 """ | 8 """ |
9 | 9 |
10 import copy | 10 import copy |
11 import gyp.common | 11 import gyp.common |
12 import os | 12 import os |
13 import os.path | 13 import os.path |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 ['armv7', 'armv7s', 'arm64'])) | 140 ['armv7', 'armv7s', 'arm64'])) |
141 return XCODE_ARCHS_DEFAULT_CACHE | 141 return XCODE_ARCHS_DEFAULT_CACHE |
142 | 142 |
143 | 143 |
144 class XcodeSettings(object): | 144 class XcodeSettings(object): |
145 """A class that understands the gyp 'xcode_settings' object.""" | 145 """A class that understands the gyp 'xcode_settings' object.""" |
146 | 146 |
147 # Populated lazily by _SdkPath(). Shared by all XcodeSettings, so cached | 147 # Populated lazily by _SdkPath(). Shared by all XcodeSettings, so cached |
148 # at class-level for efficiency. | 148 # at class-level for efficiency. |
149 _sdk_path_cache = {} | 149 _sdk_path_cache = {} |
150 _platform_path_cache = {} | |
150 _sdk_root_cache = {} | 151 _sdk_root_cache = {} |
151 | 152 |
152 # Populated lazily by GetExtraPlistItems(). Shared by all XcodeSettings, so | 153 # Populated lazily by GetExtraPlistItems(). Shared by all XcodeSettings, so |
153 # cached at class-level for efficiency. | 154 # cached at class-level for efficiency. |
154 _plist_cache = {} | 155 _plist_cache = {} |
155 | 156 |
156 # Populated lazily by GetIOSPostbuilds. Shared by all XcodeSettings, so | 157 # Populated lazily by GetIOSPostbuilds. Shared by all XcodeSettings, so |
157 # cached at class-level for efficiency. | 158 # cached at class-level for efficiency. |
158 _codesigning_key_cache = {} | 159 _codesigning_key_cache = {} |
159 | 160 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 if test_key in self._Settings(): | 216 if test_key in self._Settings(): |
216 print 'Warning: Ignoring not yet implemented key "%s".' % test_key | 217 print 'Warning: Ignoring not yet implemented key "%s".' % test_key |
217 | 218 |
218 def IsBinaryOutputFormat(self, configname): | 219 def IsBinaryOutputFormat(self, configname): |
219 default = "binary" if self.isIOS else "xml" | 220 default = "binary" if self.isIOS else "xml" |
220 format = self.xcode_settings[configname].get('INFOPLIST_OUTPUT_FORMAT', | 221 format = self.xcode_settings[configname].get('INFOPLIST_OUTPUT_FORMAT', |
221 default) | 222 default) |
222 return format == "binary" | 223 return format == "binary" |
223 | 224 |
224 def _IsBundle(self): | 225 def _IsBundle(self): |
225 return int(self.spec.get('mac_bundle', 0)) != 0 | 226 return int(self.spec.get('mac_bundle', 0)) != 0 or self._IsXCTest() |
227 | |
228 def _IsXCTest(self): | |
229 return int(self.spec.get('mac_xctest_bundle', 0)) != 0 | |
226 | 230 |
227 def _IsIosAppExtension(self): | 231 def _IsIosAppExtension(self): |
228 return int(self.spec.get('ios_app_extension', 0)) != 0 | 232 return int(self.spec.get('ios_app_extension', 0)) != 0 |
229 | 233 |
230 def _IsIosWatchKitExtension(self): | 234 def _IsIosWatchKitExtension(self): |
231 return int(self.spec.get('ios_watchkit_extension', 0)) != 0 | 235 return int(self.spec.get('ios_watchkit_extension', 0)) != 0 |
232 | 236 |
233 def _IsIosWatchApp(self): | 237 def _IsIosWatchApp(self): |
234 return int(self.spec.get('ios_watch_app', 0)) != 0 | 238 return int(self.spec.get('ios_watch_app', 0)) != 0 |
235 | 239 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
431 try: | 435 try: |
432 return GetStdout(['xcodebuild', '-version', '-sdk', sdk, infoitem]) | 436 return GetStdout(['xcodebuild', '-version', '-sdk', sdk, infoitem]) |
433 except: | 437 except: |
434 pass | 438 pass |
435 | 439 |
436 def _SdkRoot(self, configname): | 440 def _SdkRoot(self, configname): |
437 if configname is None: | 441 if configname is None: |
438 configname = self.configname | 442 configname = self.configname |
439 return self.GetPerConfigSetting('SDKROOT', configname, default='') | 443 return self.GetPerConfigSetting('SDKROOT', configname, default='') |
440 | 444 |
445 def _XcodePlatformPath(self, configname=None): | |
446 sdk_root = self._SdkRoot(configname) | |
447 if sdk_root not in XcodeSettings._platform_path_cache: | |
448 platform_path = self._GetSdkVersionInfoItem(sdk_root, 'PlatformPath') | |
449 XcodeSettings._platform_path_cache[sdk_root] = platform_path | |
450 return XcodeSettings._platform_path_cache[sdk_root] | |
451 | |
441 def _SdkPath(self, configname=None): | 452 def _SdkPath(self, configname=None): |
442 sdk_root = self._SdkRoot(configname) | 453 sdk_root = self._SdkRoot(configname) |
443 if sdk_root.startswith('/'): | 454 if sdk_root.startswith('/'): |
444 return sdk_root | 455 return sdk_root |
445 return self._XcodeSdkPath(sdk_root) | 456 return self._XcodeSdkPath(sdk_root) |
446 | 457 |
447 def _XcodeSdkPath(self, sdk_root): | 458 def _XcodeSdkPath(self, sdk_root): |
448 if sdk_root not in XcodeSettings._sdk_path_cache: | 459 if sdk_root not in XcodeSettings._sdk_path_cache: |
449 sdk_path = self._GetSdkVersionInfoItem(sdk_root, 'Path') | 460 sdk_path = self._GetSdkVersionInfoItem(sdk_root, 'Path') |
450 XcodeSettings._sdk_path_cache[sdk_root] = sdk_path | 461 XcodeSettings._sdk_path_cache[sdk_root] = sdk_path |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 if self._Test('GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS', 'YES', | 572 if self._Test('GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS', 'YES', |
562 default='NO'): | 573 default='NO'): |
563 cflags.append('-mssse3') # Note 3rd 's'. | 574 cflags.append('-mssse3') # Note 3rd 's'. |
564 if self._Test('GCC_ENABLE_SSE41_EXTENSIONS', 'YES', default='NO'): | 575 if self._Test('GCC_ENABLE_SSE41_EXTENSIONS', 'YES', default='NO'): |
565 cflags.append('-msse4.1') | 576 cflags.append('-msse4.1') |
566 if self._Test('GCC_ENABLE_SSE42_EXTENSIONS', 'YES', default='NO'): | 577 if self._Test('GCC_ENABLE_SSE42_EXTENSIONS', 'YES', default='NO'): |
567 cflags.append('-msse4.2') | 578 cflags.append('-msse4.2') |
568 | 579 |
569 cflags += self._Settings().get('WARNING_CFLAGS', []) | 580 cflags += self._Settings().get('WARNING_CFLAGS', []) |
570 | 581 |
582 platform_root = self._XcodePlatformPath(configname) | |
583 if platform_root and self._IsXCTest(): | |
584 cflags.append('-F' + platform_root + '/Developer/Library/Frameworks/') | |
585 | |
571 if sdk_root: | 586 if sdk_root: |
572 framework_root = sdk_root | 587 framework_root = sdk_root |
573 else: | 588 else: |
574 framework_root = '' | 589 framework_root = '' |
575 config = self.spec['configurations'][self.configname] | 590 config = self.spec['configurations'][self.configname] |
576 framework_dirs = config.get('mac_framework_dirs', []) | 591 framework_dirs = config.get('mac_framework_dirs', []) |
577 for directory in framework_dirs: | 592 for directory in framework_dirs: |
578 cflags.append('-F' + directory.replace('$(SDKROOT)', framework_root)) | 593 cflags.append('-F' + directory.replace('$(SDKROOT)', framework_root)) |
579 | 594 |
580 self.configname = None | 595 self.configname = None |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
824 ldflags.append('-Wl,-rpath,' + rpath) | 839 ldflags.append('-Wl,-rpath,' + rpath) |
825 | 840 |
826 sdk_root = self._SdkPath() | 841 sdk_root = self._SdkPath() |
827 if not sdk_root: | 842 if not sdk_root: |
828 sdk_root = '' | 843 sdk_root = '' |
829 config = self.spec['configurations'][self.configname] | 844 config = self.spec['configurations'][self.configname] |
830 framework_dirs = config.get('mac_framework_dirs', []) | 845 framework_dirs = config.get('mac_framework_dirs', []) |
831 for directory in framework_dirs: | 846 for directory in framework_dirs: |
832 ldflags.append('-F' + directory.replace('$(SDKROOT)', sdk_root)) | 847 ldflags.append('-F' + directory.replace('$(SDKROOT)', sdk_root)) |
833 | 848 |
849 platform_root = self._XcodePlatformPath(configname) | |
850 if sdk_root and platform_root and self._IsXCTest(): | |
851 ldflags.append('-F' + platform_root + '/Developer/Library/Frameworks/') | |
852 ldflags.append('-framework XCTest') | |
853 | |
834 is_extension = self._IsIosAppExtension() or self._IsIosWatchKitExtension() | 854 is_extension = self._IsIosAppExtension() or self._IsIosWatchKitExtension() |
835 if sdk_root and is_extension: | 855 if sdk_root and is_extension: |
836 # Adds the link flags for extensions. These flags are common for all | 856 # Adds the link flags for extensions. These flags are common for all |
837 # extensions and provide loader and main function. | 857 # extensions and provide loader and main function. |
838 # These flags reflect the compilation options used by xcode to compile | 858 # These flags reflect the compilation options used by xcode to compile |
839 # extensions. | 859 # extensions. |
840 ldflags.append('-lpkstart') | 860 ldflags.append('-lpkstart') |
841 if XcodeVersion() < '0900': | 861 if XcodeVersion() < '0900': |
842 ldflags.append(sdk_root + | 862 ldflags.append(sdk_root + |
843 '/System/Library/PrivateFrameworks/PlugInKit.framework/PlugInKit') | 863 '/System/Library/PrivateFrameworks/PlugInKit.framework/PlugInKit') |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
965 to run as postbuilds for this target, before the actual postbuilds.""" | 985 to run as postbuilds for this target, before the actual postbuilds.""" |
966 # dSYMs need to build before stripping happens. | 986 # dSYMs need to build before stripping happens. |
967 return ( | 987 return ( |
968 self._GetDebugInfoPostbuilds(configname, output, output_binary, quiet) + | 988 self._GetDebugInfoPostbuilds(configname, output, output_binary, quiet) + |
969 self._GetStripPostbuilds(configname, output_binary, quiet)) | 989 self._GetStripPostbuilds(configname, output_binary, quiet)) |
970 | 990 |
971 def _GetIOSPostbuilds(self, configname, output_binary): | 991 def _GetIOSPostbuilds(self, configname, output_binary): |
972 """Return a shell command to codesign the iOS output binary so it can | 992 """Return a shell command to codesign the iOS output binary so it can |
973 be deployed to a device. This should be run as the very last step of the | 993 be deployed to a device. This should be run as the very last step of the |
974 build.""" | 994 build.""" |
975 if not (self.isIOS and self.spec['type'] == 'executable'): | 995 if not (self.isIOS and |
996 (self.spec['type'] == 'executable' or self._IsXCTest())): | |
976 return [] | 997 return [] |
977 | 998 |
978 settings = self.xcode_settings[configname] | 999 settings = self.xcode_settings[configname] |
979 key = self._GetIOSCodeSignIdentityKey(settings) | 1000 key = self._GetIOSCodeSignIdentityKey(settings) |
980 if not key: | 1001 if not key: |
981 return [] | 1002 return [] |
982 | 1003 |
983 # Warn for any unimplemented signing xcode keys. | 1004 # Warn for any unimplemented signing xcode keys. |
984 unimpl = ['OTHER_CODE_SIGN_FLAGS'] | 1005 unimpl = ['OTHER_CODE_SIGN_FLAGS'] |
985 unimpl = set(unimpl) & set(self.xcode_settings[configname].keys()) | 1006 unimpl = set(unimpl) & set(self.xcode_settings[configname].keys()) |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1327 new_settings.update(config['xcode_settings']) | 1348 new_settings.update(config['xcode_settings']) |
1328 config['xcode_settings'] = new_settings | 1349 config['xcode_settings'] = new_settings |
1329 | 1350 |
1330 | 1351 |
1331 def IsMacBundle(flavor, spec): | 1352 def IsMacBundle(flavor, spec): |
1332 """Returns if |spec| should be treated as a bundle. | 1353 """Returns if |spec| should be treated as a bundle. |
1333 | 1354 |
1334 Bundles are directories with a certain subdirectory structure, instead of | 1355 Bundles are directories with a certain subdirectory structure, instead of |
1335 just a single file. Bundle rules do not produce a binary but also package | 1356 just a single file. Bundle rules do not produce a binary but also package |
1336 resources into that directory.""" | 1357 resources into that directory.""" |
1337 is_mac_bundle = (int(spec.get('mac_bundle', 0)) != 0 and flavor == 'mac') | 1358 is_mac_bundle = int(spec.get('mac_xctest_bundle', 0)) != 0 or \ |
1359 (int(spec.get('mac_bundle', 0)) != 0 and flavor == 'mac') | |
1360 | |
1338 if is_mac_bundle: | 1361 if is_mac_bundle: |
1339 assert spec['type'] != 'none', ( | 1362 assert spec['type'] != 'none', ( |
1340 'mac_bundle targets cannot have type none (target "%s")' % | 1363 'mac_bundle targets cannot have type none (target "%s")' % |
1341 spec['target_name']) | 1364 spec['target_name']) |
1342 return is_mac_bundle | 1365 return is_mac_bundle |
1343 | 1366 |
1344 | 1367 |
1345 def GetMacBundleResources(product_dir, xcode_settings, resources): | 1368 def GetMacBundleResources(product_dir, xcode_settings, resources): |
1346 """Yields (output, resource) pairs for every resource in |resources|. | 1369 """Yields (output, resource) pairs for every resource in |resources|. |
1347 Only call this for mac bundle targets. | 1370 Only call this for mac bundle targets. |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1618 if toolset == 'target': | 1641 if toolset == 'target': |
1619 iphoneos_config_dict['xcode_settings']['SDKROOT'] = 'iphoneos' | 1642 iphoneos_config_dict['xcode_settings']['SDKROOT'] = 'iphoneos' |
1620 return targets | 1643 return targets |
1621 | 1644 |
1622 def CloneConfigurationForDeviceAndEmulator(target_dicts): | 1645 def CloneConfigurationForDeviceAndEmulator(target_dicts): |
1623 """If |target_dicts| contains any iOS targets, automatically create -iphoneos | 1646 """If |target_dicts| contains any iOS targets, automatically create -iphoneos |
1624 targets for iOS device builds.""" | 1647 targets for iOS device builds.""" |
1625 if _HasIOSTarget(target_dicts): | 1648 if _HasIOSTarget(target_dicts): |
1626 return _AddIOSDeviceConfigurations(target_dicts) | 1649 return _AddIOSDeviceConfigurations(target_dicts) |
1627 return target_dicts | 1650 return target_dicts |
OLD | NEW |