From 183cefdad467bffadba14323964d7421f24dcfc1 Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Wed, 1 Nov 2017 12:49:23 -0700 Subject: [PATCH] [infer][java] merge identical bugs in the Buck integration for Java Summary: A source can belong to more than one target. In this case, we should keep only one of the report. Reviewed By: sblackshear Differential Revision: D6200058 fbshipit-source-id: 4eced42 --- infer/lib/python/inferlib/bucklib.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/infer/lib/python/inferlib/bucklib.py b/infer/lib/python/inferlib/bucklib.py index 87955ad1d..a341b61a6 100644 --- a/infer/lib/python/inferlib/bucklib.py +++ b/infer/lib/python/inferlib/bucklib.py @@ -142,18 +142,29 @@ def get_output_jars(targets): return filter(os.path.isfile, classpath_jars) +def get_key(e): + return (e[issues.JSON_INDEX_FILENAME], e[issues.JSON_INDEX_TYPE], + e[issues.JSON_INDEX_LINE], e[issues.JSON_INDEX_QUALIFIER]) + + +def merge_reports(report, collected): + for e in report: + key = get_key(e) + if key not in collected: + collected[key] = e + + def collect_results(args, start_time, targets): """Walks through buck-out/, collects results for the different buck targets and stores them in in args.infer_out/results.json. """ - all_json_rows = [] + collected_reports = {} for path in get_output_jars(targets): try: with zipfile.ZipFile(path) as jar: - json_rows = load_json_report(jar) - for row in json_rows: - all_json_rows.append(row) + report = load_json_report(jar) + merge_reports(report, collected_reports) except NotFoundInJar: pass except zipfile.BadZipfile: @@ -162,7 +173,7 @@ def collect_results(args, start_time, targets): json_report = os.path.join(args.infer_out, config.JSON_REPORT_FILENAME) with open(json_report, 'w') as file_out: - json.dump(all_json_rows, file_out) + json.dump(collected_reports.values(), file_out) bugs_out = os.path.join(args.infer_out, config.BUGS_FILENAME) issues.print_and_save_errors(args.infer_out, args.project_root,