SonarQube for IDE VS Code compile_commands.json rollout to a team

  • Operating system: Windows 10
  • SonarQube for VS Code plugin version: 4.15.0
  • Programming language you’re coding in: c
  • Is connected mode used:
    SonarQube Server: 9.9.5

Background: I have created a compile_commands.json file for our codebase using the build wrapper. The process isn’t tough, but there are concerns with the additional steps we would require everyone to do… my questions relate to the compile_commands.json and how it interacts with SonarQube for IDE for VS Code.

  1. How much information inside the compile_commands.json is needed? If we add new .c and .h files to the project, will we need to recompile using the build wrapper? Or does SonarQube for IDE for VS Code only need a single entry, assuming the compiler commands are the same for all files?

  2. Is there a way to rollout the compile_commands.json to a whole team. It seems like it uses absolute paths when being created, does this support relative pathing?

Hopefully I have given enough information, if not please let me know and I will be happy to explain in greater detail or provide additional information! Thanks in advance for the help.

Hi @dguy802 ,

Ideally, when you add a new file it would be better to regenerate the compilation database,
There are some heuristics and fallbacks to guess a file configuration, however, they are not documented and they may change between versions. The correct way is to have an entry for each file.++

It is not a good practice to roll out a compilation database to a project or an entire team; I would discourage this. Usually, the compilation database is dynamically generated; e.g., CMake can generate a compilation database for free during the configuration phase. Depending on your build system, it might be very easy to always have a fresh compilation database.

Thank you for the response Massimo!

That is good to know, through testing I saw that the SonarLint still worked when I removed all but a single file. As I had feared, there seems to be no guarantee that this will be the case between versions.

As for creating the compilation database… We use TI compilers, so it does not use Make or CMake, we also don’t have a good way of converting our projects into CMake projects and building through the TI compilers. Our current solution isn’t too elegant as we need to close the TI IDE then run the SonarQube build wrapper using commands to the TI compilers.

It looks like this is something we will just need to do, a good training/procedure document should do the trick if nothing else can be done to automate this.

Thanks again Massimo, I appreciate you for taking time to answer my questions.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.