| 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 os | 9 import os |
| 10 import re | 10 import re |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 result.append('obj.target') | 403 result.append('obj.target') |
| 404 elif type == self.SHARED_LIB and sys.platform != 'darwin': | 404 elif type == self.SHARED_LIB and sys.platform != 'darwin': |
| 405 result.append('lib.target') | 405 result.append('lib.target') |
| 406 subdir = kw.get('subdir') | 406 subdir = kw.get('subdir') |
| 407 if subdir: | 407 if subdir: |
| 408 result.append(subdir) | 408 result.append(subdir) |
| 409 result.append(self.built_file_basename(name, type, **kw)) | 409 result.append(self.built_file_basename(name, type, **kw)) |
| 410 return self.workpath(*result) | 410 return self.workpath(*result) |
| 411 | 411 |
| 412 | 412 |
| 413 def FindVisualStudioInstallation(): |
| 414 """Returns appropriate values for .build_tool and .uses_msbuild fields |
| 415 of TestGypBase for Visual Studio. |
| 416 |
| 417 We use the value specified by GYP_MSVS_VERSION. If not specified, we |
| 418 search %PATH% and %PATHEXT% for a devenv.{exe,bat,...} executable. |
| 419 Failing that, we search for likely deployment paths. |
| 420 """ |
| 421 possible_roots = ['C:\\Program Files (x86)', 'C:\\Program Files', |
| 422 'E:\\Program Files (x86)', 'E:\\Program Files'] |
| 423 possible_paths = { |
| 424 '2010': r'Microsoft Visual Studio 10.0\Common7\IDE\devenv.com', |
| 425 '2008': r'Microsoft Visual Studio 9.0\Common7\IDE\devenv.com', |
| 426 '2005': r'Microsoft Visual Studio 8\Common7\IDE\devenv.com'} |
| 427 msvs_version = os.environ.get('GYP_MSVS_VERSION', 'auto') |
| 428 build_tool = None |
| 429 if msvs_version in possible_paths: |
| 430 # Check that the path to the specified GYP_MSVS_VERSION exists. |
| 431 path = possible_paths[msvs_version] |
| 432 for r in possible_roots: |
| 433 bt = os.path.join(r, path) |
| 434 if os.path.exists(bt): |
| 435 build_tool = bt |
| 436 uses_msbuild = msvs_version >= '2010' |
| 437 return build_tool, uses_msbuild |
| 438 else: |
| 439 print ('Warning: Environment variable GYP_MSVS_VERSION specifies "%s" ' |
| 440 'but corresponding "%s" was not found.' % (msvs_version, path)) |
| 441 if build_tool: |
| 442 # We found 'devenv' on the path, use that and try to guess the version. |
| 443 for version, path in possible_paths.iteritems(): |
| 444 if build_tool.find(path) >= 0: |
| 445 uses_msbuild = version >= '2010' |
| 446 return build_tool, uses_msbuild |
| 447 else: |
| 448 # If not, assume not MSBuild. |
| 449 uses_msbuild = False |
| 450 return build_tool, uses_msbuild |
| 451 # Neither GYP_MSVS_VERSION nor the path help us out. Iterate through |
| 452 # the choices looking for a match. |
| 453 for version, path in possible_paths.iteritems(): |
| 454 for r in possible_roots: |
| 455 bt = os.path.join(r, path) |
| 456 if os.path.exists(bt): |
| 457 build_tool = bt |
| 458 uses_msbuild = msvs_version >= '2010' |
| 459 return build_tool, uses_msbuild |
| 460 print 'Error: could not find devenv' |
| 461 sys.exit(1) |
| 462 |
| 463 |
| 413 class TestGypNinja(TestGypBase): | 464 class TestGypNinja(TestGypBase): |
| 414 """ | 465 """ |
| 415 Subclass for testing the GYP Ninja generator. | 466 Subclass for testing the GYP Ninja generator. |
| 416 """ | 467 """ |
| 417 format = 'ninja' | 468 format = 'ninja' |
| 418 build_tool_list = ['ninja'] | 469 build_tool_list = ['ninja'] |
| 419 ALL = 'all' | 470 ALL = 'all' |
| 420 DEFAULT = 'all' | 471 DEFAULT = 'all' |
| 421 | 472 |
| 473 def initialize_build_tool(self): |
| 474 super(TestGypNinja, self).initialize_build_tool() |
| 475 if sys.platform == 'win32': |
| 476 # Compiler and linker aren't in the path by default on Windows, so we |
| 477 # make our "build tool" be set up + run ninja. |
| 478 devenv_path, _ = FindVisualStudioInstallation() |
| 479 devenv_dir = os.path.split(devenv_path)[0] |
| 480 vsvars_path = os.path.join(devenv_path, '../../Tools/vsvars32.bat') |
| 481 vsvars_path = os.path.normpath(vsvars_path) |
| 482 self.build_tool = os.environ.get('COMSPEC', 'cmd.exe') |
| 483 self.helper_args = ['/c', vsvars_path, '&&', 'ninja'] |
| 484 |
| 422 def run_gyp(self, gyp_file, *args, **kw): | 485 def run_gyp(self, gyp_file, *args, **kw): |
| 423 TestGypBase.run_gyp(self, gyp_file, *args, **kw) | 486 TestGypBase.run_gyp(self, gyp_file, *args, **kw) |
| 424 | 487 |
| 425 def build(self, gyp_file, target=None, **kw): | 488 def build(self, gyp_file, target=None, **kw): |
| 426 arguments = kw.get('arguments', [])[:] | 489 arguments = kw.get('arguments', [])[:] |
| 427 | 490 |
| 428 # Add a -C output/path to the command line. | 491 # Add a -C output/path to the command line. |
| 429 arguments.append('-C') | 492 arguments.append('-C') |
| 430 arguments.append(os.path.join('out', self.configuration_dirname())) | 493 arguments.append(os.path.join('out', self.configuration_dirname())) |
| 431 | 494 |
| 432 if target is None: | 495 if target is None: |
| 433 target = 'all' | 496 target = 'all' |
| 434 arguments.append(target) | 497 arguments.append(target) |
| 435 | 498 |
| 499 if sys.platform == 'win32': |
| 500 arguments = self.helper_args + arguments |
| 501 |
| 436 kw['arguments'] = arguments | 502 kw['arguments'] = arguments |
| 437 return self.run(program=self.build_tool, **kw) | 503 return self.run(program=self.build_tool, **kw) |
| 438 | 504 |
| 439 def run_built_executable(self, name, *args, **kw): | 505 def run_built_executable(self, name, *args, **kw): |
| 440 # Enclosing the name in a list avoids prepending the original dir. | 506 # Enclosing the name in a list avoids prepending the original dir. |
| 441 program = [self.built_file_path(name, type=self.EXECUTABLE, **kw)] | 507 program = [self.built_file_path(name, type=self.EXECUTABLE, **kw)] |
| 442 if sys.platform == 'darwin': | 508 if sys.platform == 'darwin': |
| 443 libdir = os.path.join('out', 'Default') | 509 libdir = os.path.join('out', 'Default') |
| 444 if self.configuration: | 510 if self.configuration: |
| 445 libdir = os.path.join('out', self.configuration) | 511 libdir = os.path.join('out', self.configuration) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 up_to_date_re = re.compile(u, re.M) | 551 up_to_date_re = re.compile(u, re.M) |
| 486 | 552 |
| 487 # Initial None element will indicate to our .initialize_build_tool() | 553 # Initial None element will indicate to our .initialize_build_tool() |
| 488 # method below that 'devenv' was not found on %PATH%. | 554 # method below that 'devenv' was not found on %PATH%. |
| 489 # | 555 # |
| 490 # Note: we must use devenv.com to be able to capture build output. | 556 # Note: we must use devenv.com to be able to capture build output. |
| 491 # Directly executing devenv.exe only sends output to BuildLog.htm. | 557 # Directly executing devenv.exe only sends output to BuildLog.htm. |
| 492 build_tool_list = [None, 'devenv.com'] | 558 build_tool_list = [None, 'devenv.com'] |
| 493 | 559 |
| 494 def initialize_build_tool(self): | 560 def initialize_build_tool(self): |
| 495 """ Initializes the Visual Studio .build_tool and .uses_msbuild parameters. | |
| 496 | |
| 497 We use the value specified by GYP_MSVS_VERSION. If not specified, we | |
| 498 search %PATH% and %PATHEXT% for a devenv.{exe,bat,...} executable. | |
| 499 Failing that, we search for likely deployment paths. | |
| 500 """ | |
| 501 super(TestGypMSVS, self).initialize_build_tool() | 561 super(TestGypMSVS, self).initialize_build_tool() |
| 502 possible_roots = ['C:\\Program Files (x86)', 'C:\\Program Files', | 562 self.build_tool, self.uses_msbuild = FindVisualStudioInstallation() |
| 503 'E:\\Program Files (x86)', 'E:\\Program Files'] | |
| 504 possible_paths = { | |
| 505 '2010': r'Microsoft Visual Studio 10.0\Common7\IDE\devenv.com', | |
| 506 '2008': r'Microsoft Visual Studio 9.0\Common7\IDE\devenv.com', | |
| 507 '2005': r'Microsoft Visual Studio 8\Common7\IDE\devenv.com'} | |
| 508 msvs_version = os.environ.get('GYP_MSVS_VERSION', 'auto') | |
| 509 if msvs_version in possible_paths: | |
| 510 # Check that the path to the specified GYP_MSVS_VERSION exists. | |
| 511 path = possible_paths[msvs_version] | |
| 512 for r in possible_roots: | |
| 513 bt = os.path.join(r, path) | |
| 514 if os.path.exists(bt): | |
| 515 self.build_tool = bt | |
| 516 self.uses_msbuild = msvs_version >= '2010' | |
| 517 return | |
| 518 else: | |
| 519 print ('Warning: Environment variable GYP_MSVS_VERSION specifies "%s" ' | |
| 520 'but corresponding "%s" was not found.' % (msvs_version, path)) | |
| 521 if self.build_tool: | |
| 522 # We found 'devenv' on the path, use that and try to guess the version. | |
| 523 for version, path in possible_paths.iteritems(): | |
| 524 if self.build_tool.find(path) >= 0: | |
| 525 self.uses_msbuild = version >= '2010' | |
| 526 return | |
| 527 else: | |
| 528 # If not, assume not MSBuild. | |
| 529 self.uses_msbuild = False | |
| 530 return | |
| 531 # Neither GYP_MSVS_VERSION nor the path help us out. Iterate through | |
| 532 # the choices looking for a match. | |
| 533 for version, path in possible_paths.iteritems(): | |
| 534 for r in possible_roots: | |
| 535 bt = os.path.join(r, path) | |
| 536 if os.path.exists(bt): | |
| 537 self.build_tool = bt | |
| 538 self.uses_msbuild = msvs_version >= '2010' | |
| 539 return | |
| 540 print 'Error: could not find devenv' | |
| 541 sys.exit(1) | |
| 542 def build(self, gyp_file, target=None, rebuild=False, **kw): | 563 def build(self, gyp_file, target=None, rebuild=False, **kw): |
| 543 """ | 564 """ |
| 544 Runs a Visual Studio build using the configuration generated | 565 Runs a Visual Studio build using the configuration generated |
| 545 from the specified gyp_file. | 566 from the specified gyp_file. |
| 546 """ | 567 """ |
| 547 configuration = self.configuration_buildname() | 568 configuration = self.configuration_buildname() |
| 548 if rebuild: | 569 if rebuild: |
| 549 build = '/Rebuild' | 570 build = '/Rebuild' |
| 550 else: | 571 else: |
| 551 build = '/Build' | 572 build = '/Build' |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 """ | 820 """ |
| 800 format = kw.get('format') | 821 format = kw.get('format') |
| 801 if format: | 822 if format: |
| 802 del kw['format'] | 823 del kw['format'] |
| 803 else: | 824 else: |
| 804 format = os.environ.get('TESTGYP_FORMAT') | 825 format = os.environ.get('TESTGYP_FORMAT') |
| 805 for format_class in format_class_list: | 826 for format_class in format_class_list: |
| 806 if format == format_class.format: | 827 if format == format_class.format: |
| 807 return format_class(*args, **kw) | 828 return format_class(*args, **kw) |
| 808 raise Exception, "unknown format %r" % format | 829 raise Exception, "unknown format %r" % format |
| OLD | NEW |