From 8cbe9a8cfdf5b4c6a96d5d379d3a561e75c5b6b1 Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Mon, 27 Apr 2020 11:03:58 -0400 Subject: [PATCH] CI: clang-tidy all headers Hijack the already existing dummy.cc to include a dynamically created header that includes all deal.II header files. This will run clang-tidy on all headers. I tried running clang-tidy on a .cc generated inside the build directory, but this doesn't work for some reason. closes #9933 --- contrib/utilities/run_clang_tidy.sh | 16 ++++++++++++---- source/dummy.cc | 9 +++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/contrib/utilities/run_clang_tidy.sh b/contrib/utilities/run_clang_tidy.sh index 667bba5a86..f8fb8bb397 100755 --- a/contrib/utilities/run_clang_tidy.sh +++ b/contrib/utilities/run_clang_tidy.sh @@ -57,13 +57,21 @@ CC=clang CXX=clang++ cmake "${ARGS[@]}" "$SRC" || (echo "cmake failed!"; false) cmake --build . --target expand_all_instantiations || (echo "make expand_all_instantiations failed!"; false) || exit 3 -# finally run it: +# generate allheaders.h +(cd include; find . -name '*.h'; cd $SRC/include/; find . -name '*.h') | grep -v allheaders.h | grep -v undefine_macros.h | sed 's|^./|#include <|' | sed 's|$|>|' >include/deal.II/allheaders.h + +# finally run it clang-tidy on deal.II +# # pipe away stderr (just contains nonsensical "x warnings generated") # pipe output to output.txt -run-clang-tidy.py -p . -quiet -header-filter="$SRC/include/*" 2>error.txt >output.txt +run-clang-tidy.py -p . -quiet -header-filter "$SRC/include/*" -extra-arg='-DCLANG_TIDY' 2>error.txt >output.txt + +# grep interesting errors and make sure we remove duplicates: +grep -E '(warning|error): ' output.txt output2.txt | sort | uniq >clang-tidy.log -if grep -E -q '(warning|error): ' output.txt; then - grep -E '(warning|error): ' output.txt +# if we have errors, report them and set exit status to failure +if [ -s clang-tidy.log ]; then + cat clang-tidy.log exit 4 fi diff --git a/source/dummy.cc b/source/dummy.cc index 4f56c4fc0b..20c308a63a 100644 --- a/source/dummy.cc +++ b/source/dummy.cc @@ -26,3 +26,12 @@ use_global_symbol_42() { (void)global_symbol_42; } + +/** + * If we are running the contrib/utilities/run_clang_tidy.sh script, we + * generate a header file allheaders.h that includes all deal.II + * headers. Include the file here so that all headers are being checked. + */ +#ifdef CLANG_TIDY +# include +#endif -- 2.39.5