From 1aa5b1e94763a959422f53458838c46ce6893047 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Tue, 8 Mar 2016 05:53:04 -0800 Subject: [PATCH] do not print source excerpts in bugs.txt Summary:public bugs.txt only contains the summary of each report. The terminal output contains a bit more information, such as source excerpts. If one wants to save the terminal output into a file, they can always use shell redirection anyway. closes #294 Reviewed By: martinoluca Differential Revision: D3023796 fb-gh-sync-id: 9a21d17 shipit-source-id: 9a21d17 --- infer/lib/python/inferlib/issues.py | 61 +++++++++++++++-------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/infer/lib/python/inferlib/issues.py b/infer/lib/python/inferlib/issues.py index cac2ba43c..44601bf53 100644 --- a/infer/lib/python/inferlib/issues.py +++ b/infer/lib/python/inferlib/issues.py @@ -174,22 +174,26 @@ def text_of_report(report): ) -def _text_of_report_list(reports): +def _text_of_report_list(reports, formatter=source.TERMINAL_FORMATTER): text_errors_list = [] error_types_count = {} for report in reports: filename = report[JSON_INDEX_FILENAME] line = report[JSON_INDEX_LINE] - source_context = source.build_source_context( - filename, - source.TERMINAL_FORMATTER, - line, - ) - indenter = source.Indenter() \ - .indent_push() \ - .add(source_context) - source_context = unicode(indenter) - text = '%s\n%s' % (text_of_report(report), source_context) + + source_context = '' + if formatter is not None: + source_context = source.build_source_context( + filename, + source.TERMINAL_FORMATTER, + line, + ) + indenter = source.Indenter() \ + .indent_push() \ + .add(source_context) + source_context = '\n' + unicode(indenter) + + text = '%s%s' % (text_of_report(report), source_context) text_errors_list.append(text) t = report[JSON_INDEX_TYPE] @@ -205,23 +209,23 @@ def _text_of_report_list(reports): n_issues = len(text_errors_list) if n_issues == 0: return 'No issues found' - else: - max_type_length = max(map(len, error_types_count.keys())) + 2 - sorted_error_types = error_types_count.items() - sorted_error_types.sort(key=operator.itemgetter(1), reverse=True) - types_text_list = map(lambda (t, count): '%s: %d' % ( - t.rjust(max_type_length), - count, - ), sorted_error_types) - text_errors = '\n\n'.join(text_errors_list) + max_type_length = max(map(len, error_types_count.keys())) + 2 + sorted_error_types = error_types_count.items() + sorted_error_types.sort(key=operator.itemgetter(1), reverse=True) + types_text_list = map(lambda (t, count): '%s: %d' % ( + t.rjust(max_type_length), + count, + ), sorted_error_types) + + text_errors = '\n\n'.join(text_errors_list) - msg = '\nFound %s\n\n%s\n\nSummary of the reports:\n\n%s' % ( - utils.get_plural('issue', n_issues), - text_errors, - '\n'.join(types_text_list), - ) - return msg + msg = 'Found %s\n\n%s\n\nSummary of the reports:\n\n%s' % ( + utils.get_plural('issue', n_issues), + text_errors, + '\n'.join(types_text_list), + ) + return msg def _is_user_visible(report): @@ -234,11 +238,10 @@ def _is_user_visible(report): def print_and_save_errors(json_report, bugs_out): errors = utils.load_json_from_path(json_report) errors = filter(_is_user_visible, errors) - text = _text_of_report_list(errors) - utils.stdout(text) + utils.stdout('\n' + _text_of_report_list(errors)) with codecs.open(bugs_out, 'w', encoding=config.LOCALE, errors='replace') as file_out: - file_out.write(text) + file_out.write(_text_of_report_list(errors, formatter=None)) def merge_reports_from_paths(report_paths):