Mixed obj-c swift project, how scan handles code coverage

According to the official scanner docs, both the swift and Obj-C sonarsource scanners want code coverage data and in different ways (build-wrapper vs xccov). But this got me thinking, code coverage is for an entire target/project in xcode, not just files for a particular language . So for a mixed Obj-C and swift project, does SonarQube want the same entire-project-xcode-generated coverage data twice (once per scanner)? If not, how does it relate code coverage for a particular language in a sonar project, or does it not care at all?

Only asking this because again, and much to my surprise, the docs for the two scanners list different code coverage instructions, leading the user to wonder if each scanner doesn’t expect the data to be mixed together like it is with xcode and a mixed obj-c swift project (i.e. its the same data)

Hi @mstoner,

you can use the generic coverage format which is independent from the analyser, have a look at this guide: [Coverage & Test Data] Generate Reports for Swift.

Yes I saw that. Thats not my question. Question is not what format coverage needs to be in. Its a general question about how sonar scanner handles fact that theres one coverage report from xcode but 2 diff language scanners

What I’m confused by is both scanners’ doc sites mention how to get coverage data formatted to the generic format. That’s fine, but again xcode only generates one piece of coverage data for an entire app. So does each scanner parse the same coverage data to look at only the relevant language lines? Trying to understand how that works

For example, the sonarswift scanner doc mentions using a script to convert the xccov data to generic report xml format. The CFamily scanner doc mentions just use the wrapper to build and test. How do those two operations play together when mixed in one project? Also, the CFamily doc mentions sonar.cfamily.llvm-cov.reportPath but the instructions just say to use the wrapper. So the wrapper knows where the llvm cov report will be?

Hi @mstoner,

if you use generic coverage format there is a single property independent from the analyzer, a single report containing coverage for both swift and objective-c is good.

@mpaladin OK, understood, thanks. One follow up: is that clarified in the docs somewhere? Specificially the SonarCFamily doc here calls out the sonar.cfamily.llvm-cov.reportPath setting, and simply says to “use the build wrapper”. Obviously, that’s not enough, since the wrapper doesn’t inherently convert to generic coverage format does it? The swift scanner portion of the doc around test coverage at least is clear, telling the user to convert to generic themselves. But the reason I was confused is the SonarCFamily doc is not clear around that part

Hi @mstoner,

we are working on documentation, it should be more precise in the future. Thank you for your feedback.

I have verified, through use of a trial license, that indeed a single report is all that needs uploaded. That makes sense, so like @mpaladin said, really the docs just need to be clarified. Thanks for the help

1 Like