Common code frameworks that compile depending on application

Information:

  • SonarScanner: sonar-scanner-cli-4.8.0.2856-linux
  • Build Wrapper: build-wrapper-linux-x86
  • Language: C

Objective

I have a variety of applications using a common code framework. The framework is compiled based on the top level Makefile configuration of the application, so not all of the code is compiled depending on the application (e.g. platform specific code). I would like to perform static code analysis on the common code framework independent of any application (its own project in SonarQube) so code clean up can be done separately.

Directory Structure

  • common
    • Makefile.inc
    • code
  • application
    • Makefile.top
    • code

Actions taken

I set up two projects in SonarQube (one for common one for application). I compile using make -f Makefile.top clean all with the build wrapper. I then have a sonar-project.properties.common and a sonar-project.properties.app configuration in the application directory from above. Once the build is done. I run the sonar scanner twice, one for each project. So only the code from the common framework that was compiled for the application will have any analysis.

Hi,

Welcome to the community!

Did you have a question, or was your intent just to share your (successful?) workflow?

 
Ann

Hi Ann, thank you for your response. I should have explicitly stated my question!

How would I achieve analysis on the entire common code framework independent from the applications that use it? Since the code that is compiled is configured by the application.

Hi,

Analysis is based (essentially) on compilation. But assuming that across all your variants, all the code is hit at least once, then what you’re looking for is variant analysis.

 
HTH,
Ann

Hi Ann, I’ve given the variant analysis a try by setting my sonar-project.properties accordingly

sonar.projectKey=My-Project

sonar.sources=apps,libs

sonar.cfamily.variants.names=cpu1,cpu2
sonar.cfamily.variants.dir=build/arm-cortexa8_neon-linux-gnueabi

But I am getting the error:

Could it be that my sonarscanner version or CFamily plugin version does not support the cfamily.variants property?

CFamily plugin version: 6.43.0.61486
SonarScanner version 4.8.0.2856

Thanks for pointing me torwards variant analysis, this is exactly what I needed!

Hi,

What’s your SonarQube version? Check your page footer if you’re not sure.

 
Ann

Hi Ann, my SonarQube version is 10.0

Hi,

SonarQube 10.0 is EOL. Can you upgrade to 10.6 and try again?

 
Thx,
Ann

Hi Ann, the upgrade to 10.6 worked! Thanks for the help!

1 Like