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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: build/android/findbugs_diff.py
diff --git a/build/android/findbugs_diff.py b/build/android/findbugs_diff.py
index 28224f1a3871c59dfe53e58c25a7140bc781834d..5a596b9b26b2480a55e79b4dfb30ce6a9fd1aabf 100755
--- a/build/android/findbugs_diff.py
+++ b/build/android/findbugs_diff.py
@@ -5,14 +5,6 @@
# found in the LICENSE file.
"""Runs findbugs, and returns an error code if there are new warnings.
-This runs findbugs with an additional flag to exclude known bugs.
-To update the list of known bugs, do this:
-
- findbugs_diff.py --rebaseline
-
-Note that this is separate from findbugs_exclude.xml. The "exclude" file has
-false positives that we do not plan to fix. The "known bugs" file has real
-bugs that we *do* plan to fix (but haven't done so yet).
Other options
--only-analyze used to only analyze the class you are interested.
@@ -20,30 +12,116 @@ Other options
--findbugs-args used to passin other findbugs's options.
Run
- $CHROM_SRC/third_party/findbugs/bin/findbugs -textui for details.
+ $CHROMIUM_SRC/third_party/findbugs/bin/findbugs -textui for details.
"""
+import argparse
+import logging
import os
import sys
from pylib import constants
from pylib.utils import findbugs
+_DEFAULT_BASE_DIR = os.path.join(
+ constants.DIR_SOURCE_ROOT, 'build', 'android', 'findbugs_filter')
+
+sys.path.append(
+ os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'android', 'gyp'))
+from util import build_utils
+
+
+# TODO(jbudorick): Delete this once it's no longer used to support clients
+# who aren't explicitly passing jars.
+def DEPRECATED_GetChromeJars(release):
+ path = os.path.join(
+ constants.DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUT_DIR', 'out'),
+ 'Release' if release else 'Debug', 'lib.java')
+ jars = []
+ for dir_path, _, filenames in os.walk(path):
+ jars.extend(os.path.join(dir_path, f) for f in filenames
+ if f.endswith('.jar') and not f.endswith('.dex.jar'))
+ return jars
+
def main():
- parser = findbugs.GetCommonParser()
+ parser = argparse.ArgumentParser()
- options, _ = parser.parse_args()
+ parser.add_argument(
+ '-r', '--rebaseline', action='store_true', dest='rebaseline',
+ help='DEPRECATED')
+ parser.add_argument(
+ '-a', '--auxclasspath', action='store', default=None, dest='auxclasspath',
+ help='Set aux classpath for analysis.')
+ parser.add_argument(
+ '--auxclasspath-gyp', dest='auxclasspath_gyp',
+ help='A gyp list containing the aux classpath for analysis')
+ parser.add_argument(
+ '-o', '--only-analyze', action='store', default='org.chromium.-',
+ dest='only_analyze', help='Only analyze the given classes and packages.')
+ parser.add_argument(
+ '-e', '--exclude', action='store', default=None, dest='exclude',
+ help='Exclude bugs matching given filter.')
+ parser.add_argument(
+ '-k', '--known-bugs', action='store', default=None, dest='known_bugs',
+ help='DEPRECATED')
+ parser.add_argument(
+ '-l', '--release-build', action='store_true', dest='release_build',
+ help='Analyze release build instead of debug.')
+ parser.add_argument(
+ '-f', '--findbug-args', action='store', default=None, dest='findbug_args',
+ help='Additional findbug arguments.')
+ parser.add_argument(
+ '-b', '--base-dir', action='store', default=_DEFAULT_BASE_DIR,
+ dest='base_dir', help='Base directory for configuration file.')
+ parser.add_argument(
+ '--output-file', action='store', dest='output_file',
+ help='Path to save the output to.')
+ parser.add_argument('--stamp')
cjhopman 2015/03/12 19:22:43 This should also have a depfile argument. The dep
- if not options.base_dir:
- options.base_dir = os.path.join(constants.DIR_SOURCE_ROOT, 'build',
- 'android', 'findbugs_filter')
- if not options.only_analyze:
- options.only_analyze = 'org.chromium.-'
+ # TODO(jbudorick): Switch this to nargs='+' once all clients explicitly pass
+ # the jars they want to run against.
+ parser.add_argument(
+ 'jar_paths', metavar='JAR_PATH', nargs='*',
+ help='JAR file to analyze')
- return findbugs.Run(options)
+ args = parser.parse_args(build_utils.ExpandFileArgs(sys.argv[1:]))
+ if args.auxclasspath:
+ args.auxclasspath = args.auxclasspath.split(':')
+ elif args.auxclasspath_gyp:
+ args.auxclasspath = build_utils.ParseGypList(args.auxclasspath_gyp)
+
+ # TODO(jbudorick): Remove this once all clients explicitly pass the jars
+ # they want to run against.
+ if not args.jar_paths:
+ args.jar_paths = DEPRECATED_GetChromeJars(args.release_build)
+
+ if args.base_dir:
+ if not args.exclude:
+ args.exclude = os.path.join(args.base_dir, 'findbugs_exclude.xml')
+
+ findbugs_command, findbugs_warnings = findbugs.Run(
+ args.exclude, args.only_analyze, args.auxclasspath,
+ args.output_file, args.findbug_args, args.jar_paths)
+
+ if findbugs_warnings:
+ print
+ print '*' * 80
+ print 'FindBugs run via:'
+ print findbugs_command
+ print
+ print 'FindBugs reported the following issues:'
+ for warning in sorted(findbugs_warnings):
+ print ' %s' % warning
+ print '*' * 80
+ print
+ elif args.stamp:
+ build_utils.Touch(args.stamp)
+
+ return len(findbugs_warnings)
if __name__ == '__main__':
sys.exit(main())
+

Powered by Google App Engine
This is Rietveld 408576698