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): | 11 def _CheckUnwantedDependencies(input_api, output_api): |
12 """Runs checkdeps on #include statements added in this | 12 """Runs checkdeps on #include statements added in this |
13 change. Breaking - rules is an error, breaking ! rules is a | 13 change. Breaking - rules is an error, breaking ! rules is a |
14 warning. | 14 warning. |
15 """ | 15 """ |
16 import sys | 16 import sys |
17 # We need to wait until we have an input_api object and use this | 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 | 18 # roundabout construct to import checkdeps because this file is |
19 # eval-ed and thus doesn't have __file__. | 19 # eval-ed and thus doesn't have __file__. |
20 original_sys_path = sys.path | 20 original_sys_path = sys.path |
21 try: | 21 try: |
22 sys.path = sys.path + [input_api.os_path.join( | 22 checkdeps_relpath = input_api.os_path.join('buildtools', 'checkdeps') |
23 input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')] | 23 checkdeps_basepath = input_api.PresubmitLocalPath() |
24 checkdeps_path = input_api.os_path.join(checkdeps_basepath, | |
25 checkdeps_relpath) | |
26 while not input_api.os_path.exists(checkdeps_path): | |
27 if checkdeps_basepath == input_api.os_path.dirname(checkdeps_basepath): | |
Lei Zhang
2015/11/20 02:57:42
Well, in theory, /buildtools/checkdeps may contain
| |
28 raise ImportError('Cannot find checkdeps') | |
29 checkdeps_basepath = input_api.os_path.dirname(checkdeps_basepath) | |
hans
2015/11/20 03:26:28
Sorry for being a little slow here.. how does this
Lei Zhang
2015/11/20 03:29:19
It's essentially: foo = os.path.dirname(foo)
https
hans
2015/11/20 03:52:21
Ah, I get it now, thanks.
| |
30 checkdeps_path = input_api.os_path.join(checkdeps_basepath, | |
31 checkdeps_relpath) | |
32 | |
33 sys.path.append(checkdeps_path) | |
24 import checkdeps | 34 import checkdeps |
25 from cpp_checker import CppChecker | 35 from cpp_checker import CppChecker |
26 from rules import Rule | 36 from rules import Rule |
27 finally: | 37 finally: |
28 # Restore sys.path to what it was before. | 38 # Restore sys.path to what it was before. |
29 sys.path = original_sys_path | 39 sys.path = original_sys_path |
30 | 40 |
31 added_includes = [] | 41 added_includes = [] |
32 for f in input_api.AffectedFiles(): | 42 for f in input_api.AffectedFiles(): |
33 if not CppChecker.IsCppFile(f.LocalPath()): | 43 if not CppChecker.IsCppFile(f.LocalPath()): |
(...skipping 30 matching lines...) Expand all Loading... | |
64 | 74 |
65 def CheckChangeOnUpload(input_api, output_api): | 75 def CheckChangeOnUpload(input_api, output_api): |
66 results = [] | 76 results = [] |
67 results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api) | 77 results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api) |
68 results += _CheckUnwantedDependencies(input_api, output_api) | 78 results += _CheckUnwantedDependencies(input_api, output_api) |
69 return results | 79 return results |
70 | 80 |
71 | 81 |
72 def CheckChangeOnCommit(input_api, output_api): | 82 def CheckChangeOnCommit(input_api, output_api): |
73 return CheckChangeOnUpload(input_api, output_api) | 83 return CheckChangeOnUpload(input_api, output_api) |
OLD | NEW |