Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Side by Side Diff: build/android/gyp/lint.py

Issue 86313004: [Android] Add lint as a gyp action. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
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
5 # found in the LICENSE file.
6
7 """Runs Android's lint tool."""
8
9
10 import optparse
11 import os
12 import sys
13 import time
14 from xml.dom import minidom
15
16 from util import build_utils
17
18
19 def _ParseAndShowResultFile(result_path):
20 dom = minidom.parse(result_path)
21 for issue in dom.getElementsByTagName('issue'):
22 issue_id = issue.attributes['id'].value
23 severity = issue.attributes['severity'].value
24 message = issue.attributes['message'].value
25 location_elem = issue.getElementsByTagName('location')[0]
26 file_path = location_elem.attributes['file'].value
27 line = location_elem.attributes['line'].value
28
29 error = '%s:%s %s: %s [%s]' % (file_path, line, severity, message,
30 issue_id)
31 print >> sys.stderr, error
32
33
34 def _RunLint(lint_path, config_path, result_path, src_root, src_dirs,
35 classes_dir):
36
37 def _RelativizePath(path):
38 """Returns relative path to top-level src dir.
39
40 Args:
41 path: A path relative to cwd.
42 """
43 return os.path.relpath(os.path.abspath(path), os.path.abspath(src_root))
44
45 cmd = [
46 lint_path, '-Werror', '--exitcode', '--showall',
47 '--config', _RelativizePath(config_path),
48 '--classpath', _RelativizePath(classes_dir),
49 '--xml', _RelativizePath(result_path),
50 ]
51
52 for src in src_dirs:
53 cmd.extend(['--sources', _RelativizePath(src)])
54
55 cmd.append(_RelativizePath(os.path.join(config_path, os.pardir)))
56
57 rc, _ = build_utils.CheckCall(cmd, suppress_output=True,
58 cwd=os.path.abspath(src_root))
59 if rc:
60 _ParseAndShowResultFile(result_path)
61 print >> sys.stderr, ('\nWanna suppress lint issues? Refer to %s' %
62 _RelativizePath(config_path))
63 sys.exit(rc)
64
65
66 def main(argv):
67 start = time.time()
68
69 parser = optparse.OptionParser()
70 parser.add_option('--lint-path', help='Path to lint executable.')
71 parser.add_option('--config-path', help='Path to lint suppressions file.')
72 parser.add_option('--result-path', help='Path to xml file')
73 parser.add_option('--src-root', help='Path to top-level src dir.')
74 parser.add_option('--src-dirs', help='Directories containing java files.')
75 parser.add_option('--classes-dir', help='Directory containing class files.')
76 parser.add_option('--stamp', help='Path to touch on success.')
77 parser.add_option('--enable', action='store_true',
78 help='Run lint instead of just touching stamp.')
79
80 options, _ = parser.parse_args()
81
82 assert (options.lint_path and options.config_path and options.result_path and
83 options.src_root and options.src_dirs and options.classes_dir)
84
85 src_dirs = build_utils.ParseGypList(options.src_dirs)
86
87 if options.enable:
88 _RunLint(options.lint_path, options.config_path, options.result_path,
89 options.src_root, src_dirs, options.classes_dir)
90
91 if options.stamp:
92 build_utils.Touch(options.stamp)
93
94 # TODO(frankf): Remove this before committing.
95 print 'Lint took %s' % str(int(time.time() - start))
96
97
98 if __name__ == '__main__':
99 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698