Commit a5a381bd authored by Tamer Tas's avatar Tamer Tas Committed by Commit Bot

[test] add an option for disabling linter cache in the pre_submit check

Adds a flag to specify whether to disable the linter caching.

R=machenbach@chromium.org,sergiyb@chromium.org
CC=​​yangguo@chromium.org

Bug: v8:8482
Change-Id: I62a9b7cffb3adb50b136659568ad52078675ca4b
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/1370029Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Commit-Queue: Tamer Tas <tmrts@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58329}
parent e9a0e0e5
...@@ -18,7 +18,7 @@ from v8_presubmit import FileContentsCache, CacheableSourceFileProcessor ...@@ -18,7 +18,7 @@ from v8_presubmit import FileContentsCache, CacheableSourceFileProcessor
class FakeCachedProcessor(CacheableSourceFileProcessor): class FakeCachedProcessor(CacheableSourceFileProcessor):
def __init__(self, cache_file_path): def __init__(self, cache_file_path):
super(FakeCachedProcessor, self).__init__( super(FakeCachedProcessor, self).__init__(
cache_file_path=cache_file_path, file_type='.test') use_cache=True, cache_file_path=cache_file_path, file_type='.test')
def GetProcessorWorker(self): def GetProcessorWorker(self):
return object return object
def GetProcessorScript(self): def GetProcessorScript(self):
......
...@@ -235,7 +235,8 @@ class CacheableSourceFileProcessor(SourceFileProcessor): ...@@ -235,7 +235,8 @@ class CacheableSourceFileProcessor(SourceFileProcessor):
the files requiring intervention after processing the source files. the files requiring intervention after processing the source files.
""" """
def __init__(self, cache_file_path, file_type): def __init__(self, use_cache, cache_file_path, file_type):
self.use_cache = use_cache
self.cache_file_path = cache_file_path self.cache_file_path = cache_file_path
self.file_type = file_type self.file_type = file_type
...@@ -260,6 +261,7 @@ class CacheableSourceFileProcessor(SourceFileProcessor): ...@@ -260,6 +261,7 @@ class CacheableSourceFileProcessor(SourceFileProcessor):
return command return command
def ProcessFiles(self, files): def ProcessFiles(self, files):
if self.use_cache:
cache = FileContentsCache(self.cache_file_path) cache = FileContentsCache(self.cache_file_path)
cache.Load() cache.Load()
files = cache.FilterUnchangedFiles(files) files = cache.FilterUnchangedFiles(files)
...@@ -272,10 +274,12 @@ class CacheableSourceFileProcessor(SourceFileProcessor): ...@@ -272,10 +274,12 @@ class CacheableSourceFileProcessor(SourceFileProcessor):
print ( print (
'Total %s files found that require formatting: %d' % 'Total %s files found that require formatting: %d' %
(self.file_type, len(files_requiring_changes))) (self.file_type, len(files_requiring_changes)))
if self.use_cache:
for file in files_requiring_changes: for file in files_requiring_changes:
cache.RemoveFile(file) cache.RemoveFile(file)
cache.Save() cache.Save()
return files_requiring_changes == [] return files_requiring_changes == []
def DetectFilesToChange(self, files): def DetectFilesToChange(self, files):
...@@ -306,9 +310,9 @@ class CppLintProcessor(CacheableSourceFileProcessor): ...@@ -306,9 +310,9 @@ class CppLintProcessor(CacheableSourceFileProcessor):
Lint files to check that they follow the google code style. Lint files to check that they follow the google code style.
""" """
def __init__(self): def __init__(self, use_cache=True):
super(CppLintProcessor, self).__init__( super(CppLintProcessor, self).__init__(
cache_file_path='.cpplint-cache', file_type='C/C++') use_cache=use_cache, cache_file_path='.cpplint-cache', file_type='C/C++')
def IsRelevant(self, name): def IsRelevant(self, name):
return name.endswith('.cc') or name.endswith('.h') return name.endswith('.cc') or name.endswith('.h')
...@@ -348,9 +352,9 @@ class TorqueFormatProcessor(CacheableSourceFileProcessor): ...@@ -348,9 +352,9 @@ class TorqueFormatProcessor(CacheableSourceFileProcessor):
Check .tq files to verify they follow the Torque style guide. Check .tq files to verify they follow the Torque style guide.
""" """
def __init__(self): def __init__(self, use_cache=True):
super(TorqueFormatProcessor, self).__init__( super(TorqueFormatProcessor, self).__init__(
cache_file_path='.torquelint-cache', file_type='Torque') use_cache=use_cache, cache_file_path='.torquelint-cache', file_type='Torque')
def IsRelevant(self, name): def IsRelevant(self, name):
return name.endswith('.tq') return name.endswith('.tq')
...@@ -660,6 +664,9 @@ def GetOptions(): ...@@ -660,6 +664,9 @@ def GetOptions():
result = optparse.OptionParser() result = optparse.OptionParser()
result.add_option('--no-lint', help="Do not run cpplint", default=False, result.add_option('--no-lint', help="Do not run cpplint", default=False,
action="store_true") action="store_true")
result.add_option('--no-linter-cache', help="Do not cache linter results", default=False,
action="store_true")
return result return result
...@@ -670,11 +677,13 @@ def Main(): ...@@ -670,11 +677,13 @@ def Main():
success = True success = True
print "Running checkdeps..." print "Running checkdeps..."
success &= CheckDeps(workspace) success &= CheckDeps(workspace)
use_linter_cache = not options.no_linter_cache
if not options.no_lint: if not options.no_lint:
print "Running C++ lint check..." print "Running C++ lint check..."
success &= CppLintProcessor().RunOnPath(workspace) success &= CppLintProcessor(use_cache=use_linter_cache).RunOnPath(workspace)
print "Running Torque formatting check..." print "Running Torque formatting check..."
success &= TorqueFormatProcessor().RunOnPath(workspace) success &= TorqueFormatProcessor(use_cache=use_linter_cache).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().RunOnPath(workspace) success &= SourceProcessor().RunOnPath(workspace)
......
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