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

Unified 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, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: build/android/gyp/lint.py
diff --git a/build/android/gyp/lint.py b/build/android/gyp/lint.py
new file mode 100755
index 0000000000000000000000000000000000000000..41de0ee8aa704a8b4fd5c9802e1d72be9e1cec12
--- /dev/null
+++ b/build/android/gyp/lint.py
@@ -0,0 +1,99 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Runs Android's lint tool."""
+
+
+import optparse
+import os
+import sys
+import time
+from xml.dom import minidom
+
+from util import build_utils
+
+
+def _ParseAndShowResultFile(result_path):
+ dom = minidom.parse(result_path)
+ for issue in dom.getElementsByTagName('issue'):
+ issue_id = issue.attributes['id'].value
+ severity = issue.attributes['severity'].value
+ message = issue.attributes['message'].value
+ location_elem = issue.getElementsByTagName('location')[0]
+ file_path = location_elem.attributes['file'].value
+ line = location_elem.attributes['line'].value
+
+ error = '%s:%s %s: %s [%s]' % (file_path, line, severity, message,
+ issue_id)
+ print >> sys.stderr, error
+
+
+def _RunLint(lint_path, config_path, result_path, src_root, src_dirs,
+ classes_dir):
+
+ def _RelativizePath(path):
+ """Returns relative path to top-level src dir.
+
+ Args:
+ path: A path relative to cwd.
+ """
+ return os.path.relpath(os.path.abspath(path), os.path.abspath(src_root))
+
+ cmd = [
+ lint_path, '-Werror', '--exitcode', '--showall',
+ '--config', _RelativizePath(config_path),
+ '--classpath', _RelativizePath(classes_dir),
+ '--xml', _RelativizePath(result_path),
+ ]
+
+ for src in src_dirs:
+ cmd.extend(['--sources', _RelativizePath(src)])
+
+ cmd.append(_RelativizePath(os.path.join(config_path, os.pardir)))
+
+ rc, _ = build_utils.CheckCall(cmd, suppress_output=True,
+ cwd=os.path.abspath(src_root))
+ if rc:
+ _ParseAndShowResultFile(result_path)
+ print >> sys.stderr, ('\nWanna suppress lint issues? Refer to %s' %
+ _RelativizePath(config_path))
+ sys.exit(rc)
+
+
+def main(argv):
+ start = time.time()
+
+ parser = optparse.OptionParser()
+ parser.add_option('--lint-path', help='Path to lint executable.')
+ parser.add_option('--config-path', help='Path to lint suppressions file.')
+ parser.add_option('--result-path', help='Path to xml file')
+ parser.add_option('--src-root', help='Path to top-level src dir.')
+ parser.add_option('--src-dirs', help='Directories containing java files.')
+ parser.add_option('--classes-dir', help='Directory containing class files.')
+ parser.add_option('--stamp', help='Path to touch on success.')
+ parser.add_option('--enable', action='store_true',
+ help='Run lint instead of just touching stamp.')
+
+ options, _ = parser.parse_args()
+
+ assert (options.lint_path and options.config_path and options.result_path and
+ options.src_root and options.src_dirs and options.classes_dir)
+
+ src_dirs = build_utils.ParseGypList(options.src_dirs)
+
+ if options.enable:
+ _RunLint(options.lint_path, options.config_path, options.result_path,
+ options.src_root, src_dirs, options.classes_dir)
+
+ if options.stamp:
+ build_utils.Touch(options.stamp)
+
+ # TODO(frankf): Remove this before committing.
+ print 'Lint took %s' % str(int(time.time() - start))
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))

Powered by Google App Engine
This is Rietveld 408576698