cococo — Code Coverage Converter from Xcode 11 to SonarQube

Michael Heinzl
Monster Culture
Published in
2 min readFeb 6, 2020

TL;DR: Use cococo to speed up your conversion from Xcode 11’s code coverage data to SonarQube’s generic XML format.

Why do we need to convert our code coverage data?

So, let’s start with the basics: SonarQube (SonarCloud) provides us with code analysis tools to keep track of our code quality including code smells, potential bugs and test coverage. Unfortunately, SonarQube does not support Xcode’s code coverage data directly so it has to be converted to their generic XML format. Before Xcode 11, we just used the shell script provided by SonarQube to convert Xcode’s code coverage data to their generic XML format. It wasn’t super fast but it got the job done.

Now, what has changed?

As SonarQube’s code analysis is part of our Continuous Integration (CI) pipeline, we want to avoid the process of converting to take a lot of time. With Xcode 11 however, Apple changed the file format of its code coverage data. 🙈 Therefore, SonarQube updated its shell script to work with the new format. Including the updated shell script into our workflow led to an increase in the build time of our CI pipeline by 20 minutes! 😭 This wasn’t only affecting us — other people in the community also faced increased build times up to 2 hours, depending on how big their project is. This was the moment when I decided to take a closer look at the shell script and re-wrote it in Swift.

The solution

https://github.com/mysugr/cococo

cococo is a command-line tool for macOS. By implementing it, we managed to decrease the conversion time on our CI pipeline from 25 to 4 minutes. 🚀

cococo still uses xcrun xccov to extract the code coverage data from the xcresult archive. Basically, it does the same thing as the old shell script but instead of processing the coverage data file by file on a single thread, cococo leverages multiple threads to distribute the workload.

Usage:

$ cococo myproject.xcresult > sonarqube-generic-coverage.xml

You can download the binary from the latest release on Github: https://github.com/mysugr/cococo/releases/latest

To summarize, Xcode 11 changed the format of its code coverage data. 😓 If you are using SonarQube (SonarCloud) to analyze your project’s test coverage and if you are also facing performance issues when converting Xcode 11’s code coverage data: Give cococo a try! 😉

--

--