I have a project with platform files (like CMSIS, etc) being part of the project - for various reasons!
Those files are included as instructed by build_flags = -I src/CMSIS
.
When I use cppcheck with misra I am getting hundreds of warnings originating from the CMSIS and others that are not user code.
When I run pio check -v
, I can see all the Includes being listed. I don’t want any of them - per the manual:
How can I remove arbitrary or all the includes? I can only add new ones using check_flags . It would be best if that check_flags = cppcheck: --I xxxxx
command was replacing the Includes, instead of adding to them.
I tried a few different versions of it, but I cannot make it work. This also probably would have to be an absolute path judging by the rest of the arguments cppcheck.exe is getting.
check_flags =
cppcheck:--addon=misra.json --std=c99 --language=c --suppress=*:C:\Users\dzidm\Repos\firmware\src\CMSIS\core_cm3.h:*
I think suppression may not work with misra plugin - based on issues online…
Besides, Cppcheck would run much much faster if it didn’t have go through all the includes.
Indeed, --suppress=*:*/src/CMSIS/*
should be used as the flag so that the path in front of it doesn’t matter.
This does work, I have personally tested this with the GitHub - maxgerhardt/pio-exclude-cppcheck project.
Without the suppress, found defects:
Component HIGH MEDIUM LOW
----------- ------ -------- -----
src 0 0 6
src\CMSIS 0 0 1304
src\Device 0 0 40
Total 0 0 1350
With the flag:
Component HIGH MEDIUM LOW
----------- ------ -------- -----
src 0 0 6
src\Device 0 0 40
Total 0 0 46
Since I don’t see an option in PlatformIO to do this, you would have to file a feature request at Issues · platformio/platformio-core · GitHub .
Ah - that extra *
in front did the job. Thank you for the example.
Any idea how would you suppress multiple directories? - src/CMSIS
and src/Device
from your example.
I have created a feature request as suggested:
opened 03:22PM - 20 Aug 22 UTC
help wanted
static analysis
- [x] **Feature Request**.
--------------------------------------------------… ----------------
### Configuration
**Operating system**:
**PlatformIO Version** (`platformio --version`):
PlatformIO Core, version 6.1.4
### Description of problem
Lack of ability to exclude Includes from cppcheck analysis. Long analysis and a long output.
Related [conversation](https://community.platformio.org/t/cppcheck-how-to-exclude-includes/29265/5?u=dzidmail).
#### Steps to Reproduce
1. Create project which includes hal headers from within the repository.
2. Setup cppcheck with misra check:
3. Perform static analysis `platformio.exe check`
### Actual Results
Analysis that is slow and outputs thousands of MISRA violations
```
Component HIGH MEDIUM LOW
----------- ------ -------- -----
src 0 0 4
src\CMSIS 0 0 1173
src\Device 0 0 8279
Total 0 0 9456
Environment Tool Status Duration
------------------ -------- -------- ------------
genericSTM32F103C8 cppcheck PASSED 00:00:19.038
```
### Expected Results
A quick analysis of user code only without entering hal headers
```
Component HIGH MEDIUM LOW
----------- ------ -------- -----
src 0 0 4
Total 0 0 4
Environment Tool Status Duration
------------------ -------- -------- ------------
genericSTM32F103C8 cppcheck PASSED 00:00:1.234
```
### If problems with PlatformIO Build System:
**The content of `platformio.ini`:**
```ini
[env:genericSTM32F103C8]
platform = ststm32
board = genericSTM32F103C8
board_build.ldscript = src/Device/STM32F103XB_FLASH.ld
build_flags =
-Isrc/CMSIS/
-Isrc/Device
check_skip_packages = yes ;don't inlcude compiler package inludes
check_patterns =
src/*.c
src/*.h
check_flags =
cppcheck:--addon=misra --suppress=suppress.txt
```
**Source file to reproduce issue:**
Working example:
https://github.com/dzid26/pio-exclude-cppcheck.
Adding multiple --suppress
flags is allowed.
check_flags =
cppcheck:--addon=misra.json --std=c99 --language=c --suppress=*:*/src/CMSIS/* --suppress=*:*/src/Device/*
gives only
Component HIGH MEDIUM LOW
----------- ------ -------- -----
src 0 0 6
Total 0 0 6
1 Like
And of course that worked!
Interesting that --addon=misra
gives less results than --addon=misra.json
:
Checking genericSTM32F103C8 > cppcheck (platform: ststm32; board: genericSTM32F103C8)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
src\main.c:4: [low:style] misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-8.2]
src\main.c:8: [low:style] misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-10.1]
src\main.c:5: [low:style] misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-11.4]
src\main.c:6: [low:style] misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-11.4]
============================================================================================================== [PASSED] Took 4.27 seconds ==============================================================================================================
Component HIGH MEDIUM LOW
----------- ------ -------- -----
src 0 0 4
Total 0 0 4
Environment Tool Status Duration
------------------ -------- -------- ------------
genericSTM32F103C8 cppcheck PASSED 00:00:04.267
Perhaps related to:
https://sourceforge.net/p/cppcheck/discussion/development/thread/0e4ddebe12/