From dd0202a78673677f73edee1c0dfe828023464c94 Mon Sep 17 00:00:00 2001 From: machenbach Date: Tue, 6 Dec 2016 03:41:35 -0800 Subject: [PATCH] [test] Only run presubmit for changed status files This turns the status files check into a source processor similar to lint and copyright check. On upload and on trybots it will only run on the affected files. BUG=v8:5603 NOTRY=true Review-Url: https://codereview.chromium.org/2553633002 Cr-Commit-Position: refs/heads/master@{#41516} --- PRESUBMIT.py | 5 +++-- tools/presubmit.py | 27 +++++++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 1c161cb25e..8321f5cedf 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -67,7 +67,7 @@ def _V8PresubmitChecks(input_api, output_api): input_api.PresubmitLocalPath(), 'tools')) from presubmit import CppLintProcessor from presubmit import SourceProcessor - from presubmit import CheckStatusFiles + from presubmit import StatusFilesProcessor results = [] if not CppLintProcessor().RunOnFiles( @@ -78,7 +78,8 @@ def _V8PresubmitChecks(input_api, output_api): results.append(output_api.PresubmitError( "Copyright header, trailing whitespaces and two empty lines " \ "between declarations check failed")) - if not CheckStatusFiles(input_api.PresubmitLocalPath()): + if not StatusFilesProcessor().RunOnFiles( + input_api.AffectedFiles(include_deletes=False)): results.append(output_api.PresubmitError("Status file check failed")) results.extend(input_api.canned_checks.CheckAuthorizedAuthor( input_api, output_api)) diff --git a/tools/presubmit.py b/tools/presubmit.py index 583b918e4b..50e91bcb65 100755 --- a/tools/presubmit.py +++ b/tools/presubmit.py @@ -461,17 +461,23 @@ def _CheckStatusFileForDuplicateKeys(filepath): json.loads(contents, object_pairs_hook=check_pairs) return status["success"] -def CheckStatusFiles(workspace): - success = True - suite_paths = utils.GetSuitePaths(join(workspace, "test")) - for root in suite_paths: - suite_path = join(workspace, "test", root) - status_file_path = join(suite_path, root + ".status") - suite = testsuite.TestSuite.LoadTestSuite(suite_path) - if suite and exists(status_file_path): + +class StatusFilesProcessor(SourceFileProcessor): + """Checks status files for incorrect syntax and duplicate keys.""" + + def IsRelevant(self, name): + return name.endswith('.status') + + def GetPathsToSearch(self): + return ['test'] + + def ProcessFiles(self, files): + success = True + for status_file_path in files: success &= statusfile.PresubmitCheck(status_file_path) success &= _CheckStatusFileForDuplicateKeys(status_file_path) - return success + return success + def GetOptions(): result = optparse.OptionParser() @@ -491,7 +497,8 @@ def Main(): print "Running copyright header, trailing whitespaces and " \ "two empty lines between declarations check..." success &= SourceProcessor().RunOnPath(workspace) - success &= CheckStatusFiles(workspace) + print "Running status-files check..." + success &= StatusFilesProcessor().RunOnPath(workspace) if success: return 0 else: