OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 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 """Runs findbugs, and returns an error code if there are new warnings. | 7 """Runs findbugs, and returns an error code if there are new warnings. |
8 This runs findbugs with an additional flag to exclude known bugs. | |
9 To update the list of known bugs, do this: | |
10 | |
11 findbugs_diff.py --rebaseline | |
12 | |
13 Note that this is separate from findbugs_exclude.xml. The "exclude" file has | |
14 false positives that we do not plan to fix. The "known bugs" file has real | |
15 bugs that we *do* plan to fix (but haven't done so yet). | |
16 | 8 |
17 Other options | 9 Other options |
18 --only-analyze used to only analyze the class you are interested. | 10 --only-analyze used to only analyze the class you are interested. |
19 --relase-build analyze the classes in out/Release directory. | 11 --relase-build analyze the classes in out/Release directory. |
20 --findbugs-args used to passin other findbugs's options. | 12 --findbugs-args used to passin other findbugs's options. |
21 | 13 |
22 Run | 14 Run |
23 $CHROM_SRC/third_party/findbugs/bin/findbugs -textui for details. | 15 $CHROMIUM_SRC/third_party/findbugs/bin/findbugs -textui for details. |
24 | 16 |
25 """ | 17 """ |
26 | 18 |
| 19 import argparse |
27 import os | 20 import os |
28 import sys | 21 import sys |
29 | 22 |
30 from pylib import constants | 23 from pylib import constants |
31 from pylib.utils import findbugs | 24 from pylib.utils import findbugs |
32 | 25 |
| 26 _DEFAULT_BASE_DIR = os.path.join( |
| 27 constants.DIR_SOURCE_ROOT, 'build', 'android', 'findbugs_filter') |
| 28 |
| 29 sys.path.append( |
| 30 os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'android', 'gyp')) |
| 31 from util import build_utils |
| 32 |
| 33 |
| 34 # TODO(jbudorick): Delete this once it's no longer used to support clients |
| 35 # who aren't explicitly passing jars. |
| 36 def DEPRECATED_GetChromeJars(release): |
| 37 path = os.path.join( |
| 38 constants.DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUT_DIR', 'out'), |
| 39 'Release' if release else 'Debug', 'lib.java') |
| 40 jars = [] |
| 41 for dir_path, _, filenames in os.walk(path): |
| 42 jars.extend(os.path.join(dir_path, f) for f in filenames |
| 43 if f.endswith('.jar') and not f.endswith('.dex.jar')) |
| 44 return jars |
| 45 |
33 | 46 |
34 def main(): | 47 def main(): |
35 parser = findbugs.GetCommonParser() | 48 parser = argparse.ArgumentParser() |
36 | 49 |
37 options, _ = parser.parse_args() | 50 parser.add_argument( |
| 51 '-r', '--rebaseline', action='store_true', dest='rebaseline', |
| 52 help='DEPRECATED') |
| 53 parser.add_argument( |
| 54 '-a', '--auxclasspath', default=None, dest='auxclasspath', |
| 55 help='Set aux classpath for analysis.') |
| 56 parser.add_argument( |
| 57 '--auxclasspath-gyp', dest='auxclasspath_gyp', |
| 58 help='A gyp list containing the aux classpath for analysis') |
| 59 parser.add_argument( |
| 60 '-o', '--only-analyze', default=None, |
| 61 dest='only_analyze', help='Only analyze the given classes and packages.') |
| 62 parser.add_argument( |
| 63 '-e', '--exclude', default=None, dest='exclude', |
| 64 help='Exclude bugs matching given filter.') |
| 65 parser.add_argument( |
| 66 '-k', '--known-bugs', default=None, dest='known_bugs', |
| 67 help='DEPRECATED') |
| 68 parser.add_argument( |
| 69 '-l', '--release-build', action='store_true', dest='release_build', |
| 70 help='Analyze release build instead of debug.') |
| 71 parser.add_argument( |
| 72 '-f', '--findbug-args', default=None, dest='findbug_args', |
| 73 help='Additional findbug arguments.') |
| 74 parser.add_argument( |
| 75 '-b', '--base-dir', default=_DEFAULT_BASE_DIR, |
| 76 dest='base_dir', help='Base directory for configuration file.') |
| 77 parser.add_argument( |
| 78 '--output-file', dest='output_file', |
| 79 help='Path to save the output to.') |
| 80 parser.add_argument( |
| 81 '--stamp', help='Path to touch on success.') |
| 82 parser.add_argument( |
| 83 '--depfile', help='Path to the depfile. This must be specified as the ' |
| 84 "action's first output.") |
38 | 85 |
39 if not options.base_dir: | 86 # TODO(jbudorick): Switch this to nargs='+' once all clients explicitly pass |
40 options.base_dir = os.path.join(constants.DIR_SOURCE_ROOT, 'build', | 87 # the jars they want to run against. |
41 'android', 'findbugs_filter') | 88 parser.add_argument( |
42 if not options.only_analyze: | 89 'jar_paths', metavar='JAR_PATH', nargs='*', |
43 options.only_analyze = 'org.chromium.-' | 90 help='JAR file to analyze') |
44 | 91 |
45 return findbugs.Run(options) | 92 args = parser.parse_args(build_utils.ExpandFileArgs(sys.argv[1:])) |
| 93 if args.auxclasspath: |
| 94 args.auxclasspath = args.auxclasspath.split(':') |
| 95 elif args.auxclasspath_gyp: |
| 96 args.auxclasspath = build_utils.ParseGypList(args.auxclasspath_gyp) |
| 97 |
| 98 # TODO(jbudorick): Remove this once all clients explicitly pass the jars |
| 99 # they want to run against. |
| 100 if not args.jar_paths: |
| 101 args.jar_paths = DEPRECATED_GetChromeJars(args.release_build) |
| 102 |
| 103 if args.base_dir: |
| 104 if not args.exclude: |
| 105 args.exclude = os.path.join(args.base_dir, 'findbugs_exclude.xml') |
| 106 |
| 107 findbugs_command, findbugs_warnings = findbugs.Run( |
| 108 args.exclude, args.only_analyze, args.auxclasspath, |
| 109 args.output_file, args.findbug_args, args.jar_paths) |
| 110 |
| 111 if findbugs_warnings: |
| 112 print |
| 113 print '*' * 80 |
| 114 print 'FindBugs run via:' |
| 115 print findbugs_command |
| 116 print |
| 117 print 'FindBugs reported the following issues:' |
| 118 for warning in sorted(findbugs_warnings): |
| 119 print str(warning) |
| 120 print '*' * 80 |
| 121 print |
| 122 elif args.stamp: |
| 123 build_utils.Touch(args.stamp) |
| 124 |
| 125 return len(findbugs_warnings) |
46 | 126 |
47 | 127 |
48 if __name__ == '__main__': | 128 if __name__ == '__main__': |
49 sys.exit(main()) | 129 sys.exit(main()) |
| 130 |
OLD | NEW |