OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2010 Google Inc. All rights reserved. | 3 # Copyright (c) 2010 Google Inc. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 import filecmp | 7 import filecmp |
8 import gyp.common | 8 import gyp.common |
9 import gyp.xcodeproj_file | 9 import gyp.xcodeproj_file |
10 import errno | 10 import errno |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 if xcode_target.support_target: | 218 if xcode_target.support_target: |
219 support_targets.append(xcode_target.support_target) | 219 support_targets.append(xcode_target.support_target) |
220 targets.append(xcode_target.support_target) | 220 targets.append(xcode_target.support_target) |
221 | 221 |
222 if not int(target.get('suppress_wildcard', False)): | 222 if not int(target.get('suppress_wildcard', False)): |
223 targets_for_all.append(xcode_target) | 223 targets_for_all.append(xcode_target) |
224 | 224 |
225 if target_name.lower() == 'all': | 225 if target_name.lower() == 'all': |
226 has_custom_all = True; | 226 has_custom_all = True; |
227 | 227 |
228 # If this target has a 'run_as' attribute, or is a test, add its | 228 # If this target has a 'run_as' attribute, add its target to the |
229 # target to the targets, and (if it's a test) add it the to the | 229 # targets, and add it to the test targets. |
230 # test targets. | 230 if target.get('run_as'): |
231 is_test = int(target.get('test', 0)) | |
232 if target.get('run_as') or is_test: | |
233 # Make a target to run something. It should have one | 231 # Make a target to run something. It should have one |
234 # dependency, the parent xcode target. | 232 # dependency, the parent xcode target. |
235 xccl = CreateXCConfigurationList(configurations) | 233 xccl = CreateXCConfigurationList(configurations) |
236 run_target = gyp.xcodeproj_file.PBXAggregateTarget({ | 234 run_target = gyp.xcodeproj_file.PBXAggregateTarget({ |
237 'name': 'Run ' + target_name, | 235 'name': 'Run ' + target_name, |
238 'productName': xcode_target.GetProperty('productName'), | 236 'productName': xcode_target.GetProperty('productName'), |
239 'buildConfigurationList': xccl, | 237 'buildConfigurationList': xccl, |
240 }, | 238 }, |
241 parent=self.project) | 239 parent=self.project) |
242 run_target.AddDependency(xcode_target) | 240 run_target.AddDependency(xcode_target) |
243 | 241 |
244 # The test runner target has a build phase that executes the | 242 command = target['run_as'] |
245 # test, if this has the 'test' attribute. If the 'run_as' tag | |
246 # doesn't exist (meaning that this must be a test), then we | |
247 # define a default test command line. | |
248 command = target.get('run_as', { | |
249 'action': ['${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}'] | |
250 }) | |
251 | |
252 script = '' | 243 script = '' |
253 if command.get('working_directory'): | 244 if command.get('working_directory'): |
254 script = script + 'cd "%s"\n' % \ | 245 script = script + 'cd "%s"\n' % \ |
255 gyp.xcodeproj_file.ConvertVariablesToShellSyntax( | 246 gyp.xcodeproj_file.ConvertVariablesToShellSyntax( |
256 command.get('working_directory')) | 247 command.get('working_directory')) |
257 | 248 |
258 if command.get('environment'): | 249 if command.get('environment'): |
259 script = script + "\n".join( | 250 script = script + "\n".join( |
260 ['export %s="%s"' % | 251 ['export %s="%s"' % |
261 (key, gyp.xcodeproj_file.ConvertVariablesToShellSyntax(val)) | 252 (key, gyp.xcodeproj_file.ConvertVariablesToShellSyntax(val)) |
262 for (key, val) in command.get('environment').iteritems()]) + "\n" | 253 for (key, val) in command.get('environment').iteritems()]) + "\n" |
263 | 254 |
264 # Some test end up using sockets, files on disk, etc. and can get | 255 # Some test end up using sockets, files on disk, etc. and can get |
265 # confused if more then one test runs at a time. The generator | 256 # confused if more then one test runs at a time. The generator |
266 # flag 'xcode_serialize_all_test_runs' controls the forcing of all | 257 # flag 'xcode_serialize_all_test_runs' controls the forcing of all |
267 # tests serially. It defaults to True. To get serial runs this | 258 # tests serially. It defaults to True. To get serial runs this |
268 # little bit of python does the same as the linux flock utility to | 259 # little bit of python does the same as the linux flock utility to |
269 # make sure only one runs at a time. | 260 # make sure only one runs at a time. |
270 command_prefix = '' | 261 command_prefix = '' |
271 if is_test and serialize_all_tests: | 262 if serialize_all_tests: |
272 command_prefix = \ | 263 command_prefix = \ |
273 """python -c "import fcntl, subprocess, sys | 264 """python -c "import fcntl, subprocess, sys |
274 file = open('$TMPDIR/GYP_serialize_test_runs', 'a') | 265 file = open('$TMPDIR/GYP_serialize_test_runs', 'a') |
275 fcntl.flock(file.fileno(), fcntl.LOCK_EX) | 266 fcntl.flock(file.fileno(), fcntl.LOCK_EX) |
276 sys.exit(subprocess.call(sys.argv[1:]))" """ | 267 sys.exit(subprocess.call(sys.argv[1:]))" """ |
277 | 268 |
278 # If we were unable to exec for some reason, we want to exit | 269 # If we were unable to exec for some reason, we want to exit |
279 # with an error, and fixup variable references to be shell | 270 # with an error, and fixup variable references to be shell |
280 # syntax instead of xcode syntax. | 271 # syntax instead of xcode syntax. |
281 script = script + 'exec ' + command_prefix + '%s\nexit 1\n' % \ | 272 script = script + 'exec ' + command_prefix + '%s\nexit 1\n' % \ |
282 gyp.xcodeproj_file.ConvertVariablesToShellSyntax( | 273 gyp.xcodeproj_file.ConvertVariablesToShellSyntax( |
283 gyp.common.EncodePOSIXShellList(command.get('action'))) | 274 gyp.common.EncodePOSIXShellList(command.get('action'))) |
284 | 275 |
285 ssbp = gyp.xcodeproj_file.PBXShellScriptBuildPhase({ | 276 ssbp = gyp.xcodeproj_file.PBXShellScriptBuildPhase({ |
286 'shellScript': script, | 277 'shellScript': script, |
287 'showEnvVarsInLog': 0, | 278 'showEnvVarsInLog': 0, |
288 }) | 279 }) |
289 run_target.AppendProperty('buildPhases', ssbp) | 280 run_target.AppendProperty('buildPhases', ssbp) |
290 | 281 |
291 # Add the run target to the project file. | 282 # Add the run target to the project file. |
292 targets.append(run_target) | 283 targets.append(run_target) |
293 if is_test: | 284 run_test_targets.append(run_target) |
294 run_test_targets.append(run_target) | 285 xcode_target.test_runner = run_target |
295 xcode_target.test_runner = run_target | |
296 | 286 |
297 | 287 |
298 # Make sure that the list of targets being replaced is the same length as | 288 # Make sure that the list of targets being replaced is the same length as |
299 # the one replacing it, but allow for the added test runner targets. | 289 # the one replacing it, but allow for the added test runner targets. |
300 assert len(self.project._properties['targets']) == \ | 290 assert len(self.project._properties['targets']) == \ |
301 len(ordinary_targets) + len(support_targets) | 291 len(ordinary_targets) + len(support_targets) |
302 | 292 |
303 self.project._properties['targets'] = targets | 293 self.project._properties['targets'] = targets |
304 | 294 |
305 # Get rid of unnecessary levels of depth in groups like the Source group. | 295 # Get rid of unnecessary levels of depth in groups like the Source group. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 qualified_target = gyp.common.QualifiedTarget(self.gyp_path, | 355 qualified_target = gyp.common.QualifiedTarget(self.gyp_path, |
366 tgt_name, toolset) | 356 tgt_name, toolset) |
367 xcode_target = xcode_targets[qualified_target] | 357 xcode_target = xcode_targets[qualified_target] |
368 if isinstance(xcode_target, gyp.xcodeproj_file.PBXAggregateTarget): | 358 if isinstance(xcode_target, gyp.xcodeproj_file.PBXAggregateTarget): |
369 # Collect all the run test targets. | 359 # Collect all the run test targets. |
370 all_run_tests = [] | 360 all_run_tests = [] |
371 pbxtds = xcode_target.GetProperty('dependencies') | 361 pbxtds = xcode_target.GetProperty('dependencies') |
372 for pbxtd in pbxtds: | 362 for pbxtd in pbxtds: |
373 pbxcip = pbxtd.GetProperty('targetProxy') | 363 pbxcip = pbxtd.GetProperty('targetProxy') |
374 dependency_xct = pbxcip.GetProperty('remoteGlobalIDString') | 364 dependency_xct = pbxcip.GetProperty('remoteGlobalIDString') |
375 target_dict = xcode_target_to_target_dict[dependency_xct] | 365 if hasattr(dependency_xct, 'test_runner'): |
376 if target_dict and int(target_dict.get('test', 0)): | |
377 assert dependency_xct.test_runner | |
378 all_run_tests.append(dependency_xct.test_runner) | 366 all_run_tests.append(dependency_xct.test_runner) |
379 | 367 |
380 # Directly depend on all the runners as they depend on the target | 368 # Directly depend on all the runners as they depend on the target |
381 # that builds them. | 369 # that builds them. |
382 if len(all_run_tests) > 0: | 370 if len(all_run_tests) > 0: |
383 run_all_target = gyp.xcodeproj_file.PBXAggregateTarget({ | 371 run_all_target = gyp.xcodeproj_file.PBXAggregateTarget({ |
384 'name': 'Run %s Tests' % tgt_name, | 372 'name': 'Run %s Tests' % tgt_name, |
385 'productName': tgt_name, | 373 'productName': tgt_name, |
386 }, | 374 }, |
387 parent=self.project) | 375 parent=self.project) |
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 | 1150 |
1163 for build_file in build_files: | 1151 for build_file in build_files: |
1164 xcode_projects[build_file].Finalize1(xcode_targets, serialize_all_tests) | 1152 xcode_projects[build_file].Finalize1(xcode_targets, serialize_all_tests) |
1165 | 1153 |
1166 for build_file in build_files: | 1154 for build_file in build_files: |
1167 xcode_projects[build_file].Finalize2(xcode_targets, | 1155 xcode_projects[build_file].Finalize2(xcode_targets, |
1168 xcode_target_to_target_dict) | 1156 xcode_target_to_target_dict) |
1169 | 1157 |
1170 for build_file in build_files: | 1158 for build_file in build_files: |
1171 xcode_projects[build_file].Write() | 1159 xcode_projects[build_file].Write() |
OLD | NEW |