Sonar Analysis of swift project failing

We are running an Azure DevOps YAML pipeline to gather code coverage on an iOS swift project. The SonarQubeAnalyze task consistently fails with the error

The only way to get an accurate analysis of C/C++/Objective-C files
 is by using the SonarSourcebuild-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.

Our configuration is

  • macOS 14.7.2 Azure hosted agent
  • Xcode 15.4
  • SonarQube Server: Server version: 9.9.6.92038
  • SonarQubePrepare@7 task
  • SonarQubeAnalyze@7 task
  • Xcode@5task

We have followed this document Coverage & Test Data Generate Reports for Swift
We have tried using the SonarQube generic coverage format xccov-to-sonarqube-generic.sh
and also xcpretty to generate a compilation database file compile_commands.json
Both methods fail the same way.

The buildwrapper method only works on macOS before version 13 and macOS 13.7.2 is the lowest available on Azure hosted agents.

Attaching the files

  • compile_commands.json
  • sonarqube-generic-coverage.xml had to upload with txt extension
  • soanrqubeanalysetasklog.txt

Hi,

The analysis is failing because it detects C / C++ or Objective-C code that it is unable to analyze.

You say you’re trying to analyze a Swift project, but you’ve provided a compile_commands.json file. Can you clarify the languages in your project that you want to analyze versus the full list of languages in your project?

To easily exclude CFamily languages, you can add the following properties to your analysis parameters:

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

 
HTH,
Ann

Hi Ann,

I will run as you suggest. Do these three properties go under extraProperties in the SonarQubePrepare task?

I will run the scripts/xccov-to-sonarqube-generic.sh to generate the sonarqube-generic-coverage.xml file and reference that file in the sonar.coverageReportPaths property

Hi,

Yes, add them as extraProperties.

 
HTH,
Ann

Hi Ann,

It worked. Two things had to be changed

  1. Add the extra properties you mentioned
  2. Have them properly formatted in the task
  3. run the xccov-to-sonarqube-generic.sh script

Now that it is running leads me to ask a second question.
In the project there are three different Test schemes.
How do we use the output from three different runs of the xcode task?
Is there a way to combine the three files into one for the analysis?

Thanks,
Kirk

Another thought.
Could we do the following.

Run SonarQubePrepare
Run xcode test test target 1
Run xccov-to-sonarqube-generic.sh
Run SonarQubeAnalyze
Run SonarQubePublish

Run xcode test test target 2
Run xccov-to-sonarqube-generic.sh
Run SonarQubeAnalyze
Run SonarQubePublish

Run xcode test test target 3
Run xccov-to-sonarqube-generic.sh
Run SonarQubeAnalyze
Run SonarQubePublish