OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 """Presubmit script for pdfium. | 5 """Presubmit script for pdfium. |
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 15 matching lines...) Expand all Loading... |
26 # Need to fix two snprintf TODOs | 26 # Need to fix two snprintf TODOs |
27 '-runtime/printf', | 27 '-runtime/printf', |
28 # Lots of non-const references need to be fixed | 28 # Lots of non-const references need to be fixed |
29 '-runtime/references', | 29 '-runtime/references', |
30 # We are not thread safe, so this will never pass. | 30 # We are not thread safe, so this will never pass. |
31 '-runtime/threadsafe_fn', | 31 '-runtime/threadsafe_fn', |
32 # Figure out how to deal with #defines that git cl format creates. | 32 # Figure out how to deal with #defines that git cl format creates. |
33 '-whitespace/indent', | 33 '-whitespace/indent', |
34 ] | 34 ] |
35 | 35 |
| 36 |
| 37 def _CheckUnwantedDependencies(input_api, output_api): |
| 38 """Runs checkdeps on #include statements added in this |
| 39 change. Breaking - rules is an error, breaking ! rules is a |
| 40 warning. |
| 41 """ |
| 42 import sys |
| 43 # We need to wait until we have an input_api object and use this |
| 44 # roundabout construct to import checkdeps because this file is |
| 45 # eval-ed and thus doesn't have __file__. |
| 46 original_sys_path = sys.path |
| 47 try: |
| 48 sys.path = sys.path + [input_api.os_path.join( |
| 49 input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')] |
| 50 import checkdeps |
| 51 from cpp_checker import CppChecker |
| 52 from rules import Rule |
| 53 finally: |
| 54 # Restore sys.path to what it was before. |
| 55 sys.path = original_sys_path |
| 56 |
| 57 added_includes = [] |
| 58 for f in input_api.AffectedFiles(): |
| 59 if not CppChecker.IsCppFile(f.LocalPath()): |
| 60 continue |
| 61 |
| 62 changed_lines = [line for line_num, line in f.ChangedContents()] |
| 63 added_includes.append([f.LocalPath(), changed_lines]) |
| 64 |
| 65 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath()) |
| 66 |
| 67 error_descriptions = [] |
| 68 warning_descriptions = [] |
| 69 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes( |
| 70 added_includes): |
| 71 description_with_path = '%s\n %s' % (path, rule_description) |
| 72 if rule_type == Rule.DISALLOW: |
| 73 error_descriptions.append(description_with_path) |
| 74 else: |
| 75 warning_descriptions.append(description_with_path) |
| 76 |
| 77 results = [] |
| 78 if error_descriptions: |
| 79 results.append(output_api.PresubmitError( |
| 80 'You added one or more #includes that violate checkdeps rules.', |
| 81 error_descriptions)) |
| 82 if warning_descriptions: |
| 83 results.append(output_api.PresubmitPromptOrNotify( |
| 84 'You added one or more #includes of files that are temporarily\n' |
| 85 'allowed but being removed. Can you avoid introducing the\n' |
| 86 '#include? See relevant DEPS file(s) for details and contacts.', |
| 87 warning_descriptions)) |
| 88 return results |
| 89 |
| 90 |
36 def CheckChangeOnUpload(input_api, output_api): | 91 def CheckChangeOnUpload(input_api, output_api): |
37 results = [] | 92 results = [] |
| 93 results += _CheckUnwantedDependencies(input_api, output_api) |
38 results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api) | 94 results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api) |
39 results += input_api.canned_checks.CheckChangeLintsClean( | 95 results += input_api.canned_checks.CheckChangeLintsClean( |
40 input_api, output_api, None, LINT_FILTERS) | 96 input_api, output_api, None, LINT_FILTERS) |
| 97 |
41 return results | 98 return results |
OLD | NEW |