Roll src/third_party/WebKit a3b4a2e:7441784 (svn 202551:202552)
[chromium-blink-merge.git] / build / android / findbugs_diff.py
blobd222e324373906d2c80344c129a34b378a2e563c
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 devil.utils import run_tests_helper
24 from pylib import constants
25 from pylib.utils import findbugs
27 _DEFAULT_BASE_DIR = os.path.join(
28 constants.DIR_SOURCE_ROOT, 'build', 'android', 'findbugs_filter')
30 sys.path.append(
31 os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'android', 'gyp'))
32 from util import build_utils # pylint: disable=import-error
35 def main():
36 parser = argparse.ArgumentParser()
38 parser.add_argument(
39 '-v', '--verbose', action='count', help='Enable verbose logging.')
40 parser.add_argument(
41 '-a', '--auxclasspath', default=None, dest='auxclasspath',
42 help='Set aux classpath for analysis.')
43 parser.add_argument(
44 '--auxclasspath-gyp', dest='auxclasspath_gyp',
45 help='A gyp list containing the aux classpath for analysis')
46 parser.add_argument(
47 '-o', '--only-analyze', default=None,
48 dest='only_analyze', help='Only analyze the given classes and packages.')
49 parser.add_argument(
50 '-e', '--exclude', default=None, dest='exclude',
51 help='Exclude bugs matching given filter.')
52 parser.add_argument(
53 '-l', '--release-build', action='store_true', dest='release_build',
54 help='Analyze release build instead of debug.')
55 parser.add_argument(
56 '-f', '--findbug-args', default=None, dest='findbug_args',
57 help='Additional findbug arguments.')
58 parser.add_argument(
59 '-b', '--base-dir', default=_DEFAULT_BASE_DIR,
60 dest='base_dir', help='Base directory for configuration file.')
61 parser.add_argument(
62 '--output-file', dest='output_file',
63 help='Path to save the output to.')
64 parser.add_argument(
65 '--stamp', help='Path to touch on success.')
66 parser.add_argument(
67 '--depfile', help='Path to the depfile. This must be specified as the '
68 "action's first output.")
70 parser.add_argument(
71 'jar_paths', metavar='JAR_PATH', nargs='+',
72 help='JAR file to analyze')
74 args = parser.parse_args(build_utils.ExpandFileArgs(sys.argv[1:]))
76 run_tests_helper.SetLogLevel(args.verbose)
78 if args.auxclasspath:
79 args.auxclasspath = args.auxclasspath.split(':')
80 elif args.auxclasspath_gyp:
81 args.auxclasspath = build_utils.ParseGypList(args.auxclasspath_gyp)
83 if args.base_dir:
84 if not args.exclude:
85 args.exclude = os.path.join(args.base_dir, 'findbugs_exclude.xml')
87 findbugs_command, findbugs_warnings = findbugs.Run(
88 args.exclude, args.only_analyze, args.auxclasspath,
89 args.output_file, args.findbug_args, args.jar_paths)
91 if findbugs_warnings:
92 print
93 print '*' * 80
94 print 'FindBugs run via:'
95 print findbugs_command
96 print
97 print 'FindBugs reported the following issues:'
98 for warning in sorted(findbugs_warnings):
99 print str(warning)
100 print '*' * 80
101 print
102 else:
103 if args.depfile:
104 build_utils.WriteDepfile(
105 args.depfile,
106 build_utils.GetPythonDependencies() + args.auxclasspath
107 + args.jar_paths)
108 if args.stamp:
109 build_utils.Touch(args.stamp)
111 return len(findbugs_warnings)
114 if __name__ == '__main__':
115 sys.exit(main())