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 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 with open(result_path, 'wb') as f: | 49 with open(result_path, 'wb') as f: |
50 f.write(content) | 50 f.write(content) |
51 | 51 |
52 def _ParseAndShowResultFile(): | 52 def _ParseAndShowResultFile(): |
53 dom = minidom.parse(result_path) | 53 dom = minidom.parse(result_path) |
54 issues = dom.getElementsByTagName('issue') | 54 issues = dom.getElementsByTagName('issue') |
55 print >> sys.stderr | 55 print >> sys.stderr |
56 for issue in issues: | 56 for issue in issues: |
57 issue_id = issue.attributes['id'].value | 57 issue_id = issue.attributes['id'].value |
58 severity = issue.attributes['severity'].value | |
59 message = issue.attributes['message'].value | 58 message = issue.attributes['message'].value |
60 location_elem = issue.getElementsByTagName('location')[0] | 59 location_elem = issue.getElementsByTagName('location')[0] |
61 path = location_elem.attributes['file'].value | 60 path = location_elem.attributes['file'].value |
62 line = location_elem.getAttribute('line') | 61 line = location_elem.getAttribute('line') |
63 if line: | 62 if line: |
64 error = '%s:%s %s: %s [%s]' % (path, line, severity, message, | 63 error = '%s:%s %s: %s [warning]' % (path, line, message, issue_id) |
65 issue_id) | |
66 else: | 64 else: |
67 # Issues in class files don't have a line number. | 65 # Issues in class files don't have a line number. |
68 error = '%s %s: %s [%s]' % (path, severity, message, issue_id) | 66 error = '%s %s: %s [warning]' % (path, message, issue_id) |
69 print >> sys.stderr, error | 67 print >> sys.stderr, error |
70 for attr in ['errorLine1', 'errorLine2']: | 68 for attr in ['errorLine1', 'errorLine2']: |
71 error_line = issue.getAttribute(attr) | 69 error_line = issue.getAttribute(attr) |
72 if error_line: | 70 if error_line: |
73 print >> sys.stderr, error_line | 71 print >> sys.stderr, error_line |
74 return len(issues) | 72 return len(issues) |
75 | 73 |
76 _ProcessConfigFile() | 74 _ProcessConfigFile() |
77 | 75 |
78 cmd = [ | 76 cmd = [ |
79 lint_path, '-Werror', '--exitcode', '--showall', | 77 lint_path, '-Werror', '--exitcode', '--showall', |
80 '--config', _RelativizePath(processed_config_path), | 78 '--config', _RelativizePath(processed_config_path), |
81 '--classpath', _RelativizePath(classes_dir), | 79 '--classpath', _RelativizePath(classes_dir), |
82 '--xml', _RelativizePath(result_path), | 80 '--xml', _RelativizePath(result_path), |
83 ] | 81 ] |
84 for src in src_dirs: | 82 for src in src_dirs: |
85 cmd.extend(['--sources', _RelativizePath(src)]) | 83 cmd.extend(['--sources', _RelativizePath(src)]) |
86 cmd.append(_RelativizePath(os.path.join(manifest_path, os.pardir))) | 84 cmd.append(_RelativizePath(os.path.join(manifest_path, os.pardir))) |
87 | 85 |
88 if os.path.exists(result_path): | 86 if os.path.exists(result_path): |
89 os.remove(result_path) | 87 os.remove(result_path) |
90 | 88 |
91 try: | 89 try: |
92 build_utils.CheckOutput(cmd, cwd=_SRC_ROOT) | 90 build_utils.CheckOutput(cmd, cwd=_SRC_ROOT) |
93 except build_utils.CalledProcessError: | 91 except build_utils.CalledProcessError as e: |
94 # There is a problem with lint usage | 92 # There is a problem with lint usage |
95 if not os.path.exists(result_path): | 93 if not os.path.exists(result_path): |
96 raise | 94 print 'Something is wrong:' |
| 95 print e |
| 96 return 0 |
| 97 |
97 # There are actual lint issues | 98 # There are actual lint issues |
98 else: | 99 else: |
99 num_issues = _ParseAndShowResultFile() | 100 try: |
| 101 num_issues = _ParseAndShowResultFile() |
| 102 except Exception: |
| 103 print 'Lint created unparseable xml file...' |
| 104 print 'File contents:' |
| 105 with open(result_path) as f: |
| 106 print f.read() |
| 107 return 0 |
| 108 |
100 _ProcessResultFile() | 109 _ProcessResultFile() |
101 msg = ('\nLint found %d new issues.\n' | 110 msg = ('\nLint found %d new issues.\n' |
102 ' - For full explanation refer to %s\n' | 111 ' - For full explanation refer to %s\n' |
103 ' - Wanna suppress these issues?\n' | 112 ' - Wanna suppress these issues?\n' |
104 ' 1. Read comment in %s\n' | 113 ' 1. Read comment in %s\n' |
105 ' 2. Run "python %s %s"\n' % | 114 ' 2. Run "python %s %s"\n' % |
106 (num_issues, | 115 (num_issues, |
107 _RelativizePath(result_path), | 116 _RelativizePath(result_path), |
108 _RelativizePath(config_path), | 117 _RelativizePath(config_path), |
109 _RelativizePath(os.path.join(_SRC_ROOT, 'build', 'android', | 118 _RelativizePath(os.path.join(_SRC_ROOT, 'build', 'android', |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 options.product_dir, src_dirs, options.classes_dir) | 159 options.product_dir, src_dirs, options.classes_dir) |
151 | 160 |
152 if options.stamp and not rc: | 161 if options.stamp and not rc: |
153 build_utils.Touch(options.stamp) | 162 build_utils.Touch(options.stamp) |
154 | 163 |
155 return rc | 164 return rc |
156 | 165 |
157 | 166 |
158 if __name__ == '__main__': | 167 if __name__ == '__main__': |
159 sys.exit(main()) | 168 sys.exit(main()) |
OLD | NEW |