Skip to content

Pass include paths to cppcheck - #117

Merged
jacobperron merged 16 commits into
masterfrom
pass_include_cppcheck
Jan 10, 2019
Merged

jacobperron merged 16 commits into
masterfrom
pass_include_cppcheck

Conversation

@jacobperron

Copy link
Copy Markdown
Contributor

Specifically, passing the parent directories of all source files since a typical include
for a C/C++ header are located in a subdirectory named after the package or library.


Resolves #116

Test CI with cppcheck v1.86 (up to rclcpp): Build Status

@jacobperron jacobperron added the in progress Actively being worked on (Kanban column) label Dec 18, 2018
@jacobperron jacobperron added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Dec 19, 2018
Comment thread ament_cppcheck/ament_cppcheck/main.py Resolved
@jacobperron

Copy link
Copy Markdown
Contributor Author
  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

And CI machine with new version of cppcheck (v1.86)

  • macOS Build Status

@jacobperron

Copy link
Copy Markdown
Contributor Author

With lint fixes:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

cppcheck v1.86:

  • macOS Build Status

jacobperron and others added 6 commits January 3, 2019 13:18
Specifically, passing the parent directories of all source files since a typical include
for a C/C++ header are located in a subdirectory named after the package or library.
@jacobperron
jacobperron force-pushed the pass_include_cppcheck branch from fce39dd to c3d0e8d Compare January 7, 2019 19:40
@jacobperron

Copy link
Copy Markdown
Contributor Author

I've updated the PR to use BUILDSYSTEM_TARGETS if cmake version is >= 3.7. We're not experiencing cppcheck issues for systems with older cmake versions, like Xenial, so not passing include directories (as before) should remain okay.
@dirk-thomas Please take another look.

Comment thread ament_cppcheck/ament_cppcheck/main.py Resolved
Comment thread ament_cppcheck/ament_cppcheck/main.py Resolved
@jacobperron

Copy link
Copy Markdown
Contributor Author

A couple issues I've identified with this approach:

  1. Passing include directories to cppcheck significantly increases the time it takes to run.
    It doesn't seem like 120s is enough in some situations. Likely need to bump the timeout >200s (maybe 300s if we can live with it).
  2. Errors are reported from included headers from outside the package being tested.
    I have a hack to handle this in e67e564.

Thoughts?

…being tested

This eliminates the need for a longer test timeout and avoids cppcheck from testing external files.
Reverted prior changes accordingly.
@jacobperron

jacobperron commented Jan 8, 2019 •

Copy link
Copy Markdown
Contributor Author

Attempt to resolve timeout issue and errors from external packages by only including headers from the package being tested.

@jacobperron

jacobperron commented Jan 9, 2019 •

Copy link
Copy Markdown
Contributor Author

Ready for another round of review.

Passing include directories to cppcheck uncovered a potential issue in rcl (fixed in ros2/rcl#371). It's possible there will be more uncovered issues.

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@jacobperron

Copy link
Copy Markdown
Contributor Author

CI is good. The one cppcheck error is handled by ros2/rcl#371.

Comment thread ament_cppcheck/ament_cppcheck/main.py Resolved
@jacobperron

Copy link
Copy Markdown
Contributor Author

CI (linter tests only):

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@jacobperron
jacobperron merged commit 8d2ef3b into master Jan 10, 2019
@jacobperron
jacobperron deleted the pass_include_cppcheck branch January 10, 2019 01:55
@jacobperron jacobperron removed the in review Waiting for review (Kanban column) label Jan 10, 2019
PROPERTY INCLUDE_DIRECTORIES
)

# Only append include directories that are from the package being tested

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sloretz See #125.

You can pass cppcheck one or more include directories that contain the macros it is trying to resolve.
I'm not satisfied with the solution, but I think anything better would require changes in cppcheck itself.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, I missed that PR

Comment thread ament_cppcheck/ament_cppcheck/main.py Resolved
# Only append include directories that are from the package being tested
# This accomplishes two things:
# 1. Reduces execution time (less include directories to search)
# 2. cppcheck will not check for errors in external packages

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails on Windows in this case: ros2/ros2#942.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the case that's failing. From the referenced ticket, it looks like the failures are due to headers from external packages not being passed to cppcheck (which is the intended behavior). For this case, we have ament_cmake_cppcheck_ADDITIONAL_INCLUDE_DIRS that can be set (introduced in #125).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the proper include directories cppcheck warns for unknown macros.

ros2/rclpy#577 sets an additional include dir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants