OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 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 components/viz. |
6 | 6 |
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
8 for more details about the presubmit API built into depot_tools. | 8 for more details about the presubmit API built into depot_tools. |
9 """ | 9 """ |
10 | 10 |
11 import re | 11 import re |
12 import string | 12 import string |
13 | 13 |
14 CC_SOURCE_FILES=(r'^cc[\\/].*\.(cc|h)$',) | 14 VIZ_SOURCE_FILES=(r'^components[\\/]viz[\\/].*\.(cc|h)$',) |
15 | 15 |
16 def CheckChangeLintsClean(input_api, output_api): | 16 def CheckChangeLintsClean(input_api, output_api): |
17 source_filter = lambda x: input_api.FilterSourceFile( | 17 source_filter = lambda x: input_api.FilterSourceFile( |
18 x, white_list=CC_SOURCE_FILES, black_list=None) | 18 x, white_list=VIZ_SOURCE_FILES, black_list=None) |
19 | 19 |
20 return input_api.canned_checks.CheckChangeLintsClean( | 20 return input_api.canned_checks.CheckChangeLintsClean( |
21 input_api, output_api, source_filter, lint_filters=[], verbose_level=1) | 21 input_api, output_api, source_filter, lint_filters=[], verbose_level=1) |
22 | 22 |
23 def CheckAsserts(input_api, output_api, white_list=CC_SOURCE_FILES, black_list=N
one): | 23 def CheckAsserts(input_api, output_api, white_list=VIZ_SOURCE_FILES, black_list=
None): |
24 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) | 24 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) |
25 source_file_filter = lambda x: input_api.FilterSourceFile(x, white_list, black
_list) | 25 source_file_filter = lambda x: input_api.FilterSourceFile(x, white_list, black
_list) |
26 | 26 |
27 assert_files = [] | 27 assert_files = [] |
28 notreached_files = [] | |
29 | 28 |
30 for f in input_api.AffectedSourceFiles(source_file_filter): | 29 for f in input_api.AffectedSourceFiles(source_file_filter): |
31 contents = input_api.ReadFile(f, 'rb') | 30 contents = input_api.ReadFile(f, 'rb') |
32 # WebKit ASSERT() is not allowed. | 31 # WebKit ASSERT() is not allowed. |
33 if re.search(r"\bASSERT\(", contents): | 32 if re.search(r"\bASSERT\(", contents): |
34 assert_files.append(f.LocalPath()) | 33 assert_files.append(f.LocalPath()) |
35 # WebKit ASSERT_NOT_REACHED() is not allowed. | |
36 if re.search(r"ASSERT_NOT_REACHED\(", contents): | |
37 notreached_files.append(f.LocalPath()) | |
38 | 34 |
39 if assert_files: | 35 if assert_files: |
40 return [output_api.PresubmitError( | 36 return [output_api.PresubmitError( |
41 'These files use ASSERT instead of using DCHECK:', | 37 'These files use ASSERT instead of using DCHECK:', |
42 items=assert_files)] | 38 items=assert_files)] |
43 if notreached_files: | |
44 return [output_api.PresubmitError( | |
45 'These files use ASSERT_NOT_REACHED instead of using NOTREACHED:', | |
46 items=notreached_files)] | |
47 return [] | 39 return [] |
48 | 40 |
49 def CheckStdAbs(input_api, output_api, | 41 def CheckStdAbs(input_api, output_api, |
50 white_list=CC_SOURCE_FILES, black_list=None): | 42 white_list=VIZ_SOURCE_FILES, black_list=None): |
51 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) | 43 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) |
52 source_file_filter = lambda x: input_api.FilterSourceFile(x, | 44 source_file_filter = lambda x: input_api.FilterSourceFile(x, |
53 white_list, | 45 white_list, |
54 black_list) | 46 black_list) |
55 | 47 |
56 using_std_abs_files = [] | 48 using_std_abs_files = [] |
57 found_fabs_files = [] | 49 found_fabs_files = [] |
58 missing_std_prefix_files = [] | 50 missing_std_prefix_files = [] |
59 | 51 |
60 for f in input_api.AffectedSourceFiles(source_file_filter): | 52 for f in input_api.AffectedSourceFiles(source_file_filter): |
(...skipping 26 matching lines...) Expand all Loading... |
87 items=found_fabs_files)) | 79 items=found_fabs_files)) |
88 if missing_std_prefix_files: | 80 if missing_std_prefix_files: |
89 result.append(output_api.PresubmitError( | 81 result.append(output_api.PresubmitError( |
90 'These files use abs(), absf(), fabs(), or fabsf() without qualifying ' | 82 'These files use abs(), absf(), fabs(), or fabsf() without qualifying ' |
91 'the std namespace. Please use std::abs() in all places.', | 83 'the std namespace. Please use std::abs() in all places.', |
92 items=missing_std_prefix_files)) | 84 items=missing_std_prefix_files)) |
93 return result | 85 return result |
94 | 86 |
95 def CheckPassByValue(input_api, | 87 def CheckPassByValue(input_api, |
96 output_api, | 88 output_api, |
97 white_list=CC_SOURCE_FILES, | 89 white_list=VIZ_SOURCE_FILES, |
98 black_list=None): | 90 black_list=None): |
99 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) | 91 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) |
100 source_file_filter = lambda x: input_api.FilterSourceFile(x, | 92 source_file_filter = lambda x: input_api.FilterSourceFile(x, |
101 white_list, | 93 white_list, |
102 black_list) | 94 black_list) |
103 | 95 |
104 local_errors = [] | 96 local_errors = [] |
105 | 97 |
106 # Well-defined simple classes containing only <= 4 ints, or <= 2 floats. | 98 # Well-defined simple classes the same size as a primitive type. |
107 pass_by_value_types = ['base::Time', | 99 pass_by_value_types = ['base::Time', |
108 'base::TimeTicks', | 100 'base::TimeTicks', |
109 ] | 101 ] |
110 | 102 |
111 for f in input_api.AffectedSourceFiles(source_file_filter): | 103 for f in input_api.AffectedSourceFiles(source_file_filter): |
112 contents = input_api.ReadFile(f, 'rb') | 104 contents = input_api.ReadFile(f, 'rb') |
113 match = re.search( | 105 match = re.search( |
114 r'\bconst +' + '(?P<type>(%s))&' % | 106 r'\bconst +' + '(?P<type>(%s))&' % |
115 string.join(pass_by_value_types, '|'), | 107 string.join(pass_by_value_types, '|'), |
116 contents) | 108 contents) |
117 if match: | 109 if match: |
118 local_errors.append(output_api.PresubmitError( | 110 local_errors.append(output_api.PresubmitError( |
119 '%s passes %s by const ref instead of by value.' % | 111 '%s passes %s by const ref instead of by value.' % |
120 (f.LocalPath(), match.group('type')))) | 112 (f.LocalPath(), match.group('type')))) |
121 return local_errors | 113 return local_errors |
122 | 114 |
123 def CheckTodos(input_api, output_api): | 115 def CheckTodos(input_api, output_api): |
124 errors = [] | 116 errors = [] |
125 | 117 |
126 source_file_filter = lambda x: x | 118 source_file_filter = lambda x: x |
127 for f in input_api.AffectedSourceFiles(source_file_filter): | 119 for f in input_api.AffectedSourceFiles(source_file_filter): |
128 contents = input_api.ReadFile(f, 'rb') | 120 contents = input_api.ReadFile(f, 'rb') |
129 if ('FIX'+'ME') in contents: | 121 if ('FIX'+'ME') in contents: |
130 errors.append(f.LocalPath()) | 122 errors.append(f.LocalPath()) |
131 | 123 |
132 if errors: | 124 if errors: |
133 return [output_api.PresubmitError( | 125 return [output_api.PresubmitError( |
134 'All TODO comments should be of the form TODO(name). ' + | 126 'All TODO comments should be of the form TODO(name/bug). ' + |
135 'Use TODO instead of FIX' + 'ME', | 127 'Use TODO instead of FIX' + 'ME', |
136 items=errors)] | 128 items=errors)] |
137 return [] | 129 return [] |
138 | 130 |
139 def CheckDoubleAngles(input_api, output_api, white_list=CC_SOURCE_FILES, | 131 def CheckDoubleAngles(input_api, output_api, white_list=VIZ_SOURCE_FILES, |
140 black_list=None): | 132 black_list=None): |
141 errors = [] | 133 errors = [] |
142 | 134 |
143 source_file_filter = lambda x: input_api.FilterSourceFile(x, | 135 source_file_filter = lambda x: input_api.FilterSourceFile(x, |
144 white_list, | 136 white_list, |
145 black_list) | 137 black_list) |
146 for f in input_api.AffectedSourceFiles(source_file_filter): | 138 for f in input_api.AffectedSourceFiles(source_file_filter): |
147 contents = input_api.ReadFile(f, 'rb') | 139 contents = input_api.ReadFile(f, 'rb') |
148 if ('> >') in contents: | 140 if ('> >') in contents: |
149 errors.append(f.LocalPath()) | 141 errors.append(f.LocalPath()) |
150 | 142 |
151 if errors: | 143 if errors: |
152 return [output_api.PresubmitError('Use >> instead of > >:', items=errors)] | 144 return [output_api.PresubmitError('Use >> instead of > >:', items=errors)] |
153 return [] | 145 return [] |
154 | 146 |
155 def CheckUniquePtr(input_api, output_api, | 147 def CheckUniquePtr(input_api, output_api, |
156 white_list=CC_SOURCE_FILES, black_list=None): | 148 white_list=VIZ_SOURCE_FILES, black_list=None): |
157 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) | 149 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) |
158 source_file_filter = lambda x: input_api.FilterSourceFile(x, | 150 source_file_filter = lambda x: input_api.FilterSourceFile(x, |
159 white_list, | 151 white_list, |
160 black_list) | 152 black_list) |
161 errors = [] | 153 errors = [] |
162 for f in input_api.AffectedSourceFiles(source_file_filter): | 154 for f in input_api.AffectedSourceFiles(source_file_filter): |
163 for line_number, line in f.ChangedContents(): | 155 for line_number, line in f.ChangedContents(): |
164 # Disallow: | 156 # Disallow: |
165 # return std::unique_ptr<T>(foo); | 157 # return std::unique_ptr<T>(foo); |
166 # bar = std::unique_ptr<T>(foo); | 158 # bar = std::unique_ptr<T>(foo); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 in_whitelist = False | 223 in_whitelist = False |
232 for w in whitelist: | 224 for w in whitelist: |
233 if re.match(w, contents[next:]): | 225 if re.match(w, contents[next:]): |
234 in_whitelist = True | 226 in_whitelist = True |
235 break | 227 break |
236 if not in_whitelist: | 228 if not in_whitelist: |
237 return True | 229 return True |
238 pos = next + 1 | 230 pos = next + 1 |
239 return False | 231 return False |
240 | 232 |
241 # Checks for the use of cc:: within the cc namespace, which is usually | 233 # Checks for the use of viz:: within the viz namespace, which is usually |
242 # redundant. | 234 # redundant. |
243 def CheckNamespace(input_api, output_api): | 235 def CheckNamespace(input_api, output_api): |
244 errors = [] | 236 errors = [] |
245 | 237 |
246 source_file_filter = lambda x: x | 238 source_file_filter = lambda x: x |
247 for f in input_api.AffectedSourceFiles(source_file_filter): | 239 for f in input_api.AffectedSourceFiles(source_file_filter): |
248 contents = input_api.ReadFile(f, 'rb') | 240 contents = input_api.ReadFile(f, 'rb') |
249 match = re.search(r'namespace\s*cc\s*{', contents) | 241 match = re.search(r'namespace\s*viz\s*{', contents) |
250 if match: | 242 if match: |
251 whitelist = [] | 243 whitelist = [] |
252 if FindNamespaceInBlock(match.end(), 'cc', contents, whitelist=whitelist): | 244 if FindNamespaceInBlock(match.end(), 'viz', contents, whitelist=whitelist)
: |
253 errors.append(f.LocalPath()) | 245 errors.append(f.LocalPath()) |
254 | 246 |
255 if errors: | 247 if errors: |
256 return [output_api.PresubmitError( | 248 return [output_api.PresubmitError( |
257 'Do not use cc:: inside of the cc namespace.', | 249 'Do not use viz:: inside of the viz namespace.', |
258 items=errors)] | 250 items=errors)] |
259 return [] | 251 return [] |
260 | 252 |
261 def CheckForUseOfWrongClock(input_api, | 253 def CheckForUseOfWrongClock(input_api, |
262 output_api, | 254 output_api, |
263 white_list=CC_SOURCE_FILES, | 255 white_list=VIZ_SOURCE_FILES, |
264 black_list=None): | 256 black_list=None): |
265 """Make sure new lines of code don't use a clock susceptible to skew.""" | 257 """Make sure new lines of code don't use a clock susceptible to skew.""" |
266 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) | 258 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) |
267 source_file_filter = lambda x: input_api.FilterSourceFile(x, | 259 source_file_filter = lambda x: input_api.FilterSourceFile(x, |
268 white_list, | 260 white_list, |
269 black_list) | 261 black_list) |
270 # Regular expression that should detect any explicit references to the | 262 # Regular expression that should detect any explicit references to the |
271 # base::Time type (or base::Clock/DefaultClock), whether in using decls, | 263 # base::Time type (or base::Clock/DefaultClock), whether in using decls, |
272 # typedefs, or to call static methods. | 264 # typedefs, or to call static methods. |
273 base_time_type_pattern = r'(^|\W)base::(Time|Clock|DefaultClock)(\W|$)' | 265 base_time_type_pattern = r'(^|\W)base::(Time|Clock|DefaultClock)(\W|$)' |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 results += CheckStdAbs(input_api, output_api) | 309 results += CheckStdAbs(input_api, output_api) |
318 results += CheckPassByValue(input_api, output_api) | 310 results += CheckPassByValue(input_api, output_api) |
319 results += CheckChangeLintsClean(input_api, output_api) | 311 results += CheckChangeLintsClean(input_api, output_api) |
320 results += CheckTodos(input_api, output_api) | 312 results += CheckTodos(input_api, output_api) |
321 results += CheckDoubleAngles(input_api, output_api) | 313 results += CheckDoubleAngles(input_api, output_api) |
322 results += CheckUniquePtr(input_api, output_api) | 314 results += CheckUniquePtr(input_api, output_api) |
323 results += CheckNamespace(input_api, output_api) | 315 results += CheckNamespace(input_api, output_api) |
324 results += CheckForUseOfWrongClock(input_api, output_api) | 316 results += CheckForUseOfWrongClock(input_api, output_api) |
325 results += FindUselessIfdefs(input_api, output_api) | 317 results += FindUselessIfdefs(input_api, output_api) |
326 return results | 318 return results |
327 | |
328 def PostUploadHook(cl, change, output_api): | |
329 """git cl upload will call this hook after the issue is created/modified. | |
330 | |
331 This hook adds an extra try bot list to the CL description in order to run | |
332 Blink tests in addition to the CQ try bots. | |
333 """ | |
334 return output_api.EnsureCQIncludeTrybotsAreAdded( | |
335 cl, | |
336 ['master.tryserver.blink:linux_trusty_blink_rel'], | |
337 'Automatically added Blink trybots to run Blink tests on CQ.') | |
OLD | NEW |