From e72c5f519a8194e55a07f350f572d81b0b85f4d4 Mon Sep 17 00:00:00 2001 From: "enne@chromium.org" Date: Tue, 16 Apr 2013 00:36:40 +0000 Subject: [PATCH] Add cpplint to presubmit input_api This will let clients that don't use the heavily filtered canned cpplint check and want to behave more strictly (aka cc/) reuse any common settings applied to the cpplint module. R=maruel@chromium.org BUG=none Review URL: https://codereview.chromium.org/13866044 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@194264 0039d316-1c4b-4281-b951-d872f2087c98 --- presubmit_canned_checks.py | 11 +---------- presubmit_support.py | 14 +++++++++++++- tests/presubmit_unittest.py | 25 ++++++++++++------------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 62471fc83..209d65434 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -95,8 +95,7 @@ def CheckChangeLintsClean(input_api, output_api, source_file_filter=None): _RE_IS_TEST = input_api.re.compile(r'.*tests?.(cc|h)$') result = [] - # Initialize cpplint. - import cpplint + cpplint = input_api.cpplint # Access to a protected member _XX of a client class # pylint: disable=W0212 cpplint._cpplint_state.ResetErrorCounts() @@ -114,14 +113,6 @@ def CheckChangeLintsClean(input_api, output_api, source_file_filter=None): '-readability/casting,-runtime/int,-runtime/virtual,' '-whitespace/braces') - # Replace and as headers that need to be included - # with "base/hash_tables.h" instead. - cpplint._re_pattern_templates = [ - (a, b, 'base/hash_tables.h') - if header in ('', '') else (a, b, header) - for (a, b, header) in cpplint._re_pattern_templates - ] - # We currently are more strict with normal code than unit tests; 4 and 5 are # the verbosity level that would normally be passed to cpplint.py through # --verbose=#. Hopefully, in the future, we can be more verbose. diff --git a/presubmit_support.py b/presubmit_support.py index 814d3fc37..fe1c2878c 100755 --- a/presubmit_support.py +++ b/presubmit_support.py @@ -6,12 +6,13 @@ """Enables directory-specific presubmit checks to run at upload and/or commit. """ -__version__ = '1.6.1' +__version__ = '1.6.2' # TODO(joi) Add caching where appropriate/needed. The API is designed to allow # caching (between all different invocations of presubmit scripts for a given # change). We should add it as our presubmit scripts start feeling slow. +import cpplint import cPickle # Exposed through the API. import cStringIO # Exposed through the API. import contextlib @@ -247,6 +248,7 @@ class InputApi(object): # so that presubmit scripts don't have to import them. self.basename = os.path.basename self.cPickle = cPickle + self.cpplint = cpplint self.cStringIO = cStringIO self.glob = glob.glob self.json = json @@ -283,6 +285,16 @@ class InputApi(object): fopen=file, os_path=self.os_path, glob=self.glob) self.verbose = verbose + # Replace and as headers that need to be included + # with "base/hash_tables.h" instead. + # Access to a protected member _XX of a client class + # pylint: disable=W0212 + self.cpplint._re_pattern_templates = [ + (a, b, 'base/hash_tables.h') + if header in ('', '') else (a, b, header) + for (a, b, header) in cpplint._re_pattern_templates + ] + def PresubmitLocalPath(self): """Returns the local path of the presubmit script currently being run. diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index dc5c85404..243c9070f 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -161,14 +161,13 @@ class PresubmitUnittest(PresubmitTestsBase): 'GitChange', 'InputApi', 'ListRelevantPresubmitFiles', 'Main', 'NonexistantCannedCheckFilter', 'OutputApi', 'ParseFiles', 'PresubmitFailure', 'PresubmitExecuter', 'PresubmitOutput', 'ScanSubDirs', - 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO', 'contextlib', - 'canned_check_filter', 'fix_encoding', 'fnmatch', 'gclient_utils', 'glob', - 'inspect', 'json', 'load_files', - 'logging', 'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle', + 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cpplint', 'cStringIO', + 'contextlib', 'canned_check_filter', 'fix_encoding', 'fnmatch', + 'gclient_utils', 'glob', 'inspect', 'json', 'load_files', 'logging', + 'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle', 'presubmit_canned_checks', 'random', 're', 'rietveld', 'scm', - 'subprocess', - 'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2', - 'warn', + 'subprocess', 'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', + 'urllib2', 'warn', ] # If this test fails, you should add the relevant test. self.compareMembers(presubmit, members) @@ -884,12 +883,12 @@ class InputApiUnittest(PresubmitTestsBase): 'DepotToLocalPath', 'FilterSourceFile', 'LocalPaths', 'LocalToDepotPath', 'PresubmitLocalPath', 'ReadFile', 'RightHandSideLines', 'ServerPaths', - 'basename', 'cPickle', 'cStringIO', 'canned_checks', 'change', 'environ', - 'glob', 'host_url', 'is_committing', 'json', 'logging', 'marshal', - 'os_listdir', 'os_walk', - 'os_path', 'owners_db', 'pickle', 'platform', 'python_executable', 're', - 'rietveld', 'subprocess', 'tbr', 'tempfile', 'time', 'traceback', - 'unittest', 'urllib2', 'version', 'verbose', + 'basename', 'cPickle', 'cpplint', 'cStringIO', 'canned_checks', 'change', + 'environ', 'glob', 'host_url', 'is_committing', 'json', 'logging', + 'marshal', 'os_listdir', 'os_walk', 'os_path', 'owners_db', 'pickle', + 'platform', 'python_executable', 're', 'rietveld', 'subprocess', 'tbr', + 'tempfile', 'time', 'traceback', 'unittest', 'urllib2', 'version', + 'verbose', ] # If this test fails, you should add the relevant test. self.compareMembers(