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 = [] | 28 notreached_files = [] |
danakj
2017/04/05 16:59:41
same
kylechar
2017/04/05 17:08:47
Done.
| |
29 | 29 |
30 for f in input_api.AffectedSourceFiles(source_file_filter): | 30 for f in input_api.AffectedSourceFiles(source_file_filter): |
31 contents = input_api.ReadFile(f, 'rb') | 31 contents = input_api.ReadFile(f, 'rb') |
32 # WebKit ASSERT() is not allowed. | 32 # WebKit ASSERT() is not allowed. |
33 if re.search(r"\bASSERT\(", contents): | 33 if re.search(r"\bASSERT\(", contents): |
34 assert_files.append(f.LocalPath()) | 34 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 | 35 |
39 if assert_files: | 36 if assert_files: |
40 return [output_api.PresubmitError( | 37 return [output_api.PresubmitError( |
41 'These files use ASSERT instead of using DCHECK:', | 38 'These files use ASSERT instead of using DCHECK:', |
42 items=assert_files)] | 39 items=assert_files)] |
43 if notreached_files: | 40 if notreached_files: |
danakj
2017/04/05 16:59:41
same
kylechar
2017/04/05 17:08:47
Done.
| |
44 return [output_api.PresubmitError( | 41 return [output_api.PresubmitError( |
45 'These files use ASSERT_NOT_REACHED instead of using NOTREACHED:', | 42 'These files use ASSERT_NOT_REACHED instead of using NOTREACHED:', |
46 items=notreached_files)] | 43 items=notreached_files)] |
47 return [] | 44 return [] |
48 | 45 |
49 def CheckStdAbs(input_api, output_api, | 46 def CheckStdAbs(input_api, output_api, |
50 white_list=CC_SOURCE_FILES, black_list=None): | 47 white_list=VIZ_SOURCE_FILES, black_list=None): |
51 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) | 48 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) |
52 source_file_filter = lambda x: input_api.FilterSourceFile(x, | 49 source_file_filter = lambda x: input_api.FilterSourceFile(x, |
53 white_list, | 50 white_list, |
54 black_list) | 51 black_list) |
55 | 52 |
56 using_std_abs_files = [] | 53 using_std_abs_files = [] |
57 found_fabs_files = [] | 54 found_fabs_files = [] |
58 missing_std_prefix_files = [] | 55 missing_std_prefix_files = [] |
59 | 56 |
60 for f in input_api.AffectedSourceFiles(source_file_filter): | 57 for f in input_api.AffectedSourceFiles(source_file_filter): |
(...skipping 26 matching lines...) Expand all Loading... | |
87 items=found_fabs_files)) | 84 items=found_fabs_files)) |
88 if missing_std_prefix_files: | 85 if missing_std_prefix_files: |
89 result.append(output_api.PresubmitError( | 86 result.append(output_api.PresubmitError( |
90 'These files use abs(), absf(), fabs(), or fabsf() without qualifying ' | 87 'These files use abs(), absf(), fabs(), or fabsf() without qualifying ' |
91 'the std namespace. Please use std::abs() in all places.', | 88 'the std namespace. Please use std::abs() in all places.', |
92 items=missing_std_prefix_files)) | 89 items=missing_std_prefix_files)) |
93 return result | 90 return result |
94 | 91 |
95 def CheckPassByValue(input_api, | 92 def CheckPassByValue(input_api, |
96 output_api, | 93 output_api, |
97 white_list=CC_SOURCE_FILES, | 94 white_list=VIZ_SOURCE_FILES, |
98 black_list=None): | 95 black_list=None): |
99 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) | 96 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) |
100 source_file_filter = lambda x: input_api.FilterSourceFile(x, | 97 source_file_filter = lambda x: input_api.FilterSourceFile(x, |
101 white_list, | 98 white_list, |
102 black_list) | 99 black_list) |
103 | 100 |
104 local_errors = [] | 101 local_errors = [] |
105 | 102 |
106 # Well-defined simple classes containing only <= 4 ints, or <= 2 floats. | 103 # Well-defined simple classes the same size as a primative type. |
107 pass_by_value_types = ['base::Time', | 104 pass_by_value_types = ['base::Time', |
108 'base::TimeTicks', | 105 'base::TimeTicks', |
109 ] | 106 ] |
110 | 107 |
111 for f in input_api.AffectedSourceFiles(source_file_filter): | 108 for f in input_api.AffectedSourceFiles(source_file_filter): |
112 contents = input_api.ReadFile(f, 'rb') | 109 contents = input_api.ReadFile(f, 'rb') |
113 match = re.search( | 110 match = re.search( |
114 r'\bconst +' + '(?P<type>(%s))&' % | 111 r'\bconst +' + '(?P<type>(%s))&' % |
115 string.join(pass_by_value_types, '|'), | 112 string.join(pass_by_value_types, '|'), |
116 contents) | 113 contents) |
117 if match: | 114 if match: |
118 local_errors.append(output_api.PresubmitError( | 115 local_errors.append(output_api.PresubmitError( |
119 '%s passes %s by const ref instead of by value.' % | 116 '%s passes %s by const ref instead of by value.' % |
120 (f.LocalPath(), match.group('type')))) | 117 (f.LocalPath(), match.group('type')))) |
121 return local_errors | 118 return local_errors |
122 | 119 |
123 def CheckTodos(input_api, output_api): | 120 def CheckTodos(input_api, output_api): |
124 errors = [] | 121 errors = [] |
125 | 122 |
126 source_file_filter = lambda x: x | 123 source_file_filter = lambda x: x |
127 for f in input_api.AffectedSourceFiles(source_file_filter): | 124 for f in input_api.AffectedSourceFiles(source_file_filter): |
128 contents = input_api.ReadFile(f, 'rb') | 125 contents = input_api.ReadFile(f, 'rb') |
129 if ('FIX'+'ME') in contents: | 126 if ('FIX'+'ME') in contents: |
130 errors.append(f.LocalPath()) | 127 errors.append(f.LocalPath()) |
131 | 128 |
132 if errors: | 129 if errors: |
133 return [output_api.PresubmitError( | 130 return [output_api.PresubmitError( |
134 'All TODO comments should be of the form TODO(name). ' + | 131 'All TODO comments should be of the form TODO(name/bug). ' + |
135 'Use TODO instead of FIX' + 'ME', | 132 'Use TODO instead of FIX' + 'ME', |
136 items=errors)] | 133 items=errors)] |
137 return [] | 134 return [] |
138 | 135 |
139 def CheckDoubleAngles(input_api, output_api, white_list=CC_SOURCE_FILES, | 136 def CheckDoubleAngles(input_api, output_api, white_list=VIZ_SOURCE_FILES, |
140 black_list=None): | 137 black_list=None): |
141 errors = [] | 138 errors = [] |
142 | 139 |
143 source_file_filter = lambda x: input_api.FilterSourceFile(x, | 140 source_file_filter = lambda x: input_api.FilterSourceFile(x, |
144 white_list, | 141 white_list, |
145 black_list) | 142 black_list) |
146 for f in input_api.AffectedSourceFiles(source_file_filter): | 143 for f in input_api.AffectedSourceFiles(source_file_filter): |
147 contents = input_api.ReadFile(f, 'rb') | 144 contents = input_api.ReadFile(f, 'rb') |
148 if ('> >') in contents: | 145 if ('> >') in contents: |
149 errors.append(f.LocalPath()) | 146 errors.append(f.LocalPath()) |
150 | 147 |
151 if errors: | 148 if errors: |
152 return [output_api.PresubmitError('Use >> instead of > >:', items=errors)] | 149 return [output_api.PresubmitError('Use >> instead of > >:', items=errors)] |
153 return [] | 150 return [] |
154 | 151 |
155 def CheckUniquePtr(input_api, output_api, | 152 def CheckUniquePtr(input_api, output_api, |
156 white_list=CC_SOURCE_FILES, black_list=None): | 153 white_list=VIZ_SOURCE_FILES, black_list=None): |
157 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) | 154 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) |
158 source_file_filter = lambda x: input_api.FilterSourceFile(x, | 155 source_file_filter = lambda x: input_api.FilterSourceFile(x, |
159 white_list, | 156 white_list, |
160 black_list) | 157 black_list) |
161 errors = [] | 158 errors = [] |
162 for f in input_api.AffectedSourceFiles(source_file_filter): | 159 for f in input_api.AffectedSourceFiles(source_file_filter): |
163 for line_number, line in f.ChangedContents(): | 160 for line_number, line in f.ChangedContents(): |
164 # Disallow: | 161 # Disallow: |
165 # return std::unique_ptr<T>(foo); | 162 # return std::unique_ptr<T>(foo); |
166 # bar = std::unique_ptr<T>(foo); | 163 # bar = std::unique_ptr<T>(foo); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 in_whitelist = False | 228 in_whitelist = False |
232 for w in whitelist: | 229 for w in whitelist: |
233 if re.match(w, contents[next:]): | 230 if re.match(w, contents[next:]): |
234 in_whitelist = True | 231 in_whitelist = True |
235 break | 232 break |
236 if not in_whitelist: | 233 if not in_whitelist: |
237 return True | 234 return True |
238 pos = next + 1 | 235 pos = next + 1 |
239 return False | 236 return False |
240 | 237 |
241 # Checks for the use of cc:: within the cc namespace, which is usually | 238 # Checks for the use of viz:: within the viz namespace, which is usually |
242 # redundant. | 239 # redundant. |
243 def CheckNamespace(input_api, output_api): | 240 def CheckNamespace(input_api, output_api): |
244 errors = [] | 241 errors = [] |
245 | 242 |
246 source_file_filter = lambda x: x | 243 source_file_filter = lambda x: x |
247 for f in input_api.AffectedSourceFiles(source_file_filter): | 244 for f in input_api.AffectedSourceFiles(source_file_filter): |
248 contents = input_api.ReadFile(f, 'rb') | 245 contents = input_api.ReadFile(f, 'rb') |
249 match = re.search(r'namespace\s*cc\s*{', contents) | 246 match = re.search(r'namespace\s*viz\s*{', contents) |
250 if match: | 247 if match: |
251 whitelist = [] | 248 whitelist = [] |
252 if FindNamespaceInBlock(match.end(), 'cc', contents, whitelist=whitelist): | 249 if FindNamespaceInBlock(match.end(), 'viz', contents, whitelist=whitelist) : |
253 errors.append(f.LocalPath()) | 250 errors.append(f.LocalPath()) |
254 | 251 |
255 if errors: | 252 if errors: |
256 return [output_api.PresubmitError( | 253 return [output_api.PresubmitError( |
257 'Do not use cc:: inside of the cc namespace.', | 254 'Do not use viz:: inside of the viz namespace.', |
258 items=errors)] | 255 items=errors)] |
259 return [] | 256 return [] |
260 | 257 |
261 def CheckForUseOfWrongClock(input_api, | 258 def CheckForUseOfWrongClock(input_api, |
262 output_api, | 259 output_api, |
263 white_list=CC_SOURCE_FILES, | 260 white_list=VIZ_SOURCE_FILES, |
264 black_list=None): | 261 black_list=None): |
265 """Make sure new lines of code don't use a clock susceptible to skew.""" | 262 """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) | 263 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) |
267 source_file_filter = lambda x: input_api.FilterSourceFile(x, | 264 source_file_filter = lambda x: input_api.FilterSourceFile(x, |
268 white_list, | 265 white_list, |
269 black_list) | 266 black_list) |
270 # Regular expression that should detect any explicit references to the | 267 # Regular expression that should detect any explicit references to the |
271 # base::Time type (or base::Clock/DefaultClock), whether in using decls, | 268 # base::Time type (or base::Clock/DefaultClock), whether in using decls, |
272 # typedefs, or to call static methods. | 269 # typedefs, or to call static methods. |
273 base_time_type_pattern = r'(^|\W)base::(Time|Clock|DefaultClock)(\W|$)' | 270 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) | 314 results += CheckStdAbs(input_api, output_api) |
318 results += CheckPassByValue(input_api, output_api) | 315 results += CheckPassByValue(input_api, output_api) |
319 results += CheckChangeLintsClean(input_api, output_api) | 316 results += CheckChangeLintsClean(input_api, output_api) |
320 results += CheckTodos(input_api, output_api) | 317 results += CheckTodos(input_api, output_api) |
321 results += CheckDoubleAngles(input_api, output_api) | 318 results += CheckDoubleAngles(input_api, output_api) |
322 results += CheckUniquePtr(input_api, output_api) | 319 results += CheckUniquePtr(input_api, output_api) |
323 results += CheckNamespace(input_api, output_api) | 320 results += CheckNamespace(input_api, output_api) |
324 results += CheckForUseOfWrongClock(input_api, output_api) | 321 results += CheckForUseOfWrongClock(input_api, output_api) |
325 results += FindUselessIfdefs(input_api, output_api) | 322 results += FindUselessIfdefs(input_api, output_api) |
326 return results | 323 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 |