| 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 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 black_list) | 145 black_list) |
| 146 for f in input_api.AffectedSourceFiles(source_file_filter): | 146 for f in input_api.AffectedSourceFiles(source_file_filter): |
| 147 contents = input_api.ReadFile(f, 'rb') | 147 contents = input_api.ReadFile(f, 'rb') |
| 148 if ('> >') in contents: | 148 if ('> >') in contents: |
| 149 errors.append(f.LocalPath()) | 149 errors.append(f.LocalPath()) |
| 150 | 150 |
| 151 if errors: | 151 if errors: |
| 152 return [output_api.PresubmitError('Use >> instead of > >:', items=errors)] | 152 return [output_api.PresubmitError('Use >> instead of > >:', items=errors)] |
| 153 return [] | 153 return [] |
| 154 | 154 |
| 155 def CheckScopedPtr(input_api, output_api, | 155 def CheckUniquePtr(input_api, output_api, |
| 156 white_list=CC_SOURCE_FILES, black_list=None): | 156 white_list=CC_SOURCE_FILES, black_list=None): |
| 157 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) | 157 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) |
| 158 source_file_filter = lambda x: input_api.FilterSourceFile(x, | 158 source_file_filter = lambda x: input_api.FilterSourceFile(x, |
| 159 white_list, | 159 white_list, |
| 160 black_list) | 160 black_list) |
| 161 errors = [] | 161 errors = [] |
| 162 for f in input_api.AffectedSourceFiles(source_file_filter): | 162 for f in input_api.AffectedSourceFiles(source_file_filter): |
| 163 for line_number, line in f.ChangedContents(): | 163 for line_number, line in f.ChangedContents(): |
| 164 # Disallow: | 164 # Disallow: |
| 165 # return scoped_ptr<T>(foo); | 165 # return std::unique_ptr<T>(foo); |
| 166 # bar = scoped_ptr<T>(foo); | 166 # bar = std::unique_ptr<T>(foo); |
| 167 # But allow: | 167 # But allow: |
| 168 # return scoped_ptr<T[]>(foo); | 168 # return std::unique_ptr<T[]>(foo); |
| 169 # bar = scoped_ptr<T[]>(foo); | 169 # bar = std::unique_ptr<T[]>(foo); |
| 170 if re.search(r'(=|\breturn)\s*scoped_ptr<.*?(?<!])>\([^)]+\)', line): | 170 if re.search(r'(=|\breturn)\s*std::unique_ptr<.*?(?<!])>\([^)]+\)', line): |
| 171 errors.append(output_api.PresubmitError( | 171 errors.append(output_api.PresubmitError( |
| 172 ('%s:%d uses explicit scoped_ptr constructor. ' + | 172 ('%s:%d uses explicit std::unique_ptr constructor. ' + |
| 173 'Use make_scoped_ptr() instead.') % (f.LocalPath(), line_number))) | 173 'Use base::WrapUnique() instead.') % (f.LocalPath(), line_number))) |
| 174 # Disallow: | 174 # Disallow: |
| 175 # scoped_ptr<T>() | 175 # std::unique_ptr<T>() |
| 176 if re.search(r'\bscoped_ptr<.*?>\(\)', line): | 176 if re.search(r'\bstd::unique_ptr<.*?>\(\)', line): |
| 177 errors.append(output_api.PresubmitError( | 177 errors.append(output_api.PresubmitError( |
| 178 '%s:%d uses scoped_ptr<T>(). Use nullptr instead.' % | 178 '%s:%d uses std::unique_ptr<T>(). Use nullptr instead.' % |
| 179 (f.LocalPath(), line_number))) | 179 (f.LocalPath(), line_number))) |
| 180 return errors | 180 return errors |
| 181 | 181 |
| 182 def FindUnquotedQuote(contents, pos): | 182 def FindUnquotedQuote(contents, pos): |
| 183 match = re.search(r"(?<!\\)(?P<quote>\")", contents[pos:]) | 183 match = re.search(r"(?<!\\)(?P<quote>\")", contents[pos:]) |
| 184 return -1 if not match else match.start("quote") + pos | 184 return -1 if not match else match.start("quote") + pos |
| 185 | 185 |
| 186 def FindUselessIfdefs(input_api, output_api): | 186 def FindUselessIfdefs(input_api, output_api): |
| 187 errors = [] | 187 errors = [] |
| 188 source_file_filter = lambda x: x | 188 source_file_filter = lambda x: x |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 return [] | 311 return [] |
| 312 | 312 |
| 313 def CheckChangeOnUpload(input_api, output_api): | 313 def CheckChangeOnUpload(input_api, output_api): |
| 314 results = [] | 314 results = [] |
| 315 results += CheckAsserts(input_api, output_api) | 315 results += CheckAsserts(input_api, output_api) |
| 316 results += CheckStdAbs(input_api, output_api) | 316 results += CheckStdAbs(input_api, output_api) |
| 317 results += CheckPassByValue(input_api, output_api) | 317 results += CheckPassByValue(input_api, output_api) |
| 318 results += CheckChangeLintsClean(input_api, output_api) | 318 results += CheckChangeLintsClean(input_api, output_api) |
| 319 results += CheckTodos(input_api, output_api) | 319 results += CheckTodos(input_api, output_api) |
| 320 results += CheckDoubleAngles(input_api, output_api) | 320 results += CheckDoubleAngles(input_api, output_api) |
| 321 results += CheckScopedPtr(input_api, output_api) | 321 results += CheckUniquePtr(input_api, output_api) |
| 322 results += CheckNamespace(input_api, output_api) | 322 results += CheckNamespace(input_api, output_api) |
| 323 results += CheckForUseOfWrongClock(input_api, output_api) | 323 results += CheckForUseOfWrongClock(input_api, output_api) |
| 324 results += FindUselessIfdefs(input_api, output_api) | 324 results += FindUselessIfdefs(input_api, output_api) |
| 325 results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api) | 325 results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api) |
| 326 return results | 326 return results |
| 327 | 327 |
| 328 def PostUploadHook(cl, change, output_api): | 328 def PostUploadHook(cl, change, output_api): |
| 329 """git cl upload will call this hook after the issue is created/modified. | 329 """git cl upload will call this hook after the issue is created/modified. |
| 330 | 330 |
| 331 This hook adds extra try bots list to the CL description in order to run | 331 This hook adds extra try bots list to the CL description in order to run |
| (...skipping 12 matching lines...) Expand all Loading... |
| 344 results = [] | 344 results = [] |
| 345 new_description = description | 345 new_description = description |
| 346 new_description += '\nCQ_INCLUDE_TRYBOTS=%s' % ';'.join(bots) | 346 new_description += '\nCQ_INCLUDE_TRYBOTS=%s' % ';'.join(bots) |
| 347 results.append(output_api.PresubmitNotifyResult( | 347 results.append(output_api.PresubmitNotifyResult( |
| 348 'Automatically added Blink trybots to run Blink tests on CQ.')) | 348 'Automatically added Blink trybots to run Blink tests on CQ.')) |
| 349 | 349 |
| 350 if new_description != description: | 350 if new_description != description: |
| 351 rietveld_obj.update_description(issue, new_description) | 351 rietveld_obj.update_description(issue, new_description) |
| 352 | 352 |
| 353 return results | 353 return results |
| OLD | NEW |