From: Timo Heister Date: Mon, 28 Jan 2019 21:17:53 +0000 (-0700) Subject: [CI] introduce clang-tidy check X-Git-Tag: v9.1.0-rc1~384^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c89f3783f74db28e1127a351494514a84463199;p=dealii.git [CI] introduce clang-tidy check - remove -fix - allow bundled/ by including two .clang-tidy files - add jenkins script --- diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000000..5b4e0fd778 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,9 @@ +# Settings file automatically used by clang-tidy +# +# See ./contrib/utilities/run_clang_tidy.sh for details + +# We disable performance-inefficient-string-concatenation because we don't care about "a"+to_string(5)+... + +Checks: "-*,cppcoreguidelines-pro-type-static-cast-downcast,google-readability-casting,modernize-*,-modernize-pass-by-value,-modernize-raw-string-literal,-modernize-use-auto,-modernize-use-override,-modernize-use-default-member-init,-modernize-use-transparent-functors,use-emplace,mpi-*,performance-*,-performance-inefficient-string-concatenation" + +WarningsAsErrors: '*' diff --git a/bundled/.clang-tidy b/bundled/.clang-tidy new file mode 100644 index 0000000000..eb40a98a77 --- /dev/null +++ b/bundled/.clang-tidy @@ -0,0 +1,6 @@ +# Disable all checks because we don't want to fix things inside +# bundled/. Clang-tidy fails if nothing is chosen, so we just enable a single +# harmless warning: + +Checks: "-*,misc-sizeof-container" + diff --git a/contrib/ci/Jenkinsfile.tidy b/contrib/ci/Jenkinsfile.tidy new file mode 100644 index 0000000000..05c0134826 --- /dev/null +++ b/contrib/ci/Jenkinsfile.tidy @@ -0,0 +1,90 @@ +#!groovy + +/* +Settings to apply inside Jenkins: + - discover pull requests (remove branches/master) + - Strategy: merged PR + - enable "Disable GitHub Multibranch Status Plugin" + - trigger build on pull request comment: .* /rebuild.* (without space!) + - Jenkinsfile: choose contrib/ci/Jenkinsfile.tidy + - scan: every 4 hours + - discard: 5+ items +*/ + +pipeline +{ + agent none + + stages + { + stage("check") + { + when { + allOf { + not {branch 'master'} + } + } + + agent + { + docker + { + image 'dealii/indent' + } + } + + steps + { + githubNotify context: 'tidy', description: 'pending...', status: 'PENDING' + sh ''' + wget -q -O - https://api.github.com/repos/dealii/dealii/issues/${CHANGE_ID}/labels | grep 'ready to test' || \ + { echo "This commit will only be tested when it has the label 'ready to test'. Trigger a rebuild by adding a comment that contains '/rebuild'..."; exit 1; } + ''' + } + post + { + failure + { + githubNotify context: 'tidy', description: 'need ready to test label and /rebuild', status: 'PENDING' + script + { + currentBuild.result='NOT_BUILT' + } + } + } + } + + stage('build') + { + agent + { + docker + { + image 'tjhei/candi-base-clang' + } + } + steps + { + timeout(time: 2, unit: 'HOURS') + { + sh "echo \"building on node ${env.NODE_NAME}\"" + + sh '''#!/bin/bash + mkdir build && cd build + $WORKSPACE/contrib/utilities/run_clang_tidy.sh $WORKSPACE + ''' + githubNotify context: 'tidy', description: 'OK', status: 'SUCCESS' + } + } + + post + { + failure + { + githubNotify context: 'tidy', description: 'build failed', status: 'FAILURE' + } + } + } + + } +} diff --git a/contrib/utilities/run_clang_tidy.sh b/contrib/utilities/run_clang_tidy.sh index d292ef84a0..d013f56639 100755 --- a/contrib/utilities/run_clang_tidy.sh +++ b/contrib/utilities/run_clang_tidy.sh @@ -21,7 +21,7 @@ # Usage: # /contrib/utilities/run_clang_tidy.sh SRC_DIR OPTIONAL_CMAKE_ARGS # with: -# SRC_DIR is an absolute path to a deal.II source directory +# SRC_DIR points to a deal.II source directory # OPTIONAL_CMAKE_ARGS are optional arguments to pass to CMake # make sure to run this script in an empty build directory # @@ -29,8 +29,9 @@ # Clang 5.0.1+ and have clang, clang++, and run-clang-tidy.py in # your path. -# grab first argument: +# grab first argument and make relative path an absolute one: SRC=$1 +SRC=$(cd "$SRC";pwd) shift if test ! -d "$SRC/source" -o ! -d "$SRC/include" -o ! -d "$SRC/examples" -o ! -f "$SRC/CMakeLists.txt" ; then @@ -40,36 +41,32 @@ if test ! -d "$SRC/source" -o ! -d "$SRC/include" -o ! -d "$SRC/examples" -o ! - fi echo "SRC-DIR=$SRC" -# do not allow bundled packages, otherwise we get too many warnings from TBB/UMFPACK/etc. # enable MPI (to get MPI warnings) # export compile commands (so that run-clang-tidy.py works) -ARGS="-D DEAL_II_ALLOW_BUNDLED=OFF -D DEAL_II_WITH_MPI=ON -D CMAKE_EXPORT_COMPILE_COMMANDS=ON $@" +ARGS=("-D" "DEAL_II_WITH_MPI=ON" "-D" "CMAKE_EXPORT_COMPILE_COMMANDS=ON" "$@") -# disable performance-inefficient-string-concatenation because we don't care about "a"+to_string(5)+... -CHECKS="-*, - cppcoreguidelines-pro-type-static-cast-downcast, - google-readability-casting, - modernize-*, - -modernize-pass-by-value, - -modernize-raw-string-literal, - -modernize-use-auto, - -modernize-use-override, - -modernize-use-default-member-init, - -modernize-use-transparent-functors, - mpi-*, - performance-*, - -performance-inefficient-string-concatenation" - -CHECKS="$(echo "${CHECKS}" | tr -d '[:space:]')" -echo "$CHECKS" +# for a list of checks, see /.clang-tidy +cat "$SRC/.clang-tidy" if ! [ -x "$(command -v run-clang-tidy.py)" ] || ! [ -x "$(command -v clang++)" ]; then echo "make sure clang, clang++, and run-clang-tidy.py (part of clang) are in the path" exit 2 fi -CC=clang CXX=clang++ cmake $ARGS "$SRC" || (echo "cmake failed!"; false) || exit 2 +CC=clang CXX=clang++ cmake "${ARGS[@]}" "$SRC" || (echo "cmake failed!"; false) || exit 2 cmake --build . --target expand_all_instantiations || (echo "make expand_all_instantiations failed!"; false) || exit 3 -run-clang-tidy.py -p . -checks="$CHECKS" -quiet -header-filter="$SRC/include/*" -fix +# finally run it: +# 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 + +if grep -E -q '(warning|error): ' output.txt; then + grep -E '(warning|error): ' output.txt + exit 4 +fi + +echo "OK" +exit 0 +