I wanted to run some clang-tidy checks on some robot code and it wasn’t immediately obvious how to do this. Here’s the steps I had to take to get things somewhat-working.
- Before getting started, make sure you have a pretty recent build of clang-tidy. I used a nightly build.
- Build and install Bear from source.
./gradlew cleanin your project dir.
bear --use-c++ cc1plus ./gradlew buildto generate a compilation database.
- Clang doesn’t understand a couple of options that the build uses, so we need to manually clean up the database. Just run
sed -i 's/-mtls-dialect=gnu//' compile_commands.jsonand
sed -i 's/-quiet//' compile_commands.jsonto remove them.
- We can run clang-tidy now, just make sure to pass
--extra-arg=--target=armwhen invoking it. For example:
clang-tidy -p . --extra-arg=--target=arm --checks='performance-*' $(find . -name '*.cpp')will run performance checks on all cpp files in the current tree.
Note that Bear won’t work on macOS with SIP enabled or Linux with selinux enabled. Otherwise, I’ve gotten it to work on Linux and WSL.
Running the actual checks can be pretty slow. Any ideas to speed it up are appreciated - there’s probably some option for caching I’m not using.