Android: Disable findbugs
Now that we have errorprone enabled by default, we get faster static analysis with fewer false positives. Findbugs is no longer necessary. This CL also unblocks upgrading errorprone to 2.1.2. The rest of the findbugs annotations and gn args will be removed later. BUG=777511 Cq-Include-Trybots: master.tryserver.chromium.android:android_cronet_tester;master.tryserver.chromium.mac:ios-simulator-cronet Change-Id: I9c32f3773f44a7c58813c0ef6a35a81dc9818178 Reviewed-on: https://chromium-review.googlesource.com/734220 Reviewed-by: agrieve <agrieve@chromium.org> Reviewed-by: John Budorick <jbudorick@chromium.org> Reviewed-by: Ken Rockot <rockot@chromium.org> Reviewed-by: Bernhard Bauer <bauerb@chromium.org> Reviewed-by: Egor Pasko <pasko@chromium.org> Reviewed-by: Andrei Kapishnikov <kapishnikov@chromium.org> Commit-Queue: Peter Wen <wnwen@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#514187} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: a7606e61e83da06c29dd5a25e10e3fde4acd6737
This commit is contained in:
Родитель
39dce1570c
Коммит
000a387616
|
@ -1,129 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
"""Runs findbugs, and returns an error code if there are new warnings.
|
||||
|
||||
Other options
|
||||
--only-analyze used to only analyze the class you are interested.
|
||||
--relase-build analyze the classes in out/Release directory.
|
||||
--findbugs-args used to passin other findbugs's options.
|
||||
|
||||
Run
|
||||
$CHROMIUM_SRC/third_party/findbugs/bin/findbugs -textui for details.
|
||||
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
import devil_chromium
|
||||
from devil.utils import run_tests_helper
|
||||
|
||||
from pylib.constants import host_paths
|
||||
from pylib.utils import findbugs
|
||||
|
||||
_DEFAULT_BASE_DIR = os.path.join(
|
||||
host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'findbugs_filter')
|
||||
|
||||
sys.path.append(
|
||||
os.path.join(host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'gyp'))
|
||||
from util import build_utils # pylint: disable=import-error
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument(
|
||||
'-v', '--verbose', action='count', help='Enable verbose logging.')
|
||||
parser.add_argument(
|
||||
'--system-jar', default=None, dest='system_jars', action='append',
|
||||
help='System JAR for analysis.')
|
||||
parser.add_argument(
|
||||
'-a', '--auxclasspath', 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', default=None,
|
||||
dest='only_analyze', help='Only analyze the given classes and packages.')
|
||||
parser.add_argument(
|
||||
'-e', '--exclude', default=None, dest='exclude',
|
||||
help='Exclude bugs matching given filter.')
|
||||
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', default=None, dest='findbug_args',
|
||||
help='Additional findbug arguments.')
|
||||
parser.add_argument(
|
||||
'-b', '--base-dir', default=_DEFAULT_BASE_DIR,
|
||||
dest='base_dir', help='Base directory for configuration file.')
|
||||
parser.add_argument(
|
||||
'--output-file', dest='output_file',
|
||||
help='Path to save the output to.')
|
||||
parser.add_argument(
|
||||
'--stamp', help='Path to touch on success.')
|
||||
parser.add_argument(
|
||||
'--depfile', help='Path to the depfile. This must be specified as the '
|
||||
"action's first output.")
|
||||
|
||||
parser.add_argument(
|
||||
'jar_paths', metavar='JAR_PATH', nargs='+',
|
||||
help='JAR file to analyze')
|
||||
|
||||
args = parser.parse_args(build_utils.ExpandFileArgs(sys.argv[1:]))
|
||||
|
||||
run_tests_helper.SetLogLevel(args.verbose)
|
||||
|
||||
devil_chromium.Initialize()
|
||||
|
||||
if args.auxclasspath:
|
||||
args.auxclasspath = args.auxclasspath.split(':')
|
||||
elif args.auxclasspath_gyp:
|
||||
args.auxclasspath = build_utils.ParseGnList(args.auxclasspath_gyp)
|
||||
|
||||
if args.base_dir:
|
||||
if not args.exclude:
|
||||
args.exclude = os.path.join(args.base_dir, 'findbugs_exclude.xml')
|
||||
|
||||
findbugs_command, findbugs_errors, findbugs_warnings = findbugs.Run(
|
||||
args.exclude, args.only_analyze, args.system_jars, args.auxclasspath,
|
||||
args.output_file, args.findbug_args, args.jar_paths)
|
||||
|
||||
if findbugs_warnings or findbugs_errors:
|
||||
print
|
||||
print '*' * 80
|
||||
print 'FindBugs run via:'
|
||||
print findbugs_command
|
||||
if findbugs_errors:
|
||||
print
|
||||
print 'FindBugs encountered the following errors:'
|
||||
for error in sorted(findbugs_errors):
|
||||
print str(error)
|
||||
print '*' * 80
|
||||
print
|
||||
if findbugs_warnings:
|
||||
print
|
||||
print 'FindBugs reported the following issues:'
|
||||
for warning in sorted(findbugs_warnings):
|
||||
print str(warning)
|
||||
print '*' * 80
|
||||
print
|
||||
else:
|
||||
if args.depfile:
|
||||
deps = args.auxclasspath + args.jar_paths
|
||||
build_utils.WriteDepfile(args.depfile, args.output_file, deps)
|
||||
if args.stamp:
|
||||
build_utils.Touch(args.stamp)
|
||||
|
||||
return len(findbugs_errors) + len(findbugs_warnings)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
Use of this source code is governed by a BSD-style license that can be
|
||||
found in the LICENSE file.
|
||||
-->
|
||||
|
||||
<!--
|
||||
Documentation: http://findbugs.sourceforge.net/manual/filter.html
|
||||
In particular, ~ at the start of a string means it's a regex.
|
||||
-->
|
||||
<FindBugsFilter>
|
||||
<!-- Skip the generated resource classes (including nested classes). -->
|
||||
<Match>
|
||||
<Class name="~.*\.R(\$\w+)?" />
|
||||
</Match>
|
||||
<!-- Skip the generated Manifest class (including nested classes). -->
|
||||
<Match>
|
||||
<Class name="~.*\.Manifest(\$\w+)?" />
|
||||
</Match>
|
||||
<Bug pattern="DM_STRING_CTOR" />
|
||||
<!-- Ignore "reliance on default String encoding" warnings, as we're not multi-platform -->
|
||||
<Bug pattern="DM_DEFAULT_ENCODING" />
|
||||
<!--
|
||||
Legacy code, discouraged on Android:
|
||||
https://developer.android.com/reference/java/security/AccessController.html
|
||||
-->
|
||||
<Bug pattern="DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED" />
|
||||
<!--
|
||||
Ignore unchecked casts.
|
||||
See https://groups.google.com/a/chromium.org/forum/#!topic/java/xfXmNLI4SqM for details.
|
||||
-->
|
||||
<Bug pattern="BC_UNCONFIRMED_CAST" />
|
||||
|
||||
<!-- Ignore unused public rules and implementations thereof in instrumentation tests -->
|
||||
<Match>
|
||||
<Class name="~.*\.*Test" />
|
||||
<Field type="android.support.test.rule.UiThreadTestRule" />
|
||||
<Bug pattern="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Class name="~.*\.*Test" />
|
||||
<Field type="org.junit.rules.RuleChain" />
|
||||
<Bug pattern="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Class name="~.*\.*Test" />
|
||||
<Field type="org.junit.rules.TestRule" />
|
||||
<Bug pattern="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD" />
|
||||
</Match>
|
||||
|
||||
</FindBugsFilter>
|
|
@ -16,5 +16,4 @@ android_library("bootstrap_java") {
|
|||
"java/org/chromium/incrementalinstall/SecondInstrumentation.java",
|
||||
]
|
||||
emma_never_instrument = true
|
||||
run_findbugs_override = false
|
||||
}
|
||||
|
|
|
@ -1,202 +0,0 @@
|
|||
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import logging
|
||||
import os
|
||||
import xml.dom.minidom
|
||||
|
||||
from devil.utils import cmd_helper
|
||||
from pylib.constants import host_paths
|
||||
|
||||
|
||||
_FINDBUGS_HOME = os.path.join(host_paths.DIR_SOURCE_ROOT, 'third_party',
|
||||
'findbugs')
|
||||
_FINDBUGS_JAR = os.path.join(_FINDBUGS_HOME, 'lib', 'findbugs.jar')
|
||||
_FINDBUGS_MAX_HEAP = 768
|
||||
_FINDBUGS_PLUGIN_PATH = os.path.join(
|
||||
host_paths.DIR_SOURCE_ROOT, 'tools', 'android', 'findbugs_plugin', 'lib',
|
||||
'chromiumPlugin.jar')
|
||||
|
||||
|
||||
def _ParseXmlResults(results_doc):
|
||||
errors = set()
|
||||
warnings = set()
|
||||
for en in (n for n in results_doc.documentElement.childNodes
|
||||
if n.nodeType == xml.dom.Node.ELEMENT_NODE):
|
||||
if en.tagName == 'Errors':
|
||||
errors.update(_ParseErrors(en))
|
||||
if en.tagName == 'BugInstance':
|
||||
warnings.add(_ParseBugInstance(en))
|
||||
return errors, warnings
|
||||
|
||||
|
||||
def _GetMessage(node):
|
||||
for c in (n for n in node.childNodes
|
||||
if n.nodeType == xml.dom.Node.ELEMENT_NODE):
|
||||
if c.tagName == 'Message':
|
||||
if (len(c.childNodes) == 1
|
||||
and c.childNodes[0].nodeType == xml.dom.Node.TEXT_NODE):
|
||||
return c.childNodes[0].data
|
||||
return None
|
||||
|
||||
|
||||
def _GetTextContent(node):
|
||||
if (len(node.childNodes) == 1
|
||||
and node.childNodes[0].nodeType == xml.dom.Node.TEXT_NODE):
|
||||
return node.childNodes[0].data
|
||||
return ''
|
||||
|
||||
|
||||
def _ParseErrors(node):
|
||||
errors = set()
|
||||
for error_node in (n for n in node.childNodes
|
||||
if n.nodeType == xml.dom.Node.ELEMENT_NODE):
|
||||
error_text = '(unable to determine error text)'
|
||||
if error_node.tagName == 'Error':
|
||||
error_message_nodes = (
|
||||
n for n in error_node.childNodes
|
||||
if (n.nodeType == xml.dom.Node.ELEMENT_NODE
|
||||
and n.tagName == 'ErrorMessage'))
|
||||
text_pieces = [_GetTextContent(n) for n in error_message_nodes]
|
||||
if text_pieces:
|
||||
error_text = ', '.join(t for t in text_pieces if t)
|
||||
errors.add(FindBugsError(error_node.tagName, error_text))
|
||||
return errors
|
||||
|
||||
|
||||
def _ParseBugInstance(node):
|
||||
bug = FindBugsWarning(node.getAttribute('type'))
|
||||
msg_parts = []
|
||||
for c in (n for n in node.childNodes
|
||||
if n.nodeType == xml.dom.Node.ELEMENT_NODE):
|
||||
if c.tagName == 'Class':
|
||||
msg_parts.append(_GetMessage(c))
|
||||
elif c.tagName == 'Method':
|
||||
msg_parts.append(_GetMessage(c))
|
||||
elif c.tagName == 'Field':
|
||||
msg_parts.append(_GetMessage(c))
|
||||
elif c.tagName == 'SourceLine':
|
||||
bug.file_name = c.getAttribute('sourcefile')
|
||||
if c.hasAttribute('start'):
|
||||
bug.start_line = int(c.getAttribute('start'))
|
||||
if c.hasAttribute('end'):
|
||||
bug.end_line = int(c.getAttribute('end'))
|
||||
msg_parts.append(_GetMessage(c))
|
||||
elif c.tagName == 'ShortMessage':
|
||||
msg_parts.append(_GetTextContent(c))
|
||||
bug.message = tuple(m for m in msg_parts if m)
|
||||
return bug
|
||||
|
||||
|
||||
class FindBugsError(object):
|
||||
def __init__(self, error_type='', error_val=''):
|
||||
self.error_type = error_type
|
||||
self.error_val = error_val
|
||||
|
||||
def __cmp__(self, other):
|
||||
return (cmp(self.error_type, other.error_type)
|
||||
or cmp(self.error_val, other.error_val))
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __hash__(self):
|
||||
return hash((self.error_type, self.error_val))
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self == other
|
||||
|
||||
def __str__(self):
|
||||
return '%s: %s' % (self.error_type, self.error_val)
|
||||
|
||||
|
||||
class FindBugsWarning(object):
|
||||
|
||||
def __init__(self, bug_type='', end_line=0, file_name='', message=None,
|
||||
start_line=0):
|
||||
self.bug_type = bug_type
|
||||
self.end_line = end_line
|
||||
self.file_name = file_name
|
||||
if message is None:
|
||||
self.message = tuple()
|
||||
else:
|
||||
self.message = message
|
||||
self.start_line = start_line
|
||||
|
||||
def __cmp__(self, other):
|
||||
return (cmp(self.file_name, other.file_name)
|
||||
or cmp(self.start_line, other.start_line)
|
||||
or cmp(self.end_line, other.end_line)
|
||||
or cmp(self.bug_type, other.bug_type)
|
||||
or cmp(self.message, other.message))
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __hash__(self):
|
||||
return hash((self.bug_type, self.end_line, self.file_name, self.message,
|
||||
self.start_line))
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self == other
|
||||
|
||||
def __str__(self):
|
||||
return '%s: %s' % (self.bug_type, '\n '.join(self.message))
|
||||
|
||||
|
||||
def Run(exclude, classes_to_analyze, system_classes, auxiliary_classes,
|
||||
output_file, findbug_args, jars):
|
||||
"""Run FindBugs.
|
||||
|
||||
Args:
|
||||
exclude: the exclude xml file, refer to FindBugs's -exclude command option.
|
||||
classes_to_analyze: the list of classes need to analyze, refer to FindBugs'
|
||||
-onlyAnalyze command line option.
|
||||
system_classes: system classes to help analysis.
|
||||
auxiliary_classes: other classes to help analysis. Refer to FindBugs'
|
||||
-auxclasspath command line option.
|
||||
output_file: An optional path to dump XML results to.
|
||||
findbug_args: A list of additional command line options to pass to Findbugs.
|
||||
"""
|
||||
# TODO(jbudorick): Get this from the build system.
|
||||
all_aux_classes = []
|
||||
all_aux_classes.extend(system_classes or [])
|
||||
all_aux_classes.extend(
|
||||
os.path.abspath(classes)
|
||||
for classes in auxiliary_classes or [])
|
||||
|
||||
cmd = ['java',
|
||||
'-classpath', '%s:' % _FINDBUGS_JAR,
|
||||
'-Xmx%dm' % _FINDBUGS_MAX_HEAP,
|
||||
'-Dfindbugs.home="%s"' % _FINDBUGS_HOME,
|
||||
'-jar', _FINDBUGS_JAR,
|
||||
'-textui', '-sortByClass',
|
||||
'-pluginList', _FINDBUGS_PLUGIN_PATH, '-xml:withMessages']
|
||||
if system_classes:
|
||||
cmd.extend(['-auxclasspath', ':'.join(all_aux_classes)])
|
||||
if classes_to_analyze:
|
||||
cmd.extend(['-onlyAnalyze', classes_to_analyze])
|
||||
if exclude:
|
||||
cmd.extend(['-exclude', os.path.abspath(exclude)])
|
||||
if output_file:
|
||||
cmd.extend(['-output', output_file])
|
||||
if findbug_args:
|
||||
cmd.extend(findbug_args)
|
||||
cmd.extend(os.path.abspath(j) for j in jars or [])
|
||||
|
||||
if output_file:
|
||||
_, _, stderr = cmd_helper.GetCmdStatusOutputAndError(cmd)
|
||||
|
||||
results_doc = xml.dom.minidom.parse(output_file)
|
||||
else:
|
||||
_, raw_out, stderr = cmd_helper.GetCmdStatusOutputAndError(cmd)
|
||||
results_doc = xml.dom.minidom.parseString(raw_out)
|
||||
|
||||
for line in stderr.splitlines():
|
||||
logging.debug(' %s', line)
|
||||
|
||||
current_errors_set, current_warnings_set = _ParseXmlResults(results_doc)
|
||||
|
||||
return (' '.join(cmd), current_errors_set, current_warnings_set)
|
||||
|
|
@ -901,51 +901,6 @@ if (enable_java_templates) {
|
|||
}
|
||||
}
|
||||
|
||||
template("findbugs") {
|
||||
action(target_name) {
|
||||
forward_variables_from(invoker,
|
||||
[
|
||||
"deps",
|
||||
"testonly",
|
||||
])
|
||||
script = "//build/android/findbugs_diff.py"
|
||||
depfile = "$target_gen_dir/$target_name.d"
|
||||
_result_path = "$target_gen_dir/$target_name/result.xml"
|
||||
_exclusions_file = "//build/android/findbugs_filter/findbugs_exclude.xml"
|
||||
|
||||
_rebased_build_config = rebase_path(invoker.build_config, root_build_dir)
|
||||
|
||||
inputs = [
|
||||
"//build/android/pylib/utils/findbugs.py",
|
||||
_exclusions_file,
|
||||
invoker.jar_path,
|
||||
invoker.build_config,
|
||||
]
|
||||
|
||||
outputs = [
|
||||
_result_path,
|
||||
]
|
||||
|
||||
args = [
|
||||
"--depfile",
|
||||
rebase_path(depfile, root_build_dir),
|
||||
"--exclude",
|
||||
rebase_path(_exclusions_file, root_build_dir),
|
||||
"--system-jar",
|
||||
rebase_path(android_sdk_jar, root_build_dir),
|
||||
"--auxclasspath-gyp",
|
||||
"@FileArg($_rebased_build_config:javac:classpath)",
|
||||
"--output-file",
|
||||
rebase_path(_result_path, root_build_dir),
|
||||
rebase_path(invoker.jar_path, root_build_dir),
|
||||
]
|
||||
|
||||
if (findbugs_verbose) {
|
||||
args += [ "-vv" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Generates a script in the build bin directory to run a java binary.
|
||||
#
|
||||
# Variables
|
||||
|
@ -2642,15 +2597,8 @@ if (enable_java_templates) {
|
|||
[ "//build/android/buildhooks:build_hooks_android_java" ]
|
||||
}
|
||||
|
||||
if (defined(invoker.run_findbugs_override)) {
|
||||
_run_findbugs = invoker.run_findbugs_override
|
||||
} else {
|
||||
_run_findbugs = run_findbugs # Default to build arg if not overridden.
|
||||
}
|
||||
assert(_run_findbugs || true) # Mark as used.
|
||||
|
||||
# Don't enable coverage, lint, findbugs unless the target has some
|
||||
# non-generated files.
|
||||
# Don't enable coverage or lint unless the target has some non-generated
|
||||
# files.
|
||||
if (defined(invoker.chromium_code)) {
|
||||
_chromium_code = invoker.chromium_code
|
||||
} else {
|
||||
|
@ -2848,14 +2796,6 @@ if (enable_java_templates) {
|
|||
}
|
||||
}
|
||||
|
||||
if (_run_findbugs) {
|
||||
findbugs("${_template_name}__findbugs") {
|
||||
build_config = _build_config
|
||||
jar_path = _jar_path
|
||||
deps = _accumulated_deps
|
||||
}
|
||||
}
|
||||
|
||||
# Use an intermediate group() rather as the data_deps target in order to
|
||||
# avoid lint artifacts showing up as runtime_deps (while still having lint
|
||||
# run in parallel to other targets).
|
||||
|
@ -2863,9 +2803,6 @@ if (enable_java_templates) {
|
|||
public_deps = [
|
||||
":${_template_name}__lint",
|
||||
]
|
||||
if (_run_findbugs) {
|
||||
public_deps += [ ":${_template_name}__findbugs" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче