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. |
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.path | 12 import os.path |
13 import re | 13 import re |
14 import shlex | 14 import shlex |
15 import subprocess | 15 import subprocess |
16 import sys | 16 import sys |
17 from gyp.common import GypError | 17 from gyp.common import GypError |
18 | 18 |
19 class XcodeSettings(object): | 19 class XcodeSettings(object): |
20 """A class that understands the gyp 'xcode_settings' object.""" | 20 """A class that understands the gyp 'xcode_settings' object.""" |
21 | 21 |
22 # Populated lazily by _SdkPath(). Shared by all XcodeSettings, so cached | 22 # Populated lazily by _SdkPath(). Shared by all XcodeSettings, so cached |
23 # at class-level for efficiency. | 23 # at class-level for efficiency. |
24 _sdk_path_cache = {} | 24 _sdk_path_cache = {} |
25 | 25 |
26 # Populated lazily by GetExtraPlistItems(). Shared by all XcodeSettings, so | 26 # Populated lazily by GetExtraPlistItems(). Shared by all XcodeSettings, so |
27 # cached at class-level for efficiency. | 27 # cached at class-level for efficiency. |
28 _plist_cache = {} | 28 _plist_cache = {} |
29 | 29 |
30 # Populated lazily by GetIOSPostbuilds. Shared by all XcodeSettings, so | |
31 # cached at class-level for efficiency. | |
32 _codesigning_key_cache = {} | |
33 | |
30 def __init__(self, spec): | 34 def __init__(self, spec): |
31 self.spec = spec | 35 self.spec = spec |
32 | 36 |
33 self.isIOS = False | 37 self.isIOS = False |
34 | 38 |
35 # Per-target 'xcode_settings' are pushed down into configs earlier by gyp. | 39 # Per-target 'xcode_settings' are pushed down into configs earlier by gyp. |
36 # This means self.xcode_settings[config] always contains all settings | 40 # This means self.xcode_settings[config] always contains all settings |
37 # for that config -- the per-target settings as well. Settings that are | 41 # for that config -- the per-target settings as well. Settings that are |
38 # the same for all configs are implicitly per-target settings. | 42 # the same for all configs are implicitly per-target settings. |
39 self.xcode_settings = {} | 43 self.xcode_settings = {} |
40 configs = spec['configurations'] | 44 configs = spec['configurations'] |
41 for configname, config in configs.iteritems(): | 45 for configname, config in configs.iteritems(): |
42 self.xcode_settings[configname] = config.get('xcode_settings', {}) | 46 self.xcode_settings[configname] = config.get('xcode_settings', {}) |
43 if self.xcode_settings[configname].get('IPHONEOS_DEPLOYMENT_TARGET', | 47 if self.xcode_settings[configname].get('IPHONEOS_DEPLOYMENT_TARGET', |
44 None): | 48 None): |
45 self.isIOS = True | 49 self.isIOS = True |
46 | 50 |
47 # If you need this, speak up at http://crbug.com/122592 | 51 if self.isIOS: |
48 conditional_keys = [key for key in self.xcode_settings[configname] | 52 self._ConvertConditionalKeys(configname) |
49 if key.endswith(']')] | 53 else: |
Nico
2013/10/14 16:54:55
Why else?
justincohen
2013/10/14 16:59:12
I wasn't sure what to do here. I thought it would
Nico
2013/10/14 17:00:07
Sure, but shouldn't you have it for ios builds too
justincohen
2013/10/14 17:01:49
I'll change it not warn for ios/sdk=iphoneos*, but
| |
50 if conditional_keys: | 54 # If you need this, speak up at http://crbug.com/122592 |
51 print 'Warning: Conditional keys not implemented, ignoring:', \ | 55 conditional_keys = [key for key in self.xcode_settings[configname] |
52 ' '.join(conditional_keys) | 56 if key.endswith(']')] |
53 for key in conditional_keys: | 57 if conditional_keys: |
54 del self.xcode_settings[configname][key] | 58 print 'Warning: Conditional keys not implemented, ignoring:', \ |
59 ' '.join(conditional_keys) | |
60 for key in conditional_keys: | |
61 del self.xcode_settings[configname][key] | |
55 | 62 |
56 # This is only non-None temporarily during the execution of some methods. | 63 # This is only non-None temporarily during the execution of some methods. |
57 self.configname = None | 64 self.configname = None |
58 | 65 |
59 # Used by _AdjustLibrary to match .a and .dylib entries in libraries. | 66 # Used by _AdjustLibrary to match .a and .dylib entries in libraries. |
60 self.library_re = re.compile(r'^lib([^/]+)\.(a|dylib)$') | 67 self.library_re = re.compile(r'^lib([^/]+)\.(a|dylib)$') |
61 | 68 |
69 def _ConvertConditionalKeys(self, configname): | |
70 settings = self.xcode_settings[configname] | |
71 conditional_keys = [key for key in settings if key.endswith(']')] | |
72 for key in conditional_keys: | |
73 if key.endswith("[sdk=iphoneos*]") and configname.endswith("iphoneos"): | |
74 new_key = key.split("[")[0] | |
75 settings[new_key] = settings[key] | |
76 del settings[key] | |
77 | |
62 def _Settings(self): | 78 def _Settings(self): |
63 assert self.configname | 79 assert self.configname |
64 return self.xcode_settings[self.configname] | 80 return self.xcode_settings[self.configname] |
65 | 81 |
66 def _Test(self, test_key, cond_key, default): | 82 def _Test(self, test_key, cond_key, default): |
67 return self._Settings().get(test_key, default) == cond_key | 83 return self._Settings().get(test_key, default) == cond_key |
68 | 84 |
69 def _Appendf(self, lst, test_key, format_str, default=None): | 85 def _Appendf(self, lst, test_key, format_str, default=None): |
70 if test_key in self._Settings(): | 86 if test_key in self._Settings(): |
71 lst.append(format_str % str(self._Settings()[test_key])) | 87 lst.append(format_str % str(self._Settings()[test_key])) |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
745 return result | 761 return result |
746 | 762 |
747 def GetTargetPostbuilds(self, configname, output, output_binary, quiet=False): | 763 def GetTargetPostbuilds(self, configname, output, output_binary, quiet=False): |
748 """Returns a list of shell commands that contain the shell commands | 764 """Returns a list of shell commands that contain the shell commands |
749 to run as postbuilds for this target, before the actual postbuilds.""" | 765 to run as postbuilds for this target, before the actual postbuilds.""" |
750 # dSYMs need to build before stripping happens. | 766 # dSYMs need to build before stripping happens. |
751 return ( | 767 return ( |
752 self._GetDebugInfoPostbuilds(configname, output, output_binary, quiet) + | 768 self._GetDebugInfoPostbuilds(configname, output, output_binary, quiet) + |
753 self._GetStripPostbuilds(configname, output_binary, quiet)) | 769 self._GetStripPostbuilds(configname, output_binary, quiet)) |
754 | 770 |
771 def GetIOSPostbuilds(self, configname, output_binary, postbuilds): | |
772 if self.isIOS: | |
773 self.configname = configname | |
774 identity = self._Settings().get('CODE_SIGN_IDENTITY') | |
775 if identity == None: | |
776 return postbuilds | |
777 | |
778 if identity not in XcodeSettings._codesigning_key_cache: | |
779 proc = subprocess.Popen(['security', 'find-identity', '-p', | |
780 'codesigning', '-v'], stdout=subprocess.PIPE) | |
781 output = proc.communicate()[0].strip() | |
782 key_id = None | |
783 for item in output.split("\n"): | |
784 if identity in item: | |
785 assert key_id == None, ( | |
786 "Multiple codesigning identities for identity: %s" % | |
787 identity) | |
788 key = item.split(' ')[1] | |
789 XcodeSettings._codesigning_key_cache[identity] = key | |
790 postbuilds.append( | |
791 "/usr/bin/codesign -v --force --sign %s %s" % | |
792 (XcodeSettings._codesigning_key_cache[identity], output_binary)) | |
793 return postbuilds | |
794 | |
755 def _AdjustLibrary(self, library, config_name=None): | 795 def _AdjustLibrary(self, library, config_name=None): |
756 if library.endswith('.framework'): | 796 if library.endswith('.framework'): |
757 l = '-framework ' + os.path.splitext(os.path.basename(library))[0] | 797 l = '-framework ' + os.path.splitext(os.path.basename(library))[0] |
758 else: | 798 else: |
759 m = self.library_re.match(library) | 799 m = self.library_re.match(library) |
760 if m: | 800 if m: |
761 l = '-l' + m.group(1) | 801 l = '-l' + m.group(1) |
762 else: | 802 else: |
763 l = library | 803 l = library |
764 return l.replace('$(SDKROOT)', self._SdkPath(config_name)) | 804 return l.replace('$(SDKROOT)', self._SdkPath(config_name)) |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1227 new_config_dict['xcode_settings']['SDKROOT'] = 'iphoneos' | 1267 new_config_dict['xcode_settings']['SDKROOT'] = 'iphoneos' |
1228 target_dict['configurations'][new_config_name] = new_config_dict | 1268 target_dict['configurations'][new_config_name] = new_config_dict |
1229 return targets | 1269 return targets |
1230 | 1270 |
1231 def CloneConfigurationForDeviceAndEmulator(target_dicts): | 1271 def CloneConfigurationForDeviceAndEmulator(target_dicts): |
1232 """If |target_dicts| contains any iOS targets, automatically create -iphoneos | 1272 """If |target_dicts| contains any iOS targets, automatically create -iphoneos |
1233 targets for iOS device builds.""" | 1273 targets for iOS device builds.""" |
1234 if _HasIOSTarget(target_dicts): | 1274 if _HasIOSTarget(target_dicts): |
1235 return _AddIOSDeviceConfigurations(target_dicts) | 1275 return _AddIOSDeviceConfigurations(target_dicts) |
1236 return target_dicts | 1276 return target_dicts |
OLD | NEW |