fenugrec / freediag

OBD2 scantool
GNU General Public License v3.0
338 stars 75 forks source link

Run cppcheck in Windows and linux configuration successfully on the s… #70

Closed cfehse closed 3 years ago

cfehse commented 3 years ago

Scope

The scope of this PR is to integrate static code checks with Cppcheck. This integration will be done in two steps:

  1. Determine a sensible Cppcheck configuration (as Cppcheck GUI projects) and initially change sources to remove any warning found with this configuration. This configuration should be able to run against an unconfigured source tree.
  2. Integrate the Cppcheck checks into the cmake build process itself to be run as part of the configured build process.

What has changed?

Source Files:

CMakeLists.txt scantool/CMakeLists.txt

cppcheck\win32.cppcheck cppcheck\linux.cppcheck cppcheck\run-cppckeck.bat

scantool/diag.h scantool/diag_os.h cconf.h.in

scantool/diag_l2_iso14230.c

scantool/diag_l2_saej1979.c

scantool/scantool_cli.c

scantool/diag_os_win.c

scantool/diag_cfg.c

Tested Environments:

All changes where tested using these environments:

Cppcheck:

Compiler/Build Environment:

Perhaps you like the changes and accept this merge request.

Thanks!

@fenugrec @nsajko

fenugrec commented 3 years ago

Wow, thanks a lot for not only implementing this, but addressing some of those warnings !!

cfehse commented 3 years ago

@fenugrec

I implemented the Cmake integration for the Cppcheck analysis. This point are to be discussed from my point of view:

  • Changed the minimum required Cmake version to 3.10 to be able to use the build-in cppcheck integration.

This can be solved differently by checking the cmake version before integration Cppcheck

  • Added The Cppcheck target to the build process. The analysis will now run before any compilation of a source file.

This can be implemented differently for example by having a cmake configuration option to enable the checks.

  • The analysis target is configured to fail if any warnings are found meaning that the software can only be build successfully if warning free.

This can also implemented differently to have only informative checks.

What are your options about this topics?

fenugrec commented 3 years ago
  • Changed the minimum required Cmake version to 3.10 to be able to use the build-in cppcheck integration.

I think 3.10 is a reasonable requirement. Even ubuntu 18.04 has 3.10; if someone runs into problems because their distro doesn't have at least 3.10, we can do something different.

This can be implemented differently for example by having a cmake configuration option to enable the checks.

Hmm. On my system cppcheck is reasonably fast, but perhaps an option (default-enabled) would be nice, if it can be done without you ripping out all your additions and starting over? Otherwise I don't mind manually setting cppcheck to "NOTFOUND" to disable it.

  • The analysis target is configured to fail if any warnings are found

Hehe, that's strong, but I think we have acceptable suppressions for this not to be too severe. I assume if cppcheck isn't found (or set to "NOTFOUND"), the analysis target is ignored ? (i.e. build can still succeed )

cfehse commented 3 years ago

Hmm. On my system cppcheck is reasonably fast, but perhaps an option (default-enabled) would be nice, if it can be done without you ripping out all your additions and starting over? Otherwise I don't mind manually setting cppcheck to "NOTFOUND" to disable it.

This can be done but there is a caveat: Cmake treats the CMAKE_CPPCHECK like the CMAKE_COMPILER variables. Meaning you cannot change it after the build directory has been created. So a change of that new option after the build directory is initially configured results in a not working build environment. This seems a bit of a flaw in Cmake (or is intended by design?). Let's leave the mechanism as is.

cfehse commented 3 years ago

I assume if cppcheck isn't found (or set to "NOTFOUND"), the analysis target is ignored ? (i.e. build can still succeed )

Yes. If cppcheck is not found during the initial generation of the build directory the analysis targets are not created. To create them after the initial configuration the build directory must be removed.

cfehse commented 3 years ago

I added a corrected Embarcadero platform definition file to the cmake directory. This is a bit out of place here but the platform file which comes with the C++ Builder Community edition does not work correctly with all compilers so I corrected the file.

fenugrec commented 3 years ago

I added a corrected Embarcadero platform definition file to the cmake directory.

Ok. Let me know when you're ready for this to be merged! (if you have a chance, can you check your whitespace - there seems to be one or two "missing newlines", and a bit of trailing space on a few lines)

cfehse commented 3 years ago

Let me know when you're ready for this to be merged!

This PR is ready

(if you have a chance, can you check your whitespace - there seems to be one or two "missing newlines", and a bit of trailing space on a few lines)

Do you have an example in which file the formatting is off?

fenugrec commented 3 years ago

Do you have an example in which file the formatting is off?

It was minor EOL whitespace mostly. Fixed + rebased + merged , thanks !

cfehse commented 3 years ago

My pleasure...