Skip to content

[cmd] parse extends sarif output with extra fields - #4925

Merged
barnabasdomozi merged 4 commits into
Ericsson:masterfrom
andyg319:sarif-extra-fields
Aug 26, 2026
Merged

[cmd] parse extends sarif output with extra fields#4925
barnabasdomozi merged 4 commits into
Ericsson:masterfrom
andyg319:sarif-extra-fields

Conversation

@andyg319

Copy link
Copy Markdown
Collaborator

There are a few fields in the SARIF specification which would be meaningful to be filled out, but today are not generated into the exported files.

  • CodeChecker parse already populates Report objects with review status information, but currently only JSON export makes use of it. This PR adds suppression objects to individual results in the SARIF file, according to the spec, including suppression source (source code comment or review config file) and justification message.
    location.physicalLocation may be added in a follow-up PR.

  • SARIF rules[] (~checkers) are extended with defaultConfiguration.level and helpUri fields (spec), corresponding to the severity and doc_url checker labels in CodeChecker config.
    Note that this only applies to the CodeChecker parse command at the moment, which has the analyzer context (including a CheckerLabel object) readily available. Doing the same for the standalone report-converter is an orthogonal task, and might entail bigger refactorings.

@andyg319
andyg319 requested review from bruntib and vodorok as code owners June 26, 2026 10:23
@andyg319
andyg319 marked this pull request as draft June 29, 2026 11:09
@andyg319
andyg319 force-pushed the sarif-extra-fields branch 3 times, most recently from 8d36e16 to e3ec728 Compare June 29, 2026 14:34
@andyg319
andyg319 marked this pull request as ready for review June 29, 2026 16:29

@dkrupp dkrupp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation works nicely, Please check my comments related to the default filters.

self.__log_and_analyze()

parse_sarif_cmd = [self._codechecker_cmd, "parse", self.report_dir,
"-e", "sarif", "--review-status", "false_positive"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sarif export I think the convenient default would be to export everything into sarif and not just the ['confirmed', 'unreviewed'] reports. For standard command line outptut and possible from html, the current default is meaningful (you dont want to see dismissed reports).

Can you please add a filter option "everything" and make that as the default for sarif export?
This way the users would not need to list all review status possibilities at command line invocation if they want to export everything.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be fixed in a followup TR

@dkrupp
dkrupp self-requested a review August 5, 2026 10:20

@dkrupp dkrupp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@barnabasdomozi barnabasdomozi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests cases were not executed for some reason. Can you try force pushing a commit that would trigger the CI?

a.o: a.cpp
$(CXX) -c a.cpp -o /dev/null

clean:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clean target is pointless. On the line above, the output of the compilation is sent to /dev/null.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

analyzer/tests/functional/parse_status does the same, let's patch them together if we think this extra foolproofness is not necessary.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shouldn't commit code to the repository that would be eventually removed anyway.
Cleaning up analyzer/tests/functional/parse_status should be a separate task, unreleated to this change.


severity = checker_labels.severity(
checker_name,
report.analyzer_name) # type: ignore[call-arg]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of ignoring type warnings, the current type stub should be updated in file tools/report-converter/codechecker_report_converter/report/checker_labels.py.

@andyg319 andyg319 Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding an Optional parameter to the stub does not satisfy mypy for some reason. It errors with "Too many|few arguments" either way. Note that the other method in the stub has the same problem in the first place, but label_of_checker is called with the same number of arguments everywhere (when typed with this stub at least), so the problem has not surfaced yet (if you try it, mypy complains right away).

@andyg319 andyg319 Aug 24, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that you cannot specify the default None value for Optional arguments in type hints, and therefore this was an incorrect stub for the actual CheckerLabels implementation in codechecker_common. The only solution seems to be to provide placeholder implementations for the methods, instead of mere Callable hints.

build_json = os.path.join(self.test_workspace, "build.json")

clean_cmd = ["make", "clean"]
out = subprocess.check_output(clean_cmd,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, why not reuse the existing __run_cmd function?

if process.returncode != (2 if "parse" in cmd else 0):
return err

return ''.join(out)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out is already a string, consider:

Suggested change
return ''.join(out)
return out

a.o: a.cpp
$(CXX) -c a.cpp -o /dev/null

clean:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shouldn't commit code to the repository that would be eventually removed anyway.
Cleaning up analyzer/tests/functional/parse_status should be a separate task, unreleated to this change.

@dkrupp dkrupp added this to the release 6.29.0 milestone Aug 19, 2026
@barnabasdomozi
barnabasdomozi self-requested a review August 19, 2026 11:10

@barnabasdomozi barnabasdomozi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, some of the test cases are failing in the CI.

@andyg319
andyg319 force-pushed the sarif-extra-fields branch 2 times, most recently from 0d1620c to 0474abd Compare August 24, 2026 18:06
@andyg319
andyg319 force-pushed the sarif-extra-fields branch 3 times, most recently from 331259f to fc2c5dd Compare August 25, 2026 13:33
@andyg319
andyg319 force-pushed the sarif-extra-fields branch from fc2c5dd to a2de619 Compare August 25, 2026 13:37
@andyg319
andyg319 removed the request for review from gulyasgergely902 August 25, 2026 13:47
@andyg319
andyg319 force-pushed the sarif-extra-fields branch from a2de619 to cb88192 Compare August 25, 2026 13:56
@barnabasdomozi

Copy link
Copy Markdown
Collaborator

Please rebase to master, the linter error is already fixed on it.

@andyg319
andyg319 force-pushed the sarif-extra-fields branch from cb88192 to d07c26a Compare August 25, 2026 19:06
@andyg319

Copy link
Copy Markdown
Collaborator Author

Please rebase to master, the linter error is already fixed on it.

Still not okay.

@barnabasdomozi

Copy link
Copy Markdown
Collaborator

@andyg319 I believe its fixed now. Try to rebase again.

@andyg319
andyg319 force-pushed the sarif-extra-fields branch from d07c26a to 7af842b Compare August 26, 2026 12:06

@barnabasdomozi barnabasdomozi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@barnabasdomozi
barnabasdomozi merged commit fd4a63c into Ericsson:master Aug 26, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants