SonarLint failure due to `Ignore unknown compiler`

Dear Sonar Lint Team,

I’m struggling to get SonarLint running for my C++ project. We use SonarCloud to improve our code base and the analysis with the build wrappers works like a charm. I’m trying to get SonarLint running such that I can avoid triggering the entire CI before fixing all code smells and so forth. I installed the plugin and it does find the compile commands. However, when I open new files I don’t get any feedback from sonar lint. I turned on the debugging output and it shows the following

[Debug - 10:30:46.619] Start analysis

[Info - 10:30:46.622] Index files

[Debug - 10:30:46.623] Language of file 'file:///Users/tobias/tmp/biodynamo/src/core/diffusion/euler_depletion_grid.cc' is set to 'C++'

[Info - 10:30:46.623] 1 file indexed

[Debug - 10:30:46.644] 'JavaSensor' skipped because there is no related files in the current project

[Debug - 10:30:46.644] Execute Sensor: CFamily

[Debug - 10:30:46.702] Cached compilation database content did not change

[Debug - 10:30:46.702] Time to parse Compilation Database: 46ms

[Info - 10:30:46.702] Ignore unknown compiler: /opt/homebrew/bin/mpicxx -DUSE_DICT -DUSE_MPI -DUSE_PARAVIEW -D_LIBCPP_NO_EXPERIMENTAL_DEPRECATION_WARNING_FILESYSTEM -Dbiodynamo_EXPORTS -I/opt/homebrew/Cellar/open-mpi/4.1.4_2/include -I/Users/tobias/tmp/biodynamo/build/third_party/paraview/include/paraview-5.10 -I/Users/tobias/tmp/biodynamo/build/optim-prefix/src/optim/include -I/Users/tobias/tmp/biodynamo/build/third_party/root/include -I/Users/tobias/tmp/biodynamo/src -I/Users/tobias/tmp/biodynamo/test -I/Users/tobias/tmp/biodynamo/third_party -I/Users/tobias/tmp/biodynamo/third_party/omp -I/Users/tobias/tmp/biodynamo/third_party/opencl -I/Users/tobias/tmp/biodynamo/third_party/unibn -I/Users/tobias/tmp/biodynamo/third_party/nanoflann -I/Users/tobias/tmp/biodynamo/third_party/cxxopts-v2.2.1 -I/Users/tobias/tmp/biodynamo/build/extracted-third-party-libs -I/Users/tobias/tmp/biodynamo/build/version -I/Users/tobias/tmp/biodynamo/build/omp -I/Users/tobias/tmp/biodynamo/build/opencl -I/Users/tobias/tmp/biodynamo/build/gtest/src/gtest/googletest/include -isystem /opt/homebrew/opt/libomp/include -Wall -Wno-missing-braces -m64 -fPIC -Xclang -fopenmp -Wno-undefined-var-template -g -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk -mmacosx-version-min=12.6 -fPIC -fvisibility-inlines-hidden -Xclang -fopenmp -std=c++14 -o CMakeFiles/biodynamo.dir/src/core/diffusion/euler_depletion_grid.cc.o -c /Users/tobias/tmp/biodynamo/src/core/diffusion/euler_depletion_grid.cc

[Info - 10:30:46.703] Subprocess(es) done in 57ms

[Info - 10:30:46.703] 0 compilation units analyzed

[Debug - 10:30:46.703] 'Python Sensor' skipped because there is no related files in the current project

[Debug - 10:30:46.703] Execute Sensor: HTML

[Debug - 10:30:46.703] 'XML Sensor' skipped because there is no related files in the current project

[Debug - 10:30:46.704] 'PHP sensor' skipped because there is no related files in the current project

[Debug - 10:30:46.704] 'Analyzer for "php.ini" files' skipped because there is no related files in the current project

[Debug - 10:30:46.704] Execute Sensor: Sonar Secrets Detection Sensor

[Info - 10:30:46.752] Found 0 issues

The failed analysis must be related to [Info - 10:30:46.702] Ignore unknown compiler but I have no idea how to bypass that. I’d be very grateful about any suggestions on how to get it running.

Thank you very much! :slight_smile:

Best,
Tobias

Hard facts:

  • Operating system: macOS 12.6.1
  • SonarLint plugin version: v3.13.0
  • Programming language you’re coding in: C++
  • Is connected mode used: No

Hi @TobiasDuswald ,

the reason why it works with build-wrapper is that build-wrapper is catching the real compiler invocation and using it to configure the analysis.

In SonarLint you are currently pointing to a generated Compilation Database which contains mpicxx calls, which is not a compiler wrapper we support. From what I understand mpicxx is a compiler wrapper used to properly configure the linking part.

How are you currently generating the Compilation Database? You could try to do the following:

  • either modify the Compilation Database generation to point to a real compiler instead of mpicxx
  • or manually post-modifying the Compilation Database by replacing /opt/homebrew/bin/mpicxx with the absolute path to the real compiler

Thanks for the quick reply. I’m not very familiar with compiler wrappers and how they are organized in the operating system. But first things first, if I replace the /opt/homebrew/bin/mpicxx occurrences in the compile commands with clang++, SonarLint starts to work, and I get the suggestions I would have expected. That’s great!

The solution is a big hacky, but I’ll be able to get the SonarLint suggestions which is the important point. If I understand correctly, /opt/homebrew/bin/mpicxx is a symlink that at some point calls back to the regular apple compiler via something called opal_wrapper. I suppose this is the compiler wrapper that SonarLint does not yet support, isn’t it?

> ls -lR /opt/homebrew/bin | grep mpicxx                                                                             ─╯
lrwxr-xr-x  1 tobias  admin    37 Nov 23 10:53 mpicxx -> ../Cellar/open-mpi/4.1.4_2/bin/mpicxx

> ls -lR /opt/homebrew/Cellar/open-mpi/4.1.4_2/bin | grep mpicxx
lrwxr-xr-x  1 tobias  admin      12 May 26  2022 mpicxx -> opal_wrapper

> /opt/homebrew/bin/mpicxx --version                                                                                 ─╯
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

So if you say Sonar does not yet support this compiler wrapper, it means that SonarLint cannot resolve how to get from /opt/homebrew/bin/mpicxx to the Apple Clang 14.0.0, correct? Consequently, I need to figure out how to tell the Cmake build system how to write down the actual compiler instead of /opt/homebrew/bin/mpicxx.

Hi @TobiasDuswald ,

:+1:

Yes, this is correct! You should be able to see how to achieve that by looking at the CMakeLists.txt.

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