Integrate CppDepend with AppVeyor


Integrate CppDepend with AppVeyor


This awesome in-depth tutorial is based on the NDepend (CppDepend like for .Net) integration written by Jimmy Pelletier reproduced below, courtesy of the author.


In this documentation I provide step by step instructions on how to integrate CppDepend into your CI pipeline for quality control and historical analytics. For quality control I will demonstrate how to fail your build when violating an CppDepend rule and for historical analytics we will publish the CppDepend report as a build artifact.


Prerequisites & Assumptions

In order to follow along with the steps provided in this article there are a few prerequisites. You will need:

  • A C/C++ project of some kind checked into GitHub.

  • A DevOps license key. To obtain such file contact us at support@codergears.com. If you are in trial period let us know your company name and postal address in the email. Else if you own a DevOps license key, let us know your license key in the email.

I have also assumed you know how to work with C/C++, Visual Studio and Git.


Go to top


Making the tools available during the build

In order to run CppDepend as part of your build pipeline you will need to make the CppDepend.Console.exe available to run during the build. When working with a cloud build agent like AppVeyor, options for installing tools and setting up the environment are limited. We’ll simply be checking CppDepend into source control. First download the CppDepend Installer. Then copy its content into a tools directory. I put mine in ./tools/CppDepend. You will also need to activate your DevOps license key.


Create an CppDepend project

To do anything with CppDepend we need to create an CppDepend project. The way to get this done is to:

  • Install CppDepend in Visual Studio with CppDepend.VisualStudioExtensionInstaller.exe.;

  • Open your solution in Visual Studio.

  • Build your solution to produce assemblies.

  • Select “Attach New CppDepend project to Current VS Solution” from the CppDepend menu.

  • Click “Add VS Project(s)”.

  • Select your solution.

  • Click “Analyze Project”.

  • Select “Edit Project” from the “Project” menu in the “CppDepend” menu.

  • Select “Paths Referenced” on the right hand side.

  • Select each path listed and Right click to select “Set as Path Relative (to the CppDepend Project File Location)”.

  • Save your changes.
An CppDepend Developer license is needed to do these steps. If you only have DevOps licensing you can still create a CppDepend project from a VS solution from VisualCppDepend.exe Start Page > New CppDepend project, and then populate the list of projects to analyze. In such situation you'll still need to set paths referenced as relative to the CppDepend Project File Location, as explained above.


Go to top


Create your build script

Next we need to add a build script to tell AppVeyor how to build your project. Full details of how AppVeyor build scripts work can be found in the AppVeyor documentation but the one I’ll include here is pretty self explanatory and is correct at the time of writing (September 2018). The file is placed in the root of the repository and is called appveyor.yaml.

The interesting thing to note is that we need to resolve the full absolute path of the CppDepend project file to pass in to CppDepend. Notice that here our CppDepend project file is named SomeProject.cdproj.

image: Visual Studio 2017
before_build:
  - ps: nuget restore
build:
  project: SomeProject.sln
after_build:
  - ps: $cdproj = Resolve-Path .\SomeProject.cdproj
  - ps: .tools\CppDepend\CppDepend.Console.exe $cdproj

Go to top


Setting up AppVeyor and our first build

Next we need to set up our GitHub repo to build in AppVeyor.

  • Log in or sign up to AppVeyor using your GitHub account.

  • Click “New Project” from the home screen.

  • Add your project from the list of repos available from your GitHub account.

  • Click “New Build”.

Go to top


Failing the build

CppDepend will now fail on any Quality Gate failure. AppVeyor terminates a build upon a command that returns a non-zero exit code. At least one Quality Gate failing means that CppDepend.Console.exe will return a non-zero exit code as explained in Quality Gates and Build Failure.

Thus, the easiest way to test build failure is to modify the “Critical Issues” quality gate. First remove the predicate that restricts this rule to considering only critical issues. Then reduce the failif threshold so it will fail on a single issue. With the default rule set and nearly any solution this should be enough to trip the quality gate. Your Quality Gate CQLinq query should now look like this:

// <QualityGate Name="Critical Issues" Unit="issues" />
failif count > 1 issues
warnif count > 0 issues
from i in Issues
select new { i, i.Severity, i.Debt, i.AnnualInterest }

Go to top


Publishing the CppDepend report

To publish the CppDepend report we need a bunch of files the CppDepend writes to ./CppDependOut during the build process. AppVeyor allows us to zip these files up and present them for download. Add the following to the end of your appveyor.yaml file:

artifacts:
  - path: CppDependOut
    name: CppDependOut
    type: zip

Then download the zip file from the “Artifacts” tab on a completed build and extract it to view the html report.


CppDepend offers a wide range of features. It is often described as a Swiss Army Knife for C and C++ developers.

Start Free Trial
.