Skip to content

sonar.cxx.vc.reportPaths

Günter Wirth edited this page Nov 22, 2024 · 15 revisions

Overview

Sensor to read reports from the Visual Studio C/C++ Compiler. The compiler sensor consumes the warning messages available in the LOG file. Depending on the compiler options there are more or less warnings available.

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!

Supported versions

Create report

In order to generate a fitting report:

  • To create the 'C/C++ Build Warnings C4001-C5999' you have to activate the following configuration properties. Open the project property page with Project > Properties. Select Configuration Properties > C/C++ > General and set Warning Level to Level3 or Level4.
  • Enable 'C++ Core Guidelines checker warnings': Select Project > Properties > Configuration Properties > Code Analysis > General, activate Enable Code Analysis on Build and Enable Microsoft Code Analysis. As default you can use Microsoft > Active rules > Microsoft Native Recommended Rules.
  • To create absolute paths in the LOG file open Tools > Options and set option for Project and Solutions > Build and Run to MSBuild project build log file verbosity = Detailed.
  • That the paths in the LOG file matches the sonar.sources list in sonar-project.properties.

Sample command lines:

Visual Studio provides two tools to build and analyze a project from the command-line. With both tools it is the easiest to redirect stdout to a LOG file:

devenv.exe ... > output.log
msbuild.exe ... > output.log

Devenv example doing a solution rebuild and write the warnings to example.log:

rem VS2019 Enterprise
call "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
devenv example.sln /rebuild Release /out example.log

MSBuild example doing a project rebuild and write the warnings to example.log:

rem VS2019 Enterprise
call "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
MSBuild.exe example.proj /t:rebuild /p:Configuration=Release;WarningLevel=3 /fileLogger /fileLoggerParameters:WarningsOnly;LogFile=example.log;Verbosity=detailed;Encoding=UTF-8

Example of a report file

If the tool was executed successfully, a report like the example below should be generated:

Build started 26.01.2021 14:16:53.
Logging verbosity is set to: Detailed.
  1>Project "D:\Sample\Sample.vcxproj" on node 3 (Rebuild target(s)).
  ...
  1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29333\include\string.h(107,17): warning C4995: 'memcpy': name was marked as #pragma deprecated [D:\Sample\Sample.vcxproj]
  1>D:\Sample\File1.cpp(44,89): warning C4838: conversion from 'uint' to 'uint8' requires a narrowing conversion [D:\Sample\Sample.vcxproj]
  1>D:\Sample\File2.cpp(7,1): warning C4100: 'result_listener': unreferenced formal parameter [D:\Sample\Sample.vcxproj]
  1>D:\Sample\File1.cpp(414,41): warning C4239: nonstandard
  ...

Configure cxx plugin

  1. First check if the file extensions read in by the cxx plugin are set (sonar.cxx.file.suffixes).
  2. 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.
  3. Set the analysis parameter sonar.cxx.vc.reportPaths in the configuration file sonar-project.properties of your project. The Report Paths link describes the configuration options.
  4. Normally the File Encoding is UTF-8. Use the parameter sonar.cxx.vc.encoding to use another one.
  5. A default sonar.cxx.vc.regex is already set, this can be customized if required.
  6. Execute the SonarScanner to transfer the project with the report to the SonarQube Server.
  7. With CXX Custom Template Rules it's possible to extend the rule repository.
  8. It is also possible to display unknown rules on the SonarQube Server.

Sample for sonar-project.properties:

sonar.cxx.vc.reportPaths=*.log
sonar.cxx.vc.encoding=UTF-8

Troubleshooting

Clone this wiki locally