Commit e72c5f51 authored by enne@chromium.org's avatar enne@chromium.org

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
parent 29ff7cd4
......@@ -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 <hash_map> and <hash_set> 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 ('<hash_map>', '<hash_set>') 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.
......
......@@ -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 <hash_map> and <hash_set> 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 ('<hash_map>', '<hash_set>') 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.
......
......@@ -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(
......
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