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 | 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 CC_SOURCE_FILES=(r'^cc[\\/].*\.(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=CC_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=CC_SOURCE_FILES, black_list=N one): |
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
this goes
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
this goes
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=CC_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, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 output_api, | 93 output_api, |
97 white_list=CC_SOURCE_FILES, | 94 white_list=CC_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. |
Fady Samuel
2017/04/05 17:09:14
nit: primitive
kylechar
2017/04/05 17:14:09
Done.
| |
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=CC_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, |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 def PostUploadHook(cl, change, output_api): | 325 def PostUploadHook(cl, change, output_api): |
329 """git cl upload will call this hook after the issue is created/modified. | 326 """git cl upload will call this hook after the issue is created/modified. |
330 | 327 |
331 This hook adds an extra try bot list to the CL description in order to run | 328 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. | 329 Blink tests in addition to the CQ try bots. |
333 """ | 330 """ |
334 return output_api.EnsureCQIncludeTrybotsAreAdded( | 331 return output_api.EnsureCQIncludeTrybotsAreAdded( |
335 cl, | 332 cl, |
336 ['master.tryserver.blink:linux_trusty_blink_rel'], | 333 ['master.tryserver.blink:linux_trusty_blink_rel'], |
337 'Automatically added Blink trybots to run Blink tests on CQ.') | 334 'Automatically added Blink trybots to run Blink tests on CQ.') |
OLD | NEW |