| 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 GetUnitTestsRecursively(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 check(filename): | 
|  | 573     return (any(input_api.re.match(f, filename) for f in whitelist) and | 
|  | 574             not any(input_api.re.match(f, filename) for f in blacklist)) | 
|  | 575 | 
|  | 576   tests = [] | 
|  | 577 | 
|  | 578   to_run = found = 0 | 
|  | 579   for filepath in input_api.change.AllFiles(directory): | 
|  | 580     found += 1 | 
|  | 581     if check(filepath): | 
|  | 582       to_run += 1 | 
|  | 583       tests.append(filepath) | 
|  | 584   input_api.logging.debug('Found %d files, running %d' % (found, to_run)) | 
|  | 585   if not to_run: | 
|  | 586     return [ | 
|  | 587         output_api.PresubmitPromptWarning( | 
|  | 588           'Out of %d files, found none that matched w=%r, b=%r in directory %s' | 
|  | 589           % (found, whitelist, blacklist, directory)) | 
|  | 590     ] | 
|  | 591 | 
|  | 592   return GetUnitTests(input_api, output_api, tests) | 
|  | 593 | 
|  | 594 | 
| 565 def GetPythonUnitTests(input_api, output_api, unit_tests): | 595 def GetPythonUnitTests(input_api, output_api, unit_tests): | 
| 566   """Run the unit tests out of process, capture the output and use the result | 596   """Run the unit tests out of process, capture the output and use the result | 
| 567   code to determine success. | 597   code to determine success. | 
| 568 | 598 | 
| 569   DEPRECATED. | 599   DEPRECATED. | 
| 570   """ | 600   """ | 
| 571   # We don't want to hinder users from uploading incomplete patches. | 601   # We don't want to hinder users from uploading incomplete patches. | 
| 572   if input_api.is_committing: | 602   if input_api.is_committing: | 
| 573     message_type = output_api.PresubmitError | 603     message_type = output_api.PresubmitError | 
| 574   else: | 604   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 | 767   # Passing py files one at time is slower and can produce | 
| 738   # different results.  input_api.verbose used to be used | 768   # different results.  input_api.verbose used to be used | 
| 739   # to enable this behaviour but differing behaviour in | 769   # to enable this behaviour but differing behaviour in | 
| 740   # verbose mode is not desirable. | 770   # verbose mode is not desirable. | 
| 741   # Leave this unreachable code in here so users can make | 771   # Leave this unreachable code in here so users can make | 
| 742   # a quick local edit to diagnose pylint issues more | 772   # a quick local edit to diagnose pylint issues more | 
| 743   # easily. | 773   # easily. | 
| 744   if True: | 774   if True: | 
| 745     return [GetPylintCmd(files)] | 775     return [GetPylintCmd(files)] | 
| 746   else: | 776   else: | 
| 747     return map(GetPylintCmd, files) | 777     return map(lambda x: GetPylintCmd([x]), files) | 
| 748 | 778 | 
| 749 | 779 | 
| 750 def RunPylint(input_api, *args, **kwargs): | 780 def RunPylint(input_api, *args, **kwargs): | 
| 751   """Legacy presubmit function. | 781   """Legacy presubmit function. | 
| 752 | 782 | 
| 753   For better performance, get all tests and then pass to | 783   For better performance, get all tests and then pass to | 
| 754   input_api.RunTests. | 784   input_api.RunTests. | 
| 755   """ | 785   """ | 
| 756   return input_api.RunTests(GetPylint(input_api, *args, **kwargs), False) | 786   return input_api.RunTests(GetPylint(input_api, *args, **kwargs), False) | 
| 757 | 787 | 
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1064 def CheckPatchFormatted(input_api, output_api): | 1094 def CheckPatchFormatted(input_api, output_api): | 
| 1065   import git_cl | 1095   import git_cl | 
| 1066   cmd = ['cl', 'format', '--dry-run', input_api.PresubmitLocalPath()] | 1096   cmd = ['cl', 'format', '--dry-run', input_api.PresubmitLocalPath()] | 
| 1067   code, _ = git_cl.RunGitWithCode(cmd, suppress_stderr=True) | 1097   code, _ = git_cl.RunGitWithCode(cmd, suppress_stderr=True) | 
| 1068   if code == 2: | 1098   if code == 2: | 
| 1069     return [output_api.PresubmitPromptWarning( | 1099     return [output_api.PresubmitPromptWarning( | 
| 1070       'Your patch is not formatted, please run git cl format.')] | 1100       'Your patch is not formatted, please run git cl format.')] | 
| 1071   # As this is just a warning, ignore all other errors if the user | 1101   # 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. | 1102   # happens to have a broken clang-format, doesn't use git, etc etc. | 
| 1073   return [] | 1103   return [] | 
| OLD | NEW | 
|---|