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

Unified Diff: cc/PRESUBMIT.py

Issue 14410002: cc: Add PRESUBMIT check for passing simple gfx types by value. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/PRESUBMIT.py
diff --git a/cc/PRESUBMIT.py b/cc/PRESUBMIT.py
index e82e9abb0dd5008ab0d15786eb90e077e6035b8a..e133e9ab5f069b79d4c5ab00c759f57a03dd51cc 100644
--- a/cc/PRESUBMIT.py
+++ b/cc/PRESUBMIT.py
@@ -9,6 +9,7 @@ details on the presubmit API built into gcl.
"""
import re
+import string
CC_SOURCE_FILES=(r'^cc/.*\.(cc|h)$',)
CC_PERF_TEST =(r'^.*_perftest.*\.(cc|h)$',)
@@ -56,9 +57,14 @@ def CheckAsserts(input_api, output_api, white_list=CC_SOURCE_FILES, black_list=N
items=notreached_files)]
return []
-def CheckSpamLogging(input_api, output_api, white_list=CC_SOURCE_FILES, black_list=None):
+def CheckSpamLogging(input_api,
+ output_api,
+ white_list=CC_SOURCE_FILES,
+ black_list=None):
black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST)
- source_file_filter = lambda x: input_api.FilterSourceFile(x, white_list, black_list)
+ source_file_filter = lambda x: input_api.FilterSourceFile(x,
+ white_list,
+ black_list)
log_info = []
printf = []
@@ -80,11 +86,46 @@ def CheckSpamLogging(input_api, output_api, white_list=CC_SOURCE_FILES, black_li
items=printf)]
return []
+def CheckPassByValue(input_api,
+ output_api,
+ white_list=CC_SOURCE_FILES,
+ black_list=None):
+ black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST)
+ source_file_filter = lambda x: input_api.FilterSourceFile(x,
+ white_list,
+ black_list)
+
+ local_errors = []
+
+ # Well-defined simple classes containing only <= 4 ints, or <= 2 floats.
+ pass_by_value_types = ['base::Time',
+ 'base::TimeTicks',
+ 'gfx::Point',
+ 'gfx::PointF',
+ 'gfx::Rect',
+ 'gfx::Size',
+ 'gfx::SizeF',
+ 'gfx::Vector2d',
+ 'gfx::Vector2dF',
+ ]
+
+ for f in input_api.AffectedSourceFiles(source_file_filter):
+ contents = input_api.ReadFile(f, 'rb')
+ match = re.search(
+ r'\bconst +' + '(?P<type>(%s))&' %
+ string.join(pass_by_value_types, '|'),
+ contents)
+ if match:
+ local_errors.append(output_api.PresubmitError(
+ '%s passes %s by const ref instead of by value.' %
+ (f.LocalPath(), match.group('type'))))
+ return local_errors
def CheckChangeOnUpload(input_api, output_api):
results = []
results += CheckAsserts(input_api, output_api)
results += CheckSpamLogging(input_api, output_api, black_list=CC_PERF_TEST)
+ results += CheckPassByValue(input_api, output_api)
results += CheckChangeLintsClean(input_api, output_api)
return results
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698