| 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 = [] | |
| 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=CC_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 = [] |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 output_api, | 88 output_api, |
| 97 white_list=CC_SOURCE_FILES, | 89 white_list=CC_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=CC_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, |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 def PostUploadHook(cl, change, output_api): | 320 def PostUploadHook(cl, change, output_api): |
| 329 """git cl upload will call this hook after the issue is created/modified. | 321 """git cl upload will call this hook after the issue is created/modified. |
| 330 | 322 |
| 331 This hook adds an extra try bot list to the CL description in order to run | 323 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. | 324 Blink tests in addition to the CQ try bots. |
| 333 """ | 325 """ |
| 334 return output_api.EnsureCQIncludeTrybotsAreAdded( | 326 return output_api.EnsureCQIncludeTrybotsAreAdded( |
| 335 cl, | 327 cl, |
| 336 ['master.tryserver.blink:linux_trusty_blink_rel'], | 328 ['master.tryserver.blink:linux_trusty_blink_rel'], |
| 337 'Automatically added Blink trybots to run Blink tests on CQ.') | 329 'Automatically added Blink trybots to run Blink tests on CQ.') |
| OLD | NEW |