From 82954364c260a2925216231b322e99b0506e7c31 Mon Sep 17 00:00:00 2001 From: Jakub Strzebonski Date: Tue, 19 Jul 2022 11:04:17 +0200 Subject: [PATCH 1/3] #874 add docker to run custom clang-tidy version --- ci/clang_tidy_cpp.sh | 9 +++ ci/docker/vt-clang-tidy.dockerfile | 92 ++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100755 ci/clang_tidy_cpp.sh create mode 100644 ci/docker/vt-clang-tidy.dockerfile diff --git a/ci/clang_tidy_cpp.sh b/ci/clang_tidy_cpp.sh new file mode 100755 index 0000000000..2d3f224706 --- /dev/null +++ b/ci/clang_tidy_cpp.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -ex + +build_dir=${1} +pushd "${build_dir}/vt" + +# That's just an example of how to set checks +run-clang-tidy -checks='-*, bugprone-easily-swappable-parameters' diff --git a/ci/docker/vt-clang-tidy.dockerfile b/ci/docker/vt-clang-tidy.dockerfile new file mode 100644 index 0000000000..69dafb42fd --- /dev/null +++ b/ci/docker/vt-clang-tidy.dockerfile @@ -0,0 +1,92 @@ +FROM jstrz/vt-clang-tidy:pr-1-merge AS base + +ENV DEBIAN_FRONTEND=noninteractive +WORKDIR / + +RUN apt-get remove cmake -y -q +RUN apt-get update -y -q +RUN apt-get install -y -q --no-install-recommends \ + ca-certificates \ + ccache \ + curl \ + git \ + less \ + libomp-dev \ + libomp5 \ + make-guile \ + ninja-build \ + python \ + python3 \ + valgrind \ + wget \ + zlib1g \ + zlib1g-dev && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +ENV CC=clang \ + CXX=clang++ + +COPY ./ci/deps/libunwind.sh libunwind.sh +RUN ./libunwind.sh 1.6.2 + +COPY ./ci/deps/cmake.sh cmake.sh +RUN ./cmake.sh 3.18.4 + +ENV PATH=/cmake/bin/:$PATH +ENV LESSCHARSET=utf-8 + +COPY ./ci/deps/mpich.sh mpich.sh +RUN ./mpich.sh 4.0.2 -j"$(nproc)" + +ENV MPI_EXTRA_FLAGS="" \ + CMAKE_PREFIX_PATH="/lib/x86_64-linux-gnu/" \ + PATH=/usr/lib/ccache/:$PATH \ + CMAKE_EXE_LINKER_FLAGS="-pthread" + +FROM base AS build +COPY . /vt + +ARG BUILD_SHARED_LIBS +ARG CMAKE_BUILD_TYPE +ARG VT_ASAN_ENABLED +ARG VT_DOXYGEN_ENABLED +ARG VT_EXTENDED_TESTS_ENABLED +ARG VT_FCONTEXT_ENABLED +ARG VT_LB_ENABLED +ARG VT_MIMALLOC_ENABLED +ARG VT_NO_COLOR_ENABLED +ARG VT_POOL_ENABLED +ARG VT_PRODUCTION_BUILD_ENABLED +ARG VT_TRACE_ENABLED +ARG VT_TRACE_RUNTIME_ENABLED +ARG VT_UBSAN_ENABLED +ARG VT_USE_OPENMP +ARG VT_USE_STD_THREAD +ARG VT_WERROR_ENABLED + +ENV BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} \ + CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \ + VT_ASAN_ENABLED=${VT_ASAN_ENABLED} \ + VT_DIAGNOSTICS_ENABLED=${VT_DIAGNOSTICS_ENABLED} \ + VT_DIAGNOSTICS_RUNTIME_ENABLED=${VT_DIAGNOSTICS_RUNTIME_ENABLED} \ + VT_DOXYGEN_ENABLED=${VT_DOXYGEN_ENABLED} \ + VT_EXTENDED_TESTS_ENABLED=${VT_EXTENDED_TESTS_ENABLED} \ + VT_FCONTEXT_ENABLED=${VT_FCONTEXT_ENABLED} \ + VT_LB_ENABLED=${VT_LB_ENABLED} \ + VT_MIMALLOC_ENABLED=${VT_MIMALLOC_ENABLED} \ + VT_MPI_GUARD_ENABLED=${VT_MPI_GUARD_ENABLED} \ + VT_NO_COLOR_ENABLED=${VT_NO_COLOR_ENABLED} \ + VT_POOL_ENABLED=${VT_POOL_ENABLED} \ + VT_PRODUCTION_BUILD_ENABLED=${VT_PRODUCTION_BUILD_ENABLED} \ + VT_TRACE_ENABLED=${VT_TRACE_ENABLED} \ + VT_TRACE_RUNTIME_ENABLED=${VT_TRACE_RUNTIME} \ + VT_UBSAN_ENABLED=${VT_UBSAN_ENABLED} \ + VT_UNITY_BUILD_ENABLED=${VT_UNITY_BUILD_ENABLED} \ + VT_USE_OPENMP=${VT_USE_OPENMP} \ + VT_USE_STD_THREAD=${VT_USE_STD_THREAD} \ + VT_WERROR_ENABLED=${VT_WERROR_ENABLED} + +# Without build there is no `vt_git_revision.cc` which causes clang-tidy to exit with error +RUN /vt/ci/build_cpp.sh /vt /build +RUN /vt/ci/clang_tidy_cpp.sh /build From 77e7a7040ee56ca3798f6f3d035dbf31aec86dfc Mon Sep 17 00:00:00 2001 From: Jakub Strzebonski Date: Wed, 20 Jul 2022 14:17:24 +0200 Subject: [PATCH 2/3] #874 run clang-tidy workflow --- .github/workflows/run-clang-tidy.yml | 25 ++++ .gitignore | 3 + ci/clang_tidy_cpp.sh | 134 +++++++++++++++++++- ci/docker/vt-clang-tidy.dockerfile | 4 +- cmake/build_git_info.cmake | 2 +- src/vt/configs/generated/vt_git_revision.cc | 64 ++++++++++ 6 files changed, 224 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/run-clang-tidy.yml create mode 100644 src/vt/configs/generated/vt_git_revision.cc diff --git a/.github/workflows/run-clang-tidy.yml b/.github/workflows/run-clang-tidy.yml new file mode 100644 index 0000000000..13be5749f7 --- /dev/null +++ b/.github/workflows/run-clang-tidy.yml @@ -0,0 +1,25 @@ +name: PR tests (clang-tidy) + +on: + push: + branches: + - develop + - 1.* + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + + env: + CMAKE_BUILD_TYPE: release + VT_LB_ENABLED: 1 + VT_TRACE_ENABLED: 1 + VT_USE_OPENMP: 0 + VT_USE_STD_THREAD: 0 + + steps: + - uses: actions/checkout@v2 + - name: Run clang-tidy docker + shell: bash + run: docker build -f ci/docker/vt-clang-tidy.dockerfile -t vt-clang-tidy . diff --git a/.gitignore b/.gitignore index a8e6e47a87..0e25bd0659 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,6 @@ compile_commands.json .dir-locals.el .idea/ + +# Autogenerated file +src/vt/configs/generated/vt_git_revision.cc diff --git a/ci/clang_tidy_cpp.sh b/ci/clang_tidy_cpp.sh index 2d3f224706..3748abbd92 100755 --- a/ci/clang_tidy_cpp.sh +++ b/ci/clang_tidy_cpp.sh @@ -2,8 +2,134 @@ set -ex -build_dir=${1} -pushd "${build_dir}/vt" +source_dir=${1} +build_dir=${2} -# That's just an example of how to set checks -run-clang-tidy -checks='-*, bugprone-easily-swappable-parameters' +# Dependency versions, when fetched via git. +detector_rev=master +checkpoint_rev=develop + +if [ -z ${4} ]; then + dashj="" +else + dashj="-j ${4}" +fi + +mkdir -p "${build_dir}" +pushd "${build_dir}" + +if test -d "detector" +then + rm -Rf detector +fi + +if test -d "checkpoint" +then + rm -Rf checkpoint +fi + +if test -d "${source_dir}/lib/detector" +then + { echo "Detector already in lib... not downloading, building, and installing"; } 2>/dev/null +else + if test "${VT_DOXYGEN_ENABLED:-0}" -eq 1 + then + cd "${source_dir}/lib" + git clone -b "${detector_rev}" --depth 1 https://github.com/DARMA-tasking/detector.git + cd - + else + git clone -b "${detector_rev}" --depth 1 https://github.com/DARMA-tasking/detector.git + export DETECTOR=$PWD/detector + export DETECTOR_BUILD=${build_dir}/detector + mkdir -p "$DETECTOR_BUILD" + cd "$DETECTOR_BUILD" + mkdir build + cd build + cmake -G "${CMAKE_GENERATOR:-Ninja}" \ + -DCMAKE_INSTALL_PREFIX="$DETECTOR_BUILD/install" \ + "$DETECTOR" + cmake --build . ${dashj} --target install + fi +fi + +if test -d "${source_dir}/lib/checkpoint" +then + { echo "Checkpoint already in lib... not downloading, building, and installing"; } 2>/dev/null +else + if test "${VT_DOXYGEN_ENABLED:-0}" -eq 1 + then + cd "${source_dir}/lib" + git clone -b "${checkpoint_rev}" --depth 1 https://github.com/DARMA-tasking/checkpoint.git + cd - + else + git clone -b "${checkpoint_rev}" --depth 1 https://github.com/DARMA-tasking/checkpoint.git + export CHECKPOINT=$PWD/checkpoint + export CHECKPOINT_BUILD=${build_dir}/checkpoint + mkdir -p "$CHECKPOINT_BUILD" + cd "$CHECKPOINT_BUILD" + mkdir build + cd build + cmake -G "${CMAKE_GENERATOR:-Ninja}" \ + -DCMAKE_INSTALL_PREFIX="$CHECKPOINT_BUILD/install" \ + -Ddetector_DIR="$DETECTOR_BUILD/install" \ + "$CHECKPOINT" + cmake --build . ${dashj} --target install + fi +fi + +if test "${VT_ZOLTAN_ENABLED:-0}" -eq 1 +then + export Zoltan_DIR=${ZOLTAN_DIR:-""} +fi + +export VT=${source_dir} +export VT_BUILD=${build_dir}/vt +mkdir -p "$VT_BUILD" +cd "$VT_BUILD" +rm -Rf ./* +cmake -G "${CMAKE_GENERATOR:-Ninja}" \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \ + -Dvt_test_trace_runtime_enabled="${VT_TRACE_RUNTIME_ENABLED:-0}" \ + -Dvt_lb_enabled="${VT_LB_ENABLED:-1}" \ + -Dvt_trace_enabled="${VT_TRACE_ENABLED:-0}" \ + -Dvt_trace_only="${VT_BUILD_TRACE_ONLY:-0}" \ + -Dvt_doxygen_enabled="${VT_DOXYGEN_ENABLED:-0}" \ + -Dvt_mimalloc_enabled="${VT_MIMALLOC_ENABLED:-0}" \ + -Dvt_asan_enabled="${VT_ASAN_ENABLED:-0}" \ + -Dvt_ubsan_enabled="${VT_UBSAN_ENABLED:-0}" \ + -Dvt_werror_enabled="${VT_WERROR_ENABLED:-0}" \ + -Dvt_pool_enabled="${VT_POOL_ENABLED:-1}" \ + -Dvt_build_extended_tests="${VT_EXTENDED_TESTS_ENABLED:-1}" \ + -Dvt_zoltan_enabled="${VT_ZOLTAN_ENABLED:-0}" \ + -Dvt_production_build_enabled="${VT_PRODUCTION_BUILD_ENABLED:-0}" \ + -Dvt_unity_build_enabled="${VT_UNITY_BUILD_ENABLED:-0}" \ + -Dvt_diagnostics_enabled="${VT_DIAGNOSTICS_ENABLED:-1}" \ + -Dvt_diagnostics_runtime_enabled="${VT_DIAGNOSTICS_RUNTIME_ENABLED:-0}" \ + -Dvt_fcontext_enabled="${VT_FCONTEXT_ENABLED:-0}" \ + -Dvt_fcontext_build_tests_examples="${VT_FCONTEXT_BUILD_TESTS_EXAMPLES:-0}" \ + -Dvt_rdma_tests_enabled="${VT_RDMA_TESTS_ENABLED:-1}" \ + -DUSE_OPENMP="${VT_USE_OPENMP:-0}" \ + -DUSE_STD_THREAD="${VT_USE_STD_THREAD:-0}" \ + -DCODE_COVERAGE="${CODE_COVERAGE:-0}" \ + -DMI_INTERPOSE:BOOL=ON \ + -DMI_OVERRIDE:BOOL=ON \ + -Dvt_mpi_guards="${VT_MPI_GUARD_ENABLED:-0}" \ + -DMPI_EXTRA_FLAGS="${MPI_EXTRA_FLAGS:-}" \ + -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE:-Release}" \ + -DMPI_C_COMPILER="${MPICC:-mpicc}" \ + -DMPI_CXX_COMPILER="${MPICXX:-mpicxx}" \ + -DCMAKE_CXX_COMPILER="${CXX:-c++}" \ + -DCMAKE_C_COMPILER="${CC:-cc}" \ + -DCMAKE_EXE_LINKER_FLAGS="${CMAKE_EXE_LINKER_FLAGS:-}" \ + -Ddetector_DIR="$DETECTOR_BUILD/install" \ + -Dcheckpoint_DIR="$CHECKPOINT_BUILD/install" \ + -DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH:-}" \ + -DCMAKE_INSTALL_PREFIX="$VT_BUILD/install" \ + -Dvt_ci_build="${VT_CI_BUILD:-0}" \ + -Dvt_debug_verbose="${VT_DEBUG_VERBOSE:-}" \ + -Dvt_tests_num_nodes="${VT_TESTS_NUM_NODES:-}" \ + -Dvt_no_color_enabled="${VT_NO_COLOR_ENABLED:-0}" \ + -DBUILD_SHARED_LIBS="${BUILD_SHARED_LIBS:-0}" \ + "$VT" + +run-clang-tidy -checks='-*, bugprone-*' diff --git a/ci/docker/vt-clang-tidy.dockerfile b/ci/docker/vt-clang-tidy.dockerfile index 69dafb42fd..1348a6024f 100644 --- a/ci/docker/vt-clang-tidy.dockerfile +++ b/ci/docker/vt-clang-tidy.dockerfile @@ -87,6 +87,4 @@ ENV BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} \ VT_USE_STD_THREAD=${VT_USE_STD_THREAD} \ VT_WERROR_ENABLED=${VT_WERROR_ENABLED} -# Without build there is no `vt_git_revision.cc` which causes clang-tidy to exit with error -RUN /vt/ci/build_cpp.sh /vt /build -RUN /vt/ci/clang_tidy_cpp.sh /build +RUN /vt/ci/clang_tidy_cpp.sh /vt /build diff --git a/cmake/build_git_info.cmake b/cmake/build_git_info.cmake index 8d47e28479..b4646ef067 100644 --- a/cmake/build_git_info.cmake +++ b/cmake/build_git_info.cmake @@ -27,7 +27,7 @@ else() endif() endif() -set(VT_GIT_CONFIG_FILE "${PROJECT_BIN_DIR}/src/vt/configs/generated/vt_git_revision.cc") +set(VT_GIT_CONFIG_FILE "${CMAKE_SOURCE_DIR}/src/vt/configs/generated/vt_git_revision.cc") add_custom_command( OUTPUT ${VT_GIT_CONFIG_FILE} COMMAND ${CMAKE_COMMAND} diff --git a/src/vt/configs/generated/vt_git_revision.cc b/src/vt/configs/generated/vt_git_revision.cc new file mode 100644 index 0000000000..d92729877a --- /dev/null +++ b/src/vt/configs/generated/vt_git_revision.cc @@ -0,0 +1,64 @@ +/* +//@HEADER +// ***************************************************************************** +// +// vt_git_revision.cc.in +// DARMA/vt => Virtual Transport +// +// Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC +// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. +// Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact darma@sandia.gov +// +// ***************************************************************************** +//@HEADER +*/ + +#include "vt/configs/generated/vt_git_revision.h" + +#include + +#define VT_VERSION_MAJOR 1 +#define VT_VERSION_MINOR 1 +#define VT_VERSION_PATCH 0 +#define VT_GIT_SHA1 "21f42e5abc76b8c3a6cccefa42d43e1b37d79c55" +#define VT_GIT_EXACT_TAG "heads/874-integrate-clang-tidy-docker" +#define VT_GIT_REFSPEC "refs/heads/874-integrate-clang-tidy-docker" +#define VT_GIT_DESCRIPTION "heads/874-integrate-clang-tidy-docker-0-g21f42e5abc" +#define VT_GIT_CLEAN_STATUS "DIRTY" + +int const vt_version_major = VT_VERSION_MAJOR; +int const vt_version_minor = VT_VERSION_MINOR; +int const vt_version_patch = VT_VERSION_PATCH; +std::string const vt_git_sha1 = VT_GIT_SHA1; +std::string const vt_git_exact_tag = VT_GIT_EXACT_TAG; +std::string const vt_git_refspec = VT_GIT_REFSPEC; +std::string const vt_git_description = VT_GIT_DESCRIPTION; +std::string const vt_git_clean_status = VT_GIT_CLEAN_STATUS; From 30d6b950db921e0f6a15e22f1f09616a959f12fe Mon Sep 17 00:00:00 2001 From: Jakub Strzebonski Date: Sat, 30 Jul 2022 23:38:08 +0200 Subject: [PATCH 3/3] #874 add mist-redundant-const-refs check --- ci/clang_tidy_cpp.sh | 2 +- src/vt/configs/generated/vt_git_revision.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/clang_tidy_cpp.sh b/ci/clang_tidy_cpp.sh index 3748abbd92..47bf6404c6 100755 --- a/ci/clang_tidy_cpp.sh +++ b/ci/clang_tidy_cpp.sh @@ -132,4 +132,4 @@ cmake -G "${CMAKE_GENERATOR:-Ninja}" \ -DBUILD_SHARED_LIBS="${BUILD_SHARED_LIBS:-0}" \ "$VT" -run-clang-tidy -checks='-*, bugprone-*' +run-clang-tidy -checks='-*, bugprone-*, misc-redundant-const-refs' diff --git a/src/vt/configs/generated/vt_git_revision.cc b/src/vt/configs/generated/vt_git_revision.cc index d92729877a..5d6cf6c8a7 100644 --- a/src/vt/configs/generated/vt_git_revision.cc +++ b/src/vt/configs/generated/vt_git_revision.cc @@ -2,7 +2,7 @@ //@HEADER // ***************************************************************************** // -// vt_git_revision.cc.in +// vt_git_revision.cc // DARMA/vt => Virtual Transport // // Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC