[infer][java] When using Buck to analyze Java projects, only report the errors found on the targets passed on the command line

Summary:
Before this diff, Infer was simply going through the list of jar files found in `buck-out` and was loading all the `report.json` files found in those jar files in order to merge them into a final report. The main drawback of this was that removing `buck-out` was mandatory to get accurate results when switching between targets to analyze.

With this diff, we now use the `buck audit classpath` option to get from a list of targets, the list of jar files to load the `report.json` files from. This allows to more easily use Infer from the command line when switch branches from the repositories or when switching between targets to analyze.

Reviewed By: martinoluca

Differential Revision: D3922548

fbshipit-source-id: ec550fa
master
Jeremy Dubreil 8 years ago committed by Facebook Github Bot 9
parent befab1007b
commit fc28683ea2

@ -273,7 +273,16 @@ def load_json_report(opened_jar):
raise NotFoundInJar raise NotFoundInJar
def collect_results(args, start_time): def get_output_jars(targets):
if len(targets) == 0:
return []
else:
audit_output = subprocess.check_output(
['buck', 'audit', 'classpath'] + targets)
return audit_output.strip().split('\n')
def collect_results(args, start_time, targets):
"""Walks through buck-gen, collects results for the different buck targets """Walks through buck-gen, collects results for the different buck targets
and stores them in in args.infer_out/results.csv. and stores them in in args.infer_out/results.csv.
""" """
@ -297,9 +306,7 @@ def collect_results(args, start_time):
expected_analyzer = stats['normal']['analyzer'] expected_analyzer = stats['normal']['analyzer']
expected_version = stats['normal']['infer_version'] expected_version = stats['normal']['infer_version']
for root, _, files in os.walk(DEFAULT_BUCK_OUT_GEN): for path in get_output_jars(targets):
for f in [f for f in files if f.endswith('.jar')]:
path = os.path.join(root, f)
try: try:
with zipfile.ZipFile(path) as jar: with zipfile.ZipFile(path) as jar:
# Accumulate integers and float values # Accumulate integers and float values
@ -308,8 +315,8 @@ def collect_results(args, start_time):
found_analyzer = target_stats['normal']['analyzer'] found_analyzer = target_stats['normal']['analyzer']
found_version = target_stats['normal']['infer_version'] found_version = target_stats['normal']['infer_version']
if (found_analyzer != expected_analyzer if found_analyzer != expected_analyzer \
or found_version != expected_version): or found_version != expected_version:
continue continue
else: else:
for type_k in ['int', 'float']: for type_k in ['int', 'float']:
@ -459,7 +466,7 @@ class Wrapper:
def _collect_results(self, start_time): def _collect_results(self, start_time):
self.timer.start('Collecting results ...') self.timer.start('Collecting results ...')
collect_results(self.infer_args, start_time) collect_results(self.infer_args, start_time, self.normalized_targets)
self.timer.stop('Done') self.timer.stop('Done')
def run(self): def run(self):

Loading…
Cancel
Save