Lintra is a C project template with a built-in, CI/CD-friendly toolkit designed to streamline the development workflow of C projects. It automates linting, testing, and building C projects with minimal setup.
Lintra enforces a strict, fail-fast workflow composed of three stages:
- Lint — Enforces MISRA C:2012 guidelines via cppcheck.
- Test — Executes unit tests using ceedling, automatically generating:
- Cobertura and HTML code coverage reports
- JUnit and HTML test reports
- Test runners and mocks
- Build — Uses make to build the project with strict compilation flags.
If any stage fails, Lintra immediately halts the process.
Start by obtaining a local copy of lintra (e.g., via Git):
git clone https://github.com/rtsworks/lintra.gitAlternatively, you can download the repository as a ZIP file from this page and extract it manually.
Once you have a local copy of lintra, follow the instructions below to complete the setup and get lintra up and running.
This project uses the file misra_c_2012__headlines_for_cppcheck - AMD1+AMD2.txt by The MISRA Consortium Limited, available here.
Licensed under CC BY-NC-ND 4.0.
To use it here, download the file from the link above, rename it to misra_c_2012_rules.txt, and move it to the scripts/ folder. No modifications are made to the file contents.
NOTE: This file is deliberately listed in .gitignore to avoid redistributing it here, ensuring that the rest of the project remains entirely under the MIT license.
Windows users should install the following tools to run lintra:
- MinGW — Provides the GCC compiler and make utility for building the project.
- MSYS2 — Offers a Unix-like shell environment required for the Makefile to run properly.
- python3 — Comes with pip3 on Windows, used to install gcovr for coverage reports.
- Ruby — Required for running Ceedling, the unit testing framework.
- Cppcheck — Used to enforce MISRA C:2012 guidelines.
Install gcovr via command line:
pip3 install gcovrAfter installation, ensure that each tool’s executable directory is added to your system’s PATH.
NOTE: The instructions below were tested on mint/ubuntu.
Linux users should install the following tools to run lintra:
- Install build essentials, Git, Ruby, Python, and pip:
sudo apt update && sudo apt install build-essential git ruby-full python3 python3-pip- Install gcovr:
sudo pip3 install gcovr- Install cppcheck:
git clone https://github.com/danmar/cppcheck.git && \ cd cppcheck && \ git checkout 2.18.x && \ sudo make FILESDIR=/usr/share/cppcheck installVerify that all required tools are installed:
gcc --version && \ make --version && \ git --version && \ ruby --version && \ cppcheck --version && \ gcovr --versionThen, run lintra as follows:
cd lintra makeAn executable should be created at bin/debug/prog.bin. Running it will print:
$ ./bin/debug/prog.bin add: 20 sub: 15 mul: 10 state: 0If you’ve reached this point, your setup is complete and ready to use.
This section explains how to use lintra after the setup is complete. If you haven’t set up lintra yet, see Getting Started.
By default, lintra expects your project to be organized into three directories:
- Source files —
.cfiles insrc/ - Header files —
.hfiles ininclude/ - Test files —
.cfiles intest/
You can also create subfolders inside each directory to organize modules. An example project is included with lintra, which uses all three directories and can be deleted after completing the setup.
WARNING:
Thetest/supportfolder is reserved for mock files generated by CMock
and should not be used by the developer. Its contents are also excluded
from version control via.gitignore.
In your lintra project directory, run:
# For debug build make # For release build make BUILD=releaseThis runs lintra’s full lint → test → build workflow as described in the workflow section.
The output files are organized by build type:
- Debug build —
bin/debug/contains the executable and map file, whilebuild/debug/contains the build artifacts. - Release build —
bin/release/contains the executable and map file, whilebuild/release/contains the build artifacts.
For both builds:
- Test reports are located in
build/ceedling/artifacts/gcov - Coverage reports are located in
build/ceedling/artifacts/gcov/gcovr
Both the test and coverage reports are generated in XML and HTML formats.
You can configure lintra’s toolkit and workflow as needed:
lintra uses CPPCheck as its linter. CPPCheck is configurable from the Makefile's CPPCheck config section. The following files are used by CPPCheck for static analysis:
script/type_sizes.xml- specifies the platform-specific variable sizes.script/misra.json- Enforces MISRA C:2012 Guidelines.script/threadsafety.json- Static thread safety analysis.
There are additional flags apart from the files above which you may choose to keep, modify, or remove.
lintra uses Ceedling for testing. You can configure the framework in the project.yml file. This allows you to:
- Add or remove test files
- Configure mock generation
- Customize test report outputs
- Customize coverage report outputs
Editing this file allows you to tailor the test framework to your project.
The build process is configurable from the Makefile using the following sections:
GENERAL- Choose the target name and default build (debug/release).Directory paths- Decide the directory paths.Files- Set the sources to be used for the build.Compiler config- Decide what compiler, and compiler flags are used for release and debug builds.Make targets- The build target controls how the executable will be created
The default lintra workflow runs lint → test → build automatically. This is controlled by the Make targets section in the Makefile:
# Make lint → test → build workflow. Stop the workflow when any step fails. # Default make target: Run the build prerequisite. all: build # Build target runs the test prerequisite. build: test # Test target runs lint prerequisite. test: lintIf you prefer to run each step manually, you can remove or reorder these lines. For example, keeping only all: build will make it build the project by default without running lint or tests first.
TODO: add later
We welcome contributions! Please see CONTRIBUTING.md for details on our code of conduct and instructions for submitting pull requests.
We use SemVer for versioning. For the versions available, see the tags on this repository.
Most of this project is licensed under the MIT License — see the LICENSE.md file for details.
The Code of Conduct is adapted from the Contributor Covenant, version 3.0, which is licensed under the CC-BY-SA-4.0 License — see the CODE_OF_CONDUCT.md file for details.
