Search code examples
c++cmsbuildpvs-studio

Integrate PVS-Studio into MSBuild file


I have many projects that I have created a common MSBuild file to run against. I am attempting to integrate PVS Studio's static analysis into the build without having it build a second time. I followed a bit of the documentation on PVS's site, but I must be missing something. I say that because when I build the PVS does not seem to my triggered/called. Does anybody have any experience with this and could give me a hand?

Here is the PVS bit of my build file.

 <UsingTask TaskName="ProgramVerificationSystems.PVSStudio.PVSStudio" 
    AssemblyFile="C:\Program Files (x86)\PVS-Studio\PVS-Studio-MSBuild.dll" />
    <Target Name="PVSStudioAnalysisBeforeCompile" BeforeTargets="ClCompile">
    <Exec Command="echo PVSStudio initiating now."/>
    <PVSStudio Condition="'%(ClCompile.ExcludedFromBuild)'!='true'" 
        Sources="@(ClCompile)" 
        BeforeClCompile="true" 
        BuildingInIDE="false" 
        TrackerLogDirectory="%(ClCompile.TrackerLogDirectory)" 
        PreprocessorPath="$(VCInstallDir)" 
        Platform="$(Platform)" 
        ProjectFullPath="$(MSBuildProjectFullPath)" 
        SolutionDir="$(SolutionDir)">
     <Output TaskParameter="SourcesAfterTlogParsing"    
        ItemName="CLCompileAfterTlogParsing" />
     </PVSStudio>
   </Target>
<Target Name="PVSStudioAnalysisAfterCompile" AfterTargets="ClCompile">
<PVSStudio Sources="@(CLCompileAfterTlogParsing)" 
    BeforeClCompile="false" 
    BuildingInIDE="$(BuildingInsideVisualStudio)" 
    PreprocessorPath="$(VCInstallDir)" 
    OutputFilePath   ="$(OutputDir)" 
    Platform="$(Platform)" 
    ProjectFullPath="$(MSBuildProjectFullPath)" 
    SolutionDir="$(SolutionDir)" />
<Exec Command="echo PVSStudio finished"/>

I'm sure you all will need a bit more info to figure this out so let me know what I should get for you.

Thanks,

TBG


Solution

  • You should do one of the following:

    1. If you want analyzer's output to be saved to a file, the you should set BuildingInIDE attribute to false in both tasks, you should also specify a file for the output to be saved to, for example, OutputFilePath = "$(OutputDir)"/pvs.log. You will be able to view such log from PVS-Studio IDE plug-in / Standalone by opening it as unparsed log.

    2. If you want to build your project from inside Visual Studio and PVS-Studio plug-in to hook up the analyzer results to it output window immediately, then you should set both BuildingInIDE attributes to true (or "$(BuildingInsideVisualStudio)") and enable the MSBuild mode by going to PVS-Studio -> Options -> Specific Analyzer Settings -> MSBuild Output Log Monitoring and set it to true.