Modify gcl lint to use regexes to figure out which files should be linted.

I've added two settings to codereview.settings - LINT_REGEX and 
LINT_IGNORE_REGEX - to specify which files should be linted. The default
is to lint anything that ends in .cpp, .cc, .inl, or .h, and to ignore 
nothing.

I have also modified GetCachedFile() to look for a locally modified version 
of codereview.settings before looking in the repository.

  R=maruel@chromium.org
  TEST=none
  BUG=none

Review URL: http://codereview.chromium.org/257054

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@30415 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
dpranke@google.com 16 years ago
parent 260c65333a
commit bb816387a8

@ -132,7 +132,7 @@ def GetCachedFile(filename, max_age=60*60*24*3, use_root=False):
directory to the root repository.
Note: The cache will be inconsistent if the same file is retrieved with both
use_root=True and use_root=False on the same file. Don't be stupid.
use_root=True and use_root=False. Don't be stupid.
"""
global FILES_CACHE
if filename not in FILES_CACHE:
@ -153,9 +153,16 @@ def GetCachedFile(filename, max_age=60*60*24*3, use_root=False):
url_path = dir_info["URL"]
content = ""
while True:
# Look for the codereview.settings file at the current level.
svn_path = url_path + "/" + filename
content, rc = RunShellWithReturnCode(["svn", "cat", svn_path])
# First, look for a locally modified version of codereview.settings.
content, rc = RunShellWithReturnCode(["svn", "status", filename])
if not rc and content.startswith('M'):
content = ReadFile(filename)
rc = 0
else:
# Then look in the repository
svn_path = url_path + "/" + filename
content, rc = RunShellWithReturnCode(["svn", "cat", svn_path])
if not rc:
# Exit the loop if the file was found. Override content.
break
@ -1077,7 +1084,8 @@ def Change(change_info, args):
IGNORE_PATHS = (os.path.join("webkit","api"),)
# Valid extensions for files we want to lint.
CPP_EXTENSIONS = ("cpp", "cc", "h")
LINT_REGEX = r"(.*\.cpp|.*\.cc|.*\.h)"
LINT_IGNORE_REGEX = r""
def Lint(change_info, args):
"""Runs cpplint.py on all the files in |change_info|"""
@ -1094,12 +1102,22 @@ def Lint(change_info, args):
# Process cpplints arguments if any.
filenames = cpplint.ParseArguments(args + change_info.GetFileNames())
white_list = GetCodeReviewSetting("LINT_REGEX")
if not white_list:
white_list = LINT_REGEX
white_regex = re.compile(white_list)
black_list = GetCodeReviewSetting("LINT_IGNORE_REGEX")
if not black_list:
black_list = LINT_IGNORE_REGEX
black_regex = re.compile(black_list)
for file in filenames:
if len([file for suffix in CPP_EXTENSIONS if file.endswith(suffix)]):
if len([file for prefix in IGNORE_PATHS if file.startswith(prefix)]):
print "Ignoring non-Google styled file %s" % file
if white_regex.match(file):
if black_regex.match(file):
print "Ignoring file %s" % file
else:
cpplint.ProcessFile(file, cpplint._cpplint_state.verbose_level)
else:
print "Skipping file %s" % file
print "Total errors found: %d\n" % cpplint._cpplint_state.error_count
os.chdir(previous_cwd)

@ -40,7 +40,7 @@ class GclUnittest(GclTestsBase):
def testMembersChanged(self):
self.mox.ReplayAll()
members = [
'CODEREVIEW_SETTINGS', 'CODEREVIEW_SETTINGS_FILE', 'CPP_EXTENSIONS',
'CODEREVIEW_SETTINGS', 'CODEREVIEW_SETTINGS_FILE',
'Change', 'ChangeInfo', 'Changes', 'DeleteEmptyChangeLists', 'Commit',
'DoPresubmitChecks',
'ErrorExit', 'FILES_CACHE', 'FilterFlag', 'GenerateChangeName',
@ -50,6 +50,7 @@ class GclUnittest(GclTestsBase):
'GetFilesNotInCL', 'GetInfoDir', 'GetIssueDescription',
'GetModifiedFiles', 'GetRepositoryRoot',
'GetSVNFileProperty', 'Help', 'IGNORE_PATHS', 'IsSVNMoved',
'LINT_IGNORE_REGEX', 'LINT_REGEX',
'Lint', 'LoadChangelistInfoForMultiple',
'MISSING_TEST_MSG', 'Opened', 'OptionallyDoPresubmitChecks',
'PresubmitCL', 'ReadFile', 'REPOSITORY_ROOT', 'RunShell',

Loading…
Cancel
Save