Commit fa37f96e authored by machenbach's avatar machenbach Committed by Commit bot

[test] Let presubmit only run over affected files.

Presubmit on upload and on trybot will use the affected files as
determined by the presubmit input_api.

The continuously run presubmit will use the old method and search all
files.

BUG=v8:5603
NOTRY=true

Review-Url: https://codereview.chromium.org/2523993003
Cr-Commit-Position: refs/heads/master@{#41248}
parent 4f798f90
...@@ -71,9 +71,9 @@ def _V8PresubmitChecks(input_api, output_api): ...@@ -71,9 +71,9 @@ def _V8PresubmitChecks(input_api, output_api):
from presubmit import CheckStatusFiles from presubmit import CheckStatusFiles
results = [] results = []
if not CppLintProcessor().Run(input_api.PresubmitLocalPath()): if not CppLintProcessor().RunOnFiles(input_api.AffectedFiles()):
results.append(output_api.PresubmitError("C++ lint check failed")) results.append(output_api.PresubmitError("C++ lint check failed"))
if not SourceProcessor().Run(input_api.PresubmitLocalPath()): if not SourceProcessor().RunOnFiles(input_api.AffectedFiles()):
results.append(output_api.PresubmitError( results.append(output_api.PresubmitError(
"Copyright header, trailing whitespaces and two empty lines " \ "Copyright header, trailing whitespaces and two empty lines " \
"between declarations check failed")) "between declarations check failed"))
......
...@@ -71,6 +71,8 @@ LINT_RULES = """ ...@@ -71,6 +71,8 @@ LINT_RULES = """
LINT_OUTPUT_PATTERN = re.compile(r'^.+[:(]\d+[:)]|^Done processing') LINT_OUTPUT_PATTERN = re.compile(r'^.+[:(]\d+[:)]|^Done processing')
FLAGS_LINE = re.compile("//\s*Flags:.*--([A-z0-9-])+_[A-z0-9].*\n") FLAGS_LINE = re.compile("//\s*Flags:.*--([A-z0-9-])+_[A-z0-9].*\n")
TOOLS_PATH = dirname(abspath(__file__))
def CppLintWorker(command): def CppLintWorker(command):
try: try:
process = subprocess.Popen(command, stderr=subprocess.PIPE) process = subprocess.Popen(command, stderr=subprocess.PIPE)
...@@ -156,13 +158,34 @@ class SourceFileProcessor(object): ...@@ -156,13 +158,34 @@ class SourceFileProcessor(object):
files and invoke a custom check on the files. files and invoke a custom check on the files.
""" """
def Run(self, path): def RunOnPath(self, path):
"""Runs processor on all files under the given path."""
all_files = [] all_files = []
for file in self.GetPathsToSearch(): for file in self.GetPathsToSearch():
all_files += self.FindFilesIn(join(path, file)) all_files += self.FindFilesIn(join(path, file))
if not self.ProcessFiles(all_files, path): return self.ProcessFiles(all_files)
return False
return True def RunOnFiles(self, files):
"""Runs processor only on affected files."""
# Helper for getting directory pieces.
dirs = lambda f: dirname(f).split(os.sep)
# Path offsets where to look (to be in sync with RunOnPath).
# Normalize '.' to check for it with str.startswith.
search_paths = [('' if p == '.' else p) for p in self.GetPathsToSearch()]
all_files = [
f.AbsoluteLocalPath()
for f in files
if (not self.IgnoreFile(f.LocalPath()) and
self.IsRelevant(f.LocalPath()) and
all(not self.IgnoreDir(d) for d in dirs(f.LocalPath())) and
any(map(f.LocalPath().startswith, search_paths)))
]
return self.ProcessFiles(all_files)
def IgnoreDir(self, name): def IgnoreDir(self, name):
return (name.startswith('.') or return (name.startswith('.') or
...@@ -214,7 +237,7 @@ class CppLintProcessor(SourceFileProcessor): ...@@ -214,7 +237,7 @@ class CppLintProcessor(SourceFileProcessor):
return None return None
def ProcessFiles(self, files, path): def ProcessFiles(self, files):
good_files_cache = FileContentsCache('.cpplint-cache') good_files_cache = FileContentsCache('.cpplint-cache')
good_files_cache.Load() good_files_cache.Load()
files = good_files_cache.FilterUnchangedFiles(files) files = good_files_cache.FilterUnchangedFiles(files)
...@@ -224,7 +247,7 @@ class CppLintProcessor(SourceFileProcessor): ...@@ -224,7 +247,7 @@ class CppLintProcessor(SourceFileProcessor):
filters = ",".join([n for n in LINT_RULES]) filters = ",".join([n for n in LINT_RULES])
command = [sys.executable, 'cpplint.py', '--filter', filters] command = [sys.executable, 'cpplint.py', '--filter', filters]
cpplint = self.GetCpplintScript(join(path, "tools")) cpplint = self.GetCpplintScript(TOOLS_PATH)
if cpplint is None: if cpplint is None:
print('Could not find cpplint.py. Make sure ' print('Could not find cpplint.py. Make sure '
'depot_tools is installed and in the path.') 'depot_tools is installed and in the path.')
...@@ -381,7 +404,7 @@ class SourceProcessor(SourceFileProcessor): ...@@ -381,7 +404,7 @@ class SourceProcessor(SourceFileProcessor):
result = False result = False
return result return result
def ProcessFiles(self, files, path): def ProcessFiles(self, files):
success = True success = True
violations = 0 violations = 0
for file in files: for file in files:
...@@ -492,10 +515,10 @@ def Main(): ...@@ -492,10 +515,10 @@ def Main():
success = True success = True
print "Running C++ lint check..." print "Running C++ lint check..."
if not options.no_lint: if not options.no_lint:
success &= CppLintProcessor().Run(workspace) success &= CppLintProcessor().RunOnPath(workspace)
print "Running copyright header, trailing whitespaces and " \ print "Running copyright header, trailing whitespaces and " \
"two empty lines between declarations check..." "two empty lines between declarations check..."
success &= SourceProcessor().Run(workspace) success &= SourceProcessor().RunOnPath(workspace)
success &= CheckStatusFiles(workspace) success &= CheckStatusFiles(workspace)
if success: if success:
return 0 return 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment