0

I have a CI script that runs clang tidy on all the cpp files to ensure that all the files are written using the rules set up in the config file. Currently, I have a script that finds all the necessary files (cpp and shader files) and runs clang tidy on them:

# scripts/clang-tidy-all.sh
#!/bin/sh

if [ -z $1 ]; then
    CMD=clang-tidy
else
    CMD=clang-tidy-$1
fi

find engine/src editor/src -type f -name "*.cpp" -o -name "*.frag" -o -name "*.vert" | xargs -I{} $CMD -header-filter=.* --p=file --quiet {} -- --std=c++17 -isystem./vendor/include -isystem./engine/src -isystem./editor/src/ -isystem./platform-tools/include -isystem/usr/local/include

## Usage from CLI
./scripts/clang-tidy-all.sh 14

This script takes 26 minutes on my CI system (I am using Github actions with their workers), which is longer than building the entire project. Is there some way to make this clang-tidy run faster. I am planning on running these tests in threads through some kind of a job system as well but I want something to make the static analysis itself faster.

Gasim
  • 7,615
  • 14
  • 64
  • 131
  • 3
    In my experience, `clang-tidy` takes about twice as long to run as compiling a project (similar numbers for `scan-build`). Static analysis is expensive. – Stephen Newell Jun 19 '22 at 11:40
  • 1
    `xargs -I{}` You are running it on one file at a time.... – KamilCuk Jun 19 '22 at 11:48
  • 2
    My project is using a different static analysis tool. The full compile takes 20 minutes. The static analysis takes 16 hours. – Eljay Jun 19 '22 at 11:56
  • @KamilCuk will it automatically run in parallel based on threads if I run them all at once? – Gasim Jun 20 '22 at 15:19
  • 1
    I do not understand. You are running one single `clang-tidy` for one single file at a time. Yes, parsing that single file maybe is happening in threads, still that's slow and still you have to execute `fork()+exec()` for every single file. You should rather generate `compile_commands.json` and let `clang-tidy` run over all files inside `compile_commands.json`. – KamilCuk Jun 20 '22 at 15:56
  • @KamilCuk What command do you run to let clang-tidy run over all files inside compile_commands.json? I tried `clang-tidy -p build` to let it use build/compile_commands.json, but clang-tidy says "Error: no input files specified". I still have to list every source file for it. – Jackoo Jun 01 '23 at 01:42
  • `clang-tidy -p ${CMAKE_BINARY_DIR} --color --quiet` works fine for me. llvm15.0.7 Check your compile_commands.json – KamilCuk Jun 01 '23 at 07:51

0 Answers0