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

[feat][report-converter][fix][server] Add support for bug path arrows into sarif parser. #4401

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -143,26 +143,30 @@ def _process_code_flows(

thread_flow_info = ThreadFlowInfo()

# TODO: Currently, we only collect bug path events.

for code_flow in result.get("codeFlows", []):
for thread_flow in code_flow.get("threadFlows", []):
for location_data in thread_flow["locations"]:
# There are a lot data stored alongside the location worth
if "location" not in location_data:
continue

# There is a lot data stored alongside the location worth
# parsing, but we only need the actual location now.
location = location_data["location"]

file, rng = self._process_location(location)
if not (file and rng):
continue

thread_flow_info.bug_path_positions.append(
BugPathPosition(file, rng)
)

if "message" not in location:
# TODO: This might be a bug path position (for arrows).
continue

message = self._process_message(
location["message"], rule_id, rules)

file, rng = self._process_location(location)
if not (file and rng):
continue

thread_flow_info.bug_path_events.append(BugPathEvent(
message, file, rng.start_line, rng.start_col, rng))

Expand Down
72 changes: 57 additions & 15 deletions web/server/codechecker_server/api/mass_store_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,34 +993,76 @@ def __add_report_context(self, session, file_path_to_id):
for db_report, report in self.__added_reports:
LOG.debug("Storing bug path positions.")
for i, p in enumerate(report.bug_path_positions):
session.add(BugReportPoint(
p.range.start_line, p.range.start_col,
p.range.end_line, p.range.end_col,
i, file_path_to_id[p.file.path], db_report.id))
if not p:
LOG.error("Missing range at index: %s", i)
continue
if p.range:
session.add(BugReportPoint(
p.range.start_line, p.range.start_col,
p.range.end_line, p.range.end_col,
i, file_path_to_id[p.file.path], db_report.id))
elif hasattr(p, "line") and hasattr(p, "column"):
session.add(BugReportPoint(
p.line, p.column,
p.line, p.column,
i, file_path_to_id[p.file.path], db_report.id))
else:
LOG.error("Missing position info from range: %s", p)
continue

LOG.debug("Storing bug path events.")
for i, event in enumerate(report.bug_path_events):
session.add(BugPathEvent(
event.range.start_line, event.range.start_col,
event.range.end_line, event.range.end_col,
i, event.message, file_path_to_id[event.file.path],
db_report.id))
if not event:
LOG.error("Missing range at index: %s", i)
continue
if event.range:
session.add(BugPathEvent(
event.range.start_line, event.range.start_col,
event.range.end_line, event.range.end_col,
i, event.message, file_path_to_id[event.file.path],
db_report.id))
elif hasattr(event, "line") and hasattr(event, "column"):
session.add(BugPathEvent(
event.line, event.column,
event.line, event.column,
i, event.message, file_path_to_id[event.file.path],
db_report.id))
else:
LOG.error(
"Missing position info from range: %s", event
)
continue

LOG.debug("Storing notes.")
for note in report.notes:
data_type = report_extended_data_type_str(
ttypes.ExtendedReportDataType.NOTE)

session.add(ExtendedReportData(
note.range.start_line, note.range.start_col,
note.range.end_line, note.range.end_col,
note.message, file_path_to_id[note.file.path],
db_report.id, data_type))
if not note:
LOG.error("Missing range at index: %s", i)
continue
if note.range:
session.add(ExtendedReportData(
note.range.start_line, note.range.start_col,
note.range.end_line, note.range.end_col,
note.message, file_path_to_id[note.file.path],
db_report.id, data_type))
elif hasattr(note, "line") and hasattr(note, "column"):
session.add(ExtendedReportData(
note.line, note.column,
note.line, note.column,
note.message, file_path_to_id[note.file.path],
db_report.id, data_type))
else:
LOG.error("Missing position info from: %s", note)
continue

LOG.debug("Storing macro expansions.")
for macro in report.macro_expansions:
data_type = report_extended_data_type_str(
ttypes.ExtendedReportDataType.MACRO)
if macro and not macro.range:
LOG.error("Missing range from: %s", macro)
continue

session.add(ExtendedReportData(
macro.range.start_line, macro.range.start_col,
Expand Down
Loading