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