Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: PRESUBMIT.py

Issue 1407033004: Presubmit enforce that DCHECK_IS_ON() does not forget the braces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: presubmit: . Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 Chromium. 5 """Top-level presubmit script for Chromium.
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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 if len(files): 351 if len(files):
352 return [ output_api.PresubmitError( 352 return [ output_api.PresubmitError(
353 'Do not #include <iostream> in header files, since it inserts static ' 353 'Do not #include <iostream> in header files, since it inserts static '
354 'initialization into every file including the header. Instead, ' 354 'initialization into every file including the header. Instead, '
355 '#include <ostream>. See http://crbug.com/94794', 355 '#include <ostream>. See http://crbug.com/94794',
356 files) ] 356 files) ]
357 return [] 357 return []
358 358
359 359
360 def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api): 360 def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api):
361 """Checks to make sure no source files use UNIT_TEST""" 361 """Checks to make sure no source files use UNIT_TEST."""
362 problems = [] 362 problems = []
363 for f in input_api.AffectedFiles(): 363 for f in input_api.AffectedFiles():
364 if (not f.LocalPath().endswith(('.cc', '.mm'))): 364 if (not f.LocalPath().endswith(('.cc', '.mm'))):
365 continue 365 continue
366 366
367 for line_num, line in f.ChangedContents(): 367 for line_num, line in f.ChangedContents():
368 if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'): 368 if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'):
369 problems.append(' %s:%d' % (f.LocalPath(), line_num)) 369 problems.append(' %s:%d' % (f.LocalPath(), line_num))
370 370
371 if not problems: 371 if not problems:
372 return [] 372 return []
373 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' + 373 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' +
374 '\n'.join(problems))] 374 '\n'.join(problems))]
375 375
376 376
377 def _CheckDCHECK_IS_ONHasBraces(input_api, output_api):
378 """Checks to make sure DCHECK_IS_ON() does not skip the braces."""
379 errors = []
380 pattern = input_api.re.compile(r'DCHECK_IS_ON(?!\(\))',
381 input_api.re.MULTILINE)
382 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
383 if (not f.LocalPath().endswith(('.cc', '.mm', '.h'))):
384 continue
385 for lnum, line in f.ChangedContents():
386 if input_api.re.search(pattern, line):
387 errors.append(output_api.PresubmitError(
388 ('%s:%d: Use of DCHECK_IS_ON() must be written as "#if ' +
danakj 2015/10/23 21:53:42 The error is nicer now too :)
389 'DCHECK_IS_ON()", not forgetting the braces.')
kjellander_chromium 2017/02/20 07:09:48 Shouldn't 'braces' be replaced by 'parentheses' or
danakj 2017/02/22 00:19:54 You can submit a CL to fix it if you want :)
390 % (f.LocalPath(), lnum)))
391 return errors
392
393
377 def _FindHistogramNameInLine(histogram_name, line): 394 def _FindHistogramNameInLine(histogram_name, line):
378 """Tries to find a histogram name or prefix in a line.""" 395 """Tries to find a histogram name or prefix in a line."""
379 if not "affected-histogram" in line: 396 if not "affected-histogram" in line:
380 return histogram_name in line 397 return histogram_name in line
381 # A histogram_suffixes tag type has an affected-histogram name as a prefix of 398 # A histogram_suffixes tag type has an affected-histogram name as a prefix of
382 # the histogram_name. 399 # the histogram_name.
383 if not '"' in line: 400 if not '"' in line:
384 return False 401 return False
385 histogram_prefix = line.split('\"')[1] 402 histogram_prefix = line.split('\"')[1]
386 return histogram_prefix in histogram_name 403 return histogram_prefix in histogram_name
(...skipping 1246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 """Checks common to both upload and commit.""" 1650 """Checks common to both upload and commit."""
1634 results = [] 1651 results = []
1635 results.extend(input_api.canned_checks.PanProjectChecks( 1652 results.extend(input_api.canned_checks.PanProjectChecks(
1636 input_api, output_api, 1653 input_api, output_api,
1637 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS)) 1654 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS))
1638 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) 1655 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
1639 results.extend( 1656 results.extend(
1640 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) 1657 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
1641 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) 1658 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
1642 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api)) 1659 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
1660 results.extend(_CheckDCHECK_IS_ONHasBraces(input_api, output_api))
1643 results.extend(_CheckNoNewWStrings(input_api, output_api)) 1661 results.extend(_CheckNoNewWStrings(input_api, output_api))
1644 results.extend(_CheckNoDEPSGIT(input_api, output_api)) 1662 results.extend(_CheckNoDEPSGIT(input_api, output_api))
1645 results.extend(_CheckNoBannedFunctions(input_api, output_api)) 1663 results.extend(_CheckNoBannedFunctions(input_api, output_api))
1646 results.extend(_CheckNoPragmaOnce(input_api, output_api)) 1664 results.extend(_CheckNoPragmaOnce(input_api, output_api))
1647 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api)) 1665 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
1648 results.extend(_CheckUnwantedDependencies(input_api, output_api)) 1666 results.extend(_CheckUnwantedDependencies(input_api, output_api))
1649 results.extend(_CheckFilePermissions(input_api, output_api)) 1667 results.extend(_CheckFilePermissions(input_api, output_api))
1650 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api)) 1668 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api))
1651 results.extend(_CheckIncludeOrder(input_api, output_api)) 1669 results.extend(_CheckIncludeOrder(input_api, output_api))
1652 results.extend(_CheckForVersionControlConflicts(input_api, output_api)) 1670 results.extend(_CheckForVersionControlConflicts(input_api, output_api))
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
1979 for master in masters: 1997 for master in masters:
1980 try_config.setdefault(master, {}) 1998 try_config.setdefault(master, {})
1981 for builder in masters[master]: 1999 for builder in masters[master]:
1982 # Do not trigger presubmit builders, since they're likely to fail 2000 # Do not trigger presubmit builders, since they're likely to fail
1983 # (e.g. OWNERS checks before finished code review), and we're 2001 # (e.g. OWNERS checks before finished code review), and we're
1984 # running local presubmit anyway. 2002 # running local presubmit anyway.
1985 if 'presubmit' not in builder: 2003 if 'presubmit' not in builder:
1986 try_config[master][builder] = ['defaulttests'] 2004 try_config[master][builder] = ['defaulttests']
1987 2005
1988 return try_config 2006 return try_config
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698