Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: cc/PRESUBMIT.py

Issue 23591027: Allow NOLINT to skip the std::abs PRESUBMIT check. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | cc/output/shader.cc » ('j') | cc/output/shader.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Top-level presubmit script for cc. 5 """Top-level presubmit script for cc.
6 6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
8 details on the presubmit API built into gcl. 8 details on the presubmit API built into gcl.
9 """ 9 """
10 10
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 missing_std_prefix_files = [] 69 missing_std_prefix_files = []
70 70
71 for f in input_api.AffectedSourceFiles(source_file_filter): 71 for f in input_api.AffectedSourceFiles(source_file_filter):
72 contents = input_api.ReadFile(f, 'rb') 72 contents = input_api.ReadFile(f, 'rb')
73 if re.search(r"using std::f?abs;", contents): 73 if re.search(r"using std::f?abs;", contents):
74 using_std_abs_files.append(f.LocalPath()) 74 using_std_abs_files.append(f.LocalPath())
75 if re.search(r"\bfabsf?\(", contents): 75 if re.search(r"\bfabsf?\(", contents):
76 found_fabs_files.append(f.LocalPath()); 76 found_fabs_files.append(f.LocalPath());
77 # The following regular expression in words says: 77 # The following regular expression in words says:
78 # "if there is no 'std::' behind an 'abs(' or 'absf(', 78 # "if there is no 'std::' behind an 'abs(' or 'absf(',
79 # or if there is no 'std::' behind a 'fabs(' or 'fabsf(', 79 # OR if there is no 'std::' behind a 'fabs(' or 'fabsf(',
80 # AND if there's no '// NOLINT' on the same line of code,
80 # then it's a match." 81 # then it's a match."
81 if re.search(r"((?<!std::)(\babsf?\()|(?<!std::)(\bfabsf?\())", contents): 82 # Note that \ characters have to be escaped since these
83 # are not explicitly defined as regexes.
84 no_abs = "((?<!std::)(\\babsf?\\()"
85 no_fabs = "(?<!std::)(\\bfabsf?\\())"
86 no_nolint = "(?![^\\n]*// NOLINT)"
enne (OOO) 2013/09/05 01:00:40 Maybe \s+ instead of the space in NOLINT?
87 expression = re.compile("%s|%s%s" % (no_abs, no_fabs, no_nolint))
enne (OOO) 2013/09/05 01:00:40 If you're going to put an | outside of the strings
88 if expression.search(contents):
82 missing_std_prefix_files.append(f.LocalPath()) 89 missing_std_prefix_files.append(f.LocalPath())
83 90
84 result = [] 91 result = []
85 if using_std_abs_files: 92 if using_std_abs_files:
86 result.append(output_api.PresubmitError( 93 result.append(output_api.PresubmitError(
87 'These files have "using std::abs" which is not permitted.', 94 'These files have "using std::abs" which is not permitted.',
88 items=using_std_abs_files)) 95 items=using_std_abs_files))
89 if found_fabs_files: 96 if found_fabs_files:
90 result.append(output_api.PresubmitError( 97 result.append(output_api.PresubmitError(
91 'std::abs() should be used instead of std::fabs() for consistency.', 98 'std::abs() should be used instead of std::fabs() for consistency.',
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 results += CheckSpamLogging(input_api, output_api, black_list=CC_PERF_TEST) 191 results += CheckSpamLogging(input_api, output_api, black_list=CC_PERF_TEST)
185 results += CheckPassByValue(input_api, output_api) 192 results += CheckPassByValue(input_api, output_api)
186 results += CheckChangeLintsClean(input_api, output_api) 193 results += CheckChangeLintsClean(input_api, output_api)
187 results += CheckTodos(input_api, output_api) 194 results += CheckTodos(input_api, output_api)
188 return results 195 return results
189 196
190 def GetPreferredTrySlaves(project, change): 197 def GetPreferredTrySlaves(project, change):
191 return [ 198 return [
192 'linux_layout_rel', 199 'linux_layout_rel',
193 ] 200 ]
OLDNEW
« no previous file with comments | « no previous file | cc/output/shader.cc » ('j') | cc/output/shader.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698