Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sonar.cxx.jsonCompilationDatabase not working? #1304

Closed
sweetim opened this issue Nov 15, 2017 · 8 comments
Closed

sonar.cxx.jsonCompilationDatabase not working? #1304

sweetim opened this issue Nov 15, 2017 · 8 comments
Assignees
Labels
Milestone

Comments

@sweetim
Copy link

sweetim commented Nov 15, 2017

I am currently using Sonar cxx v0.9.8
I found that the sonar.cxx.jsonCompilationDatabase config is not working?
When i run the sonar-scanner it still complains about

  • cannot find the sources for '#include <iostream>

The compile_commands.json file

[
{
  "directory": "/home/tim/Desktop/learn/multi-cmake/build/cmake-test/src",
  "command": "/usr/bin/c++  -DIS_TESTING=\"\\\"this is macro\\\"\" -DMACRO_VERSION=2.13 -I/home/tim/Desktop/learn/multi-cmake/cmake-test/lib  -std=c++11   -o CMakeFiles/hello.dir/main.cpp.o -c /home/tim/Desktop/learn/multi-cmake/cmake-test/src/main.cpp",
  "file": "/home/tim/Desktop/learn/multi-cmake/cmake-test/src/main.cpp"
}
]

May I know do I still need to configure the sonar.cxx.includeDirectories or the jsonCompilationDatabase should handle all these automatically?

@guwirth
Copy link
Collaborator

guwirth commented Nov 15, 2017

@sweetim I'm not really familiar with this feature. Maybe you can turn debug info on to get more help (https://github.com/SonarOpenCommunity/sonar-cxx/wiki/Get-debug-information). As far as I know the -I parameters are used to create the sonar.cxx.includeDirectories. Or maybe it's #1215?

@guwirth guwirth added this to the 0.9.8 milestone Nov 15, 2017
@sweetim
Copy link
Author

sweetim commented Nov 16, 2017

Yes, it is related to it, anyway to fix it?

I try to include those directories with sonar.cxx.includeDirectories but I found that it will get overridden by sonar.cxx.jsonCompilationDatabase

@jmecosta
Copy link
Member

jmecosta commented Nov 16, 2017

@sweetim https://github.com/SonarOpenCommunity/sonar-cxx/blob/master/cxx-sensors/src/test/resources/org/sonar/cxx/sensors/json-compilation-database-project/compile_commands.json check that file for the format of that should be expected.

#include iostream

is a system header so you will need to use

	"_comment_" : "example extension to define global defines and includes for headers and for files which are not compiled",
	"file" : "__global__",
	"defines" : {
		"GLOBAL_DEFINE" : "1"
		},
	"includes" : [
		"/usr/include"
		]

in start of the db to pass the system directories

@guwirth
Copy link
Collaborator

guwirth commented Nov 17, 2017

@guwirth
Copy link
Collaborator

guwirth commented Nov 17, 2017

@vesajaaskelainen is this __global__ something cxx plugin specific or part of the JSON compilation database definition?

@vesajaaskelainen
Copy link
Contributor

@guwirth extension to JSON compilation database only used(?) in cxx plugin. This is a workaround as cxx plugin does not use "compilation process" for header analysis so that it could capture different definition/include sets when analyzing headers. Now this global definition is used for more or less for all headers.

@guwirth
Copy link
Collaborator

guwirth commented Nov 20, 2017

@vesajaaskelainen thanks for your answer. We already discussed here in the past a solution to set system include files and local include files with different configuration properties. One solution could be to define one more property beside sonar.cxx.includeDirectories for system includes, e.g. sonar.cxx.systemIncludeDirectories. JSON compilation database would change then only sonar.cxx.includeDirectories and __global__ only sonar.cxx.systemIncludeDirectories. Optional they could also be defined in the configuration file then.

@vesajaaskelainen
Copy link
Contributor

vesajaaskelainen commented Nov 20, 2017

What we do with Klocwork is to use it capture build process as it scans for both user provided command line options (what is now in JSON compilation database example above) and also compiler internal defines and includes. Latter is needed to get proper analysis done, usually in command line there isn't many settings (at least in our cases). When we have those settings then we will utilize other extension that uses defines and includes instead of command line part. With this information we get decent analysis from cxx-plugin.

What we do for __global__ is composite of all defines and includes from all files.

We is problem still in out system is that it does not differentiate with system vs. user includes they are just combined in defines/includes fields.

Problem with sonar.cxx.systemIncludeDirectories and matching setting for defines is that there are lots of options there.

Also another problem with if one would make __system__ or __common__ is what tool is used to fill the info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants