diff --git a/infer/lib/python/inferlib/analyze.py b/infer/lib/python/inferlib/analyze.py index 0540a02fa..b42d1ec6e 100644 --- a/infer/lib/python/inferlib/analyze.py +++ b/infer/lib/python/inferlib/analyze.py @@ -348,16 +348,12 @@ class AnalyzerWrapper(object): elapsed = utils.elapsed_time(reporting_start_time) self.timing['reporting'] = elapsed if report_status == os.EX_OK and not self.args.buck: - json_report = os.path.join(self.args.infer_out, - config.JSON_REPORT_FILENAME) - bugs_out = os.path.join(self.args.infer_out, - config.BUGS_FILENAME) - xml_out = None - if self.args.pmd_xml: - xml_out = os.path.join(self.args.infer_out, - config.PMD_XML_FILENAME) - issues.print_and_save_errors(self.args.project_root, json_report, - bugs_out, xml_out) + infer_out = self.args.infer_out + json_report = os.path.join(infer_out, config.JSON_REPORT_FILENAME) + bugs_out = os.path.join(infer_out, config.BUGS_FILENAME) + issues.print_and_save_errors(self.args.project_root, + json_report, bugs_out, + self.args.pmd_xml) def analyze_and_report(self): if self.args.analyzer not in [config.ANALYZER_COMPILE, diff --git a/infer/lib/python/inferlib/bucklib.py b/infer/lib/python/inferlib/bucklib.py index 4a9fad845..c649770bf 100644 --- a/infer/lib/python/inferlib/bucklib.py +++ b/infer/lib/python/inferlib/bucklib.py @@ -359,7 +359,6 @@ def collect_results(args, start_time, targets): csv_report = os.path.join(args.infer_out, config.CSV_REPORT_FILENAME) json_report = os.path.join(args.infer_out, config.JSON_REPORT_FILENAME) - bugs_out = os.path.join(args.infer_out, config.BUGS_FILENAME) if len(headers) > 1: if any(map(lambda x: x != headers[0], headers)): @@ -387,12 +386,10 @@ def collect_results(args, start_time, targets): report.flush() print('\n') - xml_out = None - if args.pmd_xml: - xml_out = os.path.join(args.infer_out, - config.PMD_XML_FILENAME) - issues.print_and_save_errors(args.project_root, json_report, - bugs_out, xml_out) + json_report = os.path.join(args.infer_out, config.JSON_REPORT_FILENAME) + bugs_out = os.path.join(args.infer_out, config.BUGS_FILENAME) + issues.print_and_save_errors(args.project_root, json_report, bugs_out, + args.pmd_xml) stats['int']['total_time'] = int(round(utils.elapsed_time(start_time))) diff --git a/infer/lib/python/inferlib/capture/buck.py b/infer/lib/python/inferlib/capture/buck.py index 997f62279..590ae14de 100644 --- a/infer/lib/python/inferlib/capture/buck.py +++ b/infer/lib/python/inferlib/capture/buck.py @@ -199,13 +199,11 @@ class BuckAnalyzer: self.args.infer_out, config.INFER_BUCK_DEPS_FILENAME) self._merge_infer_report_files(result_paths, merged_reports_path) self._merge_infer_dep_files(result_paths, merged_deps_path) - bugs_out = os.path.join(self.args.infer_out, config.BUGS_FILENAME) - xml_out = None - if self.args.pmd_xml: - xml_out = os.path.join( - self.args.infer_out, config.PMD_XML_FILENAME) - issues.print_and_save_errors(self.args.project_root, - merged_reports_path, bugs_out, xml_out) + infer_out = self.args.infer_out + json_report = os.path.join(infer_out, config.JSON_REPORT_FILENAME) + bugs_out = os.path.join(infer_out, config.BUGS_FILENAME) + issues.print_and_save_errors(self.args.project_root, json_report, + bugs_out, self.args.pmd_xml) return os.EX_OK def capture_without_flavors(self): diff --git a/infer/lib/python/inferlib/issues.py b/infer/lib/python/inferlib/issues.py index 4beb06376..6ff3cf302 100644 --- a/infer/lib/python/inferlib/issues.py +++ b/infer/lib/python/inferlib/issues.py @@ -93,7 +93,7 @@ def text_of_report(report): ) -def _text_of_report_list(project_root, reports, bugs_txt_path, limit=-1, +def _text_of_report_list(project_root, reports, bugs_txt_path, limit=None, formatter=colorize.TERMINAL_FORMATTER): text_errors_list = [] error_types_count = {} @@ -181,18 +181,20 @@ def _is_user_visible(project_root, report): kind in [ISSUE_KIND_ERROR, ISSUE_KIND_WARNING, ISSUE_KIND_ADVICE]) -def print_and_save_errors(project_root, json_report, bugs_out, xml_out): +def print_and_save_errors(project_root, json_report, bugs_out, pmd_xml): errors = utils.load_json_from_path(json_report) errors = [e for e in errors if _is_user_visible(project_root, e)] console_out = _text_of_report_list(project_root, errors, bugs_out, limit=10) utils.stdout('\n' + console_out) - plain_out = _text_of_report_list(project_root, errors, bugs_out, limit=-1, + plain_out = _text_of_report_list(project_root, errors, bugs_out, formatter=colorize.PLAIN_FORMATTER) with codecs.open(bugs_out, 'w', encoding=config.CODESET, errors='replace') as file_out: file_out.write(plain_out) - if xml_out is not None: + + if pmd_xml: + xml_out = os.path.join(infer_out, config.PMD_XML_FILENAME) with codecs.open(xml_out, 'w', encoding=config.CODESET, errors='replace') as file_out: diff --git a/infer/lib/python/report.py b/infer/lib/python/report.py new file mode 100755 index 000000000..57920e75a --- /dev/null +++ b/infer/lib/python/report.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python2.7 + +# Copyright (c) 2016 - present Facebook, Inc. +# All rights reserved. +# +# This source code is licensed under the BSD style license found in the +# LICENSE file in the root directory of this source tree. An additional grant +# of patent rights can be found in the PATENTS file in the same directory. + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + +import argparse +import os +import sys + +import inferlib +from inferlib import config, issues, utils + +arg_parser = argparse.ArgumentParser(add_help=False) +arg_parser.add_argument('--issues-csv', metavar='', + help='Location of the csv report (ignored for now)') +arg_parser.add_argument('--issues-json', metavar='', required=True, + help='Location of the json report') +arg_parser.add_argument('--issues-txt', metavar='', + help='Location of the text report (ignored for now)') +arg_parser.add_argument('--issues-xml', metavar='', + help='Location of the xml report (ignored for now)') +arg_parser.add_argument('--pmd-xml', action='store_true', + help='Output issues in (PMD) XML format.') +arg_parser.add_argument('--project-root', metavar='', required=True, + help='Location of the project root') +arg_parser.add_argument('--results-dir', metavar='', required=True, + help='Location of the results directory') + + +def main(): + sys_argv = map(utils.decode, sys.argv) + args = arg_parser.parse_args(sys_argv[1:]) + bugs_out = os.path.join(args.results_dir, config.BUGS_FILENAME) + issues.print_and_save_errors(args.project_root, args.issues_json, bugs_out, + args.pmd_xml) + +if __name__ == '__main__': + main()