How to get build-wrapper/sonar-scanner to work with sub-makefiles

I am using 8.6.1. And I am trying to run build-wrapper on a project that has a toplevel Makefile, and which calls multiple subdirectories makefiles. build-wrapper isn’t capturing the correct path relative to code root, and sonar-scanner isn’t working. I would like to avoid having to modify the subdirectory makefiles if at all possible. How can I do this?


In makefile:
make -C subdir1
make -C subdir2

Hi @ForceConstant ,

please write how you are using build-wrapper and invoking sonar-scanner.

It should be as easy as:

cd toproot
build-wrapper --out-dir cfamily-output make clean all
sonar-scanner -Dsonar.sources=. -D......

yes my build-wrapper and sonar-scanner commands look the same. But I end up getting the error below. If I look at sonar_output/build-wrapper-dump.json, the paths are not correct. For example to add to the above drawing, I see stuff like “src/app1.cpp”, instead of “subdir1/src/app1.cpp” which I think is the problem.


java.lang.IllegalStateException: The “build-wrapper-dump.json” file was found but 0 C/C++/Objective-C files were analyzed. Please make sure that:

  • you are using the latest version of the build-wrapper and the CFamily analyzer
  • you are correctly invoking the scanner with correct configuration
  • your compiler is supported
  • you are wrapping your build correctly
  • you are wrapping a full/clean build
  • you are providing the path to the correct build-wrapper output directory
  • you are building and analyzing the same source checkout, absolute paths must be identical in build and analysis steps

Hi @ForceConstant ,

you should take into the consideration the cwd too. Would you be able to share the build-wrapper output folder, the tree list of your folder, and the entire sonar-scanner output log? I can send you a PM if you prefer to share privately.

Sorry for the delay as I was out of town. I was able to try to make a smaller build environment to help debug this, and I don’t think it is the subdir’s that is the issue, as it must be something with the legacy build files I am using for this project. Because I created 2 simple subdir’s builds and sonarqube does find it, but doesn’t find liblegacy correctly. Attached is the output log. So if you could see what is wrong with the liblegacy (20.3 KB)

include  Makefile  Makefiles   src  

c-test.h  test.hpp   u_messaging.h  u_simple_tasks.h  


c-test.c  test.cpp  u_messaging.cpp  u_simple_tasks.cpp

Makefile  src  test1


Makefile  src  test2


Hi @ForceConstant ,

I can see all correct compiler invocations, for all the files you listed. I believe you are creating a problem from something which is not a problem and a simple and common use case.

Yes but in the end in the analysis that gets sent to sonarqube, and view the code analyzed only the 2 subdirs/src/main.cpp show up, and none of the liblegacy/src/*.cpp files.

I do see this in my sonar-scanner output:

INFO: Indexing files...
INFO: Project configuration:
INFO:   Included sources: **/*.h, **/*.cpp, **/*.hpp, **/*.c
INFO:   Excluded sources: **/*.js
INFO: 2 files indexed
INFO: 418 files ignored because of inclusion/exclusion patterns
INFO: 14 files ignored because of scm ignore settings

Hi @ForceConstant ,

this has nothing to do with the build-wrapper. This has to do with the sonar-scanner invocation working directory, the sonar.sources, the sonar.inclusions property, the sonar.exclusions property and the scm ignore property.

Ok to be clear on my problem, in this example why isn’t a file like ./liblegacy/src/u_messaging.cpp being submitted to sonarqube, whereas ./subdir1/src/main.cpp is?

Hi @ForceConstant ,

please share the entire sonar-scanner output log with sonar.verbose=true property specified.

Ok now I see these incriminating lines, and I did check that it is not covered by a .gitignore file, but it is inside a git submodule, so I wonder if this is confusing scanner?

11:17:41.496 DEBUG: File ‘/mnt/sonar_test/liblegacy/include/u_messaging.h’ is excluded by the scm ignore settings.

sonar-scanner.txt (65.9 KB)

Hi @ForceConstant ,

you can disable that automatic exclusions using sonar.scm.exclusions.disabled property, see Analysis Parameters | SonarQube Docs.