OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2011 Google Inc. All rights reserved. | 3 # Copyright (c) 2011 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 """ | 7 """ |
8 TestGyp.py: a testing framework for GYP integration tests. | 8 TestGyp.py: a testing framework for GYP integration tests. |
9 """ | 9 """ |
10 | 10 |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 result.append('obj.target') | 401 result.append('obj.target') |
402 elif type == self.SHARED_LIB and sys.platform != 'darwin': | 402 elif type == self.SHARED_LIB and sys.platform != 'darwin': |
403 result.append('lib.target') | 403 result.append('lib.target') |
404 subdir = kw.get('subdir') | 404 subdir = kw.get('subdir') |
405 if subdir: | 405 if subdir: |
406 result.append(subdir) | 406 result.append(subdir) |
407 result.append(self.built_file_basename(name, type, **kw)) | 407 result.append(self.built_file_basename(name, type, **kw)) |
408 return self.workpath(*result) | 408 return self.workpath(*result) |
409 | 409 |
410 | 410 |
| 411 class TestGypNinja(TestGypBase): |
| 412 """ |
| 413 Subclass for testing the GYP Ninja generator. |
| 414 """ |
| 415 format = 'ninja' |
| 416 build_tool_list = ['ninja'] |
| 417 ALL = 'all' |
| 418 DEFAULT = 'all' |
| 419 |
| 420 # The default library prefix is computed from TestCommon.lib_prefix, |
| 421 # but ninja uses no prefix for static libraries. |
| 422 lib_ = '' |
| 423 |
| 424 def run_gyp(self, gyp_file, *args, **kw): |
| 425 # We must pass the desired configuration as a parameter. |
| 426 if self.configuration: |
| 427 args = list(args) + ['-Gconfig=' + self.configuration] |
| 428 # Stash the gyp configuration we used to run gyp, so we can |
| 429 # know whether we need to rerun it later. |
| 430 self.last_gyp_configuration = self.configuration |
| 431 TestGypBase.run_gyp(self, gyp_file, *args, **kw) |
| 432 |
| 433 def build(self, gyp_file, target=None, **kw): |
| 434 if self.last_gyp_configuration != self.configuration: |
| 435 # Rerun gyp if necessary. |
| 436 self.run_gyp(gyp_file) |
| 437 |
| 438 arguments = kw.get('arguments', [])[:] |
| 439 |
| 440 # Add a -f path/to/build.ninja to the command line. |
| 441 arguments.append('-f') |
| 442 arguments.append(os.path.join('out', self.configuration_dirname(), |
| 443 'build.ninja')) |
| 444 |
| 445 if target is None: |
| 446 target = 'all' |
| 447 arguments.append(target) |
| 448 |
| 449 kw['arguments'] = arguments |
| 450 return self.run(program=self.build_tool, **kw) |
| 451 |
| 452 def run_built_executable(self, name, *args, **kw): |
| 453 # Enclosing the name in a list avoids prepending the original dir. |
| 454 program = [self.built_file_path(name, type=self.EXECUTABLE, **kw)] |
| 455 return self.run(program=program, *args, **kw) |
| 456 |
| 457 def built_file_path(self, name, type=None, **kw): |
| 458 result = [] |
| 459 chdir = kw.get('chdir') |
| 460 if chdir: |
| 461 result.append(chdir) |
| 462 result.append('out') |
| 463 result.append(self.configuration_dirname()) |
| 464 if type in (self.STATIC_LIB,): |
| 465 result.append('obj') |
| 466 elif type in (self.SHARED_LIB,): |
| 467 result.append('lib') |
| 468 subdir = kw.get('subdir') |
| 469 if subdir: |
| 470 result.append(subdir) |
| 471 result.append(self.built_file_basename(name, type, **kw)) |
| 472 return self.workpath(*result) |
| 473 |
| 474 def up_to_date(self, gyp_file, target=None, **kw): |
| 475 # Ninja prints no output when the target is up to date. |
| 476 kw['stdout'] = "" |
| 477 return self.build(gyp_file, target, **kw) |
| 478 |
| 479 |
411 class TestGypMSVS(TestGypBase): | 480 class TestGypMSVS(TestGypBase): |
412 """ | 481 """ |
413 Subclass for testing the GYP Visual Studio generator. | 482 Subclass for testing the GYP Visual Studio generator. |
414 """ | 483 """ |
415 format = 'msvs' | 484 format = 'msvs' |
416 | 485 |
417 u = r'=== Build: 0 succeeded, 0 failed, (\d+) up-to-date, 0 skipped ===' | 486 u = r'=== Build: 0 succeeded, 0 failed, (\d+) up-to-date, 0 skipped ===' |
418 up_to_date_re = re.compile(u, re.M) | 487 up_to_date_re = re.compile(u, re.M) |
419 | 488 |
420 # Initial None element will indicate to our .initialize_build_tool() | 489 # Initial None element will indicate to our .initialize_build_tool() |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 configuration = self.configuration_dirname() | 783 configuration = self.configuration_dirname() |
715 result.extend(['build', configuration]) | 784 result.extend(['build', configuration]) |
716 result.append(self.built_file_basename(name, type, **kw)) | 785 result.append(self.built_file_basename(name, type, **kw)) |
717 return self.workpath(*result) | 786 return self.workpath(*result) |
718 | 787 |
719 | 788 |
720 format_class_list = [ | 789 format_class_list = [ |
721 TestGypGypd, | 790 TestGypGypd, |
722 TestGypMake, | 791 TestGypMake, |
723 TestGypMSVS, | 792 TestGypMSVS, |
| 793 TestGypNinja, |
724 TestGypSCons, | 794 TestGypSCons, |
725 TestGypXcode, | 795 TestGypXcode, |
726 ] | 796 ] |
727 | 797 |
728 def TestGyp(*args, **kw): | 798 def TestGyp(*args, **kw): |
729 """ | 799 """ |
730 Returns an appropriate TestGyp* instance for a specified GYP format. | 800 Returns an appropriate TestGyp* instance for a specified GYP format. |
731 """ | 801 """ |
732 format = kw.get('format') | 802 format = kw.get('format') |
733 if format: | 803 if format: |
734 del kw['format'] | 804 del kw['format'] |
735 else: | 805 else: |
736 format = os.environ.get('TESTGYP_FORMAT') | 806 format = os.environ.get('TESTGYP_FORMAT') |
737 for format_class in format_class_list: | 807 for format_class in format_class_list: |
738 if format == format_class.format: | 808 if format == format_class.format: |
739 return format_class(*args, **kw) | 809 return format_class(*args, **kw) |
740 raise Exception, "unknown format %r" % format | 810 raise Exception, "unknown format %r" % format |
OLD | NEW |