HomePhabricator

[CMAKE] Make clang-tidy fail the build rather than trying to auto-fix

Description

[CMAKE] Make clang-tidy fail the build rather than trying to auto-fix

Summary:
The current behavior when the clang-tidy option is enabled is to attempt
to auto-fix the issues. This is not the best approach:

  • It does not work for all the rules;
  • It makes other warnings (not auto-fixable) difficult to spot.

This diff changes the behavior to cause clang-tidy to fail the build
when an issue is encountered, by promoting the warnings to errors. This
will prevent the user from missing a warning which is not auto-fixed.

Note: this option could be set in the .clang-tidy configuration file,
but it seems to have a bug and enable all the checks which is not the
expected behavior.

Test Plan:

cmake -GNinja .. \
  -DCMAKE_C_COMPILER=clang \
  -DCMAKE_CXX_COMPILER=clang++ \
  -DENABLE_CLANG_TIDY=ON
ninja all check

Add some braces issues, then:

ninja

Check that the build fail with a clang-tidy error.

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D7538

Details

Provenance
FabienAuthored on Sep 23 2020, 11:28
FabienPushed on Sep 23 2020, 14:15
Reviewer
Restricted Project
Differential Revision
D7538: [CMAKE] Make clang-tidy fail the build rather than trying to auto-fix
Parents
rABC0f8fe6220df5: [CMAKE] Don't enable clang tidy on native builds
Branches
Unknown
Tags
Unknown