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 the Qt Creator GUI.
8.4.5.2. What needs to be done?¶
Configure BuildSystemIntegration¶
Create the 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 the QMake Step
This step is only required when using QMake.
Create another Command step beneath “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 that 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 project’s 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, enable it using the axivion_config GUI.
Switch the current layer to rule_config.json and activate the rule
ImportQMLLint.
Any violations caught by qmllint will now appear alongside violations caught by Axivion in the dashboard.
Configure Message Format¶
To view formatted results within the Qt Creator GUI, configure a message format in
axivion_config. Switch the current layer to rule_config.json
and select the ‘Analysis’ entry. In the right-hand pane, expand the field called
‘message_format’, and then 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 an 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} variable to reference the current project directory.
For example:
${buildDir}/../AxivionConfig/start_analysis.sh
Alternatively, set the Working directory field to your Axivion project
configuration and simply call start_analysis.sh. Qt Creator may display an
“Invalid command” message; however, the build 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 project’s 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}
Ensure that the following environment variables are set:
AXIVION_LOCAL_BUILD = 1 AXIVION_USERNAME = admin AXIVION_PASSWORD = password
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’ dropdown. Select your project’s toolchain, for example,
GNUToolchains.
In 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, for example:
$(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.
Use the ‘Add’ button to create a category for the single-file analysis tool(s).
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=falseEnsure the
Working directoryfield is set to the project’s CMake build folder.