0

When I run sonar-scanner on C project, it analyzes my submodules, but it also includes a "parent" configuration. What I mean:

sonar-project.properties

sonar.host.url=<host>
sonar.login=<token>
sonar.projectKey=PROJECT1
sonar.qualitygate.wait=true
sonar.sourceEncoding=UTF-8
sonar.scm.provider=git
sonar.verbose=true

sonar.modules=module1,module2

sonar.language=C
# if I enable below 3 lines it won't crash
#sonar.sources=.
#sonar.cfamily.build-wrapper-output=code_coverage_results
#sonar.cfamily.gcov.reportsPath=code_coverage_results

module1.sonar.projectName=Module1
module1.sonar.projectBaseDir=./module1
module1.sonar.sources=src
module1.sonar.tests=tests
module1.sonar.cfamily.build-wrapper-output=../code_coverage_results
module1.sonar.cfamily.gcov.reportsPath=../code_coverage_results
module1.sonar.exclusions=**/*.py,src/http-parser/**,obj/**,bin/**

module2.sonar.projectName=Module2
module2.sonar.projectBaseDir=./module2
module2.sonar.sources=src
module2.sonar.tests=tests
module2.sonar.cfamily.build-wrapper-output=../code_coverage_results
module2.sonar.cfamily.gcov.reportsPath=../code_coverage_results

sonar.cfamily.threads=10
sonar.cfamily.cache.enabled=true
sonar.cfamily.cache.path=sonar.cfamily.cache
sonar.scm.exclusions.disabled=true

code_coverage_results is a common folder for both submodules, basically can be separated.

What I see when run sonar-scanner -X:

------------- Run sensors on module Module1
... <analyzing> ...

------------- Run sensors on module Module2
... <analyzing> ...

------------- Run sensors on module PROJECT1
17:39:47.092 INFO: Sensor CFamily [cpp]
17:39:47.093 INFO: CFamily plugin version: 6.32.0.44918
17:39:47.093 ERROR:

he only way to get an accurate analysis of C/C++/Objective-C files is by using the SonarSource build-wrapper and setting the property "sonar.cfamily.build-wrapper-output" or by using Clang Compilation Database and setting the property "sonar.cfamily.compile-commands". None of these two options were specified.

If you don't want to analyze C/C++/Objective-C files, then prevent them from being analyzed by setting the following properties:

    sonar.c.file.suffixes=-
    sonar.cpp.file.suffixes=-
    sonar.objc.file.suffixes=-


    at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:236)
    at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:186)
    at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:62)
    at org.sonar.scanner.scan.SpringModuleScanContainer.doAfterStart(SpringModuleScanContainer.java:81)
    at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
    at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
    at org.sonar.scanner.scan.SpringProjectScanContainer.scan(SpringProjectScanContainer.java:392)

When I uncomment the lines:

sonar.sources=.
sonar.cfamily.build-wrapper-output=code_coverage_results
sonar.cfamily.gcov.reportsPath=code_coverage_results

I am getting the error like:

File module2/src/Source.c can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files

That is why I have to put

sonar.exclusions=**

in the beginning.

The question is: why it tries to analyze three modules instead of two?

I have the next structure:

root folder
   Module1
   Module2
   CommonSources
   *.sh, *.py files
   sonar-project.properties

Thanks.

0 Answers0