SonarOpenCommunity / sonar-cxx

SonarQube C++ Community plugin (cxx plugin): This plugin adds C++ support to SonarQube with the focus on integration of existing C++ tools.
GNU Lesser General Public License v3.0
993 stars 364 forks source link

Set `baseDir` explicitly for external analyser #2784

Open gennartan opened 1 day ago

gennartan commented 1 day ago

Is your feature request related to a problem? Please describe.

My project is built with the command make -C <subdir> .... When I run the scan-build command for external analyser with clang, it reports all the paths the in the plist file relative to the <subdir>. Then, when running the sonar scanner, it correctly parses the plist files, but is unable to find the files with reported errors. (*)

(*) The error shows "file /usr/src/lib/mylib.h not found" while the file is located at /usr/src/<subdir>/lib/mylib.h

Describe the solution you'd like

Add a parameter sonar.cxx.clangsa.baseDir to specify the base directory of the clang analysis. The ideal solution is probably not as simple as this, since it should be possible to add multiple reportPaths, it should also be possible to add multiple baseDir in case the current project is composed of multiple subdirectory to be analysed / build separately. And in this case, each baseDir should be linked to a reportPaths in some way.

Describe alternatives you've considered

Currently, I changed the sonar.projectBaseDir variable to match the base directory of the clang reports. But it is just a workaround as some of the files from my project root directory have now been excluded from the analysis.

guwirth commented 17 hours ago

Hi @gennartan,

thanks for your question.

First of all the documentation for the current functionality:

But I think you saw already the sonar.projectBaseDir option.

About your feature request:

It is relatively common to generate the report with external tools and possibly with different paths on other computers. So far, most customers patch the reports via scripts and replace the paths or parts of them. This is an extra step as part of the creation of the reports before they forward it to the SQ scanner.

We have already thought about it to support this as part of the plugin, but have not yet found a generic solution (or people told us, some line of Python are the easier solution). You have already described with baseDir that it can be quite complex and difficult in detail.

What is your opinion on this?

Regards,

guwirth commented 3 hours ago

Hi @gennartan,

a possible solution with XLST could be with fn:replace:

Never tried it, but maybe you can have a look …

Regards,