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, resource_dir=None, | 23 result_path, product_dir, sources, jar_path, resource_dir=None): |
24 can_fail_build=False): | |
25 | 24 |
26 def _RelativizePath(path): | 25 def _RelativizePath(path): |
27 """Returns relative path to top-level src dir. | 26 """Returns relative path to top-level src dir. |
28 | 27 |
29 Args: | 28 Args: |
30 path: A path relative to cwd. | 29 path: A path relative to cwd. |
31 """ | 30 """ |
32 return os.path.relpath(os.path.abspath(path), _SRC_ROOT) | 31 return os.path.relpath(os.path.abspath(path), _SRC_ROOT) |
33 | 32 |
34 def _ProcessConfigFile(): | 33 def _ProcessConfigFile(): |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 if os.path.exists(result_path): | 114 if os.path.exists(result_path): |
116 os.remove(result_path) | 115 os.remove(result_path) |
117 | 116 |
118 try: | 117 try: |
119 build_utils.CheckOutput(cmd, cwd=_SRC_ROOT) | 118 build_utils.CheckOutput(cmd, cwd=_SRC_ROOT) |
120 except build_utils.CalledProcessError as e: | 119 except build_utils.CalledProcessError as e: |
121 # There is a problem with lint usage | 120 # There is a problem with lint usage |
122 if not os.path.exists(result_path): | 121 if not os.path.exists(result_path): |
123 print 'Something is wrong:' | 122 print 'Something is wrong:' |
124 print e | 123 print e |
125 return 0 | 124 return 1 |
126 | 125 |
127 # There are actual lint issues | 126 # There are actual lint issues |
128 else: | 127 else: |
129 try: | 128 try: |
130 num_issues = _ParseAndShowResultFile() | 129 num_issues = _ParseAndShowResultFile() |
131 except Exception: | 130 except Exception: |
132 print 'Lint created unparseable xml file...' | 131 print 'Lint created unparseable xml file...' |
133 print 'File contents:' | 132 print 'File contents:' |
134 with open(result_path) as f: | 133 with open(result_path) as f: |
135 print f.read() | 134 print f.read() |
136 return 0 | 135 return 1 |
137 | 136 |
138 _ProcessResultFile() | 137 _ProcessResultFile() |
139 msg = ('\nLint found %d new issues.\n' | 138 msg = ('\nLint found %d new issues.\n' |
140 ' - For full explanation refer to %s\n' | 139 ' - For full explanation refer to %s\n' |
141 ' - Wanna suppress these issues?\n' | 140 ' - Wanna suppress these issues?\n' |
142 ' 1. Read comment in %s\n' | 141 ' 1. Read comment in %s\n' |
143 ' 2. Run "python %s %s"\n' % | 142 ' 2. Run "python %s %s"\n' % |
144 (num_issues, | 143 (num_issues, |
145 _RelativizePath(result_path), | 144 _RelativizePath(result_path), |
146 _RelativizePath(config_path), | 145 _RelativizePath(config_path), |
147 _RelativizePath(os.path.join(_SRC_ROOT, 'build', 'android', | 146 _RelativizePath(os.path.join(_SRC_ROOT, 'build', 'android', |
148 'lint', 'suppress.py')), | 147 'lint', 'suppress.py')), |
149 _RelativizePath(result_path))) | 148 _RelativizePath(result_path))) |
150 print >> sys.stderr, msg | 149 print >> sys.stderr, msg |
151 return 1 if can_fail_build else 0 | 150 return 1 |
152 | 151 |
153 return 0 | 152 return 0 |
154 | 153 |
155 | 154 |
156 def main(): | 155 def main(): |
157 parser = optparse.OptionParser() | 156 parser = optparse.OptionParser() |
158 build_utils.AddDepfileOption(parser) | 157 build_utils.AddDepfileOption(parser) |
159 parser.add_option('--lint-path', help='Path to lint executable.') | 158 parser.add_option('--lint-path', help='Path to lint executable.') |
160 parser.add_option('--config-path', help='Path to lint suppressions file.') | 159 parser.add_option('--config-path', help='Path to lint suppressions file.') |
161 parser.add_option('--processed-config-path', | 160 parser.add_option('--processed-config-path', |
(...skipping 29 matching lines...) Expand all Loading... |
191 sources = build_utils.FindInDirectories(src_dirs, '*.java') | 190 sources = build_utils.FindInDirectories(src_dirs, '*.java') |
192 elif options.java_files: | 191 elif options.java_files: |
193 sources = build_utils.ParseGypList(options.java_files) | 192 sources = build_utils.ParseGypList(options.java_files) |
194 else: | 193 else: |
195 print 'One of --src-dirs or --java-files must be specified.' | 194 print 'One of --src-dirs or --java-files must be specified.' |
196 return 1 | 195 return 1 |
197 rc = _RunLint(options.lint_path, options.config_path, | 196 rc = _RunLint(options.lint_path, options.config_path, |
198 options.processed_config_path, | 197 options.processed_config_path, |
199 options.manifest_path, options.result_path, | 198 options.manifest_path, options.result_path, |
200 options.product_dir, sources, options.jar_path, | 199 options.product_dir, sources, options.jar_path, |
201 options.resource_dir, options.can_fail_build) | 200 options.resource_dir) |
202 | 201 |
203 if options.depfile: | 202 if options.depfile: |
204 build_utils.WriteDepfile( | 203 build_utils.WriteDepfile( |
205 options.depfile, | 204 options.depfile, |
206 build_utils.GetPythonDependencies()) | 205 build_utils.GetPythonDependencies()) |
207 | 206 |
208 if options.stamp and not rc: | 207 if options.stamp and not rc: |
209 build_utils.Touch(options.stamp) | 208 build_utils.Touch(options.stamp) |
210 | 209 |
211 return rc | 210 return rc if options.can_fail_build else 0 |
212 | 211 |
213 | 212 |
214 if __name__ == '__main__': | 213 if __name__ == '__main__': |
215 sys.exit(main()) | 214 sys.exit(main()) |
OLD | NEW |