Sonar.cfamily.build-wrapper-output

I’m running code analysis on Swift project on SonarCloud and it was all working fine until few days back where I’m running into this error:

**ERROR: Error during SonarQube Scanner execution**
**java.lang.UnsupportedOperationException: 'sonar.cfamily.build-wrapper-output' is mandatory**
**at com.sonar.cpp.plugin.R.A(na:1573)**
**at java.util.Optional.orElseThrow(Optional.java:290)**
**at com.sonar.cpp.plugin.R.execute(na:1573)**
**at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:45)**
**at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:88)**
**at org.sonar.scanner.phases.SensorsExecutor.lambda$execute$1(SensorsExecutor.java:65)**
**at org.sonar.scanner.phases.SensorsExecutor.withGlobalStrategy(SensorsExecutor.java:80)**
**at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:65)**
**at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:74)**
**at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:164)**
**at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)**
**at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)**
**at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:319)** 

I’ve tried bypassing the wrapper by setting ‘sonar.cfamily.build-wrapper-output.bypass=true’ in project.properties file.
I’ve also excluded all the .c, .cpp, .java, and some other c related files.

How can I just bypass this issue? I only want to run analysis on .swift files.

Hello Nikhil,

You are using the 6.0 version of the CFamily analyzer, that no longer allows you to bypass the build wrapper (it was creating too many issues). So if you want to analyze C, C++ or objective-C code, you have to setup your environment so that you run the build wrapper and then use its output.

If you are only interested in Swift code, the way to go is to exclude source code from the other languages, as you already started to do. You are listing some extensions used by the CFamily analyzer, but not .h (headers) or .m (objective-C). Another option would be to use sonar.inclusions instead of sonar.exclusions to list only the extensions associated with Swift.

There is another option, that might be easier to use if you need inclusions/exclusions for another purpose: Each language has a list of file suffixes it uses to recognize its source files. So you could set those suffixes to values that do not appear in your codebase:

sonar.c.file.suffixes=disable_this_analysis
sonar.cpp.file.suffixes=disable_this_analysis_too
sonar.objc.file.suffixes=and_disable_this_to_totally_disable_cfamily

And current message

is going to be improved to reflect what @JolyLoic explained - [CPP-2062] - Jira

Thank you @JolyLoic! I forgot to exclude .objc files which was causing the issue. All good now.

@JolyLoic I was wrong. When I included only the .swift in sonar.inclusions, there were 0 files analyzed because swift classes depend on libraries which have .c, .cpp, .m, .h and other CFamily files.

Now I am back to the same error! How do I fix this?

I use SonarCloud and I run my builds on a Mac.

@nboin123 Initially you said

if you don’t want to analyze C/C++/Objective-C files and don’t want to see them in SonarQube, then as was already said before, you can exclude them by setting

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

or if you want to analyze and see only Swift files in SonarQube, then indeed you can include only them by setting

sonar.inclusions=**/*.swift

In both cases the fact that Swift classes depend on C/C++/Objective-C libraries won’t bother Swift analyzer.

If you want to analyze C/C++/Objective-C files in SonarQube, then you must set sonar.cfamily.build-wrapper-output and so must use build-wrapper - please carefully read https://docs.sonarqube.org/display/PLUG/Building+on+Mac+OS+X

Given the information so far provided by you, the above list is IMO exhaustive. So if it doesn’t help, then please be far more precise about what you want, what you have, what exactly you do and how? If the project is Open Source, then the simplest way will be just to show us a link on it. If not, then IMO simplest way will be to demonstrate your difficulties on “hello world” example that you’ll be able to share.

1 Like