0

I got an error when using SonarQube > SonarSwift plugin when trying to push the coverage report to SonarQube server. I generated the report using Xcode command line:

xcodebuild test -enableCodeCoverage YES -scheme iOS_Template -workspace iOS_Template.xcworkspace -destination 'platform=iOS Simulator,name=iPhone X'

And when I run sonar-scanner to scan the codes and upload the report I got the following error:

 INFO: Parse coverage report
(DerivedData/iOS_Template/Build/ProfileData/DDA1A82C-EB41-4E45-8DCF-428D3E879067/Coverage.profdata)
 ERROR: Can't parse coverage report file
 (DerivedData/iOS_Template/Build/ProfileData/DDA1A82C-EB41-4E45-8DCF-428D3E879067/Coverage.profdata).
 No coverage information will be saved.
 java.lang.IllegalStateException: Can not parse line: HƢ�F
 _T0SS17iOS_TemplateTestsE11isValidatedSbAA10ValidationO10validation_tF�.�������k(_T09Alamofire12TaskDelegateC10urlSessionySo10URLSessionC_So0fB0C4taskySo11InputStreamCSgc011needNewBodyI0t3��6K�2@_T09Alamofire14SessionManagerC5retrySbAA7RequestC383��J��Z8_T09Alamofire7AFErrorO31ResponseValidationFailureReasonO22acceptableContentTypesSaySSGSgf6(��W��N

[...similar set of unknown characters...] 

at com.sonar.swift.plugin.B.A(Unknown Source)
at com.sonar.swift.plugin.B.A(Unknown Source)
at java.util.Optional.ifPresent(Optional.java:159)
at com.sonar.swift.plugin.B.A(Unknown Source)
at com.sonar.swift.plugin.B.A(Unknown Source)
at com.sonar.swift.plugin.B.A(Unknown Source)
at com.sonar.swift.plugin.D.A(Unknown Source)
at com.sonar.swift.plugin.D.execute(Unknown Source)
at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)
.....

I checked the Sonarswift plugin and it looks no clue on supporting XCode9+ (my Xcode Version is Xcode 9.2) and wonder if it caused the exception

WilsonL
  • 167
  • 1
  • 2
  • 10

2 Answers2

0

Have a look at this SonarQube documentation page. You have to translate the output before sending it to SonarQube:

xcodebuild -scheme <schemeName> -enableCodeCoverage YES -derivedDataPath . clean build test
xcrun llvm-cov show -instr-profile=Build/Intermediates/CodeCoverage/Coverage.profdata <path to instrumented executable> > <coverage report file>

Also check your sonar.swift.coverage.reportPath setting. The documentation also has a link to an example project.

Jeroen Heier
  • 3,520
  • 15
  • 31
  • 32
  • The output generated from xcodebuild is already the report format (.profdata) while the second command is only for displaying the report in console.... So I wonder if SonarSwift plugin support .profdata format or it needs to translate for other formats (which the documents didnt mention) – WilsonL Feb 01 '18 at 07:48
0

It turns out to be solved by adding a command to 'generate' a coverage report file for SonarSwift to load. The command is xcrun llvm-cov show -instr-profile

WilsonL
  • 167
  • 1
  • 2
  • 10