Skip to content

Commit a5a381b

Browse files
Tamer TasCommit Bot
authored andcommitted
[test] add an option for disabling linter cache in the pre_submit check
Adds a flag to specify whether to disable the linter caching. [email protected],[email protected] CC=​​[email protected] Bug: v8:8482 Change-Id: I62a9b7cffb3adb50b136659568ad52078675ca4b No-Try: true Reviewed-on: https://chromium-review.googlesource.com/c/1370029 Reviewed-by: Michael Achenbach <[email protected]> Commit-Queue: Tamer Tas <[email protected]> Cr-Commit-Position: refs/heads/master@{#58329}
1 parent e9a0e0e commit a5a381b

2 files changed

Lines changed: 23 additions & 14 deletions

File tree

tools/unittests/v8_presubmit_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class FakeCachedProcessor(CacheableSourceFileProcessor):
1919
def __init__(self, cache_file_path):
2020
super(FakeCachedProcessor, self).__init__(
21-
cache_file_path=cache_file_path, file_type='.test')
21+
use_cache=True, cache_file_path=cache_file_path, file_type='.test')
2222
def GetProcessorWorker(self):
2323
return object
2424
def GetProcessorScript(self):

tools/v8_presubmit.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ class CacheableSourceFileProcessor(SourceFileProcessor):
235235
the files requiring intervention after processing the source files.
236236
"""
237237

238-
def __init__(self, cache_file_path, file_type):
238+
def __init__(self, use_cache, cache_file_path, file_type):
239+
self.use_cache = use_cache
239240
self.cache_file_path = cache_file_path
240241
self.file_type = file_type
241242

@@ -260,9 +261,10 @@ def GetProcessorCommand(self):
260261
return command
261262

262263
def ProcessFiles(self, files):
263-
cache = FileContentsCache(self.cache_file_path)
264-
cache.Load()
265-
files = cache.FilterUnchangedFiles(files)
264+
if self.use_cache:
265+
cache = FileContentsCache(self.cache_file_path)
266+
cache.Load()
267+
files = cache.FilterUnchangedFiles(files)
266268

267269
if len(files) == 0:
268270
print 'No changes in %s files detected. Skipping check' % self.file_type
@@ -272,10 +274,12 @@ def ProcessFiles(self, files):
272274
print (
273275
'Total %s files found that require formatting: %d' %
274276
(self.file_type, len(files_requiring_changes)))
275-
for file in files_requiring_changes:
276-
cache.RemoveFile(file)
277+
if self.use_cache:
278+
for file in files_requiring_changes:
279+
cache.RemoveFile(file)
280+
281+
cache.Save()
277282

278-
cache.Save()
279283
return files_requiring_changes == []
280284

281285
def DetectFilesToChange(self, files):
@@ -306,9 +310,9 @@ class CppLintProcessor(CacheableSourceFileProcessor):
306310
Lint files to check that they follow the google code style.
307311
"""
308312

309-
def __init__(self):
313+
def __init__(self, use_cache=True):
310314
super(CppLintProcessor, self).__init__(
311-
cache_file_path='.cpplint-cache', file_type='C/C++')
315+
use_cache=use_cache, cache_file_path='.cpplint-cache', file_type='C/C++')
312316

313317
def IsRelevant(self, name):
314318
return name.endswith('.cc') or name.endswith('.h')
@@ -348,9 +352,9 @@ class TorqueFormatProcessor(CacheableSourceFileProcessor):
348352
Check .tq files to verify they follow the Torque style guide.
349353
"""
350354

351-
def __init__(self):
355+
def __init__(self, use_cache=True):
352356
super(TorqueFormatProcessor, self).__init__(
353-
cache_file_path='.torquelint-cache', file_type='Torque')
357+
use_cache=use_cache, cache_file_path='.torquelint-cache', file_type='Torque')
354358

355359
def IsRelevant(self, name):
356360
return name.endswith('.tq')
@@ -660,6 +664,9 @@ def GetOptions():
660664
result = optparse.OptionParser()
661665
result.add_option('--no-lint', help="Do not run cpplint", default=False,
662666
action="store_true")
667+
result.add_option('--no-linter-cache', help="Do not cache linter results", default=False,
668+
action="store_true")
669+
663670
return result
664671

665672

@@ -670,11 +677,13 @@ def Main():
670677
success = True
671678
print "Running checkdeps..."
672679
success &= CheckDeps(workspace)
680+
use_linter_cache = not options.no_linter_cache
673681
if not options.no_lint:
674682
print "Running C++ lint check..."
675-
success &= CppLintProcessor().RunOnPath(workspace)
683+
success &= CppLintProcessor(use_cache=use_linter_cache).RunOnPath(workspace)
684+
676685
print "Running Torque formatting check..."
677-
success &= TorqueFormatProcessor().RunOnPath(workspace)
686+
success &= TorqueFormatProcessor(use_cache=use_linter_cache).RunOnPath(workspace)
678687
print "Running copyright header, trailing whitespaces and " \
679688
"two empty lines between declarations check..."
680689
success &= SourceProcessor().RunOnPath(workspace)

0 commit comments

Comments
 (0)