diff options
Diffstat (limited to 'third_party/waf/waflib/extras/cppcheck.py')
-rw-r--r-- | third_party/waf/waflib/extras/cppcheck.py | 81 |
1 files changed, 62 insertions, 19 deletions
diff --git a/third_party/waf/waflib/extras/cppcheck.py b/third_party/waf/waflib/extras/cppcheck.py index 3bbeabf200a..4a4e59da5f4 100644 --- a/third_party/waf/waflib/extras/cppcheck.py +++ b/third_party/waf/waflib/extras/cppcheck.py @@ -1,4 +1,8 @@ #! /usr/bin/env python +# encoding: utf-8 +# WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file + +#! /usr/bin/env python # -*- encoding: utf-8 -*- # Michel Mooij, michel.mooij7@gmail.com @@ -43,6 +47,11 @@ building the task. The result of the source code analysis will be stored both as xml and html files in the build location for the task. Should any error be detected by cppcheck the build will be aborted and a link to the html report will be shown. +By default, one index.html file is created for each task generator. A global +index.html file can be obtained by setting the following variable +in the configuration section: + + conf.env.CPPCHECK_SINGLE_HTML = False When needed source code checking by cppcheck can be disabled per task, per detected error or warning for a particular task. It can be also be disabled for @@ -85,7 +94,7 @@ script that comes shipped with the cppcheck tool. import sys import xml.etree.ElementTree as ElementTree -from waflib import Task, TaskGen, Logs, Context +from waflib import Task, TaskGen, Logs, Context, Options PYGMENTS_EXC_MSG= ''' The required module 'pygments' could not be found. Please install it using your @@ -134,6 +143,9 @@ def options(opt): default='20', action='store', help='maximum preprocessor (--max-configs) define iterations (default=20)') + opt.add_option('--cppcheck-jobs', dest='cppcheck_jobs', + default='1', action='store', + help='number of jobs (-j) to do the checking work (default=1)') def configure(conf): if conf.options.cppcheck_skip: @@ -143,20 +155,27 @@ def configure(conf): conf.env.CPPCHECK_MAX_CONFIGS = conf.options.cppcheck_max_configs conf.env.CPPCHECK_BIN_ENABLE = conf.options.cppcheck_bin_enable conf.env.CPPCHECK_LIB_ENABLE = conf.options.cppcheck_lib_enable + conf.env.CPPCHECK_JOBS = conf.options.cppcheck_jobs + if conf.options.cppcheck_jobs != '1' and ('unusedFunction' in conf.options.cppcheck_bin_enable or 'unusedFunction' in conf.options.cppcheck_lib_enable or 'all' in conf.options.cppcheck_bin_enable or 'all' in conf.options.cppcheck_lib_enable): + Logs.warn('cppcheck: unusedFunction cannot be used with multiple threads, cppcheck will disable it automatically') conf.find_program('cppcheck', var='CPPCHECK') + # set to True to get a single index.html file + conf.env.CPPCHECK_SINGLE_HTML = False @TaskGen.feature('c') @TaskGen.feature('cxx') def cppcheck_execute(self): - if len(self.env.CPPCHECK_SKIP) or self.bld.options.cppcheck_skip: + if hasattr(self.bld, 'conf'): + return + if len(self.env.CPPCHECK_SKIP) or Options.options.cppcheck_skip: return if getattr(self, 'cppcheck_skip', False): return task = self.create_task('cppcheck') task.cmd = _tgen_create_cmd(self) task.fatal = [] - if not self.bld.options.cppcheck_err_resume: + if not Options.options.cppcheck_err_resume: task.fatal.append('error') @@ -167,10 +186,12 @@ def _tgen_create_cmd(self): max_configs = self.env.CPPCHECK_MAX_CONFIGS bin_enable = self.env.CPPCHECK_BIN_ENABLE lib_enable = self.env.CPPCHECK_LIB_ENABLE + jobs = self.env.CPPCHECK_JOBS cmd = self.env.CPPCHECK args = ['--inconclusive','--report-progress','--verbose','--xml','--xml-version=2'] args.append('--max-configs=%s' % max_configs) + args.append('-j %s' % jobs) if 'cxx' in features: args.append('--language=c++') @@ -179,7 +200,7 @@ def _tgen_create_cmd(self): args.append('--language=c') args.append('--std=%s' % std_c) - if self.bld.options.cppcheck_check_config: + if Options.options.cppcheck_check_config: args.append('--check-config') if set(['cprogram','cxxprogram']) & set(features): @@ -215,8 +236,11 @@ class cppcheck(Task.Task): root = ElementTree.fromstring(s) cmd = ElementTree.SubElement(root.find('cppcheck'), 'cmd') cmd.text = str(self.cmd) - body = ElementTree.tostring(root) - node = self.generator.path.get_bld().find_or_declare('cppcheck.xml') + body = ElementTree.tostring(root).decode('us-ascii') + body_html_name = 'cppcheck-%s.xml' % self.generator.get_name() + if self.env.CPPCHECK_SINGLE_HTML: + body_html_name = 'cppcheck.xml' + node = self.generator.path.get_bld().find_or_declare(body_html_name) node.write(header + body) def _get_defects(self, xml_string): @@ -244,10 +268,10 @@ class cppcheck(Task.Task): def _create_html_files(self, defects): sources = {} - defects = [defect for defect in defects if defect.has_key('file')] + defects = [defect for defect in defects if 'file' in defect] for defect in defects: name = defect['file'] - if not sources.has_key(name): + if not name in sources: sources[name] = [defect] else: sources[name].append(defect) @@ -255,10 +279,13 @@ class cppcheck(Task.Task): files = {} css_style_defs = None bpath = self.generator.path.get_bld().abspath() - names = sources.keys() + names = list(sources.keys()) for i in range(0,len(names)): name = names[i] - htmlfile = 'cppcheck/%i.html' % (i) + if self.env.CPPCHECK_SINGLE_HTML: + htmlfile = 'cppcheck/%i.html' % (i) + else: + htmlfile = 'cppcheck/%s%i.html' % (self.generator.get_name(),i) errors = sources[name] files[name] = { 'htmlfile': '%s/%s' % (bpath, htmlfile), 'errors': errors } css_style_defs = self._create_html_file(name, htmlfile, errors) @@ -279,19 +306,25 @@ class cppcheck(Task.Task): if div.get('id') == 'header': h1 = div.find('h1') h1.text = 'cppcheck report - %s' % name + if div.get('id') == 'menu': + indexlink = div.find('a') + if self.env.CPPCHECK_SINGLE_HTML: + indexlink.attrib['href'] = 'index.html' + else: + indexlink.attrib['href'] = 'index-%s.html' % name if div.get('id') == 'content': content = div srcnode = self.generator.bld.root.find_node(sourcefile) - hl_lines = [e['line'] for e in errors if e.has_key('line')] + hl_lines = [e['line'] for e in errors if 'line' in e] formatter = CppcheckHtmlFormatter(linenos=True, style='colorful', hl_lines=hl_lines, lineanchors='line') - formatter.errors = [e for e in errors if e.has_key('line')] + formatter.errors = [e for e in errors if 'line' in e] css_style_defs = formatter.get_style_defs('.highlight') lexer = pygments.lexers.guess_lexer_for_filename(sourcefile, "") s = pygments.highlight(srcnode.read(), lexer, formatter) table = ElementTree.fromstring(s) content.append(table) - s = ElementTree.tostring(root, method='html') + s = ElementTree.tostring(root, method='html').decode('us-ascii') s = CCPCHECK_HTML_TYPE + s node = self.generator.path.get_bld().find_or_declare(htmlfile) node.write(s) @@ -315,10 +348,19 @@ class cppcheck(Task.Task): if div.get('id') == 'content': content = div self._create_html_table(content, files) + if div.get('id') == 'menu': + indexlink = div.find('a') + if self.env.CPPCHECK_SINGLE_HTML: + indexlink.attrib['href'] = 'index.html' + else: + indexlink.attrib['href'] = 'index-%s.html' % name - s = ElementTree.tostring(root, method='html') + s = ElementTree.tostring(root, method='html').decode('us-ascii') s = CCPCHECK_HTML_TYPE + s - node = self.generator.path.get_bld().find_or_declare('cppcheck/index.html') + index_html_name = 'cppcheck/index-%s.html' % name + if self.env.CPPCHECK_SINGLE_HTML: + index_html_name = 'cppcheck/index.html' + node = self.generator.path.get_bld().find_or_declare(index_html_name) node.write(s) return node @@ -330,9 +372,9 @@ class cppcheck(Task.Task): row = ElementTree.fromstring(s) table.append(row) - errors = sorted(val['errors'], key=lambda e: int(e['line']) if e.has_key('line') else sys.maxint) + errors = sorted(val['errors'], key=lambda e: int(e['line']) if 'line' in e else sys.maxint) for e in errors: - if not e.has_key('line'): + if not 'line' in e: s = '<tr><td></td><td>%s</td><td>%s</td><td>%s</td></tr>\n' % (e['id'], e['severity'], e['msg']) else: attr = '' @@ -382,7 +424,7 @@ class CppcheckHtmlFormatter(pygments.formatters.HtmlFormatter): for error in self.errors: if int(error['line']) == line_no: t = t.replace('\n', CPPCHECK_HTML_ERROR % error['msg']) - line_no = line_no + 1 + line_no += 1 yield i, t @@ -413,7 +455,7 @@ CPPCHECK_HTML_FILE = """ <div>cppcheck - a tool for static C/C++ code analysis</div> <div> Internet: <a href="http://cppcheck.sourceforge.net">http://cppcheck.sourceforge.net</a><br/> - Forum: <a href="http://apps.sourceforge.net/phpbb/cppcheck/">http://apps.sourceforge.net/phpbb/cppcheck/</a><br/> + Forum: <a href="http://apps.sourceforge.net/phpbb/cppcheck/">http://apps.sourceforge.net/phpbb/cppcheck/</a><br/> IRC: #cppcheck at irc.freenode.net </div> @@ -544,3 +586,4 @@ th, td { } """ + |