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 | |
13 | 12 |
14 CC_SOURCE_FILES=(r'^cc/.*\.(cc|h)$',) | 13 CC_SOURCE_FILES=(r'^cc/.*\.(cc|h)$',) |
15 | 14 |
16 def CheckChangeLintsClean(input_api, output_api): | 15 def CheckChangeLintsClean(input_api, output_api): |
17 input_api.cpplint._cpplint_state.ResetErrorCounts() # reset global state | 16 input_api.cpplint._cpplint_state.ResetErrorCounts() # reset global state |
18 source_filter = lambda x: input_api.FilterSourceFile( | 17 source_filter = lambda x: input_api.FilterSourceFile( |
19 x, white_list=CC_SOURCE_FILES, black_list=None) | 18 x, white_list=CC_SOURCE_FILES, black_list=None) |
20 files = [f.AbsoluteLocalPath() for f in | 19 files = [f.AbsoluteLocalPath() for f in |
21 input_api.AffectedSourceFiles(source_filter)] | 20 input_api.AffectedSourceFiles(source_filter)] |
22 level = 1 # strict, but just warn | 21 level = 1 # strict, but just warn |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 result.append(output_api.PresubmitError( | 94 result.append(output_api.PresubmitError( |
96 'std::abs() should be used instead of std::fabs() for consistency.', | 95 'std::abs() should be used instead of std::fabs() for consistency.', |
97 items=found_fabs_files)) | 96 items=found_fabs_files)) |
98 if missing_std_prefix_files: | 97 if missing_std_prefix_files: |
99 result.append(output_api.PresubmitError( | 98 result.append(output_api.PresubmitError( |
100 'These files use abs(), absf(), fabs(), or fabsf() without qualifying ' | 99 'These files use abs(), absf(), fabs(), or fabsf() without qualifying ' |
101 'the std namespace. Please use std::abs() in all places.', | 100 'the std namespace. Please use std::abs() in all places.', |
102 items=missing_std_prefix_files)) | 101 items=missing_std_prefix_files)) |
103 return result | 102 return result |
104 | 103 |
105 def CheckPassByValue(input_api, | |
enne (OOO)
2014/01/02 18:42:56
The presubmit here was nice because it communicate
| |
106 output_api, | |
107 white_list=CC_SOURCE_FILES, | |
108 black_list=None): | |
109 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) | |
110 source_file_filter = lambda x: input_api.FilterSourceFile(x, | |
111 white_list, | |
112 black_list) | |
113 | |
114 local_errors = [] | |
115 | |
116 # Well-defined simple classes containing only <= 4 ints, or <= 2 floats. | |
117 pass_by_value_types = ['base::Time', | |
118 'base::TimeTicks', | |
119 'gfx::Point', | |
120 'gfx::PointF', | |
121 'gfx::Rect', | |
122 'gfx::Size', | |
123 'gfx::SizeF', | |
124 'gfx::Vector2d', | |
125 'gfx::Vector2dF', | |
126 ] | |
127 | |
128 for f in input_api.AffectedSourceFiles(source_file_filter): | |
129 contents = input_api.ReadFile(f, 'rb') | |
130 match = re.search( | |
131 r'\bconst +' + '(?P<type>(%s))&' % | |
132 string.join(pass_by_value_types, '|'), | |
133 contents) | |
134 if match: | |
135 local_errors.append(output_api.PresubmitError( | |
136 '%s passes %s by const ref instead of by value.' % | |
137 (f.LocalPath(), match.group('type')))) | |
138 return local_errors | |
139 | |
140 def CheckTodos(input_api, output_api): | 104 def CheckTodos(input_api, output_api): |
141 errors = [] | 105 errors = [] |
142 | 106 |
143 source_file_filter = lambda x: x | 107 source_file_filter = lambda x: x |
144 for f in input_api.AffectedSourceFiles(source_file_filter): | 108 for f in input_api.AffectedSourceFiles(source_file_filter): |
145 contents = input_api.ReadFile(f, 'rb') | 109 contents = input_api.ReadFile(f, 'rb') |
146 if ('FIX'+'ME') in contents: | 110 if ('FIX'+'ME') in contents: |
147 errors.append(f.LocalPath()) | 111 errors.append(f.LocalPath()) |
148 | 112 |
149 if errors: | 113 if errors: |
150 return [output_api.PresubmitError( | 114 return [output_api.PresubmitError( |
151 'All TODO comments should be of the form TODO(name).', | 115 'All TODO comments should be of the form TODO(name).', |
152 items=errors)] | 116 items=errors)] |
153 return [] | 117 return [] |
154 | 118 |
155 | 119 |
156 def CheckChangeOnUpload(input_api, output_api): | 120 def CheckChangeOnUpload(input_api, output_api): |
157 results = [] | 121 results = [] |
158 results += CheckAsserts(input_api, output_api) | 122 results += CheckAsserts(input_api, output_api) |
159 results += CheckStdAbs(input_api, output_api) | 123 results += CheckStdAbs(input_api, output_api) |
160 results += CheckPassByValue(input_api, output_api) | |
161 results += CheckChangeLintsClean(input_api, output_api) | 124 results += CheckChangeLintsClean(input_api, output_api) |
162 results += CheckTodos(input_api, output_api) | 125 results += CheckTodos(input_api, output_api) |
163 return results | 126 return results |
164 | 127 |
165 def GetPreferredTrySlaves(project, change): | 128 def GetPreferredTrySlaves(project, change): |
166 return [ | 129 return [ |
167 'linux_layout_rel', | 130 'linux_layout_rel', |
168 'win_gpu', | 131 'win_gpu', |
169 'linux_gpu', | 132 'linux_gpu', |
170 'mac_gpu', | 133 'mac_gpu', |
171 'mac_gpu_retina', | 134 'mac_gpu_retina', |
172 ] | 135 ] |
OLD | NEW |