OLD | NEW |
1 # Copyright (c) 2014 Google Inc. All rights reserved. | 1 # Copyright (c) 2014 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 """Xcode-ninja wrapper project file generator. | 5 """Xcode-ninja wrapper project file generator. |
6 | 6 |
7 This updates the data structures passed to the Xcode gyp generator to build | 7 This updates the data structures passed to the Xcode gyp generator to build |
8 with ninja instead. The Xcode project itself is transformed into a list of | 8 with ninja instead. The Xcode project itself is transformed into a list of |
9 executable targets, each with a build step to build with ninja, and a target | 9 executable targets, each with a build step to build with ninja, and a target |
10 with every source and resource file. This appears to sidestep some of the | 10 with every source and resource file. This appears to sidestep some of the |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 new_xcode_settings['CONFIGURATION_BUILD_DIR'], | 105 new_xcode_settings['CONFIGURATION_BUILD_DIR'], |
106 target_name, | 106 target_name, |
107 ], | 107 ], |
108 'message': 'Compile and copy %s via ninja' % target_name, | 108 'message': 'Compile and copy %s via ninja' % target_name, |
109 }, | 109 }, |
110 ] | 110 ] |
111 if jobs > 0: | 111 if jobs > 0: |
112 ninja_target['actions'][0]['action'].extend(('-j', jobs)) | 112 ninja_target['actions'][0]['action'].extend(('-j', jobs)) |
113 return ninja_target | 113 return ninja_target |
114 | 114 |
| 115 def IsValidTargetForWrapper(target_extras, executable_target_pattern, spec): |
| 116 """Limit targets for Xcode wrapper. |
| 117 |
| 118 Xcode sometimes performs poorly with too many targets, so only include |
| 119 proper executable targets, with filters to customize. |
| 120 Arguments: |
| 121 target_extras: Regular expression to always add, matching any target. |
| 122 executable_target_pattern: Regular expression limiting executable targets. |
| 123 spec: Specifications for target. |
| 124 """ |
| 125 target_name = spec.get('target_name') |
| 126 # Always include targets matching target_extras. |
| 127 if target_extras is not None and re.search(target_extras, target_name): |
| 128 return True |
| 129 |
| 130 # Otherwise just show executable targets. |
| 131 if spec.get('type', '') == 'executable' and \ |
| 132 spec.get('product_extension', '') != 'bundle': |
| 133 |
| 134 # If there is a filter and the target does not match, exclude the target. |
| 135 if executable_target_pattern is not None: |
| 136 if not re.search(executable_target_pattern, target_name): |
| 137 return False |
| 138 return True |
| 139 return False |
| 140 |
115 def CreateWrapper(target_list, target_dicts, data, params): | 141 def CreateWrapper(target_list, target_dicts, data, params): |
116 """Initialize targets for the ninja wrapper. | 142 """Initialize targets for the ninja wrapper. |
117 | 143 |
118 This sets up the necessary variables in the targets to generate Xcode projects | 144 This sets up the necessary variables in the targets to generate Xcode projects |
119 that use ninja as an external builder. | 145 that use ninja as an external builder. |
120 Arguments: | 146 Arguments: |
121 target_list: List of target pairs: 'base/base.gyp:base'. | 147 target_list: List of target pairs: 'base/base.gyp:base'. |
122 target_dicts: Dict of target properties keyed on target pair. | 148 target_dicts: Dict of target properties keyed on target pair. |
123 data: Dict of flattened build files keyed on gyp path. | 149 data: Dict of flattened build files keyed on gyp path. |
124 params: Dict of global options for gyp. | 150 params: Dict of global options for gyp. |
(...skipping 16 matching lines...) Expand all Loading... |
141 new_target_dicts = {} | 167 new_target_dicts = {} |
142 new_data = {} | 168 new_data = {} |
143 | 169 |
144 # Set base keys needed for |data|. | 170 # Set base keys needed for |data|. |
145 new_data[main_gyp] = {} | 171 new_data[main_gyp] = {} |
146 new_data[main_gyp]['included_files'] = [] | 172 new_data[main_gyp]['included_files'] = [] |
147 new_data[main_gyp]['targets'] = [] | 173 new_data[main_gyp]['targets'] = [] |
148 new_data[main_gyp]['xcode_settings'] = \ | 174 new_data[main_gyp]['xcode_settings'] = \ |
149 data[orig_gyp].get('xcode_settings', {}) | 175 data[orig_gyp].get('xcode_settings', {}) |
150 | 176 |
| 177 # Normally the xcode-ninja generator includes only valid executable targets. |
| 178 # If |xcode_ninja_executable_target_pattern| is set, that list is reduced to |
| 179 # executable targets that match the pattern. (Default all) |
| 180 executable_target_pattern = \ |
| 181 generator_flags.get('xcode_ninja_executable_target_pattern', None) |
| 182 |
| 183 # For including other non-executable targets, add the matching target name |
| 184 # to the |xcode_ninja_target_pattern| regular expression. (Default none) |
| 185 target_extras = generator_flags.get('xcode_ninja_target_pattern', None) |
| 186 |
151 for old_qualified_target in target_list: | 187 for old_qualified_target in target_list: |
152 spec = target_dicts[old_qualified_target] | 188 spec = target_dicts[old_qualified_target] |
153 if spec.get('type', '') == 'executable' and \ | 189 if IsValidTargetForWrapper(target_extras, executable_target_pattern, spec): |
154 spec.get('product_extension', '') != 'bundle': | |
155 | |
156 # Add to new_target_list. | 190 # Add to new_target_list. |
157 target_name = spec.get('target_name') | 191 target_name = spec.get('target_name') |
158 | |
159 # Filter target names if requested. | |
160 target_filter = generator_flags.get('xcode_ninja_target_filter', None) | |
161 if target_filter is not None: | |
162 if not re.search(target_filter, target_name): | |
163 continue; | |
164 | |
165 new_target_name = '%s:%s#target' % (main_gyp, target_name) | 192 new_target_name = '%s:%s#target' % (main_gyp, target_name) |
166 new_target_list.append(new_target_name) | 193 new_target_list.append(new_target_name) |
167 | 194 |
168 # Add to new_target_dicts. | 195 # Add to new_target_dicts. |
169 new_target_dicts[new_target_name] = _TargetFromSpec(spec, params) | 196 new_target_dicts[new_target_name] = _TargetFromSpec(spec, params) |
170 | 197 |
171 # Add to new_data. | 198 # Add to new_data. |
172 for old_target in data[old_qualified_target.split(':')[0]]['targets']: | 199 for old_target in data[old_qualified_target.split(':')[0]]['targets']: |
173 if old_target['target_name'] == target_name: | 200 if old_target['target_name'] == target_name: |
174 new_data_target = {} | 201 new_data_target = {} |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 new_data[sources_gyp] = {} | 248 new_data[sources_gyp] = {} |
222 new_data[sources_gyp]['targets'] = [] | 249 new_data[sources_gyp]['targets'] = [] |
223 new_data[sources_gyp]['included_files'] = [] | 250 new_data[sources_gyp]['included_files'] = [] |
224 new_data[sources_gyp]['xcode_settings'] = \ | 251 new_data[sources_gyp]['xcode_settings'] = \ |
225 data[orig_gyp].get('xcode_settings', {}) | 252 data[orig_gyp].get('xcode_settings', {}) |
226 new_data[sources_gyp]['targets'].append(new_data_target) | 253 new_data[sources_gyp]['targets'].append(new_data_target) |
227 | 254 |
228 # Write workspace to file. | 255 # Write workspace to file. |
229 _WriteWorkspace(main_gyp, sources_gyp) | 256 _WriteWorkspace(main_gyp, sources_gyp) |
230 return (new_target_list, new_target_dicts, new_data) | 257 return (new_target_list, new_target_dicts, new_data) |
OLD | NEW |