Running cppcheck in development - neutrinolabs/xrdp GitHub Wiki

Introduction

This section applies to development versions of XRDP.

Pull requests made to the XRDP repository are run through a number of continuous integration (CI) checks. One of these is running the code through a recent version of the cppcheck utility.

At the time of writing XRDP uses Ubuntu Xenial containers for running CI checks. The version of cppcheck provided by this operating system is 1.72 which is somewhat dated.

In order to run a later version of cppcheck, XRDP has been provisioned with a couple of scripts which are used to build and run a later version of cppcheck on-the-fly. These scripts can also be used by developers before submitting pull requests.

cppcheck location and version

The current version of cppcheck and its download location can be found in the CI configuration file .travis.yml.

Scripts

The scripts provided for running cppcheck are:-

Script Purpose
scripts/install_cppcheck.sh Downloads a version of cppcheck to ~/cppcheck.local and builds it
scripts/run_cppcheck.sh Runs the specified version of cppcheck

Scripts are written in Bourne shell, so should run on most platforms. If you've got the tools installed to build a development version of XRDP, you should be able to build cppcheck with no problems.

install_cppcheck.sh

This script takes two arguments:-

  1. The current address of a cppcheck git repository
  2. The git tag to download and build.

As an example, at the time of writing, the following command will fetch and build version 1.90 of cppcheck:-

$ scripts/install_cppcheck.sh https://github.com/danmar/cppcheck.git 1.90

The above command takes a couple of minutes to run on a modest VM, and will produce a new directory ~/cppcheck.local/1.90/ in the user's home directory. This directory will contain the newly-built cppcheck version.

run_cppcheck.sh

A simple way to run this script is to chdir to the directory containing the files you wish to check, and to specify the cppcheck version to run with the -v flag:-

$ scripts/run_cppcheck.sh -v 1.90

Any errors are displayed on stdout.

Modifying run_cppcheck.sh behaviour

  • If you do not specify a cppcheck version with -v, the script will look for a version of cppcheck on the PATH.
  • The environment variable CPPCHECK can be used to specify the location of the cppcheck executable. This can be handy if cppcheck is installed somewhere unusual, or you do not want to keep specifying -v on the command line, e.g.:-
    $ export CPPCHECK=~/cppcheck.local/1.90/bin/cppcheck
    $ scripts/run_cppcheck.sh
    
  • Any additional arguments specified are passed to the end of the cppcheck command line. In this instance, you will also need to specify the directories to check (e.g. '.')
  • You can change the default flags passed to cppcheck by setting the environment variable CPPCHECK_FLAGS.

Updating the version of cppcheck used by CI

New versions of cppcheck are released on a regular basis. The version of cppcheck used will need to be updated on a regular basis in .travis.yml.

Before updating this file, the XRDP code can be checked for compatibility with the new version by using the scripts above. Any required changes to the XRDP codebase can be included in the same PR as the change to .travis.yml.