Can we use incremental builds for SonarQube analysis on c++ projects

I am using latest LTS SonarQube version.

I have read in some threads that full build (clean build) is required for SonarQube analysis to give consistence results.

If I have do full build on the c++ project with SonarQube analysis and generate a cache which can be used for subsequent builds. Can my subsequent build be incremental build and use the cache that was generated during full build? Is this a good approach and give me consistent result?

1 Like

Welcome to the @Sumedh.Bhogle,

Regarding your first question:

This is indeed the requirement. The process here is that we observe the build process to collect what files are built as part of the project and more importantly what compiler and compiler flags are used for each project. Performing full-build guarantees that we will collect info and thus analyze all files in the project. If an incremental/partial build would be performed, we will thread other files as they are no longer part of the project.

Now for your actual question:

The answer is different for the incremental build and using the cache:

  • Incremental build (not all files are compiled) will not give consistent results due to the reason described above
  • Using object cache from the previous build (like ccache) when performing full build (not incremental) is ok.

It is worth mentioning, that we have recently introduced support for the compilation database. In a situation when you are able to generate a compilation database without building the project (e.g. using cmake, but there are other options), you can use it to avoid building the project before performing analysis. Please note that the compilation database includes absolute paths to compiler binary and sources, so it needs to be generated on the machine where the project is analyzed.