From 82047ea282c6d7950c4adb66caf1a08d67292e80 Mon Sep 17 00:00:00 2001 From: jlguardi Date: Fri, 25 Sep 2020 20:12:41 +0200 Subject: [PATCH] =?UTF-8?q?cppcheck-htmlreport:=20Support=20for=20multiple?= =?UTF-8?q?=20input=20files=20and=20fixed=20stdin=E2=80=A6=20(#2822)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htmlreport/cppcheck-htmlreport | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/htmlreport/cppcheck-htmlreport b/htmlreport/cppcheck-htmlreport index d2664cb73..97a3af50d 100755 --- a/htmlreport/cppcheck-htmlreport +++ b/htmlreport/cppcheck-htmlreport @@ -394,9 +394,11 @@ if __name__ == '__main__': parser.add_option('--title', dest='title', help='The title of the project.', default='[project name]') - parser.add_option('--file', dest='file', + parser.add_option('--file', dest='file', action="append", help='The cppcheck xml output file to read defects ' - 'from. Default is reading from stdin.') + 'from. You can combine results from several ' + 'xml reports i.e. "--file file1.xml --file file2.xml ..". ' + 'Default is reading from stdin.') parser.add_option('--report-dir', dest='report_dir', help='The directory where the HTML report content is ' 'written.') @@ -423,21 +425,15 @@ if __name__ == '__main__': if options.source_dir: source_dir = options.source_dir - # Get the stream that we read cppcheck errors from. - input_file = sys.stdin - if options.file: - if not os.path.exists(options.file): - parser.error('cppcheck xml file: %s not found.' % options.file) - input_file = io.open(options.file, 'r') - else: - parser.error('No cppcheck xml file specified. (--file=)') - - # Parse the xml file and produce a simple list of errors. + # Parse the xml from all files defined in file argument + # or from stdin. If no input is provided, stdin is used + # Produce a simple list of errors. print('Parsing xml report.') try: contentHandler = CppCheckHandler() - xml_parse(input_file, contentHandler) - except XmlParseException as msg: + for fname in options.file or [sys.stdin]: + xml_parse(fname, contentHandler) + except (XmlParseException, ValueError) as msg: print('Failed to parse cppcheck xml file: %s' % msg) sys.exit(1)