Skip to content

sonar.cxx.msbuild.reportPaths

Günter Wirth edited this page Feb 22, 2023 · 6 revisions

Overview

The cxx plugin supports reading the MSBuild .LOG file to automatically extract the required macros (sonar.cxx.defines) and include directories (sonar.cxx.includeDirectories).

The Predefined Macros matching the Visual Studio version are generated and further definitions are read from the .LOG file.

Supported versions

Create .LOG file

A .LOG file is generated when MSBuild is executed. It is the easiest to redirect stdout to a LOG file:

Hint: This function is enabled only if the .LOG generated during compilation contains sufficient information. MSBuild verbosity must be set to detailed or diagnostic!

msbuild.exe /v:Detailed  MySolution.sln > MSBuild.log

Advanced MSBuild example doing a project rebuild and write to MSBuild.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=MSBuild.log;Verbosity=detailed;Encoding=UTF-8

Example of a .LOG 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. Set the analysis parameter sonar.cxx.msbuild.reportPaths in the configuration file sonar-project.properties of your project. The Report Paths link describes the configuration options.
  3. Normally the File Encoding is UTF-8. Use the parameter sonar.cxx.msbuild.encoding to use another one.
  4. Narrowing the Focus gives more hints how to include and exclude files. At least sonar.sources must match the contents of the database.
  5. Execute the SonarScanner to transfer the project with the report to the SonarQube Server.

If the includes and macros come from multiple sources, they are processed in the following order:

  1. Definitions assigned to a file.
  2. Global definitions.
  3. Definitions from sonar-project.properties.
  4. Predefined Macros
sonar.cxx.includeDirectoris=1,2,3 // searching files in directories from left to right
sonar.cxx.defines=1,2,3,4         // first macro definition found is used, search from left to right

Sample for sonar-project.properties:

sonar.cxx.msbuild.reportPaths=MSBuild.log
sonar.cxx.msbuild.encoding=UTF-8
Clone this wiki locally