From f72a1a421013c193a5721ae41f7e2ed017dc0d9d Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Wed, 11 Nov 2015 07:47:51 -0800 Subject: [PATCH] read errors from json instead of csv Summary: public This also fixes an issue with utf-8 in source code, as the csv report filters out non-ascii characters. Reviewed By: akotulski Differential Revision: D2641727 fb-gh-sync-id: 3ca6dc6 --- infer/lib/python/BuckAnalyze | 2 +- infer/lib/python/inferlib/analyze.py | 28 +++++++++++++--------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/infer/lib/python/BuckAnalyze b/infer/lib/python/BuckAnalyze index fcd20240e..f06d14b78 100755 --- a/infer/lib/python/BuckAnalyze +++ b/infer/lib/python/BuckAnalyze @@ -448,7 +448,7 @@ def collect_results(args, start_time): report.flush() print('\n') - analyze.print_errors(csv_report, bugs_out) + analyze.print_errors(json_report, bugs_out) stats['int']['total_time'] = int(round(utils.elapsed_time(start_time))) diff --git a/infer/lib/python/inferlib/analyze.py b/infer/lib/python/inferlib/analyze.py index 721e8a0d4..32dd1cfff 100644 --- a/infer/lib/python/inferlib/analyze.py +++ b/infer/lib/python/inferlib/analyze.py @@ -394,25 +394,23 @@ def print_and_write(file_out, message): file_out.write(message + '\n') -def print_errors(csv_report, bugs_out): - with codecs.open(csv_report, 'r', encoding=utils.LOCALE) as file_in: - reader = utils.locale_csv_reader(file_in) - reader.next() # first line is header, skip it +def print_errors(json_report, bugs_out): + with codecs.open(json_report, 'r', encoding=utils.LOCALE) as file_in: + errors = json.load(file_in) errors = filter( - lambda row: row[utils.CSV_INDEX_KIND] in [ERROR, WARNING], - reader - ) + lambda row: row[utils.JSON_INDEX_KIND] in [ERROR, WARNING], + errors) with codecs.open(bugs_out, 'w', encoding=utils.LOCALE) as file_out: text_errors_list = [] for row in errors: - filename = row[utils.CSV_INDEX_FILENAME] + filename = row[utils.JSON_INDEX_FILENAME] if os.path.isfile(filename): - kind = row[utils.CSV_INDEX_KIND] - line = row[utils.CSV_INDEX_LINE] - error_type = row[utils.CSV_INDEX_TYPE] - msg = row[utils.CSV_INDEX_QUALIFIER] + kind = row[utils.JSON_INDEX_KIND] + line = row[utils.JSON_INDEX_LINE] + error_type = row[utils.JSON_INDEX_TYPE] + msg = row[utils.JSON_INDEX_QUALIFIER] indenter = utils.Indenter() indenter.indent_push() indenter.add( @@ -761,11 +759,11 @@ class Infer: self.read_proc_stats() self.print_analysis_stats() if report_status == os.EX_OK and not self.args.buck: - csv_report = os.path.join(self.args.infer_out, - utils.CSV_REPORT_FILENAME) + json_report = os.path.join(self.args.infer_out, + utils.JSON_REPORT_FILENAME) bugs_out = os.path.join(self.args.infer_out, utils.BUGS_FILENAME) - print_errors(csv_report, bugs_out) + print_errors(json_report, bugs_out) def print_analysis_stats(self): procs_total = self.stats['int']['procedures']