| 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 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 1566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1577 break | 1577 break |
| 1578 | 1578 |
| 1579 if len(files): | 1579 if len(files): |
| 1580 return [output_api.PresubmitError( | 1580 return [output_api.PresubmitError( |
| 1581 'Do not introduce new mojom targets with use_new_wrapper_types set to ' | 1581 'Do not introduce new mojom targets with use_new_wrapper_types set to ' |
| 1582 'false. The mode is deprecated and will be removed soon.', | 1582 'false. The mode is deprecated and will be removed soon.', |
| 1583 files)] | 1583 files)] |
| 1584 return [] | 1584 return [] |
| 1585 | 1585 |
| 1586 | 1586 |
| 1587 def _CheckUselessForwardDeclarations(input_api, output_api): |
| 1588 """Checks that added or removed lines in affected header files |
| 1589 do not lead to new useless class or struct forward declaration. |
| 1590 """ |
| 1591 results = [] |
| 1592 class_pattern = input_api.re.compile(r'^class\s+(\w+);$', |
| 1593 input_api.re.MULTILINE) |
| 1594 struct_pattern = input_api.re.compile(r'^struct\s+(\w+);$', |
| 1595 input_api.re.MULTILINE) |
| 1596 for f in input_api.AffectedFiles(include_deletes=False): |
| 1597 if not f.LocalPath().endswith('.h'): |
| 1598 continue |
| 1599 |
| 1600 contents = input_api.ReadFile(f) |
| 1601 fwd_decls = input_api.re.findall(class_pattern, contents) |
| 1602 fwd_decls.extend(input_api.re.findall(struct_pattern, contents)) |
| 1603 |
| 1604 useless_fwd_decls = [] |
| 1605 for decl in fwd_decls: |
| 1606 count = sum(1 for _ in input_api.re.finditer( |
| 1607 r'\b%s\b' % input_api.re.escape(decl), contents)) |
| 1608 if count == 1: |
| 1609 useless_fwd_decls.append(decl) |
| 1610 |
| 1611 if not useless_fwd_decls: |
| 1612 continue |
| 1613 |
| 1614 for line in f.GenerateScmDiff().splitlines(): |
| 1615 if (line.startswith('-') and not line.startswith('--') or |
| 1616 line.startswith('+') and not line.startswith('++')): |
| 1617 for decl in useless_fwd_decls: |
| 1618 if input_api.re.search(r'\b%s\b' % decl, line[1:]): |
| 1619 results.append(output_api.PresubmitPromptWarning( |
| 1620 '%s: %s forward declaration is becoming useless' % |
| 1621 (f.LocalPath(), decl))) |
| 1622 useless_fwd_decls.remove(decl) |
| 1623 |
| 1624 return results |
| 1625 |
| 1626 |
| 1587 def _CheckAndroidToastUsage(input_api, output_api): | 1627 def _CheckAndroidToastUsage(input_api, output_api): |
| 1588 """Checks that code uses org.chromium.ui.widget.Toast instead of | 1628 """Checks that code uses org.chromium.ui.widget.Toast instead of |
| 1589 android.widget.Toast (Chromium Toast doesn't force hardware | 1629 android.widget.Toast (Chromium Toast doesn't force hardware |
| 1590 acceleration on low-end devices, saving memory). | 1630 acceleration on low-end devices, saving memory). |
| 1591 """ | 1631 """ |
| 1592 toast_import_pattern = input_api.re.compile( | 1632 toast_import_pattern = input_api.re.compile( |
| 1593 r'^import android\.widget\.Toast;$') | 1633 r'^import android\.widget\.Toast;$') |
| 1594 | 1634 |
| 1595 errors = [] | 1635 errors = [] |
| 1596 | 1636 |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2026 results.extend(_CheckNoDeprecatedJS(input_api, output_api)) | 2066 results.extend(_CheckNoDeprecatedJS(input_api, output_api)) |
| 2027 results.extend(_CheckParseErrors(input_api, output_api)) | 2067 results.extend(_CheckParseErrors(input_api, output_api)) |
| 2028 results.extend(_CheckForIPCRules(input_api, output_api)) | 2068 results.extend(_CheckForIPCRules(input_api, output_api)) |
| 2029 results.extend(_CheckForWindowsLineEndings(input_api, output_api)) | 2069 results.extend(_CheckForWindowsLineEndings(input_api, output_api)) |
| 2030 results.extend(_CheckSingletonInHeaders(input_api, output_api)) | 2070 results.extend(_CheckSingletonInHeaders(input_api, output_api)) |
| 2031 results.extend(_CheckNoDeprecatedCompiledResourcesGYP(input_api, output_api)) | 2071 results.extend(_CheckNoDeprecatedCompiledResourcesGYP(input_api, output_api)) |
| 2032 results.extend(_CheckPydepsNeedsUpdating(input_api, output_api)) | 2072 results.extend(_CheckPydepsNeedsUpdating(input_api, output_api)) |
| 2033 results.extend(_CheckJavaStyle(input_api, output_api)) | 2073 results.extend(_CheckJavaStyle(input_api, output_api)) |
| 2034 results.extend(_CheckIpcOwners(input_api, output_api)) | 2074 results.extend(_CheckIpcOwners(input_api, output_api)) |
| 2035 results.extend(_CheckMojoUsesNewWrapperTypes(input_api, output_api)) | 2075 results.extend(_CheckMojoUsesNewWrapperTypes(input_api, output_api)) |
| 2076 results.extend(_CheckUselessForwardDeclarations(input_api, output_api)) |
| 2036 | 2077 |
| 2037 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): | 2078 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): |
| 2038 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( | 2079 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |
| 2039 input_api, output_api, | 2080 input_api, output_api, |
| 2040 input_api.PresubmitLocalPath(), | 2081 input_api.PresubmitLocalPath(), |
| 2041 whitelist=[r'^PRESUBMIT_test\.py$'])) | 2082 whitelist=[r'^PRESUBMIT_test\.py$'])) |
| 2042 return results | 2083 return results |
| 2043 | 2084 |
| 2044 | 2085 |
| 2045 def _CheckAuthorizedAuthor(input_api, output_api): | 2086 def _CheckAuthorizedAuthor(input_api, output_api): |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2306 results.extend(input_api.canned_checks.CheckTreeIsOpen( | 2347 results.extend(input_api.canned_checks.CheckTreeIsOpen( |
| 2307 input_api, | 2348 input_api, |
| 2308 output_api, | 2349 output_api, |
| 2309 json_url='http://chromium-status.appspot.com/current?format=json')) | 2350 json_url='http://chromium-status.appspot.com/current?format=json')) |
| 2310 | 2351 |
| 2311 results.extend(input_api.canned_checks.CheckChangeHasBugField( | 2352 results.extend(input_api.canned_checks.CheckChangeHasBugField( |
| 2312 input_api, output_api)) | 2353 input_api, output_api)) |
| 2313 results.extend(input_api.canned_checks.CheckChangeHasDescription( | 2354 results.extend(input_api.canned_checks.CheckChangeHasDescription( |
| 2314 input_api, output_api)) | 2355 input_api, output_api)) |
| 2315 return results | 2356 return results |
| OLD | NEW |