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 argparse | 10 import argparse |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 if cache_dir: | 134 if cache_dir: |
135 # When _JAVA_OPTIONS is set, java prints to stderr: | 135 # When _JAVA_OPTIONS is set, java prints to stderr: |
136 # Picked up _JAVA_OPTIONS: ... | 136 # Picked up _JAVA_OPTIONS: ... |
137 env['_JAVA_OPTIONS'] = '-Duser.home=%s' % _RelativizePath(cache_dir) | 137 env['_JAVA_OPTIONS'] = '-Duser.home=%s' % _RelativizePath(cache_dir) |
138 stderr_filter = lambda l: '' if '_JAVA_OPTIONS' in l else l | 138 stderr_filter = lambda l: '' if '_JAVA_OPTIONS' in l else l |
139 | 139 |
140 try: | 140 try: |
141 build_utils.CheckOutput(cmd, cwd=_SRC_ROOT, env=env or None, | 141 build_utils.CheckOutput(cmd, cwd=_SRC_ROOT, env=env or None, |
142 stderr_filter=stderr_filter) | 142 stderr_filter=stderr_filter) |
143 except build_utils.CalledProcessError: | 143 except build_utils.CalledProcessError: |
144 if can_fail_build: | |
145 traceback.print_exc() | |
146 | |
147 # There is a problem with lint usage | 144 # There is a problem with lint usage |
148 if not os.path.exists(result_path): | 145 if not os.path.exists(result_path): |
149 raise | 146 raise |
150 | 147 |
| 148 # Sometimes produces empty (almost) files: |
| 149 if os.path.getsize(result_path) < 10: |
| 150 if can_fail_build: |
| 151 raise |
| 152 elif not silent: |
| 153 traceback.print_exc() |
| 154 return |
| 155 |
151 # There are actual lint issues | 156 # There are actual lint issues |
152 else: | 157 try: |
153 try: | 158 num_issues = _ParseAndShowResultFile() |
154 num_issues = _ParseAndShowResultFile() | 159 except Exception: # pylint: disable=broad-except |
155 except Exception: # pylint: disable=broad-except | 160 if not silent: |
156 if not silent: | 161 print 'Lint created unparseable xml file...' |
157 print 'Lint created unparseable xml file...' | 162 print 'File contents:' |
158 print 'File contents:' | 163 with open(result_path) as f: |
159 with open(result_path) as f: | 164 print f.read() |
160 print f.read() | 165 if not can_fail_build: |
161 if not can_fail_build: | 166 return |
162 return | |
163 raise | |
164 | 167 |
165 _ProcessResultFile() | 168 if can_fail_build and not silent: |
166 msg = ('\nLint found %d new issues.\n' | 169 traceback.print_exc() |
167 ' - For full explanation refer to %s\n' % | 170 |
168 (num_issues, | 171 # There are actual lint issues |
169 _RelativizePath(result_path))) | 172 try: |
170 if config_path: | 173 num_issues = _ParseAndShowResultFile() |
171 msg += (' - Wanna suppress these issues?\n' | 174 except Exception: # pylint: disable=broad-except |
172 ' 1. Read comment in %s\n' | |
173 ' 2. Run "python %s %s"\n' % | |
174 (_RelativizePath(config_path), | |
175 _RelativizePath(os.path.join(_SRC_ROOT, 'build', 'android', | |
176 'lint', 'suppress.py')), | |
177 _RelativizePath(result_path))) | |
178 if not silent: | 175 if not silent: |
179 print >> sys.stderr, msg | 176 print 'Lint created unparseable xml file...' |
180 if can_fail_build: | 177 print 'File contents:' |
181 raise Exception('Lint failed.') | 178 with open(result_path) as f: |
| 179 print f.read() |
| 180 raise |
| 181 |
| 182 _ProcessResultFile() |
| 183 msg = ('\nLint found %d new issues.\n' |
| 184 ' - For full explanation refer to %s\n' % |
| 185 (num_issues, |
| 186 _RelativizePath(result_path))) |
| 187 if config_path: |
| 188 msg += (' - Wanna suppress these issues?\n' |
| 189 ' 1. Read comment in %s\n' |
| 190 ' 2. Run "python %s %s"\n' % |
| 191 (_RelativizePath(config_path), |
| 192 _RelativizePath(os.path.join(_SRC_ROOT, 'build', 'android', |
| 193 'lint', 'suppress.py')), |
| 194 _RelativizePath(result_path))) |
| 195 if not silent: |
| 196 print >> sys.stderr, msg |
| 197 if can_fail_build: |
| 198 raise Exception('Lint failed.') |
182 | 199 |
183 | 200 |
184 def main(): | 201 def main(): |
185 parser = argparse.ArgumentParser() | 202 parser = argparse.ArgumentParser() |
186 build_utils.AddDepfileOption(parser) | 203 build_utils.AddDepfileOption(parser) |
187 | 204 |
188 parser.add_argument('--lint-path', required=True, | 205 parser.add_argument('--lint-path', required=True, |
189 help='Path to lint executable.') | 206 help='Path to lint executable.') |
190 parser.add_argument('--product-dir', required=True, | 207 parser.add_argument('--product-dir', required=True, |
191 help='Path to product dir.') | 208 help='Path to product dir.') |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 silent=args.silent), | 303 silent=args.silent), |
287 args, | 304 args, |
288 input_paths=input_paths, | 305 input_paths=input_paths, |
289 input_strings=input_strings, | 306 input_strings=input_strings, |
290 output_paths=output_paths, | 307 output_paths=output_paths, |
291 pass_changes=True) | 308 pass_changes=True) |
292 | 309 |
293 | 310 |
294 if __name__ == '__main__': | 311 if __name__ == '__main__': |
295 sys.exit(main()) | 312 sys.exit(main()) |
OLD | NEW |