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.
[email protected]
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
diff --git a/gcl.py b/gcl.py
index 54bc26a..2a81861 100755
--- a/gcl.py
+++ b/gcl.py
@@ -132,7 +132,7 @@
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 @@
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 @@
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 @@
# 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)