Analyzing a C/CPP project with make results in 0 compilation units analyzed

Hello, unfortunately during the running of the build for our custom Makefile based C project we ran into this issue (Jenkins):

13:24:45 INFO: Number of compilation units in the provided Compilation Database: 666
13:24:45 INFO: Number of skipped unsupported compilation units: 666
13:24:45 INFO: Number of skipped non-indexed compilation units: 0
13:24:45 INFO: Number of skipped duplicate compilation units: 0
13:24:45 INFO: Number of remaining compilation units to be analyzed: 0

We have other issues, but I would prefer not to share the compilation database in the message on the forum.

We are running the build on cygwin in this pattern:

cat <<EOF > build_for_sonar.sh
#!/bin/bash
set -e
make -j8 Nightly_build CONFIG=default -C cypress
EOF

chmod u+x build_for_sonar.sh

build-wrapper-win-x86-64.exe --out-dir bw-output bash build_for_sonar.sh

cat <<EOF > sonar-project.properties
sonar.inclusions=platform33/src/audio/ambackground.c, \
platform33/src/audio/ambridge.c, \
...cont...
EOF

sonar-scanner.bat \
  -Dsonar.organization=REDACTED\
  -Dsonar.projectKey=REDACTED \
  -Dsonar.sources=. \
  -Dsonar.cfamily.compile-commands=bw-output/compile_commands.json \
  -Dsonar.host.url=https://sonarcloud.io

I’m not sure if this means that the compiler is not recognized or something else?

This pattern works for other Makefile C projects we have in-house with sonarcloud.

Thanks!

Hey there.

I’ve opened up a private message where you can share more logs / the compdb.

Hello @mvidakovic_j, and thanks for sharing the files with us,

I had a look at the compilation database you shared, and I could notice the following:

  1. Most of the the entries that were compiled using C:\cygwin64\bin\gcc.exe\gcc.exe have the -MM flag specified (632 out of 653). This suggests that the captured command was used by the build system to query the dependencies of the file (most likely in order to determine whether it needs to be recompiled in an incremental build). Note that build-wrapper requires running on a clean build in order to generate a usable compilation database. Are you wrapping a “clean” build? Could try rerunning your build command under build-wrapper after deleting your build directory?
  2. Entries that are compiled using cl.exe (20 out of 653) are all .cpp files that are not listed in sonar.inclusions, and are therefore excluded from the analysis. Furthermore, there is another problem preventing the analyzer from determining the standard include paths for them:
    The "INCLUDE" environment variable was not found, make sure that you are running the analysis from the right environment. Skip analysis of files: ...
    
    If you wish to analyze these files, you need to add their patterns to sonar.inclusions first, and then I would recommend adjusting your build to add the /X flag to your cl.exe invocations if you are providing the standard include paths using the /I switches.

I hope this helps,

Best regards,
Michael

Update: Regarding 1, I opened a ticket to improve the logs in this case: [CPP-5568] - Jira