-
Notifications
You must be signed in to change notification settings - Fork 362
sonar.cxx.gcc.reportPaths
Günter Wirth edited this page Nov 22, 2024
·
12 revisions
Sensor to read reports from the GNU C++ Compiler tool. The GNU Compiler Collection (GCC) is an optimizing compiler produced by the GNU Project supporting various programming languages, hardware architectures and operating systems. GCC is a key component of the GNU toolchain and the standard compiler for most projects related to GNU and the Linux kernel.
Note: The cxx plugin itself does not run the tool, you have to do that yourself beforehand. The sensor only reads the report generated by the tool!
- Link to the tool page: https://gcc.gnu.org/
- The sensor supports rules from GNU C++ Compiler with version GCC 6.3.
In order to run GNU C++ Compiler and generate a fitting report, make sure:
- to call it from the projects root directory, so that the paths in the report fit
- that the parameter matches the
sonar.sources
list insonar-project.properties
- add the
-fdiagnostics-show-option
option in your GCC build options (CFLAGS
,CPPFLAGS
or similar) - capture the warnings from your build into a file (e.g build.log) using shell redirections or similar)
Sample command line:
g++ -fdiagnostics-show-option foo.c -Wall > build.log
If the tool was executed successfully, a report like the example below should be generated:
Compiling...
ZipManager.cpp
src/zipmanager.cpp: In function 'int unzip(char *, int)'
src/zipmanager.cpp:141:10: warning: conversion to 'unsigned char' from 'unsigned int' may alter its value [-Wconversion]
src/zipmanager.cpp:222:9: warning: enumeration value 'Type_Deflate' not handled in switch [-Wswitch-enum]
src/zipmanager.cpp: In member function 'bool getRatio(int*) const':
src/zipmanager.cpp:271:75: warning: comparing floating point with == or != is unsafe [-Wfloat-equal]
Compiling manifest to resources...
- First check if the file extensions read in by the cxx plugin are set (sonar.cxx.file.suffixes).
- The rules for which you want to generate issue must be activated in the Quality Profile of your project. You can find instructions on how to do this under Manage Quality Profiles.
- Set the analysis parameter
sonar.cxx.gcc.reportPaths
in the configuration filesonar-project.properties
of your project. The Report Paths link describes the configuration options. - Normally the File Encoding is UTF-8. Use the parameter sonar.cxx.gcc.encoding to use another one.
- A default sonar.cxx.gcc.regex is already set, this can be customized if required.
- Execute the SonarScanner to transfer the project with the report to the SonarQube Server.
- With CXX Custom Template Rules it's possible to extend the rule repository.
- It is also possible to display unknown rules on the SonarQube Server.
Sample for sonar-project.properties:
sonar.cxx.gcc.reportPaths=*.log
sonar.cxx.gcc.encoding=UTF-8
- If no results are displayed after a successful scan, check Manage Quality Profiles first.
- If you cannot find an issue under 'New code', also look under 'Overall code' to see if it is listed there.
- If the sensor cannot read the report, check the encoding of the file, the parameter sonar.cxx.gcc.encoding must be set correctly.
- If scanning is failing, check items listed under Troubleshooting Configuration.
- If no issues are displayed for your source code in SonarQube, check the items listed under Troubleshooting Reports.
- In the case of incomplete scans, Detect and fix parsing errors gives advice on how to fix this.