8.4.5. Qt Creator

8.4.5.1. Background

  • You have a running Axivion Suite configuration.

  • You want to run an analysis.

  • You want to view stylecheck results from within Qt Creator GUI.

8.4.5.2. What needs to be done?

Configure BuildSystemIntegration

Create CreateBuildFolder Step

This step is required to maintain Qt Creator’s “out of tree” build behavior (also referred to as “shadow” building).

Switch the current layer to ci_config.json. Under ‘Project’->’BuildSystemIntegration’, expand the ‘Available actions’ option. Drag the Command action up into the ‘additional actions’ area. Set the build_command field to:

mkdir -p ../{buildAxivionPath}

Replace ‘buildAxivionPath’ with the path to the Axivion build output.

Create QMake Step

This step is only required when using QMake.

Create another Command underneath the “CreateBuildFolder”. Set the build_command field to:

qmake6 QMAKE_CXXFLAGS=-w ../{projectName}

Set the cwd field to:

../{buildAxivionPath}

Replace ‘projectName’ with the name or path to the project. Note, the -w flag is used to suppress some warnings. Replace ‘buildAxivionPath’ with the path to the Axivion build output (the same one used in the previous step).

Configure MakeIntegration

This step is only required when using QMake.

Configure the MakeIntegration for the project. Specify the build_target based on the projects Makefile. Set the options so that the C and C++ compiler variables are overwritten to call cafeCC. For example:

CC=cafeCC CXX=cafeCC

Configure qmllint

qmllint can be run as part of the Axivion analysis. To do so, it will need to be enabled using the axivion_config GUI.

Switch the current layer to ci_config.json. Under ‘Project’, expand the section called ‘BuildSystemIntegration’. Expand the ‘Available actions’ and drag the option called QMLLintIntegration up into the ‘additional actions’ area. There should now be an entry for QMLLintIntegration that is checked.

Any violations caught by qmllint will now appear alongside violations caught by Axivion in the dashboard.

Configure Message Format

In order to view formatted results within the Qt Creator GUI, a message format will have to be configured in axivion_config. Switch the current layer to rule_config.json and select the ‘Analysis’ entry. On the right-hand pane, expand the field called ‘message_format’, under that, expand the field called ‘style’.

Change the value of the primary_line field to:

%(filename)s\t%(line)d\twarn\t%(severity)s%(macro_context)s%(template_instantiation_context)s %(message)s (Rule %(errno)s)

This message format will be parsed by the Qt Creator GUI when you execute a build using cafeCC and axivion_analysis.

Create Axivion Build Configuration in Qt Creator

Creating an Axivion build configuration in Qt Creator allows you to run an analysis in the same way you would run a Debug or Release build. This analysis will be performed on the entire project.

To create the build configuration, go to the Qt Creator ‘Projects’ tab and select ‘Add’.

Under ‘General’, change Build Directory to the Axivion build directory for your project.

Remove any existing steps from Build Steps and Clean Steps.

Under Build Steps, create a new Custom Process Step that calls the start_analysis.sh script in your Axivion project configuration directory. You can use the ${buildDir} directory to reference the current project directory.

For example:

${buildDir}/../AxivionConfig/start_analysis.sh

Alternatively, you can specify the Working directory field to your Axivion project configuration and simply call start_analysis.sh. Qt Creator may display a message saying “Invalid command”, however, when you run the build it should execute if the fields were set up properly.

Create another Custom Process Step that calls the dashserver command (provided it is in your environment PATH). In the Arguments field, pass the following arguments:

start --local --noauth --install_file {path to .db file}

Replace {path to .db file} with the path to the projects database file.

Under Clean Steps, create the following Custom Process Steps:

Command:           rm
Arguments:         -rf ${buildDir}
Working directory: ${buildDir}/..

Command:           dashserver
Arguments:         stop --local
Working directory: ${buildDir}

Make sure that the following environment variables are set:

AXIVION_LOCAL_BUILD = 1
AXIVION_USERNAME = admin
AXIVION_PASSWORD = password
SKIP_POSTBUILD_CLEAN = true

You can now use this configuration to start a local analysis from Qt Creator.

If you are using qmake, an additional step is required.

In axivion_config, switch to the compiler_config.json layer. Expand the ‘CompilerToolchainIntegration’ drop down. Select your project’s toolchain, for example, GNUToolchains.

On the right-hand pane, under ‘external_postprocessor’, set the ‘command’ field to axivion_analysis. The ‘enabled’ field can be set manually or tied to an environment variable like so:

$(env:RUN_POSTPROCESSOR=false)

Configure Single File Analysis Tool(s)

For single file analysis, an external tool can be configured in Qt Creator.

Under the Tools, External, menu select the Configure… option.

In the Environment section, select the External Tools tab.

Create a category to place the single file analysis tool(s) under using the ‘Add’ GUI button.

Add a tool under the newly created category.

If configuring for qmake, use the following values:

Executable          rm
Arguments           -f %{CurrentDocument:FileBaseName}.o && make CC=cafeCC \
                    CXX=cafeCC %{CurrentDocument:FileBaseName}.o > \
                    %{ActiveProject:BuildConfig:Path}/%{CurrentDocument:FileBaseName}.tasks \
                    && qtcreator -client %{ActiveProject:BuildConfig:Path}/%{CurrentDocument:FileBaseName}.tasks \
                    && rm -f %{CurrentDocument:FileBaseName}.o
Working directory   %{ActiveProject:BuildConfig:Path}
Environment         BAUHAUS_CONFIG=/PathToYourQmakeProject
                    CAFECC_BASEPATH=/tmp
                    QTINCDIR=/PathToQtLib
                    RUN_POSTPROCESSOR=true

If configuring for cmake, use the following values:

Executable      build_compile_commands
Arguments       --single_file %{CurrentDocument:FilePath} compile_commands.json -j > \
                %{ActiveProject:BuildConfig:Path}/%{CurrentDocument:FileBaseName}.tasks \
                && qtcreator -client %{ActiveProject:BuildConfig:Path}/%{CurrentDocument:FileBaseName}.tasks
Environment     BAUHAUS_CONFIG=/PathToYourCmakeProject
                CAFECC_BASEPATH=/tmp
                QTINCDIR=/PathToQtLib
                RUN_POSTPROCESSOR=false

Make sure the Working directory field is set to the projects cmake build folder.