Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: build/android/findbugs_diff.py

Issue 1000793002: [Android] Incorporate findbugs into android builds. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
20 import logging
27 import os 21 import os
28 import sys 22 import sys
29 23
30 from pylib import constants 24 from pylib import constants
31 from pylib.utils import findbugs 25 from pylib.utils import findbugs
32 26
27 _DEFAULT_BASE_DIR = os.path.join(
28 constants.DIR_SOURCE_ROOT, 'build', 'android', 'findbugs_filter')
29
30 sys.path.append(
31 os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'android', 'gyp'))
32 from util import build_utils
33
34
35 # TODO(jbudorick): Delete this once it's no longer used to support clients
36 # who aren't explicitly passing jars.
37 def DEPRECATED_GetChromeJars(release):
38 path = os.path.join(
39 constants.DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUT_DIR', 'out'),
40 'Release' if release else 'Debug', 'lib.java')
41 jars = []
42 for dir_path, _, filenames in os.walk(path):
43 jars.extend(os.path.join(dir_path, f) for f in filenames
44 if f.endswith('.jar') and not f.endswith('.dex.jar'))
45 return jars
46
33 47
34 def main(): 48 def main():
35 parser = findbugs.GetCommonParser() 49 parser = argparse.ArgumentParser()
36 50
37 options, _ = parser.parse_args() 51 parser.add_argument(
52 '-r', '--rebaseline', action='store_true', dest='rebaseline',
53 help='DEPRECATED')
54 parser.add_argument(
55 '-a', '--auxclasspath', action='store', default=None, dest='auxclasspath',
56 help='Set aux classpath for analysis.')
57 parser.add_argument(
58 '--auxclasspath-gyp', dest='auxclasspath_gyp',
59 help='A gyp list containing the aux classpath for analysis')
60 parser.add_argument(
61 '-o', '--only-analyze', action='store', default='org.chromium.-',
62 dest='only_analyze', help='Only analyze the given classes and packages.')
63 parser.add_argument(
64 '-e', '--exclude', action='store', default=None, dest='exclude',
65 help='Exclude bugs matching given filter.')
66 parser.add_argument(
67 '-k', '--known-bugs', action='store', default=None, dest='known_bugs',
68 help='DEPRECATED')
69 parser.add_argument(
70 '-l', '--release-build', action='store_true', dest='release_build',
71 help='Analyze release build instead of debug.')
72 parser.add_argument(
73 '-f', '--findbug-args', action='store', default=None, dest='findbug_args',
74 help='Additional findbug arguments.')
75 parser.add_argument(
76 '-b', '--base-dir', action='store', default=_DEFAULT_BASE_DIR,
77 dest='base_dir', help='Base directory for configuration file.')
78 parser.add_argument(
79 '--output-file', action='store', dest='output_file',
80 help='Path to save the output to.')
81 parser.add_argument('--stamp')
cjhopman 2015/03/12 19:22:43 This should also have a depfile argument. The dep
38 82
39 if not options.base_dir: 83 # TODO(jbudorick): Switch this to nargs='+' once all clients explicitly pass
40 options.base_dir = os.path.join(constants.DIR_SOURCE_ROOT, 'build', 84 # the jars they want to run against.
41 'android', 'findbugs_filter') 85 parser.add_argument(
42 if not options.only_analyze: 86 'jar_paths', metavar='JAR_PATH', nargs='*',
43 options.only_analyze = 'org.chromium.-' 87 help='JAR file to analyze')
44 88
45 return findbugs.Run(options) 89 args = parser.parse_args(build_utils.ExpandFileArgs(sys.argv[1:]))
90 if args.auxclasspath:
91 args.auxclasspath = args.auxclasspath.split(':')
92 elif args.auxclasspath_gyp:
93 args.auxclasspath = build_utils.ParseGypList(args.auxclasspath_gyp)
94
95 # TODO(jbudorick): Remove this once all clients explicitly pass the jars
96 # they want to run against.
97 if not args.jar_paths:
98 args.jar_paths = DEPRECATED_GetChromeJars(args.release_build)
99
100 if args.base_dir:
101 if not args.exclude:
102 args.exclude = os.path.join(args.base_dir, 'findbugs_exclude.xml')
103
104 findbugs_command, findbugs_warnings = findbugs.Run(
105 args.exclude, args.only_analyze, args.auxclasspath,
106 args.output_file, args.findbug_args, args.jar_paths)
107
108 if findbugs_warnings:
109 print
110 print '*' * 80
111 print 'FindBugs run via:'
112 print findbugs_command
113 print
114 print 'FindBugs reported the following issues:'
115 for warning in sorted(findbugs_warnings):
116 print ' %s' % warning
117 print '*' * 80
118 print
119 elif args.stamp:
120 build_utils.Touch(args.stamp)
121
122 return len(findbugs_warnings)
46 123
47 124
48 if __name__ == '__main__': 125 if __name__ == '__main__':
49 sys.exit(main()) 126 sys.exit(main())
127
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698