Mjolnir Core
Core functionality of the Mjolnir API
|
This section lists all external tools that are used to maintain a good code quality standard. Every time a new commit is pushed to the repository, they run inside a GitHub action and are required to pass in order to merge a pull request into the master branch. Most of them can be run locally. The following sections describe the tools and how to run them. In case the descriptions do not work, have a look into the GitHub workflow files (.github/workflows
) and check which commands they use. If something differs, consider opening an issue to request an update of this documentation.
Clang-format automatically refactors your code to match a specified format. It is possible to run it from the command line, for example with:
However, most IDEs support clang-format so that your code gets formatted every time the file is saved. If you use QtCreator, enable the beautifier plugin in the C++ section. This generates a new submenu in the Options where you can select and configure clang-format. The configuration file .clang-format
is located in the root directory.
Every time you push to the GitHub repository, all files are checked. In case that a file is not formatted correctly, the corresponding action fails and pull requests can't be merged into the master branch until all issues are fixed.
Clang-tidy checks that the code follows several guidelines. It also checks the coding style, which is defined in the file .clang-tidy
. It only runs on .cpp
files and can check just a single file per execution. You can run it like this:
However, this will most likely produce unwanted errors because of missing includes or ignore the code of the included headers. This can be solved by additional parameters that are explained in the official documentation (check for newer versions). There is a special python script to run clang-tidy on all project files with the correct setup. It can be executed with:
You can specify which clang-tidy version should by adding --version <VERSION>
. To list all other available options, use:
Clang comes with different sanitizer tools that can be activated with additional compiler and linker commands. When the compiled code is executed it generates extra warnings and errors if problems are detected. Have a look into the file .github/workflows/compiletime_and_runtime_analysis.yml
to get an overview which tools are currently used to maintain a good code quality. The basic usage is mostly the same. Run CMake as follows:
The CMake variables MJOLNIR_CORE_ADDITIONAL_COMPILE_OPTIONS
and MJOLNIR_CORE_ADDITIONAL_LINK_OPTIONS
are used to build all library files with the specified options. Now run the following command to build:
Finally, run the compiled code to see if there are any issues. In the GitHub actions, all tests are build and run with different tools:
You can always have a look into compiletime_and_runtime_analysis.yml
if you are not sure how to run a specific tool that runs on the GitHub repository.
To run this tool, create a new build directory and run:
Note that you might need to use a different version number of the tool.
IMPORTANT: Always clear the directory (rm -rf *
) and run both commands. It seems like the tool doesn't find any bugs after the first run for some reason.
The root directory contains a cppcheck project file named .cppcheck
. If you have cppcheck installed, run the following command to perform the checks on your local machine:
Note that the config file enables addons that require Python 3. If you want to run cppcheck without the addons, use:
This should basically give you the same test results just without the ones added by the addons.
You can also add a C++ standard with the option --std=
. For example, use --std=c++17
to enable C++ 17 support
cmake-format
is a Python based tool that checks the formatting of CMake files. To install it locally, use Pythons package manager pip
:
You can run it from the libraries root directory with:
The --check
option lets the program fail in case of a formatting error. -c .cmake-format.yaml
specifies the configuration file that should be used. So in case you want to run the program inside any other directory than the rood directory, you have to adjust the path. To let cmake-format
correct any formatting errors, simply replace --check
with -i
:
Unfortunately, there is no build in mechanism to check multiple files at once. However, there are two python scripts that perform this task. To check all files run the following command (requires Python3) in the root directory:
To reformat all files run:
The official documentation can be found here
cmake-lint
comes together with cmake-format
when installing cmakelang
. Its usage is quite similar to cmake-format
and both share the same configuration file:
It also has the limitation that it runs only with a single file. The Python script that runs cmake-lint
for all files can be executed with:
The official documentation can be found here