SonarQube Code Coverage Xcode 13

Hi, We are using Enterprise Edition Version 8.6.1 (build 40680) and we are trying to gather Code Coverage for Swift Project.

We have successfully generated the .xcresult file but when we run the following command we get the following error

bash xccov-to-sonarqube-generic.sh Build/Logs/Test/*.xcresult/ > sonarqube-generic-coverage.xml

2021-11-18 14:32:20.086 xccov[13750:4774495] Requested but did not find extension point with identifier Xcode.IDEFoundation.IDEResultKitSerializationConverter
2021-11-18 14:32:20.097 xccov[13750:4774495] [MT] DVTAssertions: Warning in /Library/Caches/com.apple.xbs/Sources/DVTFrameworks/DVTFrameworks-19457/DVTFoundation/DocumentLocations/DVTDocumentLocation.m:277
Details: DVTDocumentLocation: Failed to find requested class with name Xcode3ProjectDocumentLocation (or isn’t a subclass of DVTDocumentLocation). Falling back to DVTDocumentLocation.
Object:
Method: +deserializedDocumentLocationForClassName:stringRepresentation:error:
Thread: <NSThread: 0x7fa88ee16660>{number = 1, name = main}
Please file a bug at https://feedbackassistant.apple.com with this warning message and any useful information you can provide.

Thanks
Harsha

Hi @harshavardhan,

Welcome to the Community! :sonarsource:

Can you try a few things?

  1. Please upgrade to SonarQube 9.4 or whatever the latest version of SonarQube is. Many improvements and features have been made.
  2. Please verify that the version of the command line tools matches the version of Xcode that generated the test results.
  3. Please try this alternative method shown in mysugr/cococo’s repository:

Instead of using SonarQube’s generic code coverage format, we use the llvm-cov format which is directly supported. No conversion needed!>

* Merge all .profdata files into one
* They are located here: <derived_data>/Build/ProfileData/*/*.profdata
* Use: xcrun llvm-profdata merge <paths to profdata> -output <merged_profdata_file>
* Collect all relevant binaries to extract code coverage data
    * They are located here: <derived_data>/Build/Products/Debug-iphonesimulator/
    * Include the *.app binary (includes statically-linked frameworks)
    * Collect remaining dynamic framework binaries (You probably want to exclude external depdencies like pods)
* Iterate over relevant binaries and append code coverage data to a file
    * `xcrun --run llvm-cov show <binary_path> --instr-profile <merged_profdata_file> >> <output_file>`
* The file can then be passed to sonar-scanner
    * `sonar.cfamily.llvm-cov.reportPath` (for Obj-C code coverage)
    * `sonar.swift.coverage.reportPaths` (for Swift code coverage)

Not sure how this project is being built (xcodebuild or SwiftPM) but I got Xcode13 swift coverage working. See this thread for more details: [SOLVED] No code coverage in Swift 5.6 XCode 13 project

1 Like