Coco instrumentation with QBS

Last edited on

General principle

QBS is a build system that is part of Qt. To instrument a software project with Coco that is compiled with QBS, two changes are necessary:

  1. The property modules.cpp.toolchainInstallPath must be set to the directory in which the Coco wrappers reside. Which directory this is depends on operating system and compiler:

    1. Under Linux, the path is /opt/SquishCoco/wrapper/bin, unless Coco is installed in a non-standard directory.

    2. Under Windows, with Visual Studio, the path tends to be either C:\Program Files\squishcoco\visualstudio or C:\Program Files\squishcoco\visualstudio_x64, depending on whether it is a 32-bit or a 64-bit build. (The first part of the code may also vary a bit, depending on the directory in which Coco is installed.)

    3. There are other Compiler wrappers under Windows, like those for MinGW, which have their own subdirectory of C:\Program Files\squishcoco for wrappers.

  2. To set command line parameters for the compiler wrappers, the environment variable COVERAGESCANNER_ARGS must be set. To activate Coco, the value of COVERAGESCANNER_ARGS must contain at least the flag --cs-on.

Implementation

Qt Creator

In a project that is compiled with Qt Creator , one can set the QBS properties via the "Properties" field of the QBS build step.

The properties and their values must be separated by a colon but no spaces. If a path contains spaces, it is possible to surround them by quotation marks, so that the "Properties" entry under Windows could look like this:

modules.cpp.toolchainInstallPath:"C:\Program Files\squishcoco\visualstudio"

The variable COVERAGESCANNER_ARGS can be set in the "Build Environment" field:

Linux command line

When building from the command line, the qbs build command is used. It receives the QBS parameters as additional commmand line arguments. Before it runs, the environment variable COVERAGESCANNER_ARGS must be set. This is how it looks under Bash:

$ export COVERAGESCANNER_ARGS="--cs-on"
$ qbs build modules.cpp.toolchainInstallPath:/opt/SquishCoco/wrapper/bin

In general it is however better to write a script for the instrumented build.

Windows command line

In the Windows command shell, the syntax is a bit different. Again it is better to write a script.

set COVERAGESCANNER_ARGS="--cs-on"
qbs build modules.cpp.toolchainInstallPath:"C:\Program Files\squishcoco\visualstudio"