Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sonar-cxx: To scan 'C/C++' code using the cxx plugin, do we need to compile the code using build_wrapper before running sonar-scanner? #2827

Open
Ashokg6 opened this issue Nov 29, 2024 · 3 comments
Labels

Comments

@Ashokg6
Copy link

Ashokg6 commented Nov 29, 2024

Before you create a new issue

  • Is it really a cxx-plugin issue or a general SonarQube issue? To track SonarQube issues use the community from SonarSource please.
  • Please read the Wiki first, maybe you will find a solution there.
  • Please turn debug info on and reproduce your issue. The debug info in the log file could help to solve or locate the issue.
  • Please check if there is not already a bug report for your issue.

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Redhat 8.10
  • SonarQube version: Community Edition v9.9.7
  • cxx plugin version: 2.1.3 (build 851)
  • sonar-scanner version: sonar-scanner-4.8.1.3023-linux

Additional context
My goal is to run the static analysis of 'C/C++' code using the above combination.
My question here is, to run static analysis of C/C++ code using the sonar-cxx plugin, do I need to compile the code by using "build-wrapper-linux-x86-64 --out-dir build_wrapper_output_directory make" ? if yes do i need to add these flags - sonar.cxx.build-wrapper-output=bld/build_wrapper_output_directory , sonar.cxx.jsonCompilationDatabase=bld/build_wrapper_output_directory/compile_commands.json to add preprocessors, macros and include directories ?

OR )
This plugin only supports and only on static files, which does not require any compilation before scanning. ? If yes
In this case, how it will include/parse preprocessors, macros and include directories ?

I did not get any relevant document which can clarify these questions, so I'm requesting you to clarify it .

BR
Ashok G

@guwirth
Copy link
Collaborator

guwirth commented Nov 29, 2024

Hello @Ashokg6,

please have first a look to our Wiki to understand the basics.

This plugin only supports and only on static files, which does not require any compilation before scanning. ?

In this case, how it will include/parse preprocessors, macros and include directories ?

Regards,

@Ashokg6
Copy link
Author

Ashokg6 commented Dec 3, 2024

Hi @guwirth,

Thanks for the info shared, let me go throw it .

BR
Ashok G

@Ashokg6
Copy link
Author

Ashokg6 commented Dec 3, 2024

Hi @guwirth ,

I tried with the JsonCompilationsDatabase and manual insertion of include directories without compilation, but I'm getting below errors while parsing the include directories .
JsoncompilationDatabase:
I have generated the compilation database by running below third party tool and input that in sonar-project.properties file and ran scan as shown below .
wrapper command - build-wrapper-linux-x86-64 --out-dir build_wrapper_output_directory make clean all
file has created with the required data and input this into scanner
sonar-scanner -Dsonar.cxx.jsonCompilationDatabase=bld/build_wrapper_output_directory/compile_commands.json
error :
ERROR: preprocessor: /home/jenkins/workspace/fi_master_sonar/fi/bld/cloud/artefacts/vendorsrc/broadcom/sdk-xgs-robo-6.5.x/sdk-all-6.5.24/bmacsec/cli '/home/jenkins/workspace/fi_master_sonar/fi/bld/cloud/artefacts/vendorsrc/broadcom/sdk-xgs-robo-6.5.x/sdk-all-6.5.24/bmacsec/cli'
ERROR: preprocessor: /home/jenkins/workspace/fi_master_sonar/fi/bld/cloud/artefacts/vendorsrc/broadcom/sdk-xgs-robo-6.5.x/sdk-all-6.5.24/bmacsec/phy/bcm54380 '/home/jenkins/workspace/fi_master_sonar/fi/bld/cloud/artefacts/vendorsrc/broadcom/sdk-xgs-robo-6.5.x/sdk-all-6.5.24/bmacsec/phy/bcm54380'
ERROR: preprocessor: /home/jenkins/workspace/fi_master_sonar/fi/bld/cloud/artefacts/vendorsrc/broadcom/sdk-xgs-robo-6.5.x/sdk-all-6.5.24/bmacsec/phy/bcm8729 '/home/jenkins/workspace/fi_master_sonar/fi/bld/cloud/artefacts/vendorsrc/broadcom/sdk-xgs-robo-6.5.x/sdk-all-6.5.24/bmacsec/phy/bcm8729'
ERROR: preprocessor: /home/jenkins/workspace/fi_master_sonar/fi/bld/cloud/artefacts/vendorsrc/broadcom/sdk-xgs-robo-6.5.x/sdk-all-6.5.24/bmacsec/phy/bcm84756 '/home/jenkins/workspace/fi_master_sonar/fi/bld/cloud/artefacts/vendorsrc/broadcom/sdk-xgs-robo-6.5.x/sdk-all-6.5.24/bmacsec/phy/bcm84756'

Manually Included the included directories where I got the below error .
sonar-scanner -Dsonar.cxx.includeDirectories=bld/TNTO/Router/,pi/l2/common/inc,pi/l2/erlb/inc
Errors
preprocessor: undefined function-like macro 'KERNEL_VERSION' assuming 0
preprocessor: undefined function-like macro '__GNUC_PREREQ' assuming 0

Can you please guide me or share some clues why this parser errors are coming even I'm passing correct values as expected ?

BR
Ashok G

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants