How to use SonarLint with CLion and Docker toolchain?

Dear Community,

My team is working on a C++ project using CMake and remote toolchain with Docker. I saw this was a problem in the past, but it looks resolved? [SLI-559] - Jira

I tried to find some tutorial how to configure, but no luck.

Our tech stack:

  • Operating system: Windows 10
  • IDE: CLion 2022.2.4
  • SonarLint plugin version: 7.3.0.59206
  • Programming language you’re coding in: C++
  • Is connected mode used: yes
    • Connected to SonarQube 9.8-developer

And a thorough description of the problem / question:
We don’t seem to be able to perform analysis, neither any linting works. Log:

Trigger: ACTION
[Action] 1 file(s) submitted
Configuring analysis with org.sonarlint.intellij.clion.CFamilyAnalysisConfigurator
Using connection 'XXX' for project 'iShuttle'
Analysing 'action_handler.cpp'...
Starting analysis with configuration:
[
  projectKey: iShuttle
  baseDir: C:\Users\XXX.XXX\Documents\sandbox\project
  extraProperties: {sonar.cfamily.build-wrapper-content={"version":0,"captures":[{"compiler":"clang","cwd":"C:\\Users\\XXX.XXX\\Documents\\sandbox\\project\\build_gcc_debug\\lib\\modes","executable":"C:\\usr\\local\\bin\\g++","properties":{},"cmd":["C:\\usr\\local\\bin\\g++","C:/Users/XXX.XXX/Documents/sandbox/project/lib/modes/action_handler.cpp","-DSPDLOG_COMPILED_LIB","-DSPDLOG_FMT_EXTERNAL","-I/tmp/project/lib","-I/tmp/project/lib/modes/..","-I/tmp/project/lib/devices/status/..","-I/tmp/project/lib/utilities/..","-I/tmp/project/lib/devices/positioning/..","-I/tmp/project/lib/modes/modes/../..","-I/tmp/project/lib/modes/base_messages/../..","-isystem/home/ishuttle/.conan/data/spdlog/1.10.0/_/_/package/0ad8763f0289ded6e39ff258ec01c35b1aac6aa2/include","-isystem/home/ishuttle/.conan/data/fmt/8.1.1/_/_/package/0d8b943d676dc202f180a2598d04457e173d7b97/include","-isystem/home/ishuttle/.conan/data/nlohmann_json/3.10.5/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include","-isystem/home/ishuttle/.conan/data/json-schema-validator/2.1.0/_/_/package/5d15cb4e1c0e30811cbae274fbd7768540582e39/include","-isystem/home/ishuttle/.conan/data/paho-mqtt-cpp/1.2.0/_/_/package/d46323b77a7340224238be213657da620d082b78/include","-isystem/home/ishuttle/.conan/data/paho-mqtt-c/1.3.9/_/_/package/3b9495adc0029d7352d25243dd239ab4c096decf/include","-isystem/home/ishuttle/.conan/data/openssl/3.0.3/_/_/package/043c934abae6e21b32744bfd049e4ec71d629d9e/include","-isystem/home/ishuttle/.conan/data/zlib/1.2.12/_/_/package/d13c97721d7bdc192ca6529684f2b79beeae8a7c/include","-g","-Werror","-Wall","-Wextra","-Wshadow","-Wno-missing-field-initializers","-Wnon-virtual-dtor","-Wold-style-cast","-Wcast-align","-Wunused","-Woverloaded-virtual","-Wpedantic","-Wconversion","-Wsign-conversion","-Wno-null-dereference","-Wdouble-promotion","-Wformat=2","-Wmisleading-indentation","-pedantic","-pedantic-errors","-Wswitch-enum","-Wfatal-errors","-Wswitch-default","-std=c++20","-Wshift-overflow","-fstack-protector-all","-fstack-protector-strong","-fomit-frame-pointer","-pthread","-Wno-maybe-uninitialized","-g3","-O0","-fmax-errors=1","-Wformat-overflow=2","-Wshift-overflow=2","-Wformat-truncation=2","-Wduplicated-cond","-Wduplicated-branches","-Wlogical-op","-Wuseless-cast","-Wno-stringop-overflow","-std=c++20"]}]}}
  moduleKey: Module: 'project'
  inputFiles: [
    file:///C:/Users/XXX.XXX/Documents/sandbox/project/lib/modes/action_handler.cpp (UTF-8) [cpp]
  ]
]

 

  * cpp: 418 active rules
Rule cpp:S6069 is enabled on the server, but not available in SonarLint
Rule cpp:S2612 is enabled on the server, but not available in SonarLint
Rule cpp:S5042 is enabled on the server, but not available in SonarLint
Rule cpp:S4790 is enabled on the server, but not available in SonarLint
Rule cpp:S5527 is enabled on the server, but not available in SonarLint
Rule cpp:S5443 is enabled on the server, but not available in SonarLint
Rule cpp:S5332 is enabled on the server, but not available in SonarLint
Rule cpp:S2068 is enabled on the server, but not available in SonarLint
Rule cpp:S5813 is enabled on the server, but not available in SonarLint
Rule cpp:S5814 is enabled on the server, but not available in SonarLint
Rule cpp:S5815 is enabled on the server, but not available in SonarLint
Rule cpp:S5816 is enabled on the server, but not available in SonarLint
Rule cpp:S5824 is enabled on the server, but not available in SonarLint
Rule cpp:S4830 is enabled on the server, but not available in SonarLint
Rule cpp:S1313 is enabled on the server, but not available in SonarLint
Rule cpp:S5801 is enabled on the server, but not available in SonarLint
Rule cpp:S5802 is enabled on the server, but not available in SonarLint
Rule cpp:S5982 is enabled on the server, but not available in SonarLint
Rule cpp:S2245 is enabled on the server, but not available in SonarLint
Rule cpp:S5849 is enabled on the server, but not available in SonarLint
  * c: 208 active rules
