Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. 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 """Generic presubmit checks that can be reused by other presubmit checks.""" | 5 """Generic presubmit checks that can be reused by other presubmit checks.""" |
| 6 | 6 |
| 7 import os as _os | 7 import os as _os |
| 8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) | 8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) |
| 9 | 9 |
| 10 | 10 |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 if env: | 555 if env: |
| 556 kwargs['env'] = env | 556 kwargs['env'] = env |
| 557 results.append(input_api.Command( | 557 results.append(input_api.Command( |
| 558 name=unit_test, | 558 name=unit_test, |
| 559 cmd=cmd, | 559 cmd=cmd, |
| 560 kwargs=kwargs, | 560 kwargs=kwargs, |
| 561 message=message_type)) | 561 message=message_type)) |
| 562 return results | 562 return results |
| 563 | 563 |
| 564 | 564 |
| 565 def GetGitUnitTestsRecursively(input_api, output_api, directory, | |
| 566 whitelist, blacklist): | |
| 567 """Gets all files in the directory tree (git repo) that match the whitelist. | |
| 568 | |
| 569 Restricts itself to only find files within the Change's source repo, not | |
| 570 dependencies. | |
| 571 """ | |
| 572 def curry_check(whitelist, blacklist): | |
|
M-A Ruel
2014/05/14 00:20:57
This is not necessary, the values are bound anyhow
agable
2014/05/14 22:43:20
But but but I have to pay honor to Haskell Curry!
| |
| 573 def check(filename): | |
| 574 return (any(input_api.re.match(f, filename) for f in whitelist) and | |
| 575 not any(input_api.re.match(f, filename) for f in blacklist)) | |
| 576 return check | |
| 577 check = curry_check(whitelist, blacklist) | |
| 578 | |
| 579 tests = [] | |
| 580 | |
| 581 repo_root = input_api.change.RepositoryRoot() | |
| 582 toplevel = input_api.os_path.abspath( | |
| 583 input_api.os_path.join(input_api.PresubmitLocalPath(), directory)) | |
| 584 to_run = found = 0 | |
| 585 for root, dirs, files in input_api.os_walk(toplevel): | |
| 586 git_toplevel = input_api.subprocess.check_output( | |
| 587 ['git', 'rev-parse', '--show-toplevel'], cwd=root).strip() | |
|
M-A Ruel
2014/05/14 00:20:57
That's not how I thought about doing it, my take w
agable
2014/05/14 22:43:20
PTAL. I added one for SVN too.
| |
| 588 if git_toplevel != repo_root: | |
| 589 del dirs[:] | |
| 590 continue | |
| 591 for name in files: | |
| 592 found += 1 | |
| 593 fullname = input_api.os_path.join(root, name) | |
| 594 if check(fullname): | |
| 595 to_run += 1 | |
| 596 tests.append(fullname) | |
| 597 input_api.logging.debug('Found %d files, running %d' % (found, to_run)) | |
| 598 if not to_run: | |
| 599 return [ | |
| 600 output_api.PresubmitPromptWarning( | |
| 601 'Out of %d files, found none that matched w=%r, b=%r in directory %s' | |
| 602 % (found, whitelist, blacklist, directory)) | |
| 603 ] | |
| 604 | |
| 605 return GetUnitTests(input_api, output_api, tests) | |
| 606 | |
| 607 | |
| 565 def GetPythonUnitTests(input_api, output_api, unit_tests): | 608 def GetPythonUnitTests(input_api, output_api, unit_tests): |
| 566 """Run the unit tests out of process, capture the output and use the result | 609 """Run the unit tests out of process, capture the output and use the result |
| 567 code to determine success. | 610 code to determine success. |
| 568 | 611 |
| 569 DEPRECATED. | 612 DEPRECATED. |
| 570 """ | 613 """ |
| 571 # We don't want to hinder users from uploading incomplete patches. | 614 # We don't want to hinder users from uploading incomplete patches. |
| 572 if input_api.is_committing: | 615 if input_api.is_committing: |
| 573 message_type = output_api.PresubmitError | 616 message_type = output_api.PresubmitError |
| 574 else: | 617 else: |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 737 # Passing py files one at time is slower and can produce | 780 # Passing py files one at time is slower and can produce |
| 738 # different results. input_api.verbose used to be used | 781 # different results. input_api.verbose used to be used |
| 739 # to enable this behaviour but differing behaviour in | 782 # to enable this behaviour but differing behaviour in |
| 740 # verbose mode is not desirable. | 783 # verbose mode is not desirable. |
| 741 # Leave this unreachable code in here so users can make | 784 # Leave this unreachable code in here so users can make |
| 742 # a quick local edit to diagnose pylint issues more | 785 # a quick local edit to diagnose pylint issues more |
| 743 # easily. | 786 # easily. |
| 744 if True: | 787 if True: |
| 745 return [GetPylintCmd(files)] | 788 return [GetPylintCmd(files)] |
| 746 else: | 789 else: |
| 747 return map(GetPylintCmd, files) | 790 return map(lambda x: GetPylintCmd([x]), files) |
| 748 | 791 |
| 749 | 792 |
| 750 def RunPylint(input_api, *args, **kwargs): | 793 def RunPylint(input_api, *args, **kwargs): |
| 751 """Legacy presubmit function. | 794 """Legacy presubmit function. |
| 752 | 795 |
| 753 For better performance, get all tests and then pass to | 796 For better performance, get all tests and then pass to |
| 754 input_api.RunTests. | 797 input_api.RunTests. |
| 755 """ | 798 """ |
| 756 return input_api.RunTests(GetPylint(input_api, *args, **kwargs), False) | 799 return input_api.RunTests(GetPylint(input_api, *args, **kwargs), False) |
| 757 | 800 |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1064 def CheckPatchFormatted(input_api, output_api): | 1107 def CheckPatchFormatted(input_api, output_api): |
| 1065 import git_cl | 1108 import git_cl |
| 1066 cmd = ['cl', 'format', '--dry-run', input_api.PresubmitLocalPath()] | 1109 cmd = ['cl', 'format', '--dry-run', input_api.PresubmitLocalPath()] |
| 1067 code, _ = git_cl.RunGitWithCode(cmd, suppress_stderr=True) | 1110 code, _ = git_cl.RunGitWithCode(cmd, suppress_stderr=True) |
| 1068 if code == 2: | 1111 if code == 2: |
| 1069 return [output_api.PresubmitPromptWarning( | 1112 return [output_api.PresubmitPromptWarning( |
| 1070 'Your patch is not formatted, please run git cl format.')] | 1113 'Your patch is not formatted, please run git cl format.')] |
| 1071 # As this is just a warning, ignore all other errors if the user | 1114 # As this is just a warning, ignore all other errors if the user |
| 1072 # happens to have a broken clang-format, doesn't use git, etc etc. | 1115 # happens to have a broken clang-format, doesn't use git, etc etc. |
| 1073 return [] | 1116 return [] |
| OLD | NEW |