2017-10-29 16:32:39 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Note: Call this from a cmake build directory (e.g. cmake/) for out-of-source builds
|
|
|
|
# Examples:
|
|
|
|
# mkdir cmake && cd cmake && ../run-clang-tidy.sh
|
|
|
|
# mkdir cmake && cd cmake && ../run-clang-tidy.sh -fix
|
|
|
|
# mkdir cmake && cd cmake && ../run-clang-tidy.sh -export-fixes fixes.yaml
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2018-10-14 22:38:05 +02:00
|
|
|
export NUMCORES=`nproc` && if [ ! -n "$NUMCORES" ]; then export NUMCORES=`sysctl -n hw.ncpu`; fi
|
|
|
|
echo Using ${NUMCORES} cores
|
2017-10-29 16:32:39 +01:00
|
|
|
|
|
|
|
# Run cmake in current working directory, but on source that is in the same directory as this script file
|
2017-12-01 16:01:49 +01:00
|
|
|
cmake -DBUILD_TESTING=on -DCMAKE_EXPORT_COMPILE_COMMANDS=ON "${0%/*}"
|
|
|
|
|
2018-10-14 22:38:05 +02:00
|
|
|
# Filter all third party code from the compilation database
|
|
|
|
cat compile_commands.json|jq "map(select(.file | test(\"^$(realpath ${0%/*})/(src|test)/.*$\")))" > compile_commands2.json
|
|
|
|
rm compile_commands.json
|
|
|
|
mv compile_commands2.json compile_commands.json
|
|
|
|
|
2017-10-29 16:32:39 +01:00
|
|
|
run-clang-tidy.py -j${NUMCORES} -quiet -header-filter "$(realpath ${0%/*})/(src|test)/.*" $@
|