Is vscode expected to work with official build-wrapper output?

  • Operating system: Ubuntu x86-64
  • SonarLint plugin version: 4.9.1
  • Programming language you’re coding in: c/c++
  • Is connected mode used: yes
    • Connected to SonarQube v10.5.1
  • build-wrapper, version 6.54 (linux-x86)
  • vscode 1.92.2

Hi,
I would like to ask you if SonarLint is expected to work with build-wrapper output? I downloaded build-wrapper from our SonarQube instance and SonarLint says it is malformed or wrong structure. It generates errors like this:

[Error - 15:39:39.202] Error executing sensor: 'CFamily'
[Error - 15:39:39.202] java.lang.IllegalStateException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 2 path $
	at com.sonar.cpp.plugin.CompileCommandsReader.readCaptures(CompileCommandsReader.java:77)
	at com.sonar.cpp.plugin.SonarLintSensor.fillCapturesMaps(SonarLintSensor.java:267)
	at com.sonar.cpp.plugin.SonarLintSensor.parseCompileCommands(SonarLintSensor.java:235)
...
[Error - 16:05:00.935] Error executing sensor: 'CFamily'
[Error - 16:05:00.935] java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
	at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:358)
	at com.sonar.cpp.plugin.CompileCommandsReader.readCaptures(CompileCommandsReader.java:67)
	at com.sonar.cpp.plugin.SonarLintSensor.fillCapturesMaps(SonarLintSensor.java:267)
	at com.sonar.cpp.plugin.SonarLintSensor.parseCompileCommands(SonarLintSensor.java:235)

I get these errors for perfectly valid json. Am I missing some setting in vscode which tells SonarLint which json format to expect? I was searching for this but found nothing :frowning: From the other side it works just fine with compile_commands.json generated by compiledb, which has slightly different structure.

Hi @bodzio131,

thanks for reaching out. In order to understand your problem better and fix it as fast as possible or for me to forward it to the CFamiliy and build-wrapper experts I’d like you to check and try a few things:

The first thing that came to mind is: Please check whether the output downloaded from SonarQube is in the UTF-8 encoding. It might be the case, that it is encoded with UTF-8 with BOM and in that case it must be converted to UTF-8.

Best,
Tobias

Hi Tobias,

Please, could you tell me more what to check and how? Then only manually downloaded content from SonarQube is /static/cpp/build-wrapper-linux-x86.zip. From the other side I enabled in vscode

    "sonarlint.output.showAnalyzerLogs": true,
    "sonarlint.output.showVerboseLogs": true,

but still I don’t see any info which could give answer for your question.

Kind regards,
Bogdan

Hey @bodzio131,

You downloaded the build wrapper executable (from /static/cpp/build-wrapper-linux-x86.zip). I guess you ran it on your project, and it created an output JSON file.
This very JSON file, if you open it in VSCODE itself, it will tell you in the bottom bar which encoding it has. This is the information I’m asking for; sorry if it wasn’t clear initially.

While you already enabled the analyzer and debug logs, would you be so kind to attach them to this thread as well, maybe they also feature additional information?

Best,
Tobias

OK, so build-wrapper-dump.json is UTF-8 (no BOM).

And here is output from vscode:
SonarLint_vscode.log (104.6 KB)

BTW, I see the attachment is visible/downloadable also for not logged in users. Is there an option to make it accessible only for logged in users, or better only for you? It is quite huge to make sure I don’t put there some sensitive info.

Hi @bodzio131,

I flagged this for my colleagues working on the C/C++ language analyzer. Please give them a bit of time to pick it up!

For the attachment, I don’t think that you could upload it to be only visible to us. In case it is confidential there is always the option to share it with us via DM.

Best,
Tobias

Hi @bodzio131, and thanks for sharing the problem with us,

which has slightly different structure.

You are right. These are two different JSON formats, and they are not meant to be interchangeable:

  1. build-wrapper-dump.json is an internal format that we use to store information collected during the build, and load it during analysis.
  2. The Compilation Database format, which has a public specification and was created by Clang. This format is nowadays popular among many C++ static analysis tools and build systems.

The good news is that starting with SonarQube 10.6, the build-wrapper-dump.json was deprecated and build-wrapper is now able to generate a compilation database that can be consumed by SonarLint. See the release notes here.

Once you upgrade your SonarQube instance to 10.6, and start using the newer version of build-wrapper, you should find a compile_commands.json file in the specified output directory. You can find the relevant docs here.

I hope this helps,

Best regards,
Michael

Hi Michael,
Thank you for your explanation. I must have messed something earlier with SonarLint, because I was convinced that it worked with build-wrapper output.
Thank you!

Hi @bodzio131,

You are right, build-wrapper is one of the suggested tools to generate a compilation database for SonarLint as per our docs.

For this to work, however, you need to use a more recent version of build-wrapper (SonarQube 10.6+) or download build-wrapper from SonarCloud instead (by following the download links in the linked docs). build-wrapper now generates both formats in its output directory…

I hope this clarifies,

Best regards,
Michael

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