| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import optparse | 5 import optparse |
| 6 import os | 6 import os |
| 7 import re | 7 import re |
| 8 import shlex | 8 import shlex |
| 9 import subprocess | 9 import subprocess |
| 10 import sys | 10 import sys |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 return count | 59 return count |
| 60 | 60 |
| 61 | 61 |
| 62 def _Rebaseline(current_warnings_set, known_bugs_file): | 62 def _Rebaseline(current_warnings_set, known_bugs_file): |
| 63 with file(known_bugs_file, 'w') as known_bugs: | 63 with file(known_bugs_file, 'w') as known_bugs: |
| 64 for warning in sorted(current_warnings_set): | 64 for warning in sorted(current_warnings_set): |
| 65 print >> known_bugs, warning | 65 print >> known_bugs, warning |
| 66 return 0 | 66 return 0 |
| 67 | 67 |
| 68 | 68 |
| 69 def _GetChromeClasses(release_version): | 69 def _GetChromeClasses(): |
| 70 version = 'Debug' | 70 path = constants.GetOutDirectory() |
| 71 if release_version: | |
| 72 version = 'Release' | |
| 73 path = os.path.join(constants.DIR_SOURCE_ROOT, 'out', version) | |
| 74 cmd = 'find %s -name "*.class"' % path | 71 cmd = 'find %s -name "*.class"' % path |
| 75 out = cmd_helper.GetCmdOutput(shlex.split(cmd)) | 72 out = cmd_helper.GetCmdOutput(shlex.split(cmd)) |
| 76 if not out: | 73 if not out: |
| 77 print 'No classes found in %s' % path | 74 print 'No classes found in %s' % path |
| 78 return out | 75 return out |
| 79 | 76 |
| 80 | 77 |
| 81 def _Run(exclude, known_bugs, classes_to_analyze, auxiliary_classes, | 78 def _Run(exclude, known_bugs, classes_to_analyze, auxiliary_classes, |
| 82 rebaseline, release_version, findbug_args): | 79 rebaseline, findbug_args): |
| 83 """Run the FindBugs. | 80 """Run the FindBugs. |
| 84 | 81 |
| 85 Args: | 82 Args: |
| 86 exclude: the exclude xml file, refer to FindBugs's -exclude command option. | 83 exclude: the exclude xml file, refer to FindBugs's -exclude command option. |
| 87 known_bugs: the text file of known bugs. The bugs in it will not be | 84 known_bugs: the text file of known bugs. The bugs in it will not be |
| 88 reported. | 85 reported. |
| 89 classes_to_analyze: the list of classes need to analyze, refer to FindBug's | 86 classes_to_analyze: the list of classes need to analyze, refer to FindBug's |
| 90 -onlyAnalyze command line option. | 87 -onlyAnalyze command line option. |
| 91 auxiliary_classes: the classes help to analyze, refer to FindBug's | 88 auxiliary_classes: the classes help to analyze, refer to FindBug's |
| 92 -auxclasspath command line option. | 89 -auxclasspath command line option. |
| 93 rebaseline: True if the known_bugs file needs rebaseline. | 90 rebaseline: True if the known_bugs file needs rebaseline. |
| 94 release_version: True if the release version needs check, otherwise check | |
| 95 debug version. | |
| 96 findbug_args: addtional command line options needs pass to Findbugs. | 91 findbug_args: addtional command line options needs pass to Findbugs. |
| 97 """ | 92 """ |
| 98 | 93 |
| 99 chrome_src = constants.DIR_SOURCE_ROOT | 94 chrome_src = constants.DIR_SOURCE_ROOT |
| 100 sdk_root = constants.ANDROID_SDK_ROOT | 95 sdk_root = constants.ANDROID_SDK_ROOT |
| 101 sdk_version = constants.ANDROID_SDK_VERSION | 96 sdk_version = constants.ANDROID_SDK_VERSION |
| 102 | 97 |
| 103 system_classes = [] | 98 system_classes = [] |
| 104 system_classes.append(os.path.join(sdk_root, 'platforms', | 99 system_classes.append(os.path.join(sdk_root, 'platforms', |
| 105 'android-%s' % sdk_version, 'android.jar')) | 100 'android-%s' % sdk_version, 'android.jar')) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 128 | 123 |
| 129 if classes_to_analyze: | 124 if classes_to_analyze: |
| 130 cmd = '%s -onlyAnalyze %s ' % (cmd, classes_to_analyze) | 125 cmd = '%s -onlyAnalyze %s ' % (cmd, classes_to_analyze) |
| 131 | 126 |
| 132 if exclude: | 127 if exclude: |
| 133 cmd = '%s -exclude %s ' % (cmd, os.path.abspath(exclude)) | 128 cmd = '%s -exclude %s ' % (cmd, os.path.abspath(exclude)) |
| 134 | 129 |
| 135 if findbug_args: | 130 if findbug_args: |
| 136 cmd = '%s %s ' % (cmd, findbug_args) | 131 cmd = '%s %s ' % (cmd, findbug_args) |
| 137 | 132 |
| 138 chrome_classes = _GetChromeClasses(release_version) | 133 chrome_classes = _GetChromeClasses() |
| 139 if not chrome_classes: | 134 if not chrome_classes: |
| 140 return 1 | 135 return 1 |
| 141 cmd = '%s %s ' % (cmd, chrome_classes) | 136 cmd = '%s %s ' % (cmd, chrome_classes) |
| 142 | 137 |
| 143 proc = subprocess.Popen(shlex.split(cmd), | 138 proc = subprocess.Popen(shlex.split(cmd), |
| 144 stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 139 stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 145 out, _err = proc.communicate() | 140 out, _err = proc.communicate() |
| 146 current_warnings_set = set(_StripLineNumbers(filter(None, out.splitlines()))) | 141 current_warnings_set = set(_StripLineNumbers(filter(None, out.splitlines()))) |
| 147 | 142 |
| 148 if rebaseline: | 143 if rebaseline: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 161 | 156 |
| 162 if options.known_bugs: | 157 if options.known_bugs: |
| 163 known_bugs_file = options.known_bugs | 158 known_bugs_file = options.known_bugs |
| 164 elif options.base_dir: | 159 elif options.base_dir: |
| 165 known_bugs_file = os.path.join(options.base_dir, 'findbugs_known_bugs.txt') | 160 known_bugs_file = os.path.join(options.base_dir, 'findbugs_known_bugs.txt') |
| 166 | 161 |
| 167 auxclasspath = None | 162 auxclasspath = None |
| 168 if options.auxclasspath: | 163 if options.auxclasspath: |
| 169 auxclasspath = options.auxclasspath.split(':') | 164 auxclasspath = options.auxclasspath.split(':') |
| 170 return _Run(exclude_file, known_bugs_file, options.only_analyze, auxclasspath, | 165 return _Run(exclude_file, known_bugs_file, options.only_analyze, auxclasspath, |
| 171 options.rebaseline, options.release_build, options.findbug_args) | 166 options.rebaseline, options.findbug_args) |
| 172 | 167 |
| 173 | 168 |
| 174 def GetCommonParser(): | 169 def GetCommonParser(): |
| 175 parser = optparse.OptionParser() | 170 parser = optparse.OptionParser() |
| 176 parser.add_option('-r', | 171 parser.add_option('-r', |
| 177 '--rebaseline', | 172 '--rebaseline', |
| 178 action='store_true', | 173 action='store_true', |
| 179 dest='rebaseline', | 174 dest='rebaseline', |
| 180 help='Rebaseline known findbugs issues.') | 175 help='Rebaseline known findbugs issues.') |
| 181 | 176 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 200 dest='exclude', | 195 dest='exclude', |
| 201 help='Exclude bugs matching given filter.') | 196 help='Exclude bugs matching given filter.') |
| 202 | 197 |
| 203 parser.add_option('-k', | 198 parser.add_option('-k', |
| 204 '--known-bugs', | 199 '--known-bugs', |
| 205 action='store', | 200 action='store', |
| 206 default=None, | 201 default=None, |
| 207 dest='known_bugs', | 202 dest='known_bugs', |
| 208 help='Not report the bugs in the given file.') | 203 help='Not report the bugs in the given file.') |
| 209 | 204 |
| 210 parser.add_option('-l', | |
| 211 '--release-build', | |
| 212 action='store_true', | |
| 213 dest='release_build', | |
| 214 help='Analyze release build instead of debug.') | |
| 215 | |
| 216 parser.add_option('-f', | 205 parser.add_option('-f', |
| 217 '--findbug-args', | 206 '--findbug-args', |
| 218 action='store', | 207 action='store', |
| 219 default=None, | 208 default=None, |
| 220 dest='findbug_args', | 209 dest='findbug_args', |
| 221 help='Additional findbug arguments.') | 210 help='Additional findbug arguments.') |
| 222 | 211 |
| 223 parser.add_option('-b', | 212 parser.add_option('-b', |
| 224 '--base-dir', | 213 '--base-dir', |
| 225 action='store', | 214 action='store', |
| 226 default=None, | 215 default=None, |
| 227 dest='base_dir', | 216 dest='base_dir', |
| 228 help='Base directory for configuration file.') | 217 help='Base directory for configuration file.') |
| 229 | 218 |
| 230 return parser | 219 return parser |
| 231 | 220 |
| 232 | 221 |
| 233 def main(): | 222 def main(): |
| 234 parser = GetCommonParser() | 223 parser = GetCommonParser() |
| 235 options, _ = parser.parse_args() | 224 options, _ = parser.parse_args() |
| 236 | 225 |
| 237 return Run(options) | 226 return Run(options) |
| 238 | 227 |
| 239 | 228 |
| 240 if __name__ == '__main__': | 229 if __name__ == '__main__': |
| 241 sys.exit(main()) | 230 sys.exit(main()) |
| OLD | NEW |