Rule c:S5801 is enabled on the server, but not available in SonarLint
Rule c:S5802 is enabled on the server, but not available in SonarLint
Rule c:S1313 is enabled on the server, but not available in SonarLint
Rule c:S4830 is enabled on the server, but not available in SonarLint
Rule c:S2612 is enabled on the server, but not available in SonarLint
Rule c:S5332 is enabled on the server, but not available in SonarLint
Rule c:S2068 is enabled on the server, but not available in SonarLint
Rule c:S5443 is enabled on the server, but not available in SonarLint
Rule c:S2245 is enabled on the server, but not available in SonarLint
Rule c:S5982 is enabled on the server, but not available in SonarLint
Rule c:S5527 is enabled on the server, but not available in SonarLint
Rule c:S6069 is enabled on the server, but not available in SonarLint
Rule c:S4790 is enabled on the server, but not available in SonarLint
Rule c:S5824 is enabled on the server, but not available in SonarLint
Rule c:S5816 is enabled on the server, but not available in SonarLint
Rule c:S5813 is enabled on the server, but not available in SonarLint
Rule c:S5814 is enabled on the server, but not available in SonarLint
Rule c:S5815 is enabled on the server, but not available in SonarLint
Rule c:S5849 is enabled on the server, but not available in SonarLint
Rule c:S5042 is enabled on the server, but not available in SonarLint
Start analysis
Index files
Language of file 'file:///C:/Users/XXX.XXX/Documents/sandbox/project/lib/modes/action_handler.cpp' is set to 'C++'
1 file indexed
Execute Sensor: CFamily
Probing compiler: [C:\usr\local\bin\g++, -x, c++, --std, c++20, -v, -dM, -E, -]
stdout:

 

stderr:

 

Invalid probe found, skip analysis of files: [C:/Users/XXX.XXX/Documents/sandbox/project/lib/modes/action_handler.cpp]
The compiler probe 'stdout' is expected to contain at least one '#define' directive:

 

Subprocess(es) done in 50ms
0 compilation units analyzed
Execute Sensor: Sonar Secrets Detection Sensor
Done in 67ms

 

Processed 0 issues
Found 0 issues

My assumption is - it cannot find our compilers through Docker toolchain? Is it not supported yet, we didn’t configure something right or we’re doing something wrong? What info did I miss?

Similar issues I’ve found here were related to SonarScanner and misconfiguration on the CLI / Wrapper side, but we just wanna use SonarLint here :woman_shrugging:

For the context - we have a SonarScanner CLI with wrapper running in the CI environment (GitLab) with no issues.

Thanks in advance!
Paula

Hi @paula.kokic.bhs,

Just to be clear, are you referring to this CLion feature? Can you confirm if it is a local docker container?

We usually probe the compiler to get some information about it,
Here we are calling
C:\usr\local\bin\g++ -x c++ --stdc++20 -v -dM -E -

but we aren’t getting any output or error.
Do you confirm that when running the command?
your docker container is running Linux right?
Can you try to run the same command from the docker container?

Note that the ticket that you linked to is about remote toolchains and WSL. The story with local docker (if I guessed right) is a bit different.

Once you answer all these questions, we will see if we need a ticket and figure out if there is a workaround.

Thanks,

Hi Abbas,

Exactly. And I can confirm we have a local docker container running (we have CMake configured and all the builds and tests can be run through CLion but inside a docker container).

Yes, I can also confirm we don’t get any output when running the command. However, we do get an error in a form of a Message Box window (Windows complaining). We don’t have gcc installed on the host, so I don’t even expect that to work, but SonarLint to execute commands inside the docker container. But I’m not sure how should this be configured or should it be automatically detected?

Correct. Image is based on official gcc:12.2-bullseye image. We actually use exactly the same one in the CI to analyze with SonarCLI using build wrapper.

Sure:

root@d3c4bb7c5466:/home/ishuttle#  /usr/local/bin/g++ -x c++ --stdc++20 -v -dM -E -
Using built-in specs.
COLLECT_GCC=/usr/local/bin/g++
g++: error: unrecognized command-line option '--stdc++20'
Target: x86_64-linux-gnu
Configured with: /usr/src/gcc/configure --build=x86_64-linux-gnu --disable-multilib --enable-languages=c,c++,fortran,go
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.2.0 (GCC)
root@d3c4bb7c5466:/home/ishuttle#

Am I missing something? What should be the next steps?

Thank you very much for your effort!
Paula

Hi @paula.kokic.bhs,

Sorry I had a typo in the command; it should be --std c++20 separated by a space.

In short, the ticket you linked supports remote toolchains and WSL. Docker toolchain with Window host and Linux container isn’t. I created this ticket: [CPP-4039] - Jira

Do you have any users on Linux with a similar workflow? This would help confirm my guess that the problem is only when the host and container have different OS.

Until we fix the ticket, there is no nice workaround. We expect the output you would get when you execute the command (without the typo) in the container. That is all we need from C:\usr\local\bin\g++
If this is a blocker, you can try hacking around the issue by adding a custom-made executable in that directory with the same name that prints to the output and error streams the same way the real compiler does and works on the host.

Note: the workflow of SonarLint with Clion is different from the CI with build-wrapper. The fact that the workflow is supported on the CI doesn’t entail that it is supported in CLion.

Thanks,

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