Proper Configuration for Multi-Target C/C++ with Lots of Shared Code

Our C++ project is around 100K lines of code, and we have a lot of shared code between around 15 build targets. Around 90% of the code is shared, with minor differences (minor features etc.) between build targets.

How can we use SonarCloud/SonarScanner to analyse our code and get a good overview of the code quality? I don’t see a proper way to configure the SonarScanner for C/C++ projects with multiple targets. The documentation is not very clear on this.

We have tried monorepo feature, but every monorepo is getting multiplied with LOC and it gets exceeded the limit.

Hi,

Welcome to the community!

I think you might be looking for how to analyze code variants.

 
HTH,
Ann

Hi Ann,
Thanks for the response.
But it looks like sonar cloud doesn’t support code variants. Any plans for this ?

Hi,

Shoot! I missed that detail.

Your best option, then, is to analyze each variant as a separate branch.

 
HTH,
Ann

Will we be able to use this properly in pull requests as quality gates if we use separate branch ? For e.g. if one file is not used in some build targets, will this cause a problem ?

Hi,

I don’t quite follow the question.

You’ll need to manually specify sonar.branch.name for each of your variants, and I suppose use that same variant/branch in PR analysis too.

 
HTH,
Ann

We have a single main branch. So if I understand correctly, you meant to maintain clones of main branch just for the sake of running analysis.

main-target1
main-target2
main-target3
etc.

Now the pull request will be raised only to the main branch (not the clones)… do you mean that when running analysis, i can simply change the target branch to get results of all ??

For target 1:
sonar.pullrequest.key=123
sonar.pullrequest.base=main-target1
sonar.pullrequest.branch=pr_branch

For target2:
sonar.pullrequest.key=123
sonar.pullrequest.base=main-target2
sonar.pullrequest.branch=pr_branch

For target3:
sonar.pullrequest.key=123
sonar.pullrequest.base=main-target3
sonar.pullrequest.branch=pr_branch

Hi @ligo.george.t

We have a portal card to upvote and get updated on this (demanded) topic.
It seems you made your way to it yourself.

There is not current timeline for it but we will have to work on it for feature parity between SonarQube Server and SonarQube Cloud.

Thanks for reaching out.

Cheers

Hi,

I’m again not understanding the question.

And those analysis parameter sets look right to me.

 
HTH,
Ann

I am yet to try this method, I was asking whether we can analyse or check all targets in pull requests like this since the pull request key is same, will the last run overwrite the previous pull request analysis.

Hi,

I see!

Uhm… Yeah, that’s probably going to be a problem.

You could fiddle with the keys (123-1, 123-2 &etc) but then decoration would fail.

 
Ann