Adding Peter Thatcher to the owners file.
[chromium-blink-merge.git] / build / android / findbugs_diff.py
blobf55e46261bef9d87376dfd15e441ed54c1829d72
1 #!/usr/bin/env python
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
5 # found in the LICENSE file.
7 """Runs findbugs, and returns an error code if there are new warnings.
9 Other options
10 --only-analyze used to only analyze the class you are interested.
11 --relase-build analyze the classes in out/Release directory.
12 --findbugs-args used to passin other findbugs's options.
14 Run
15 $CHROMIUM_SRC/third_party/findbugs/bin/findbugs -textui for details.
17 """
19 import argparse
20 import os
21 import sys
23 from pylib import constants
24 from pylib.utils import findbugs
26 _DEFAULT_BASE_DIR = os.path.join(
27 constants.DIR_SOURCE_ROOT, 'build', 'android', 'findbugs_filter')
29 sys.path.append(
30 os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'android', 'gyp'))
31 from util import build_utils
34 def main():
35 parser = argparse.ArgumentParser()
37 parser.add_argument(
38 '-a', '--auxclasspath', default=None, dest='auxclasspath',
39 help='Set aux classpath for analysis.')
40 parser.add_argument(
41 '--auxclasspath-gyp', dest='auxclasspath_gyp',
42 help='A gyp list containing the aux classpath for analysis')
43 parser.add_argument(
44 '-o', '--only-analyze', default=None,
45 dest='only_analyze', help='Only analyze the given classes and packages.')
46 parser.add_argument(
47 '-e', '--exclude', default=None, dest='exclude',
48 help='Exclude bugs matching given filter.')
49 parser.add_argument(
50 '-l', '--release-build', action='store_true', dest='release_build',
51 help='Analyze release build instead of debug.')
52 parser.add_argument(
53 '-f', '--findbug-args', default=None, dest='findbug_args',
54 help='Additional findbug arguments.')
55 parser.add_argument(
56 '-b', '--base-dir', default=_DEFAULT_BASE_DIR,
57 dest='base_dir', help='Base directory for configuration file.')
58 parser.add_argument(
59 '--output-file', dest='output_file',
60 help='Path to save the output to.')
61 parser.add_argument(
62 '--stamp', help='Path to touch on success.')
63 parser.add_argument(
64 '--depfile', help='Path to the depfile. This must be specified as the '
65 "action's first output.")
67 parser.add_argument(
68 'jar_paths', metavar='JAR_PATH', nargs='+',
69 help='JAR file to analyze')
71 args = parser.parse_args(build_utils.ExpandFileArgs(sys.argv[1:]))
72 if args.auxclasspath:
73 args.auxclasspath = args.auxclasspath.split(':')
74 elif args.auxclasspath_gyp:
75 args.auxclasspath = build_utils.ParseGypList(args.auxclasspath_gyp)
77 if args.base_dir:
78 if not args.exclude:
79 args.exclude = os.path.join(args.base_dir, 'findbugs_exclude.xml')
81 findbugs_command, findbugs_warnings = findbugs.Run(
82 args.exclude, args.only_analyze, args.auxclasspath,
83 args.output_file, args.findbug_args, args.jar_paths)
85 if findbugs_warnings:
86 print
87 print '*' * 80
88 print 'FindBugs run via:'
89 print findbugs_command
90 print
91 print 'FindBugs reported the following issues:'
92 for warning in sorted(findbugs_warnings):
93 print str(warning)
94 print '*' * 80
95 print
96 else:
97 if args.depfile:
98 build_utils.WriteDepfile(
99 args.depfile,
100 build_utils.GetPythonDependencies() + args.auxclasspath
101 + args.jar_paths)
102 if args.stamp:
103 build_utils.Touch(args.stamp)
105 return len(findbugs_warnings)
108 if __name__ == '__main__':
109 sys.exit(main())