]> https://gitweb.dealii.org/ - dealii.git/commitdiff
[CI] introduce clang-tidy check
authorTimo Heister <timo.heister@gmail.com>
Mon, 28 Jan 2019 21:17:53 +0000 (14:17 -0700)
committerTimo Heister <timo.heister@gmail.com>
Thu, 31 Jan 2019 19:05:12 +0000 (12:05 -0700)
- remove -fix
- allow bundled/ by including two .clang-tidy files
- add jenkins script

.clang-tidy [new file with mode: 0644]
bundled/.clang-tidy [new file with mode: 0644]
contrib/ci/Jenkinsfile.tidy [new file with mode: 0644]
contrib/utilities/run_clang_tidy.sh

diff --git a/.clang-tidy b/.clang-tidy
new file mode 100644 (file)
index 0000000..5b4e0fd
--- /dev/null
@@ -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 (file)
index 0000000..eb40a98
--- /dev/null
@@ -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 (file)
index 0000000..05c0134
--- /dev/null
@@ -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'
+        }
+      }
+    }
+
+  }
+}
index d292ef84a0845dab5b69c1ee7bd1d7fd5314f195..d013f56639478992de0730526e64c59426581b0c 100755 (executable)
@@ -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
+

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.