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.
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.
15 $CHROMIUM_SRC/third_party/findbugs/bin/findbugs -textui for details.
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')
30 os
.path
.join(constants
.DIR_SOURCE_ROOT
, 'build', 'android', 'gyp'))
31 from util
import build_utils
35 parser
= argparse
.ArgumentParser()
38 '-a', '--auxclasspath', default
=None, dest
='auxclasspath',
39 help='Set aux classpath for analysis.')
41 '--auxclasspath-gyp', dest
='auxclasspath_gyp',
42 help='A gyp list containing the aux classpath for analysis')
44 '-o', '--only-analyze', default
=None,
45 dest
='only_analyze', help='Only analyze the given classes and packages.')
47 '-e', '--exclude', default
=None, dest
='exclude',
48 help='Exclude bugs matching given filter.')
50 '-l', '--release-build', action
='store_true', dest
='release_build',
51 help='Analyze release build instead of debug.')
53 '-f', '--findbug-args', default
=None, dest
='findbug_args',
54 help='Additional findbug arguments.')
56 '-b', '--base-dir', default
=_DEFAULT_BASE_DIR
,
57 dest
='base_dir', help='Base directory for configuration file.')
59 '--output-file', dest
='output_file',
60 help='Path to save the output to.')
62 '--stamp', help='Path to touch on success.')
64 '--depfile', help='Path to the depfile. This must be specified as the '
65 "action's first output.")
68 'jar_paths', metavar
='JAR_PATH', nargs
='+',
69 help='JAR file to analyze')
71 args
= parser
.parse_args(build_utils
.ExpandFileArgs(sys
.argv
[1:]))
73 args
.auxclasspath
= args
.auxclasspath
.split(':')
74 elif args
.auxclasspath_gyp
:
75 args
.auxclasspath
= build_utils
.ParseGypList(args
.auxclasspath_gyp
)
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
)
88 print 'FindBugs run via:'
89 print findbugs_command
91 print 'FindBugs reported the following issues:'
92 for warning
in sorted(findbugs_warnings
):
98 build_utils
.WriteDepfile(
100 build_utils
.GetPythonDependencies() + args
.auxclasspath
103 build_utils
.Touch(args
.stamp
)
105 return len(findbugs_warnings
)
108 if __name__
== '__main__':