Fixed #3057 (cppcheck-htmlreport fails since 1.50)

This commit is contained in:
Daniel Marjamäki 2011-08-30 20:30:52 +02:00
parent 0529654e37
commit c1c4ffd700
1 changed files with 30 additions and 13 deletions

View File

@ -181,6 +181,16 @@ class CppCheckHandler(XmlContentHandler):
if name != "error": if name != "error":
return return
if attributes["id"] == "missingInclude":
self.errors.append(
{
"file" : "",
"line" : 0,
"id" : attributes["id"],
"severity" : attributes["severity"],
"msg" : attributes["msg"]
})
else:
if attributes["file"] == "": if attributes["file"] == "":
sys.stderr.write("ERROR: cppcheck error reported without a file name.\n") sys.stderr.write("ERROR: cppcheck error reported without a file name.\n")
self.errors.append( self.errors.append(
@ -257,6 +267,9 @@ if __name__ == '__main__':
for error in errors: for error in errors:
lines.append(error["line"]) lines.append(error["line"])
if filename == "":
continue
source_file = os.path.join(source_dir, filename) source_file = os.path.join(source_dir, filename)
if not os.path.isfile(source_file): if not os.path.isfile(source_file):
sys.stderr.write("ERROR: Source file '%s' not found.\n" % source_file) sys.stderr.write("ERROR: Source file '%s' not found.\n" % source_file)
@ -290,6 +303,10 @@ if __name__ == '__main__':
for filename, data in files.iteritems(): for filename, data in files.iteritems():
stream.write("<tr><td colspan='4'><a href=\"%s\">%s</a></td></tr>" % (data["htmlfile"], filename)) stream.write("<tr><td colspan='4'><a href=\"%s\">%s</a></td></tr>" % (data["htmlfile"], filename))
for error in data["errors"]: for error in data["errors"]:
if error["id"] == "missingInclude":
stream.write("<tr><td></td><td>%s</td><td>%s</td><td>%s</td></tr>" %
(error["id"], error["severity"], error["msg"]))
else:
stream.write("<tr><td><a href='%s#line-%d'>%d</a></td><td>%s</td><td>%s</td><td>%s</td></tr>" % stream.write("<tr><td><a href='%s#line-%d'>%d</a></td><td>%s</td><td>%s</td><td>%s</td></tr>" %
(data["htmlfile"], error["line"], error["line"], error["id"], (data["htmlfile"], error["line"], error["line"], error["id"],
error["severity"], error["msg"])) error["severity"], error["msg"]))