diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000000000000000000000000000000000000..8f60b9574376e3f5c1a1350a60177e5c3dec6c0e --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,2 @@ +--- +Checks: '' diff --git a/BaseLib/FileTools.cpp b/BaseLib/FileTools.cpp index bd04d8b0e2586a696d4f67b0ed588ff0bbdd7874..7ed7c38676ab0a6532b99ad8aab73964a091ff17 100644 --- a/BaseLib/FileTools.cpp +++ b/BaseLib/FileTools.cpp @@ -25,7 +25,7 @@ namespace BaseLib */ bool IsFileExisting(const std::string &strFilename) { - struct stat buffer; + struct stat buffer {}; return (stat (strFilename.c_str(), &buffer) == 0); } @@ -35,7 +35,7 @@ double swapEndianness(double const& v) { double v; char c[sizeof(double)]; - } a, b; + } a {}, b {}; a.v = v; for (unsigned short i = 0; i < sizeof(double)/2; i++) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64e2403c002a8711bb658083b36973be726e0d57..23ceec6835a66bd7309c7ed9601e26b82ea3b3ee 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 957d6c9043fc2f6999db05989831fa2bdac38ccf..0ce11d19baa45a54b158cca702ecd2c36f92a6c1 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/GeoLib/IO/XmlIO/Rapid/RapidStnInterface.cpp b/GeoLib/IO/XmlIO/Rapid/RapidStnInterface.cpp index 30c32bd902f92948b7698447437d8db58681cfb1..e002c9840eead9597d604d467dfd83f4085ae7ad 100644 --- a/GeoLib/IO/XmlIO/Rapid/RapidStnInterface.cpp +++ b/GeoLib/IO/XmlIO/Rapid/RapidStnInterface.cpp @@ -29,7 +29,6 @@ namespace IO std::vector<GeoLib::Point*> *RapidStnInterface::readStationFile(const std::string &fileName) { - auto* stations = new std::vector<GeoLib::Point*>; std::ifstream in(fileName.c_str()); if (in.fail()) { @@ -55,6 +54,8 @@ std::vector<GeoLib::Point*> *RapidStnInterface::readStationFile(const std::strin return nullptr; } + auto* stations = new std::vector<GeoLib::Point*>; + // iterate over all station lists for (rapidxml::xml_node<>* station_list = doc.first_node()->first_node(); station_list; station_list = station_list->next_sibling()) { diff --git a/Jenkinsfile b/Jenkinsfile index fd01c4d17132d412867aad427329baf874f28fb0..09b1130fbf1643b6d6cce4ccabd9e7604600a112 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.minimal' + filename 'Dockerfile.clang.full' dir 'scripts/docker' label 'docker' args '-v ccache:/home/jenkins/cache/ccache -v conan-cache:/home/jenkins/cache/conan' @@ -334,11 +334,16 @@ pipeline { configure { cmakeOptions = '-DOGS_USE_CONAN=ON ' + - '-DOGS_CONAN_BUILD=never ' - config = 'Debug' + '-DOGS_CONAN_BUILD=never ' + + '"-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=include-what-you-use;-Xiwyu;--mapping_file=../scripts/jenkins/iwyu-mappings.imp" ' + + '-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' } + build { } } } post { always { dir('build') { deleteDir() } } } diff --git a/ThirdParty/.clang-tidy b/ThirdParty/.clang-tidy new file mode 100644 index 0000000000000000000000000000000000000000..8cd40d73ca6ea2462431fdf3693c0d9ab781c430 --- /dev/null +++ b/ThirdParty/.clang-tidy @@ -0,0 +1,6 @@ +--- +# Disable all checks, one check has to be enabled. +# Hack: if there is no enabled check clang-tidy (at least in the way it is +# invoked by CMake) prints out its own usage instructions. I have chosen an +# arbitrary check here. +Checks: '-*,boost-use-to-string' diff --git a/scripts/cmake/ConanSetup.cmake b/scripts/cmake/ConanSetup.cmake index 3a9a08deeaa337eaee2db6a81879fa14addaa36f..d1dcdcb9bcaeb5dd844fc0c61bb5665b122b1037 100644 --- a/scripts/cmake/ConanSetup.cmake +++ b/scripts/cmake/ConanSetup.cmake @@ -40,6 +40,10 @@ if(OGS_USE_PETSC) set(CONAN_REQUIRES ${CONAN_REQUIRES} petsc/3.8.3@bilke/testing) endif() +if(OGS_USE_LIS) + set(CONAN_REQUIRES ${CONAN_REQUIRES} lis/1.7.9@bilke/stable) +endif() + if(OGS_BUILD_GUI) set(CONAN_REQUIRES ${CONAN_REQUIRES} Shapelib/1.3.0@bilke/stable diff --git a/scripts/docker/Dockerfile.clang.full b/scripts/docker/Dockerfile.clang.full new file mode 100644 index 0000000000000000000000000000000000000000..6d643bdee4416d8ef000e05fb980b230159b45ad --- /dev/null +++ b/scripts/docker/Dockerfile.clang.full @@ -0,0 +1,78 @@ +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 + +# 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 4cf5a8dc52c9460109cfd7ac658c64bd2aea4377..3cfd2782d40bfa5b08cde46c2244bbcad8563c5a 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,45 +23,10 @@ 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 +ENV CC=clang-3.9 +ENV CXX=clang++-3.9 -# 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 - -# 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 +# 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 e49359c53dcc5083774ddbe48b2ff904e1076fb6..5e7ee337a7ce6ee62fe4b60f5081147e58b0ab21 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 \ @@ -66,4 +68,9 @@ RUN curl -L -o hugo.tar.gz https://github.com/gohugoio/hugo/releases/download/v0 && 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/jenkins/iwyu-mappings.imp b/scripts/jenkins/iwyu-mappings.imp new file mode 100644 index 0000000000000000000000000000000000000000..ee7bf2ee8f6215bf923f6e42c767705feebe3a94 --- /dev/null +++ b/scripts/jenkins/iwyu-mappings.imp @@ -0,0 +1,4 @@ +[ + { include: ["<logog/include/macro.hpp>", "private", "<logog/include/logog.hpp>", "public"] }, + { include: ["<logog/include/message.hpp>", "private", "<logog/include/logog.hpp>", "public"] } +]