OLD | NEW |
---|---|
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 |
11 import re | 11 import re |
12 import string | |
12 | 13 |
13 CC_SOURCE_FILES=(r'^cc/.*\.(cc|h)$',) | 14 CC_SOURCE_FILES=(r'^cc/.*\.(cc|h)$',) |
14 CC_PERF_TEST =(r'^.*_perftest.*\.(cc|h)$',) | 15 CC_PERF_TEST =(r'^.*_perftest.*\.(cc|h)$',) |
15 | 16 |
16 def CheckChangeLintsClean(input_api, output_api): | 17 def CheckChangeLintsClean(input_api, output_api): |
17 input_api.cpplint._cpplint_state.ResetErrorCounts() # reset global state | 18 input_api.cpplint._cpplint_state.ResetErrorCounts() # reset global state |
18 source_filter = lambda x: input_api.FilterSourceFile( | 19 source_filter = lambda x: input_api.FilterSourceFile( |
19 x, white_list=CC_SOURCE_FILES, black_list=None) | 20 x, white_list=CC_SOURCE_FILES, black_list=None) |
20 files = [f.AbsoluteLocalPath() for f in | 21 files = [f.AbsoluteLocalPath() for f in |
21 input_api.AffectedSourceFiles(source_filter)] | 22 input_api.AffectedSourceFiles(source_filter)] |
(...skipping 27 matching lines...) Expand all Loading... | |
49 if assert_files: | 50 if assert_files: |
50 return [output_api.PresubmitError( | 51 return [output_api.PresubmitError( |
51 'These files use ASSERT instead of using DCHECK:', | 52 'These files use ASSERT instead of using DCHECK:', |
52 items=assert_files)] | 53 items=assert_files)] |
53 if notreached_files: | 54 if notreached_files: |
54 return [output_api.PresubmitError( | 55 return [output_api.PresubmitError( |
55 'These files use ASSERT_NOT_REACHED instead of using NOTREACHED:', | 56 'These files use ASSERT_NOT_REACHED instead of using NOTREACHED:', |
56 items=notreached_files)] | 57 items=notreached_files)] |
57 return [] | 58 return [] |
58 | 59 |
59 def CheckSpamLogging(input_api, output_api, white_list=CC_SOURCE_FILES, black_li st=None): | 60 def CheckSpamLogging(input_api, |
61 output_api, | |
62 white_list=CC_SOURCE_FILES, | |
63 black_list=None): | |
60 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) | 64 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) |
61 source_file_filter = lambda x: input_api.FilterSourceFile(x, white_list, black _list) | 65 source_file_filter = lambda x: input_api.FilterSourceFile(x, |
66 white_list, | |
enne (OOO)
2013/04/22 18:40:23
<_<
danakj
2013/04/22 18:43:34
Linter gets what linter wants. :p
| |
67 black_list) | |
62 | 68 |
63 log_info = [] | 69 log_info = [] |
64 printf = [] | 70 printf = [] |
65 | 71 |
66 for f in input_api.AffectedSourceFiles(source_file_filter): | 72 for f in input_api.AffectedSourceFiles(source_file_filter): |
67 contents = input_api.ReadFile(f, 'rb') | 73 contents = input_api.ReadFile(f, 'rb') |
68 if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents): | 74 if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents): |
69 log_info.append(f.LocalPath()) | 75 log_info.append(f.LocalPath()) |
70 if re.search(r"\bf?printf\(", contents): | 76 if re.search(r"\bf?printf\(", contents): |
71 printf.append(f.LocalPath()) | 77 printf.append(f.LocalPath()) |
72 | 78 |
73 if log_info: | 79 if log_info: |
74 return [output_api.PresubmitError( | 80 return [output_api.PresubmitError( |
75 'These files spam the console log with LOG(INFO):', | 81 'These files spam the console log with LOG(INFO):', |
76 items=log_info)] | 82 items=log_info)] |
77 if printf: | 83 if printf: |
78 return [output_api.PresubmitError( | 84 return [output_api.PresubmitError( |
79 'These files spam the console log with printf/fprintf:', | 85 'These files spam the console log with printf/fprintf:', |
80 items=printf)] | 86 items=printf)] |
81 return [] | 87 return [] |
82 | 88 |
89 def CheckPassByValue(input_api, | |
90 output_api, | |
91 white_list=CC_SOURCE_FILES, | |
92 black_list=None): | |
93 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) | |
94 source_file_filter = lambda x: input_api.FilterSourceFile(x, | |
95 white_list, | |
96 black_list) | |
97 | |
98 local_errors = [] | |
99 | |
100 pass_by_value_types = ['Rect', 'Point', 'Size', 'Vector2d', | |
101 'PointF', 'SizeF', 'Vector2dF'] | |
102 | |
103 for f in input_api.AffectedSourceFiles(source_file_filter): | |
104 contents = input_api.ReadFile(f, 'rb') | |
105 match = re.search( | |
106 r'\bconst +' + '(?P<type>gfx::(%s))&' % | |
enne (OOO)
2013/04/22 18:40:23
I'm a little worried about false positives here.
danakj
2013/04/22 18:43:34
Hm.. true.. why must c++ be so hard to regex.
| |
107 string.join(pass_by_value_types, '|'), | |
108 contents) | |
109 if match: | |
110 local_errors.append(output_api.PresubmitError( | |
111 '%s passes %s by const ref instead of by value.' % | |
112 (f.LocalPath(), match.group('type')))) | |
113 return local_errors | |
83 | 114 |
84 def CheckChangeOnUpload(input_api, output_api): | 115 def CheckChangeOnUpload(input_api, output_api): |
85 results = [] | 116 results = [] |
86 results += CheckAsserts(input_api, output_api) | 117 results += CheckAsserts(input_api, output_api) |
87 results += CheckSpamLogging(input_api, output_api, black_list=CC_PERF_TEST) | 118 results += CheckSpamLogging(input_api, output_api, black_list=CC_PERF_TEST) |
119 results += CheckPassByValue(input_api, output_api) | |
88 results += CheckChangeLintsClean(input_api, output_api) | 120 results += CheckChangeLintsClean(input_api, output_api) |
89 return results | 121 return results |
90 | 122 |
91 def GetPreferredTrySlaves(project, change): | 123 def GetPreferredTrySlaves(project, change): |
92 return [ | 124 return [ |
93 'linux_layout_rel', | 125 'linux_layout_rel', |
94 ] | 126 ] |
OLD | NEW |