Skip to content

Commit

Permalink
[gcc][fix] Find the correct sarif file location
Browse files Browse the repository at this point in the history
The wording in the [GCC
docs](https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Diagnostic-Message-Formatting-Options.html)
is a little confusing, it says

"The ‘sarif-stderr’ and ‘sarif-file’ formats both emit diagnostics in SARIF
Version 2.1.0 format, either to stderr, or to a file named source.sarif,
respectively."

I thought this will create a sarif file right next to the source file,
but in reality, the file is created in the `directory` field of the
compilation database file. This patch fixed this.
  • Loading branch information
Szelethus committed Nov 15, 2023
1 parent 482804c commit 5d709ba
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions analyzer/codechecker_analyzer/analyzers/gcc/result_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ def postprocess_result(self, skip_handlers: Optional[SkipListHandlers]):
into the database.
"""
LOG.debug_analyzer(self.analyzer_stdout)
gcc_output_file = self.analyzed_source_file + ".sarif"

# Gcc doesn't create any files when there are no diagnostics.
# Unfortunately, we can't tell whethet the file missing was because of
# that or some other error, we need to bail out here.
if not os.path.exists(gcc_output_file):
return
# GCC places sarif files to the "directory" entry found in the
# compilation database. As of writing this comment, there is no way to
# tell GCC to place is elsewhere, so we need to find it, move it and
# rename it.
file_name = os.path.basename(self.analyzed_source_file)
gcc_output_file = \
str(Path(self.buildaction.directory, file_name)) + ".sarif"

assert os.path.exists(gcc_output_file), \
"Faile to find the sarif file for GCC analysis!"

reports = report_file.get_reports(
gcc_output_file, self.checker_labels,
Expand Down

0 comments on commit 5d709ba

Please sign in to comment.