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 TestGyp.py: a testing framework for GYP integration tests. | 6 TestGyp.py: a testing framework for GYP integration tests. |
7 """ | 7 """ |
8 | 8 |
| 9 import collections |
| 10 import itertools |
9 import os | 11 import os |
10 import re | 12 import re |
11 import shutil | 13 import shutil |
12 import stat | 14 import stat |
13 import subprocess | 15 import subprocess |
14 import sys | 16 import sys |
15 import tempfile | 17 import tempfile |
16 | 18 |
17 import TestCmd | 19 import TestCmd |
18 import TestCommon | 20 import TestCommon |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 Verifies that a build of the specified target is up to date. | 527 Verifies that a build of the specified target is up to date. |
526 """ | 528 """ |
527 kw['stdout'] = ("make: Nothing to be done for `%s'." % | 529 kw['stdout'] = ("make: Nothing to be done for `%s'." % |
528 self.target_name(target)) | 530 self.target_name(target)) |
529 | 531 |
530 # We need to supply a custom matcher, since we don't want to depend on the | 532 # We need to supply a custom matcher, since we don't want to depend on the |
531 # exact stdout string. | 533 # exact stdout string. |
532 kw['match'] = self.match_single_line | 534 kw['match'] = self.match_single_line |
533 return self.build(gyp_file, target, **kw) | 535 return self.build(gyp_file, target, **kw) |
534 | 536 |
| 537 |
| 538 class TestGypCMake(TestGypBase): |
| 539 """ |
| 540 Subclass for testing the GYP CMake generator, using cmake's ninja backend. |
| 541 """ |
| 542 format = 'cmake' |
| 543 build_tool_list = ['cmake'] |
| 544 ALL = 'all' |
| 545 |
| 546 def cmake_build(self, gyp_file, target=None, **kw): |
| 547 arguments = kw.get('arguments', [])[:] |
| 548 |
| 549 self.build_tool_list = ['cmake'] |
| 550 self.initialize_build_tool() |
| 551 |
| 552 chdir = os.path.join(kw.get('chdir', '.'), |
| 553 'out', |
| 554 self.configuration_dirname()) |
| 555 kw['chdir'] = chdir |
| 556 |
| 557 arguments.append('-G') |
| 558 arguments.append('Ninja') |
| 559 |
| 560 kw['arguments'] = arguments |
| 561 |
| 562 stderr = kw.get('stderr', None) |
| 563 if stderr: |
| 564 kw['stderr'] = stderr.split('$$$')[0] |
| 565 |
| 566 self.run(program=self.build_tool, **kw) |
| 567 |
| 568 def ninja_build(self, gyp_file, target=None, **kw): |
| 569 arguments = kw.get('arguments', [])[:] |
| 570 |
| 571 self.build_tool_list = ['ninja'] |
| 572 self.initialize_build_tool() |
| 573 |
| 574 # Add a -C output/path to the command line. |
| 575 arguments.append('-C') |
| 576 arguments.append(os.path.join('out', self.configuration_dirname())) |
| 577 |
| 578 if target not in (None, self.DEFAULT): |
| 579 arguments.append(target) |
| 580 |
| 581 kw['arguments'] = arguments |
| 582 |
| 583 stderr = kw.get('stderr', None) |
| 584 if stderr: |
| 585 stderrs = stderr.split('$$$') |
| 586 kw['stderr'] = stderrs[1] if len(stderrs) > 1 else '' |
| 587 |
| 588 return self.run(program=self.build_tool, **kw) |
| 589 |
| 590 def build(self, gyp_file, target=None, status=0, **kw): |
| 591 # Two tools must be run to build, cmake and the ninja. |
| 592 # Allow cmake to succeed when the overall expectation is to fail. |
| 593 if status is None: |
| 594 kw['status'] = None |
| 595 else: |
| 596 if not isinstance(status, collections.Iterable): status = (status,) |
| 597 kw['status'] = list(itertools.chain((0,), status)) |
| 598 self.cmake_build(gyp_file, target, **kw) |
| 599 kw['status'] = status |
| 600 self.ninja_build(gyp_file, target, **kw) |
| 601 |
| 602 def run_built_executable(self, name, *args, **kw): |
| 603 # Enclosing the name in a list avoids prepending the original dir. |
| 604 program = [self.built_file_path(name, type=self.EXECUTABLE, **kw)] |
| 605 if sys.platform == 'darwin': |
| 606 configuration = self.configuration_dirname() |
| 607 os.environ['DYLD_LIBRARY_PATH'] = os.path.join('out', configuration) |
| 608 return self.run(program=program, *args, **kw) |
| 609 |
| 610 def built_file_path(self, name, type=None, **kw): |
| 611 result = [] |
| 612 chdir = kw.get('chdir') |
| 613 if chdir: |
| 614 result.append(chdir) |
| 615 result.append('out') |
| 616 result.append(self.configuration_dirname()) |
| 617 if type == self.STATIC_LIB: |
| 618 if sys.platform != 'darwin': |
| 619 result.append('obj.target') |
| 620 elif type == self.SHARED_LIB: |
| 621 if sys.platform != 'darwin' and sys.platform != 'win32': |
| 622 result.append('lib.target') |
| 623 subdir = kw.get('subdir') |
| 624 if subdir and type != self.SHARED_LIB: |
| 625 result.append(subdir) |
| 626 result.append(self.built_file_basename(name, type, **kw)) |
| 627 return self.workpath(*result) |
| 628 |
| 629 def up_to_date(self, gyp_file, target=None, **kw): |
| 630 result = self.ninja_build(gyp_file, target, **kw) |
| 631 if not result: |
| 632 stdout = self.stdout() |
| 633 if 'ninja: no work to do' not in stdout: |
| 634 self.report_not_up_to_date() |
| 635 self.fail_test() |
| 636 return result |
| 637 |
| 638 |
535 class TestGypMake(TestGypBase): | 639 class TestGypMake(TestGypBase): |
536 """ | 640 """ |
537 Subclass for testing the GYP Make generator. | 641 Subclass for testing the GYP Make generator. |
538 """ | 642 """ |
539 format = 'make' | 643 format = 'make' |
540 build_tool_list = ['make'] | 644 build_tool_list = ['make'] |
541 ALL = 'all' | 645 ALL = 'all' |
542 def build(self, gyp_file, target=None, **kw): | 646 def build(self, gyp_file, target=None, **kw): |
543 """ | 647 """ |
544 Runs a Make build using the Makefiles generated from the specified | 648 Runs a Make build using the Makefiles generated from the specified |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 result.append(chdir) | 1092 result.append(chdir) |
989 configuration = self.configuration_dirname() | 1093 configuration = self.configuration_dirname() |
990 result.extend(['build', configuration]) | 1094 result.extend(['build', configuration]) |
991 result.append(self.built_file_basename(name, type, **kw)) | 1095 result.append(self.built_file_basename(name, type, **kw)) |
992 return self.workpath(*result) | 1096 return self.workpath(*result) |
993 | 1097 |
994 | 1098 |
995 format_class_list = [ | 1099 format_class_list = [ |
996 TestGypGypd, | 1100 TestGypGypd, |
997 TestGypAndroid, | 1101 TestGypAndroid, |
| 1102 TestGypCMake, |
998 TestGypMake, | 1103 TestGypMake, |
999 TestGypMSVS, | 1104 TestGypMSVS, |
1000 TestGypNinja, | 1105 TestGypNinja, |
1001 TestGypXcode, | 1106 TestGypXcode, |
1002 ] | 1107 ] |
1003 | 1108 |
1004 def TestGyp(*args, **kw): | 1109 def TestGyp(*args, **kw): |
1005 """ | 1110 """ |
1006 Returns an appropriate TestGyp* instance for a specified GYP format. | 1111 Returns an appropriate TestGyp* instance for a specified GYP format. |
1007 """ | 1112 """ |
1008 format = kw.pop('format', os.environ.get('TESTGYP_FORMAT')) | 1113 format = kw.pop('format', os.environ.get('TESTGYP_FORMAT')) |
1009 for format_class in format_class_list: | 1114 for format_class in format_class_list: |
1010 if format == format_class.format: | 1115 if format == format_class.format: |
1011 return format_class(*args, **kw) | 1116 return format_class(*args, **kw) |
1012 raise Exception, "unknown format %r" % format | 1117 raise Exception, "unknown format %r" % format |
OLD | NEW |