Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use clang_tidy instead of ament_clang_tidy #135

Merged
merged 9 commits into from
Mar 15, 2023

Conversation

ivanpauno
Copy link
Collaborator

@ivanpauno ivanpauno commented Mar 14, 2023

Related to #132.

Summary

Uses clang-tidy instead of ament_clang_tidy.
ament_clang_tidy does not really pass all source files to clang-tidy, but some based on the compile commands.
So I had to fix many warnings.

Something to discuss for a follow-up: clang-tidy still needs to be run inside the docker container because:

  1. The compile commands need to be generated inside it.
  2. It needs the dependencies installed in order to understand the code.
  3. It needs clang-tidy installed.

That can be solved by making the hook show a warning instead of failing when the compile commands cannot be generated or clang-tidy is not available.
e.g. using pre-commit/pre-commit#923 (comment).
For that, it would maybe be better to use a repo local entry instead of https://github.com/pocc/pre-commit-hooks, which isn't really doing much as it uses the locally installed clang-tidy.
On the other hand https://github.com/pre-commit/mirrors-clang-format provides much more, as it uses a python wheel that you can pin a clang-format version (and not the local one).

Other solutions:

  • Do not run clang-tidy with pre-commit, but have an special CI step for that (with a script that can be run locally).

Checklist

  • Read the contributing guidelines.
  • Configured pre-commit and ran colcon test locally.
  • Signed all commits for DCO.
  • Added tests (regression tests for bugs, coverage of new code for features).
  • Updated documentation (as needed).
  • Checked that CI is passing.

Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
…ctly to clang-tidy

Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
@ivanpauno ivanpauno added the enhancement New feature or request label Mar 14, 2023
@ivanpauno ivanpauno self-assigned this Mar 14, 2023
@ivanpauno
Copy link
Collaborator Author

BTW, I'm planning to migrate beluga_amcl linters in a different PR.

@ivanpauno
Copy link
Collaborator Author

I have to double check why I didn't see those errors locally ....

.pre-commit-config.yaml Outdated Show resolved Hide resolved
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Copy link
Member

@nahueespinosa nahueespinosa left a comment

Choose a reason for hiding this comment

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

@ivanpauno Left a few comments!

I'm guessing that ament_clang_tidy was ignoring the test directory, so it wasn't instantiating some templates either.

beluga/include/beluga/algorithm/sampling.hpp Outdated Show resolved Hide resolved
beluga/include/beluga/algorithm/distance_map.hpp Outdated Show resolved Hide resolved
beluga/include/beluga/sensor/likelihood_field_model.hpp Outdated Show resolved Hide resolved
beluga/include/ciabatta/ciabatta.hpp Outdated Show resolved Hide resolved
beluga/test/beluga/mixin/test_utility.cpp Outdated Show resolved Hide resolved
beluga/test/benchmark/benchmark_sampling.cpp Show resolved Hide resolved
@nahueespinosa nahueespinosa changed the title Ivanpauno/use clang tidy instead of ament clang tidy Use clang_tidy instead of ament_clang_tidy Mar 15, 2023
Co-authored-by: Nahuel Espinosa <nespinosa@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
@ivanpauno
Copy link
Collaborator Author

@ivanpauno Left a few comments!

I'm guessing that ament_clang_tidy was ignoring the test directory, so it wasn't instantiating some templates either.

Exactly, https://github.com/ament/ament_lint/blob/a1b6c57be91b05ffa11d5eb6ff8700a478f1a890/ament_clang_tidy/ament_clang_tidy/main.py#L188-L189.
I don't know why they decided to do that, it doesn't seem like a good idea IMHO.

Co-authored-by: Nahuel Espinosa <nespinosa@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
@ivanpauno ivanpauno mentioned this pull request Mar 15, 2023
6 tasks
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Copy link
Member

@nahueespinosa nahueespinosa left a comment

Choose a reason for hiding this comment

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

LGTM!

@ivanpauno ivanpauno merged commit 4f086c1 into main Mar 15, 2023
@ivanpauno ivanpauno deleted the ivanpauno/use-clang-tidy-instead-of-ament-clang-tidy branch March 15, 2023 20:33
@nahueespinosa
Copy link
Member

clang-tidy still needs to be run inside the docker container

That can be solved by making the hook show a warning instead of failing when the compile commands cannot be generated or clang-tidy is not available.

That sounds like the way to go. It'd be neat to disambiguate between "couldn't run because dependencies are missing" and "there are issues with the code", to generate a warning or an error accordingly.

@nahueespinosa nahueespinosa added the infra Related to infrastructure and CI label Mar 15, 2023
@ivanpauno
Copy link
Collaborator Author

That sounds like the way to go. It'd be neat to disambiguate between "couldn't run because dependencies are missing" and "there are issues with the code", to generate a warning or an error accordingly.

I think it would be possible to do something like that if we have our own implementation of the pre-commit hook wrapper, but I don't think that's available in the existing wrapper.
It should be more or less easy to do though, so I will take a look to it at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request infra Related to infrastructure and CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants