Chromium Code Reviews| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 if os.path.exists(result_path): | 129 if os.path.exists(result_path): |
| 130 os.remove(result_path) | 130 os.remove(result_path) |
| 131 | 131 |
| 132 env = {} | 132 env = {} |
| 133 if cache_dir: | 133 if cache_dir: |
| 134 env['_JAVA_OPTIONS'] = '-Duser.home=%s' % _RelativizePath(cache_dir) | 134 env['_JAVA_OPTIONS'] = '-Duser.home=%s' % _RelativizePath(cache_dir) |
| 135 | 135 |
| 136 try: | 136 try: |
| 137 build_utils.CheckOutput(cmd, cwd=_SRC_ROOT, env=env or None) | 137 build_utils.CheckOutput(cmd, cwd=_SRC_ROOT, env=env or None) |
| 138 except build_utils.CalledProcessError: | 138 except build_utils.CalledProcessError: |
| 139 if can_fail_build: | |
| 140 traceback.print_exc() | |
| 141 | |
| 142 # There is a problem with lint usage | 139 # There is a problem with lint usage |
| 143 if not os.path.exists(result_path): | 140 if not os.path.exists(result_path): |
| 144 raise | 141 raise |
| 145 | 142 |
| 143 # Sometimes produces empty (almost) files: | |
| 144 if os.path.getsize(result_path) < 10: | |
| 145 if can_fail_build: | |
| 146 raise | |
| 147 elif not silent: | |
| 148 traceback.print_exc() | |
| 149 return | |
|
jbudorick
2016/03/22 23:46:12
I don't think this should be in the elif.
agrieve
2016/03/23 00:03:07
Done.
| |
| 150 | |
| 151 if can_fail_build and not silent: | |
| 152 traceback.print_exc() | |
| 153 | |
| 146 # There are actual lint issues | 154 # There are actual lint issues |
| 147 else: | 155 try: |
| 148 try: | 156 num_issues = _ParseAndShowResultFile() |
| 149 num_issues = _ParseAndShowResultFile() | 157 except Exception: # pylint: disable=broad-except |
| 150 except Exception: # pylint: disable=broad-except | 158 if not silent: |
| 151 if not silent: | 159 print 'Lint created unparseable xml file...' |
| 152 print 'Lint created unparseable xml file...' | 160 print 'File contents:' |
| 153 print 'File contents:' | 161 with open(result_path) as f: |
| 154 with open(result_path) as f: | 162 print f.read() |
| 155 print f.read() | 163 raise |
| 156 raise | |
| 157 | 164 |
| 158 _ProcessResultFile() | 165 _ProcessResultFile() |
| 159 msg = ('\nLint found %d new issues.\n' | 166 msg = ('\nLint found %d new issues.\n' |
| 160 ' - For full explanation refer to %s\n' % | 167 ' - For full explanation refer to %s\n' % |
| 161 (num_issues, | 168 (num_issues, |
| 162 _RelativizePath(result_path))) | 169 _RelativizePath(result_path))) |
| 163 if config_path: | 170 if config_path: |
| 164 msg += (' - Wanna suppress these issues?\n' | 171 msg += (' - Wanna suppress these issues?\n' |
| 165 ' 1. Read comment in %s\n' | 172 ' 1. Read comment in %s\n' |
| 166 ' 2. Run "python %s %s"\n' % | 173 ' 2. Run "python %s %s"\n' % |
| 167 (_RelativizePath(config_path), | 174 (_RelativizePath(config_path), |
| 168 _RelativizePath(os.path.join(_SRC_ROOT, 'build', 'android', | 175 _RelativizePath(os.path.join(_SRC_ROOT, 'build', 'android', |
| 169 'lint', 'suppress.py')), | 176 'lint', 'suppress.py')), |
| 170 _RelativizePath(result_path))) | 177 _RelativizePath(result_path))) |
| 171 if not silent: | 178 if not silent: |
| 172 print >> sys.stderr, msg | 179 print >> sys.stderr, msg |
| 173 if can_fail_build: | 180 if can_fail_build: |
| 174 raise Exception('Lint failed.') | 181 raise Exception('Lint failed.') |
| 175 | 182 |
| 176 | 183 |
| 177 def main(): | 184 def main(): |
| 178 parser = argparse.ArgumentParser() | 185 parser = argparse.ArgumentParser() |
| 179 build_utils.AddDepfileOption(parser) | 186 build_utils.AddDepfileOption(parser) |
| 180 | 187 |
| 181 parser.add_argument('--lint-path', required=True, | 188 parser.add_argument('--lint-path', required=True, |
| 182 help='Path to lint executable.') | 189 help='Path to lint executable.') |
| 183 parser.add_argument('--product-dir', required=True, | 190 parser.add_argument('--product-dir', required=True, |
| 184 help='Path to product dir.') | 191 help='Path to product dir.') |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 silent=args.silent), | 279 silent=args.silent), |
| 273 args, | 280 args, |
| 274 input_paths=input_paths, | 281 input_paths=input_paths, |
| 275 input_strings=input_strings, | 282 input_strings=input_strings, |
| 276 output_paths=output_paths, | 283 output_paths=output_paths, |
| 277 pass_changes=True) | 284 pass_changes=True) |
| 278 | 285 |
| 279 | 286 |
| 280 if __name__ == '__main__': | 287 if __name__ == '__main__': |
| 281 sys.exit(main()) | 288 sys.exit(main()) |
| OLD | NEW |