| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 if re.search(r'(=|\breturn)\s*scoped_ptr<.*?(?<!])>\([^)]+\)', line): | 184 if re.search(r'(=|\breturn)\s*scoped_ptr<.*?(?<!])>\([^)]+\)', line): |
| 185 errors.append(output_api.PresubmitError( | 185 errors.append(output_api.PresubmitError( |
| 186 ('%s:%d uses explicit scoped_ptr constructor. ' + | 186 ('%s:%d uses explicit scoped_ptr constructor. ' + |
| 187 'Use make_scoped_ptr() instead.') % (f.LocalPath(), line_number))) | 187 'Use make_scoped_ptr() instead.') % (f.LocalPath(), line_number))) |
| 188 # Disallow: | 188 # Disallow: |
| 189 # scoped_ptr<T>() | 189 # scoped_ptr<T>() |
| 190 if re.search(r'\bscoped_ptr<.*?>\(\)', line): | 190 if re.search(r'\bscoped_ptr<.*?>\(\)', line): |
| 191 errors.append(output_api.PresubmitError( | 191 errors.append(output_api.PresubmitError( |
| 192 '%s:%d uses scoped_ptr<T>(). Use nullptr instead.' % | 192 '%s:%d uses scoped_ptr<T>(). Use nullptr instead.' % |
| 193 (f.LocalPath(), line_number))) | 193 (f.LocalPath(), line_number))) |
| 194 # Disallow: | |
| 195 # foo.PassAs<T>(); | |
| 196 if re.search(r'\bPassAs<.*?>\(\)', line): | |
| 197 errors.append(output_api.PresubmitError( | |
| 198 '%s:%d uses PassAs<T>(). Use Pass() instead.' % | |
| 199 (f.LocalPath(), line_number))) | |
| 200 return errors | 194 return errors |
| 201 | 195 |
| 202 def FindUnquotedQuote(contents, pos): | 196 def FindUnquotedQuote(contents, pos): |
| 203 match = re.search(r"(?<!\\)(?P<quote>\")", contents[pos:]) | 197 match = re.search(r"(?<!\\)(?P<quote>\")", contents[pos:]) |
| 204 return -1 if not match else match.start("quote") + pos | 198 return -1 if not match else match.start("quote") + pos |
| 205 | 199 |
| 206 def FindUselessIfdefs(input_api, output_api): | 200 def FindUselessIfdefs(input_api, output_api): |
| 207 errors = [] | 201 errors = [] |
| 208 source_file_filter = lambda x: x | 202 source_file_filter = lambda x: x |
| 209 for f in input_api.AffectedSourceFiles(source_file_filter): | 203 for f in input_api.AffectedSourceFiles(source_file_filter): |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 | 319 |
| 326 if problems: | 320 if problems: |
| 327 return [output_api.PresubmitPromptOrNotify( | 321 return [output_api.PresubmitPromptOrNotify( |
| 328 'You added one or more references to the base::Time class and/or one\n' | 322 'You added one or more references to the base::Time class and/or one\n' |
| 329 'of its member functions (or base::Clock/DefaultClock). In cc code,\n' | 323 'of its member functions (or base::Clock/DefaultClock). In cc code,\n' |
| 330 'it is most certainly incorrect! Instead use base::TimeTicks.\n\n' | 324 'it is most certainly incorrect! Instead use base::TimeTicks.\n\n' |
| 331 '\n'.join(problems))] | 325 '\n'.join(problems))] |
| 332 else: | 326 else: |
| 333 return [] | 327 return [] |
| 334 | 328 |
| 335 def CheckOverrideFinal(input_api, output_api, | |
| 336 whitelist=CC_SOURCE_FILES, blacklist=None): | |
| 337 """Make sure new lines of code don't use the OVERRIDE or FINAL macros.""" | |
| 338 | |
| 339 # TODO(mostynb): remove this check once the macros are removed | |
| 340 # from base/compiler_specific.h. | |
| 341 | |
| 342 errors = [] | |
| 343 | |
| 344 source_file_filter = lambda x: input_api.FilterSourceFile( | |
| 345 x, white_list=CC_SOURCE_FILES, black_list=None) | |
| 346 | |
| 347 override_files = [] | |
| 348 final_files = [] | |
| 349 | |
| 350 for f in input_api.AffectedSourceFiles(source_file_filter): | |
| 351 contents = input_api.ReadFile(f, 'rb') | |
| 352 | |
| 353 # "override" and "final" should be used instead of OVERRIDE/FINAL now. | |
| 354 if re.search(r"\bOVERRIDE\b", contents): | |
| 355 override_files.append(f.LocalPath()) | |
| 356 | |
| 357 if re.search(r"\bFINAL\b", contents): | |
| 358 final_files.append(f.LocalPath()) | |
| 359 | |
| 360 if override_files: | |
| 361 return [output_api.PresubmitError( | |
| 362 'These files use OVERRIDE instead of using override:', | |
| 363 items=override_files)] | |
| 364 if final_files: | |
| 365 return [output_api.PresubmitError( | |
| 366 'These files use FINAL instead of using final:', | |
| 367 items=final_files)] | |
| 368 | |
| 369 return [] | |
| 370 | |
| 371 def CheckChangeOnUpload(input_api, output_api): | 329 def CheckChangeOnUpload(input_api, output_api): |
| 372 results = [] | 330 results = [] |
| 373 results += CheckAsserts(input_api, output_api) | 331 results += CheckAsserts(input_api, output_api) |
| 374 results += CheckStdAbs(input_api, output_api) | 332 results += CheckStdAbs(input_api, output_api) |
| 375 results += CheckPassByValue(input_api, output_api) | 333 results += CheckPassByValue(input_api, output_api) |
| 376 results += CheckChangeLintsClean(input_api, output_api) | 334 results += CheckChangeLintsClean(input_api, output_api) |
| 377 results += CheckTodos(input_api, output_api) | 335 results += CheckTodos(input_api, output_api) |
| 378 results += CheckDoubleAngles(input_api, output_api) | 336 results += CheckDoubleAngles(input_api, output_api) |
| 379 results += CheckScopedPtr(input_api, output_api) | 337 results += CheckScopedPtr(input_api, output_api) |
| 380 results += CheckNamespace(input_api, output_api) | 338 results += CheckNamespace(input_api, output_api) |
| 381 results += CheckForUseOfWrongClock(input_api, output_api) | 339 results += CheckForUseOfWrongClock(input_api, output_api) |
| 382 results += FindUselessIfdefs(input_api, output_api) | 340 results += FindUselessIfdefs(input_api, output_api) |
| 383 results += CheckOverrideFinal(input_api, output_api) | |
| 384 results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api) | 341 results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api) |
| 385 return results | 342 return results |
| 386 | 343 |
| 387 def GetPreferredTryMasters(project, change): | 344 def GetPreferredTryMasters(project, change): |
| 388 return { | 345 return { |
| 389 'tryserver.blink': { | 346 'tryserver.blink': { |
| 390 'linux_blink_rel': set(['defaulttests']), | 347 'linux_blink_rel': set(['defaulttests']), |
| 391 }, | 348 }, |
| 392 } | 349 } |
| OLD | NEW |