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

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

Issue 2241563005: Handle temporary file paths in suppress.py. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 """Add all generated lint_result.xml files to suppressions.xml""" 7 """Add all generated lint_result.xml files to suppressions.xml"""
8 8
9 # pylint: disable=no-member 9 # pylint: disable=no-member
10 10
11 11
12 import collections 12 import collections
13 import optparse 13 import optparse
14 import os 14 import os
15 import re
15 import sys 16 import sys
16 from xml.dom import minidom 17 from xml.dom import minidom
17 18
18 _BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..') 19 _BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..')
19 sys.path.append(_BUILD_ANDROID_DIR) 20 sys.path.append(_BUILD_ANDROID_DIR)
20 21
21 from pylib.constants import host_paths 22 from pylib.constants import host_paths
22 23
23 24 _TMP_DIR_RE = re.compile(r'^/tmp/.*/(SRC_ROOT[0-9]+|PRODUCT_DIR)/')
24 _THIS_FILE = os.path.abspath(__file__) 25 _THIS_FILE = os.path.abspath(__file__)
25 _CONFIG_PATH = os.path.join(os.path.dirname(_THIS_FILE), 'suppressions.xml') 26 _CONFIG_PATH = os.path.join(os.path.dirname(_THIS_FILE), 'suppressions.xml')
26 _DOC = ( 27 _DOC = (
27 '\nSTOP! It looks like you want to suppress some lint errors:\n' 28 '\nSTOP! It looks like you want to suppress some lint errors:\n'
28 '- Have you tried identifing the offending patch?\n' 29 '- Have you tried identifing the offending patch?\n'
29 ' Ask the author for a fix and/or revert the patch.\n' 30 ' Ask the author for a fix and/or revert the patch.\n'
30 '- It is preferred to add suppressions in the code instead of\n' 31 '- It is preferred to add suppressions in the code instead of\n'
31 ' sweeping it under the rug here. See:\n\n' 32 ' sweeping it under the rug here. See:\n\n'
32 ' http://developer.android.com/tools/debugging/improving-w-lint.html\n' 33 ' http://developer.android.com/tools/debugging/improving-w-lint.html\n'
33 '\n' 34 '\n'
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 return issues_dict 69 return issues_dict
69 70
70 71
71 def _ParseAndMergeResultFile(result_path, issues_dict): 72 def _ParseAndMergeResultFile(result_path, issues_dict):
72 print 'Parsing and merging %s' % result_path 73 print 'Parsing and merging %s' % result_path
73 dom = minidom.parse(result_path) 74 dom = minidom.parse(result_path)
74 for issue in dom.getElementsByTagName('issue'): 75 for issue in dom.getElementsByTagName('issue'):
75 issue_id = issue.attributes['id'].value 76 issue_id = issue.attributes['id'].value
76 severity = issue.attributes['severity'].value 77 severity = issue.attributes['severity'].value
77 path = issue.getElementsByTagName('location')[0].attributes['file'].value 78 path = issue.getElementsByTagName('location')[0].attributes['file'].value
79 # Strip temporary file path and use regex instead of path.
80 regexp = re.sub(_TMP_DIR_RE, '', path)
78 if issue_id not in issues_dict: 81 if issue_id not in issues_dict:
79 issues_dict[issue_id] = _Issue(severity, set(), set()) 82 issues_dict[issue_id] = _Issue(severity, set(), set())
80 issues_dict[issue_id].paths.add(path) 83 issues_dict[issue_id].regexps.add(regexp)
81 84
82 85
83 def _WriteConfigFile(config_path, issues_dict): 86 def _WriteConfigFile(config_path, issues_dict):
84 new_dom = minidom.getDOMImplementation().createDocument(None, 'lint', None) 87 new_dom = minidom.getDOMImplementation().createDocument(None, 'lint', None)
85 top_element = new_dom.documentElement 88 top_element = new_dom.documentElement
86 top_element.appendChild(new_dom.createComment(_DOC)) 89 top_element.appendChild(new_dom.createComment(_DOC))
87 for issue_id, issue in sorted(issues_dict.iteritems(), key=lambda i: i[0]): 90 for issue_id, issue in sorted(issues_dict.iteritems(), key=lambda i: i[0]):
88 issue_element = new_dom.createElement('issue') 91 issue_element = new_dom.createElement('issue')
89 issue_element.attributes['id'] = issue_id 92 issue_element.attributes['id'] = issue_id
90 if issue.severity: 93 if issue.severity:
(...skipping 27 matching lines...) Expand all
118 _, args = parser.parse_args() 121 _, args = parser.parse_args()
119 122
120 if len(args) != 1 or not os.path.exists(args[0]): 123 if len(args) != 1 or not os.path.exists(args[0]):
121 parser.error('Must provide RESULT-FILE') 124 parser.error('Must provide RESULT-FILE')
122 125
123 _Suppress(_CONFIG_PATH, args[0]) 126 _Suppress(_CONFIG_PATH, args[0])
124 127
125 128
126 if __name__ == '__main__': 129 if __name__ == '__main__':
127 main() 130 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698