>
>
Using PVS-Studio with huge projects (MS…

Andrey Karpov
Articles: 673

Using PVS-Studio with huge projects (MSBuild integration)

If your solution includes a lot of large projects, you may find it uncomfortable to operate the PVS-Studio analyzer when checking it. In this small post we'll explain why it happens and how integrating PVS-Studio into MSBuild's build process will help you to improve the situation.

I want to make it clear right away that the analyzer's operation mode described below should be used only in rare cases when dealing with huge projects. You'll get no benefit from using it for small and medium projects - in fact analysis may even get much slower.

But let's assume your case is just that rare one - your solution includes quite a lot of projects, and the total number of files to be compiled is many thousands.

The PVS-Studio analyzer uses the API functions provided by Visual Studio to gather information about files. It needs to know which files should be checked, which preprocessor definitions are specified for each file, which directories with header files should be used, and so on.

If there are a lot of projects and files, data gathering takes too much time. PVS-Studio meditates for a long time before starting analysis. It is especially noticeable with incremental analysis. It often happens that data gathering is several times longer than the analysis of a few changed files itself.

We can't fix that because we cannot speed up calls of API functions. But there is a workaround: integration into MSBuild's build process.

We won't discuss how to get started with MSBuild in this post. This aspect is described very thoroughly in the documentation, and we find it senseless to copy text from there. Something may change in time, and this blog post will become obsolete. That's why we refer readers to the documentation section for more information: "Direct integration of PVS-Studio into MSBuild's build process. MSBuild integration mode in Visual Studio IDE".

Let's only enumerate advantages and disadvantages of the integration method here.

Advantages:

1) The analyzer doesn't need to gather information about files - MSBuild will provide it with all the necessary data. This will significantly reduce analysis time in projects containing a huge number of files.

2) In case of incremental analysis, MSBuild will run a check only for the files which have been changed and provide you with all the information you need. Therefore, using the incremental analysis mode with large projects becomes quite convenient.

3) You can check projects which are extensions to the standard Visual C++ project model (for example driver projects). Any Visual C++ user can extend the project model to add their own specific build parameters into it. But if the project is being built by MSBuild, you can integrate analysis by PVS-Studio into it, while the common operation mode of PVS-Studio as a plugin doesn't always work correctly in this case, as the extended project model won't be represented in Visual Studio Extensibility API.

4) Since analysis by PVS-Studio is integrated into the build process, you can check a project (while building it) on a system without IDE: for example on the build server during night builds.

Disadvantages:

1) Since it is MSBuild that launches the analyzer, it also appears to be responsible for parallelization. MSBuild parallelizes the build process at the project level: an individual MSBuild instance is launched for each project, which in its turn calls an individual PVS-Studio instance. The drawback here is that you can't analyze files within the framework of one project in parallel.

2) Integration into MSBuild requires modifying the project file (*.vcxproj).