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

Unified Diff: build/android/lint/suppress.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
« no previous file with comments | « build/android/lint/AndroidManifest.xml ('k') | build/android/lint/suppressions.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/lint/suppress.py
diff --git a/build/android/lint/suppress.py b/build/android/lint/suppress.py
new file mode 100755
index 0000000000000000000000000000000000000000..469dd56dc5801710529dd95b6cf8184b905ec0d0
--- /dev/null
+++ b/build/android/lint/suppress.py
@@ -0,0 +1,121 @@
+#!/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.
+
+"""Add all generated lint_result.xml files to suppressions.xml"""
+
+
+import optparse
+import os
+import sys
+from xml.dom import minidom
+
+_BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..')
+sys.path.append(_BUILD_ANDROID_DIR)
+
+from pylib import constants
+
+
+_THIS_FILE = os.path.abspath(__file__)
+_CONFIG_PATH = os.path.join(os.path.dirname(_THIS_FILE), 'suppressions.xml')
+_RESULT_FILE_NAME = 'lint_result.xml'
+_DOC = (
+ '\nSTOP! It looks like you want to suppress some lint errors:\n'
+ '- Have you tried identifing the offending patch?\n'
+ ' Ask the author for a fix and/or revert the patch.\n'
+ '- It is preferred to add suppressions in the code instead of\n'
+ ' sweeping it under the rug here. See:\n'
+ ' http://developer.android.com/tools/debugging/improving-w-lint.html\n'
+ '\n'
+ 'Still reading?\n'
+ '- You can edit this file manually to suppress an issue\n'
+ ' globally if it is not applicable to the project.\n'
+ '- You can also automatically add issues found so for in the\n'
+ ' build process by running:\n'
cjhopman 2013/11/26 23:44:15 Maybe mention that this string should be edited in
frankf 2013/11/27 03:28:45 Done.
+ ' ' + os.path.relpath(_THIS_FILE, constants.DIR_SOURCE_ROOT) + '\n'
+)
+_GLOBAL_IGNORE_FLAG = 'ignore'
+
+
cjhopman 2013/11/26 23:44:15 I think these three functions would be simpler if
frankf 2013/11/27 03:28:45 Actually, I've changed this to use a namedtuple to
+def _ParseConfigFile(config_path):
+ print 'Parsing %s' % config_path
+ issues_dict = {}
+ dom = minidom.parse(config_path)
+ for issue in dom.getElementsByTagName('issue'):
+ issue_id = issue.attributes['id'].value
+ if issue.getAttribute('severity') == 'ignore':
+ print 'Warning: %s is suppresed globally.' % issue_id
cjhopman 2013/11/26 23:44:15 s/suppresed/suppressed/
frankf 2013/11/27 03:28:45 Done.
+ issues_dict[issue_id] = _GLOBAL_IGNORE_FLAG
+ else:
+ issues_dict[issue_id] = set()
+ issues_dict[issue_id].update(
+ [p.attributes['path'].value for p in
+ issue.getElementsByTagName('ignore')])
+ return issues_dict
+
+
+def _ParseAndMergeResultFile(result_path, issues_dict):
+ print 'Parsing and merging %s' % result_path
+ dom = minidom.parse(result_path)
+ for issue in dom.getElementsByTagName('issue'):
+ issue_id = issue.attributes['id'].value
+ if issue_id not in issues_dict:
+ issues_dict[issue_id] = set()
+ elif issues_dict.get(issue_id) == _GLOBAL_IGNORE_FLAG:
+ continue
+ issues_dict[issue_id].add(
+ issue.getElementsByTagName('location')[0].attributes['file'].value)
+
+
+def _WriteConfigFile(config_path, issues_dict):
+ print 'Updating %s' % config_path
+ new_dom = minidom.getDOMImplementation().createDocument(None, 'lint', None)
+ top_element = new_dom.documentElement
+ top_element.appendChild(new_dom.createComment(_DOC))
+ for issue_id in sorted(issues_dict.keys()):
+ locations = issues_dict[issue_id]
+ issue = new_dom.createElement('issue')
+ issue.attributes['id'] = issue_id
+ if locations == _GLOBAL_IGNORE_FLAG:
+ issue.attributes['severity'] = 'ignore'
+ else:
+ for loc in sorted(locations):
+ ignore = new_dom.createElement('ignore')
+ ignore.attributes['path'] = loc
+ issue.appendChild(ignore)
+ top_element.appendChild(issue)
+
+ with open(config_path, 'w') as f:
+ f.write(new_dom.toprettyxml(indent=' ', encoding='utf-8'))
+
+
+def _Suppress(config_path):
+ issues_dict = _ParseConfigFile(config_path)
+
+ for dirpath, _, files in os.walk(constants.GetOutDirectory()):
+ for f in files:
+ if f == _RESULT_FILE_NAME:
+ _ParseAndMergeResultFile(os.path.join(dirpath, f), issues_dict)
+
+ _WriteConfigFile(config_path, issues_dict)
+
+
+def main(argv):
+ parser = optparse.OptionParser()
+ parser = optparse.OptionParser()
+ parser.add_option('--release', action='store_true',
+ help='Whether this is a Release build.')
+ options, _ = parser.parse_args()
+
+ if options.release:
+ constants.SetBuildType('Release')
+ else:
+ constants.SetBuildType('Debug')
+
+ _Suppress(_CONFIG_PATH)
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
« no previous file with comments | « build/android/lint/AndroidManifest.xml ('k') | build/android/lint/suppressions.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698