Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cli] Fix html output of CodeChecker parse #3524

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def __init__(
self._checker_labels = checker_labels
self.layout_dir = layout_dir
self.generated_html_reports: Dict[str, HTMLReports] = {}
self.html_reports: HTMLReports = []
self.files: FileSources = {}

css_dir = os.path.join(self.layout_dir, 'css')
Expand Down Expand Up @@ -151,13 +150,13 @@ def get_severity(self, checker_name: str) -> str:
return self._checker_labels.severity(checker_name) \
if self._checker_labels else 'UNSPECIFIED'

def _add_source_file(self, file: File):
def _add_source_file(self, file: File) -> FileSource:
"""
Updates file source data by file id if the given file hasn't been
processed.
"""
if file.id in self.files:
return
return self.files[file.id]

try:
file_content = file.content
Expand All @@ -167,17 +166,27 @@ def _add_source_file(self, file: File):
self.files[file.id] = {
'filePath': file.path, 'content': file_content}

def _add_html_reports(
return self.files[file.id]

def _get_html_reports(
self,
reports: List[Report]
):
) -> Tuple[HTMLReports, FileSources]:
""" Get HTML reports from the given reports.

Returns a list of html reports and references to file sources.
"""
html_reports: HTMLReports = []
files: FileSources = {}

def to_bug_path_events(
events: List[BugPathEvent]
) -> HTMLBugPathEvents:
""" Converts the given events to html compatible format. """
html_events: HTMLBugPathEvents = []
for event in events:
self._add_source_file(event.file)
files[event.file.id] = self._add_source_file(event.file)

html_events.append({
'message': event.message,
'fileId': event.file.id,
Expand All @@ -192,7 +201,9 @@ def to_macro_expansions(
""" Converts the given events to html compatible format. """
html_macro_expansions: HTMLMacroExpansions = []
for macro_expansion in macro_expansions:
self._add_source_file(macro_expansion.file)
files[macro_expansion.file.id] = self._add_source_file(
macro_expansion.file)

html_macro_expansions.append({
'message': macro_expansion.message,
'name': macro_expansion.name,
Expand All @@ -203,9 +214,9 @@ def to_macro_expansions(
return html_macro_expansions

for report in reports:
self._add_source_file(report.file)
files[report.file.id] = self._add_source_file(report.file)

self.html_reports.append({
html_reports.append({
'fileId': report.file.id,
'reportHash': report.report_hash,
'checkerName': report.checker_name,
Expand All @@ -219,6 +230,8 @@ def to_macro_expansions(
'severity': self.get_severity(report.checker_name)
})

return html_reports, files

def create(
self,
output_file_path: str,
Expand All @@ -233,15 +246,15 @@ def create(
if changed_files:
return None, changed_files

self._add_html_reports(reports)
html_reports, files = self._get_html_reports(reports)

self.generated_html_reports[output_file_path] = self.html_reports
self.generated_html_reports[output_file_path] = html_reports

substitute_data = self._tag_contents
substitute_data.update({
'report_data': json.dumps({
'files': self.files,
'reports': self.html_reports
'files': files,
'reports': html_reports
})
})

Expand All @@ -251,7 +264,7 @@ def create(
encoding='utf-8', errors='replace') as f:
f.write(content)

return self.html_reports, changed_files
return html_reports, changed_files

def create_index_html(self, output_dir: str):
"""
Expand Down
7 changes: 7 additions & 0 deletions tools/report-converter/tests/projects/inclusion/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
all: a b

a: a.cpp
g++ -c a.cpp

b: b.cpp
g++ -c b.cpp
5 changes: 5 additions & 0 deletions tools/report-converter/tests/projects/inclusion/a.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "f.h"

int a() {
foo();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>diagnostics</key>
<array>
<dict>
<key>category</key>
<string>clang</string>
<key>check_name</key>
<string>clang-diagnostic-return-type</string>
<key>description</key>
<string>non-void function does not return a value</string>
<key>issue_hash_content_of_line_in_context</key>
<string>3ab76fd265ab7140c41b3126664b29b8</string>
<key>location</key>
<dict>
<key>col</key>
<integer>1</integer>
<key>file</key>
<integer>0</integer>
<key>line</key>
<integer>5</integer>
</dict>
<key>path</key>
<array>
<dict>
<key>depth</key>
<integer>0</integer>
<key>kind</key>
<string>event</string>
<key>location</key>
<dict>
<key>col</key>
<integer>1</integer>
<key>file</key>
<integer>0</integer>
<key>line</key>
<integer>5</integer>
</dict>
<key>message</key>
<string>non-void function does not return a value</string>
</dict>
</array>
</dict>
<dict>
<key>category</key>
<string>misc</string>
<key>check_name</key>
<string>misc-definitions-in-headers</string>
<key>description</key>
<string>function 'foo' defined in a header file; function definitions in header files can lead to ODR violations</string>
<key>issue_hash_content_of_line_in_context</key>
<string>e5d8516ed0ec25a58c07f5cc15385681</string>
<key>location</key>
<dict>
<key>col</key>
<integer>5</integer>
<key>file</key>
<integer>1</integer>
<key>line</key>
<integer>4</integer>
</dict>
<key>path</key>
<array>
<dict>
<key>depth</key>
<integer>0</integer>
<key>kind</key>
<string>event</string>
<key>location</key>
<dict>
<key>col</key>
<integer>5</integer>
<key>file</key>
<integer>1</integer>
<key>line</key>
<integer>4</integer>
</dict>
<key>message</key>
<string>make as 'inline'</string>
</dict>
<dict>
<key>depth</key>
<integer>0</integer>
<key>kind</key>
<string>event</string>
<key>location</key>
<dict>
<key>col</key>
<integer>5</integer>
<key>file</key>
<integer>1</integer>
<key>line</key>
<integer>4</integer>
</dict>
<key>message</key>
<string>function 'foo' defined in a header file; function definitions in header files can lead to ODR violations</string>
</dict>
</array>
</dict>
<dict>
<key>category</key>
<string>bugprone</string>
<key>check_name</key>
<string>bugprone-sizeof-expression</string>
<key>description</key>
<string>suspicious usage of 'sizeof(K)'; did you mean 'K'?</string>
<key>issue_hash_content_of_line_in_context</key>
<string>cdff7d3bce7ee7f72e99c34e51a242c9</string>
<key>location</key>
<dict>
<key>col</key>
<integer>10</integer>
<key>file</key>
<integer>1</integer>
<key>line</key>
<integer>5</integer>
</dict>
<key>path</key>
<array>
<dict>
<key>depth</key>
<integer>0</integer>
<key>kind</key>
<string>event</string>
<key>location</key>
<dict>
<key>col</key>
<integer>10</integer>
<key>file</key>
<integer>1</integer>
<key>line</key>
<integer>5</integer>
</dict>
<key>message</key>
<string>suspicious usage of 'sizeof(K)'; did you mean 'K'?</string>
</dict>
</array>
</dict>
</array>
<key>files</key>
<array>
<string>$FILE_PATH$/a.cpp</string>
<string>$FILE_PATH$/f.h</string>
</array>
<key>metadata</key>
<dict>
<key>analyzer</key>
<dict>
<key>name</key>
<string>clang-tidy</string>
</dict>
<key>generated_by</key>
<dict>
<key>name</key>
<string>CodeChecker</string>
<key>version</key>
<string>6.19.0</string>
</dict>
</dict>
</dict>
</plist>
5 changes: 5 additions & 0 deletions tools/report-converter/tests/projects/inclusion/b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "f.h"

int b() {
return foo();
}
Loading