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 |
11 def _CheckUnwantedDependencies(input_api, output_api): | |
12 """Runs checkdeps on #include statements added in this | |
13 change. Breaking - rules is an error, breaking ! rules is a | |
14 warning. | |
15 """ | |
16 import sys | |
17 # We need to wait until we have an input_api object and use this | |
18 # roundabout construct to import checkdeps because this file is | |
19 # eval-ed and thus doesn't have __file__. | |
20 original_sys_path = sys.path | |
21 try: | |
22 sys.path = sys.path + [input_api.os_path.join( | |
23 input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')] | |
24 import checkdeps | |
25 from cpp_checker import CppChecker | |
26 from rules import Rule | |
27 finally: | |
28 # Restore sys.path to what it was before. | |
29 sys.path = original_sys_path | |
30 | |
31 added_includes = [] | |
32 for f in input_api.AffectedFiles(): | |
33 if not CppChecker.IsCppFile(f.LocalPath()): | |
34 continue | |
35 | |
36 changed_lines = [line for line_num, line in f.ChangedContents()] | |
37 added_includes.append([f.LocalPath(), changed_lines]) | |
38 | |
39 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath()) | |
40 | |
41 error_descriptions = [] | |
42 warning_descriptions = [] | |
43 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes( | |
44 added_includes): | |
45 description_with_path = '%s\n %s' % (path, rule_description) | |
46 if rule_type == Rule.DISALLOW: | |
47 error_descriptions.append(description_with_path) | |
48 else: | |
49 warning_descriptions.append(description_with_path) | |
50 | |
51 results = [] | |
52 if error_descriptions: | |
53 results.append(output_api.PresubmitError( | |
54 'You added one or more #includes that violate checkdeps rules.', | |
55 error_descriptions)) | |
56 if warning_descriptions: | |
57 results.append(output_api.PresubmitPromptOrNotify( | |
58 'You added one or more #includes of files that are temporarily\n' | |
59 'allowed but being removed. Can you avoid introducing the\n' | |
60 '#include? See relevant DEPS file(s) for details and contacts.', | |
61 warning_descriptions)) | |
62 return results | |
63 | |
64 | |
11 def CheckChangeOnUpload(input_api, output_api): | 65 def CheckChangeOnUpload(input_api, output_api): |
12 results = [] | 66 results = [] |
13 results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api) | 67 results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api) |
68 results += _CheckUnwantedDependencies(input_api, output_api) | |
14 return results | 69 return results |
70 | |
71 | |
72 def CheckChangeOnCommit(input_api, output_api): | |
Tom Sepez
2015/11/13 17:36:20
Are you sure you want to turn commit time checks o
Lei Zhang
2015/11/13 23:27:27
It succeeds locally. Do you see any reasons why ch
| |
73 return CheckChangeOnUpload(input_api, output_api) | |
OLD | NEW |