OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Runs Android's lint tool.""" | 7 """Runs Android's lint tool.""" |
8 | 8 |
9 | 9 |
10 import optparse | 10 import optparse |
11 import os | 11 import os |
12 import sys | 12 import sys |
13 from xml.dom import minidom | 13 from xml.dom import minidom |
14 | 14 |
15 from util import build_utils | 15 from util import build_utils |
16 | 16 |
17 | 17 |
18 _SRC_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), | 18 _SRC_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), |
19 '..', '..', '..')) | 19 '..', '..', '..')) |
20 | 20 |
21 | 21 |
22 def _RunLint(lint_path, config_path, processed_config_path, manifest_path, | 22 def _RunLint(lint_path, config_path, processed_config_path, manifest_path, |
23 result_path, product_dir, sources, jar_path): | 23 result_path, product_dir, sources, jar_path, resource_dir=None): |
24 | 24 |
25 def _RelativizePath(path): | 25 def _RelativizePath(path): |
26 """Returns relative path to top-level src dir. | 26 """Returns relative path to top-level src dir. |
27 | 27 |
28 Args: | 28 Args: |
29 path: A path relative to cwd. | 29 path: A path relative to cwd. |
30 """ | 30 """ |
31 return os.path.relpath(os.path.abspath(path), _SRC_ROOT) | 31 return os.path.relpath(os.path.abspath(path), _SRC_ROOT) |
32 | 32 |
33 def _ProcessConfigFile(): | 33 def _ProcessConfigFile(): |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 with build_utils.TempDir() as temp_dir: | 74 with build_utils.TempDir() as temp_dir: |
75 _ProcessConfigFile() | 75 _ProcessConfigFile() |
76 | 76 |
77 cmd = [ | 77 cmd = [ |
78 _RelativizePath(lint_path), '-Werror', '--exitcode', '--showall', | 78 _RelativizePath(lint_path), '-Werror', '--exitcode', '--showall', |
79 '--config', _RelativizePath(processed_config_path), | 79 '--config', _RelativizePath(processed_config_path), |
80 '--classpath', _RelativizePath(jar_path), | 80 '--classpath', _RelativizePath(jar_path), |
81 '--xml', _RelativizePath(result_path), | 81 '--xml', _RelativizePath(result_path), |
82 ] | 82 ] |
| 83 if resource_dir: |
| 84 cmd.extend(['--resources', _RelativizePath(resource_dir)]) |
83 | 85 |
84 # There may be multiple source files with the same basename (but in | 86 # There may be multiple source files with the same basename (but in |
85 # different directories). It is difficult to determine what part of the path | 87 # different directories). It is difficult to determine what part of the path |
86 # corresponds to the java package, and so instead just link the source files | 88 # corresponds to the java package, and so instead just link the source files |
87 # into temporary directories (creating a new one whenever there is a name | 89 # into temporary directories (creating a new one whenever there is a name |
88 # conflict). | 90 # conflict). |
89 src_dirs = [] | 91 src_dirs = [] |
90 def NewSourceDir(): | 92 def NewSourceDir(): |
91 new_dir = os.path.join(temp_dir, str(len(src_dirs))) | 93 new_dir = os.path.join(temp_dir, str(len(src_dirs))) |
92 os.mkdir(new_dir) | 94 os.mkdir(new_dir) |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 parser.add_option('--lint-path', help='Path to lint executable.') | 159 parser.add_option('--lint-path', help='Path to lint executable.') |
158 parser.add_option('--config-path', help='Path to lint suppressions file.') | 160 parser.add_option('--config-path', help='Path to lint suppressions file.') |
159 parser.add_option('--processed-config-path', | 161 parser.add_option('--processed-config-path', |
160 help='Path to processed lint suppressions file.') | 162 help='Path to processed lint suppressions file.') |
161 parser.add_option('--manifest-path', help='Path to AndroidManifest.xml') | 163 parser.add_option('--manifest-path', help='Path to AndroidManifest.xml') |
162 parser.add_option('--result-path', help='Path to XML lint result file.') | 164 parser.add_option('--result-path', help='Path to XML lint result file.') |
163 parser.add_option('--product-dir', help='Path to product dir.') | 165 parser.add_option('--product-dir', help='Path to product dir.') |
164 parser.add_option('--src-dirs', help='Directories containing java files.') | 166 parser.add_option('--src-dirs', help='Directories containing java files.') |
165 parser.add_option('--java-files', help='Paths to java files.') | 167 parser.add_option('--java-files', help='Paths to java files.') |
166 parser.add_option('--jar-path', help='Jar file containing class files.') | 168 parser.add_option('--jar-path', help='Jar file containing class files.') |
| 169 parser.add_option('--resource-dir', help='Path to resource dir.') |
167 parser.add_option('--stamp', help='Path to touch on success.') | 170 parser.add_option('--stamp', help='Path to touch on success.') |
168 parser.add_option('--enable', action='store_true', | 171 parser.add_option('--enable', action='store_true', |
169 help='Run lint instead of just touching stamp.') | 172 help='Run lint instead of just touching stamp.') |
170 | 173 |
171 options, _ = parser.parse_args() | 174 options, _ = parser.parse_args() |
172 | 175 |
173 build_utils.CheckOptions( | 176 build_utils.CheckOptions( |
174 options, parser, required=['lint_path', 'config_path', | 177 options, parser, required=['lint_path', 'config_path', |
175 'processed_config_path', 'manifest_path', | 178 'processed_config_path', 'manifest_path', |
176 'result_path', 'product_dir', | 179 'result_path', 'product_dir', |
177 'jar_path']) | 180 'jar_path']) |
178 | 181 |
179 rc = 0 | 182 rc = 0 |
180 | 183 |
181 if options.enable: | 184 if options.enable: |
182 sources = [] | 185 sources = [] |
183 if options.src_dirs: | 186 if options.src_dirs: |
184 src_dirs = build_utils.ParseGypList(options.src_dirs) | 187 src_dirs = build_utils.ParseGypList(options.src_dirs) |
185 sources = build_utils.FindInDirectories(src_dirs, '*.java') | 188 sources = build_utils.FindInDirectories(src_dirs, '*.java') |
186 elif options.java_files: | 189 elif options.java_files: |
187 sources = build_utils.ParseGypList(options.java_files) | 190 sources = build_utils.ParseGypList(options.java_files) |
188 else: | 191 else: |
189 print 'One of --src-dirs or --java-files must be specified.' | 192 print 'One of --src-dirs or --java-files must be specified.' |
190 return 1 | 193 return 1 |
191 rc = _RunLint(options.lint_path, options.config_path, | 194 rc = _RunLint(options.lint_path, options.config_path, |
192 options.processed_config_path, | 195 options.processed_config_path, |
193 options.manifest_path, options.result_path, | 196 options.manifest_path, options.result_path, |
194 options.product_dir, sources, options.jar_path) | 197 options.product_dir, sources, options.jar_path, |
| 198 options.resource_dir) |
195 | 199 |
196 if options.depfile: | 200 if options.depfile: |
197 build_utils.WriteDepfile( | 201 build_utils.WriteDepfile( |
198 options.depfile, | 202 options.depfile, |
199 build_utils.GetPythonDependencies()) | 203 build_utils.GetPythonDependencies()) |
200 | 204 |
201 if options.stamp and not rc: | 205 if options.stamp and not rc: |
202 build_utils.Touch(options.stamp) | 206 build_utils.Touch(options.stamp) |
203 | 207 |
204 return rc | 208 return rc |
205 | 209 |
206 | 210 |
207 if __name__ == '__main__': | 211 if __name__ == '__main__': |
208 sys.exit(main()) | 212 sys.exit(main()) |
OLD | NEW |