From d545da14c1c64720ac32f0d459e85398c99d02f6 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Thu, 12 Nov 2015 08:22:13 -0800 Subject: [PATCH] fix stuff that was accidentally broken Reviewed By: martinoluca Differential Revision: D2647203 fb-gh-sync-id: b1d3b78 --- infer/lib/python/inferlib/capture/buck.py | 16 +++++++++------- infer/lib/python/inferlib/issues.py | 2 +- infer/lib/python/inferlib/utils.py | 10 +++++++--- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/infer/lib/python/inferlib/capture/buck.py b/infer/lib/python/inferlib/capture/buck.py index 096daf14d..a1207a637 100644 --- a/infer/lib/python/inferlib/capture/buck.py +++ b/infer/lib/python/inferlib/capture/buck.py @@ -6,11 +6,12 @@ # of patent rights can be found in the PATENTS file in the same directory. import argparse +import json +import logging import os import subprocess import traceback import util -import logging from inferlib import utils @@ -93,7 +94,8 @@ class BuckAnalyzer: ) args = [ '--config', - 'infer.infer_bin={bin}'.format(bin=utils.get_infer_bin()), + 'infer.infer_bin={bin}' + .format(bin=utils.BIN_DIRECTORY), '--config', 'infer.clang_compiler={clang}'.format(clang=clang_path), '--config', @@ -134,11 +136,11 @@ class BuckAnalyzer: if not ret == os.EX_OK: return ret result_files = self._get_analysis_result_files() - merged_results_path = \ - os.path.join(self.args.infer_out, utils.JSON_REPORT_FILENAME) - utils.merge_json_reports( - result_files, - merged_results_path) + all_results = utils.merge_json_arrays_from_files(result_files) + merged_results_path = os.path.join(self.args.infer_out, + utils.JSON_REPORT_FILENAME) + with open(merged_results_path, 'w') as file_out: + json.dump(all_results, file_out, indent=2) # TODO: adapt issues.print_errors to support json and print on screen print('Results saved in {results_path}'.format( results_path=merged_results_path)) diff --git a/infer/lib/python/inferlib/issues.py b/infer/lib/python/inferlib/issues.py index f3428a6e9..2746c61cc 100644 --- a/infer/lib/python/inferlib/issues.py +++ b/infer/lib/python/inferlib/issues.py @@ -95,7 +95,7 @@ def clean_json(args, json_report): cmp=_compare_json_rows) temporary_file = tempfile.mktemp() with open(temporary_file, 'w') as file_out: - json.dump(collected_rows, file_out) + json.dump(collected_rows, file_out, indent=2) file_out.flush() shutil.move(temporary_file, json_report) diff --git a/infer/lib/python/inferlib/utils.py b/infer/lib/python/inferlib/utils.py index 7d4916cde..b94d4c260 100644 --- a/infer/lib/python/inferlib/utils.py +++ b/infer/lib/python/inferlib/utils.py @@ -201,9 +201,13 @@ def run_command(cmd, debug_mode, infer_out, message, env=os.environ): raise e -def print_exit(s): - print(s) - exit(os.EX_OK) +def merge_json_arrays_from_files(report_paths): + # TODO: use streams instead of loading the entire json in memory + json_data = [] + for json_path in report_paths: + with codecs.open(json_path, 'r', encoding=config.LOCALE) as fd: + json_data = json_data + json.loads(fd.read()) + return json_data def infer_version():