Skip to content

rtsworks/lintra

Lintra Banner

C project starter & CI/CD-friendly toolkit

OS: Windows / Linux License: MIT Status: Active

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:

  1. Lint — Enforces MISRA C:2012 guidelines via cppcheck.
  2. Test — Executes unit tests using ceedling, automatically generating:
    • Cobertura and HTML code coverage reports
    • JUnit and HTML test reports
    • Test runners and mocks
  3. Build — Uses make to build the project with strict compilation flags.

If any stage fails, Lintra immediately halts the process.

Getting Started

Start by obtaining a local copy of lintra (e.g., via Git):

git clone https://github.com/rtsworks/lintra.git

Alternatively, 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.

MISRA Guidelines

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 Setup

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 gcovr

After installation, ensure that each tool’s executable directory is added to your system’s PATH.

Linux Setup

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 install

Verifying the Setup

Verify that all required tools are installed:

gcc --version && \ make --version && \ git --version && \ ruby --version && \ cppcheck --version && \ gcovr --version

Then, run lintra as follows:

cd lintra make

An executable should be created at bin/debug/prog.bin. Running it will print:

$ ./bin/debug/prog.bin add: 20 sub: 15 mul: 10 state: 0

If you’ve reached this point, your setup is complete and ready to use.

Howto

This section explains how to use lintra after the setup is complete. If you haven’t set up lintra yet, see Getting Started.

Where to put your code

By default, lintra expects your project to be organized into three directories:

  1. Source files.c files in src/
  2. Header files.h files in include/
  3. Test files.c files in test/

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:
The test/support folder 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.

How to run lintra

In your lintra project directory, run:

# For debug build make # For release build make BUILD=release

This runs lintra’s full lint → test → build workflow as described in the workflow section.

Where to find lintra output

The output files are organized by build type:

  • Debug buildbin/debug/ contains the executable and map file, while build/debug/ contains the build artifacts.
  • Release buildbin/release/ contains the executable and map file, while build/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.

How to configure lintra

You can configure lintra’s toolkit and workflow as needed:

Configuring the linter

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.

Configuring the test framework

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.

Configuring the build process

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

Changing the workflow

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: lint

If 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.

CI/CD integration

TODO: add later

Contributing

We welcome contributions! Please see CONTRIBUTING.md for details on our code of conduct and instructions for submitting pull requests.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

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.

About

C project starter & CI/CD-friendly toolkit

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published