From 9834824171cf834271f7ec1d9a4d8455c985e0f5 Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Tue, 13 Feb 2018 12:21:07 +0100
Subject: [PATCH] [Jenkins] Run clang-tidy cppcheck and CMake link check in
 Analyzer job.

---
 .clang-tidy                             |  2 +
 CMakeLists.txt                          |  3 +
 GeoLib/CMakeLists.txt                   |  6 +-
 Jenkinsfile                             | 13 ++--
 ThirdParty/.clang-tidy                  |  3 +
 scripts/docker/Dockerfile.clang.full    | 86 +++++++++++++++++++++++++
 scripts/docker/Dockerfile.clang.minimal | 34 ++--------
 scripts/docker/Dockerfile.gcc.full      |  4 +-
 8 files changed, 111 insertions(+), 40 deletions(-)
 create mode 100644 .clang-tidy
 create mode 100644 ThirdParty/.clang-tidy
 create mode 100644 scripts/docker/Dockerfile.clang.full

diff --git a/.clang-tidy b/.clang-tidy
new file mode 100644
index 00000000000..8f60b957437
--- /dev/null
+++ b/.clang-tidy
@@ -0,0 +1,2 @@
+---
+Checks: ''
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 64e2403c002..23ceec6835a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -38,6 +38,9 @@ set(OGS_CPU_ARCHITECTURE "native" CACHE STRING "Processor architecture, \
 option(OGS_ENABLE_AVX2 "Enable the use of AVX2 instructions" OFF)
 option(OGS_BUILD_TESTS "Should the test executables be built?" ON)
 option(OGS_USE_PCH "Should pre-compiled headers be used?" ON)
+if(DEFINED CMAKE_CXX_CLANG_TIDY)
+    set(OGS_USE_PCH OFF CACHE INTERNAL "")
+endif()
 option(OGS_USE_CONAN "Should Conan package manager be used?" OFF)
 set(OGS_CONAN_BUILD "missing" CACHE STRING "Possible values: all, missing, \
     never or list of libs to build" )
diff --git a/GeoLib/CMakeLists.txt b/GeoLib/CMakeLists.txt
index 957d6c9043f..0ce11d19baa 100644
--- a/GeoLib/CMakeLists.txt
+++ b/GeoLib/CMakeLists.txt
@@ -11,11 +11,9 @@ if(Qt5XmlPatterns_FOUND)
 endif()
 
 # Create the library
-add_library(GeoLib ${SOURCES}
-    ${CMAKE_CURRENT_SOURCE_DIR}/../ThirdParty/tetgen/predicates.cxx
-)
+add_library(GeoLib ${SOURCES})
 
-target_link_libraries(GeoLib PUBLIC BaseLib MathLib logog)
+target_link_libraries(GeoLib PUBLIC BaseLib MathLib logog PRIVATE tet)
 
 if(Qt5XmlPatterns_FOUND)
     target_link_libraries(GeoLib PUBLIC Qt5::Xml Qt5::XmlPatterns)
diff --git a/Jenkinsfile b/Jenkinsfile
index ba94a9508de..ea2e843b2f2 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -316,11 +316,11 @@ pipeline {
     stage('Master') {
       when { environment name: 'JOB_NAME', value: 'ufz/ogs/master' }
       parallel {
-        // ************************ Check-Header *******************************
-        stage('Check-Header') {
+        // ************************* Analyzers *********************************
+        stage('Analyzers') {
           agent {
             dockerfile {
-              filename 'Dockerfile.gcc.full'
+              filename 'Dockerfile.clang.full'
               dir 'scripts/docker'
               label 'docker'
               args '-v ccache:/home/jenkins/cache/ccache -v conan-cache:/home/jenkins/cache/conan'
@@ -335,8 +335,11 @@ pipeline {
                   cmakeOptions =
                     '-DOGS_USE_CONAN=ON ' +
                     '-DOGS_CONAN_BUILD=never ' +
-                    '"-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=/usr/local/bin/include-what-you-use;--transitive_includes_only" '
-                  config = 'Debug'
+                    '"-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=include-what-you-use" ' +
+                    '-DCMAKE_LINK_WHAT_YOU_USE=ON ' +
+                    '"-DCMAKE_CXX_CPPCHECK=cppcheck;--std=c++11;--language=c++;--suppress=syntaxError;--suppress=preprocessorErrorDirective:*/ThirdParty/*;--suppress=preprocessorErrorDirective:*conan*/package/*" ' +
+                    '-DCMAKE_CXX_CLANG_TIDY=clang-tidy-3.9 '
+                  config = 'Release'
                 }
               }
               build { target = 'check-header' }
diff --git a/ThirdParty/.clang-tidy b/ThirdParty/.clang-tidy
new file mode 100644
index 00000000000..62160a2d11d
--- /dev/null
+++ b/ThirdParty/.clang-tidy
@@ -0,0 +1,3 @@
+---
+# Disable all checks, one check has to be enabled (hack)
+Checks: '-*,boost-use-to-string'
diff --git a/scripts/docker/Dockerfile.clang.full b/scripts/docker/Dockerfile.clang.full
new file mode 100644
index 00000000000..29158ca568d
--- /dev/null
+++ b/scripts/docker/Dockerfile.clang.full
@@ -0,0 +1,86 @@
+FROM ubuntu:16.04
+
+RUN apt-get update && apt-get install -y software-properties-common curl \
+  && add-apt-repository -y ppa:ubuntu-toolchain-r/test \
+  && curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash \
+  && apt-get update \
+  && apt-get -y install \
+    build-essential \
+    ccache \
+    clang-3.9 \
+    git git-lfs \
+    python-pip \
+    sudo \
+    unzip \
+    xz-utils
+
+RUN python -m pip install --upgrade pip \
+  && python -m pip install cmake conan>=1.0.0
+
+# Ninja
+RUN curl -L -o ninja-linux.zip https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip \
+  && unzip ninja-linux.zip \
+  && mv ninja /usr/local/bin/ninja \
+  && rm ninja-linux.zip
+
+ENV CC=clang-3.9
+ENV CXX=clang++-3.9
+
+# Lis
+RUN curl -L -o lis.tar.gz http://www.ssisc.org/lis/dl/lis-1.7.9.tar.gz \
+  && tar xf lis.tar.gz \
+  && cd lis-1.7.9 \
+  && ./configure \
+  && make -j$(nproc) install \
+  && cd .. && rm -rf lis-1.7.9 lis.tar.gz
+
+# Add user jenkins to the image
+RUN adduser --uid 500 --disabled-password --gecos "" jenkins \
+  # Add user jenkins to sudoers with NOPASSWD
+  && echo "jenkins ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \
+  # Set password for the jenkins user (you may want to alter this).
+  && echo "jenkins:jenkins" | chpasswd
+
+USER jenkins
+ENV CCACHE_DIR=/home/jenkins/cache/ccache
+RUN mkdir -p $CCACHE_DIR
+ENV CCACHE_MAXSIZE=15G
+ENV CCACHE_SLOPPINESS=pch_defines,time_macros
+ENV CONAN_USER_HOME=/home/jenkins/cache/conan
+WORKDIR /home/jenkins
+RUN conan user
+
+### END clang.minimal ###
+USER root
+
+RUN apt-get update \
+  && apt-get -y install apt-transport-https curl \
+  && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
+  && echo "deb https://dl.yarnpkg.com/debian/ stable main" \
+     | tee /etc/apt/sources.list.d/yarn.list \
+  && curl -s https://deb.nodesource.com/setup_8.x | bash \
+  && apt-get update && apt-get install -y \
+    biber \
+    clang-tidy-3.9 \
+    cppcheck \
+    doxygen \
+    graphviz \
+    libxml2-utils \
+    nodejs \
+    pandoc-citeproc \
+    yarn
+
+RUN update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10
+
+# Hugo
+RUN curl -L -o hugo.tar.gz https://github.com/gohugoio/hugo/releases/download/v0.32.3/hugo_0.32.3_Linux-64bit.tar.gz \
+  && tar xf hugo.tar.gz \
+  && mv hugo /usr/local/bin/hugo \
+  && rm -rf hugo.tar.gz LICENSE.md README.md
+
+# Include-what-you-use
+RUN curl https://include-what-you-use.org/downloads/include-what-you-use-0.8-x86_64-linux-gnu-ubuntu-16.04.tar.gz -O \
+  && tar xf include-what-you-use-0.8-x86_64-linux-gnu-ubuntu-16.04.tar.gz -C /usr/ --strip-components=1 \
+  && rm include-what-you-use-0.8-x86_64-linux-gnu-ubuntu-16.04.tar.gz
+
+USER jenkins
diff --git a/scripts/docker/Dockerfile.clang.minimal b/scripts/docker/Dockerfile.clang.minimal
index 4cf5a8dc52c..718aa166f51 100644
--- a/scripts/docker/Dockerfile.clang.minimal
+++ b/scripts/docker/Dockerfile.clang.minimal
@@ -7,6 +7,7 @@ RUN apt-get update && apt-get install -y software-properties-common curl \
   && apt-get -y install \
     build-essential \
     ccache \
+    clang-3.9 \
     git git-lfs \
     python-pip \
     sudo \
@@ -22,35 +23,8 @@ RUN curl -L -o ninja-linux.zip https://github.com/ninja-build/ninja/releases/dow
   && mv ninja /usr/local/bin/ninja \
   && rm ninja-linux.zip
 
-# Install LLVM, see http://llvm.org/docs/CMake.html
-RUN curl -L -o llvm.tar.xz http://releases.llvm.org/3.9.0/llvm-3.9.0.src.tar.xz \
-  && tar -Jxf llvm.tar.xz \
-  && mkdir build-llvm && cd build-llvm \
-  && cmake ../llvm-3.9.0.src -DCMAKE_BUILD_TYPE=Release \
-  && make -j$(nproc) install \
-  && cd .. && rm -rf build-llvm llvm-3.9.0.src llvm.tar.xz
-
-# Clang
-RUN curl -L -o cfe-tar-xz http://releases.llvm.org/3.9.0/cfe-3.9.0.src.tar.xz \
-  && tar -Jxf cfe-tar-xz \
-  && mkdir build-cfe && cd build-cfe \
-  && cmake ../cfe-3.9.0.src -DCMAKE_BUILD_TYPE=Release -DLLVM_CONFIG_PATH=/usr/local/bin/llvm-config \
-  && make -j$(nproc) install \
-  && cd .. && rm -rf build-cfe cfe-3.9.0.src cfe-tar-xz
-
-ENV CC=clang
-ENV CXX=clang++
-
-# Compiler-rt
-RUN curl -L -o compiler-rt.tar.xz http://releases.llvm.org/3.9.0/compiler-rt-3.9.0.src.tar.xz \
-  && tar -Jxf compiler-rt.tar.xz \
-  && mkdir build-compiler-rt && cd build-compiler-rt \
-  && cmake ../compiler-rt-3.9.0.src -DCMAKE_BUILD_TYPE=Release -DLLVM_CONFIG_PATH=/usr/local/bin/llvm-config \
-  && make -j$(nproc) install \
-  && cd .. && rm -rf build-compiler-rt compiler-rt-3.9.0.src compiler-rt.tar.xz
-
-RUN mkdir /usr/local/lib/clang/3.9.0/lib
-RUN ln -s /usr/local/lib/linux /usr/local/lib/clang/3.9.0/lib/linux
+ENV CC=clang-3.9
+ENV CXX=clang++-3.9
 
 # Lis
 RUN curl -L -o lis.tar.gz http://www.ssisc.org/lis/dl/lis-1.7.9.tar.gz \
@@ -60,7 +34,7 @@ RUN curl -L -o lis.tar.gz http://www.ssisc.org/lis/dl/lis-1.7.9.tar.gz \
   && make -j$(nproc) install \
   && cd .. && rm -rf lis-1.7.9 lis.tar.gz
 
- # Add user jenkins to the image
+# Add user jenkins to the image
 RUN adduser --uid 500 --disabled-password --gecos "" jenkins \
   # Add user jenkins to sudoers with NOPASSWD
   && echo "jenkins ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \
diff --git a/scripts/docker/Dockerfile.gcc.full b/scripts/docker/Dockerfile.gcc.full
index b9617407132..5e7ee337a7c 100644
--- a/scripts/docker/Dockerfile.gcc.full
+++ b/scripts/docker/Dockerfile.gcc.full
@@ -51,6 +51,8 @@ RUN apt-get update \
   && curl -s https://deb.nodesource.com/setup_8.x | bash \
   && apt-get update && apt-get install -y \
     biber \
+    clang-tidy \
+    cppcheck \
     doxygen \
     graphviz \
     libxml2-utils \
@@ -68,7 +70,7 @@ RUN curl -L -o hugo.tar.gz https://github.com/gohugoio/hugo/releases/download/v0
 
 # Include-what-you-use
 RUN curl https://include-what-you-use.org/downloads/include-what-you-use-0.8-x86_64-linux-gnu-ubuntu-16.04.tar.gz -O \
-  && tar xf include-what-you-use-0.8-x86_64-linux-gnu-ubuntu-16.04.tar.gz -C /usr/local/ --strip-components=1 \
+  && tar xf include-what-you-use-0.8-x86_64-linux-gnu-ubuntu-16.04.tar.gz -C /usr/ --strip-components=1 \
   && rm include-what-you-use-0.8-x86_64-linux-gnu-ubuntu-16.04.tar.gz
 
 USER jenkins
-- 
GitLab