From 1dd9314f4d5c466427e6683cabc6bf15406f48ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Nordstr=C3=B6m?= Date: Thu, 28 May 2020 12:37:16 +0200 Subject: [PATCH] Improve linting support with clang-tidy This change replaces the existing `clang-tidy` linter target with CMake's built-in support for it. The old way of invoking the linter relied on the `run-clang-tidy` wrapper script, which is not installed by default on some platforms. Discovery of the `clang-tidy` tool has also been improved to work with more installation locations. As a result, linting now happens at compile time and is enabled automatically when `clang-tidy` is installed and found. In enabling `clang-tidy`, several non-trivial issues were discovered in compression-related code. These might be false positives, but, until a proper solution can be found, "warnings-as-errors" have been disabled for that code to allow compilation to succeed with the linter enabled. --- CMakeLists.txt | 42 +++++++++++++++++++++++---------- tsl/src/compression/.clang-tidy | 8 +++++++ 2 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 tsl/src/compression/.clang-tidy diff --git a/CMakeLists.txt b/CMakeLists.txt index a426748a8..a3efd3a0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,9 @@ set(PROJECT_INSTALL_METHOD source CACHE STRING "Specify what install platform th is built for") message(STATUS "Install method is '${PROJECT_INSTALL_METHOD}'") +# Build compilation database by default +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + # Code coverage is optional and OFF by default option(CODECOVERAGE "Enable code coverage for the build" OFF) @@ -251,6 +254,12 @@ install( # in standard installation paths. find_program(CLANG_FORMAT NAMES clang-format-8 clang-format-7 clang-format + PATHS + /usr/bin + /usr/local/bin + /usr/local/opt/ + /usr/local/opt/llvm/bin + /opt/bin DOC "The path to clang-format") if (CLANG_FORMAT) @@ -287,20 +296,27 @@ else() ) endif () -find_program(RUN_CLANG_TIDY run-clang-tidy DOC "The path to run-clang-tidy") +# Linter support via clang-tidy. Enabled by default. +option(LINTER "Enable linter support using clang-tidy (default ON)" ON) -if(RUN_CLANG_TIDY) - message(STATUS "Found clang-tidy at ${RUN_CLANG_TIDY}") - if(CMAKE_EXPORT_COMPILE_COMMANDS) - add_custom_target(clang-tidy COMMAND ${RUN_CLANG_TIDY} -quiet) - else() - message(WARNING "You need to add -DCMAKE_EXPORT_COMPILE_COMMANDS=ON to use clang-tidy") - add_custom_target(clang-tidy - COMMAND ${CMAKE_COMMAND} -E echo "clang-tidy found but -DCMAKE_EXPORT_COMPILE_COMMAND was not set") - endif() -else() - message(WARNING "Did not find clang-tidy, not defining clang-tidy target.") -endif() +if (LINTER) + find_program(CLANG_TIDY + clang-tidy + PATHS + /usr/bin + /usr/local/bin + /usr/local/opt/ + /usr/local/opt/llvm/bin + /opt/bin + DOC "The path to the clang-tidy linter") + + if (CLANG_TIDY) + message(STATUS "Linter support (clang-tidy) enabled") + set(CMAKE_C_CLANG_TIDY "${CLANG_TIDY};--quiet") + else () + message(STATUS "Install clang-tidy to enable code linting") + endif (CLANG_TIDY) +endif (LINTER) option(USE_OPENSSL "Enable use of OpenSSL if available" ON) option(SEND_TELEMETRY_DEFAULT "The default value for whether to send telemetry" ON) diff --git a/tsl/src/compression/.clang-tidy b/tsl/src/compression/.clang-tidy new file mode 100644 index 000000000..77b1143ff --- /dev/null +++ b/tsl/src/compression/.clang-tidy @@ -0,0 +1,8 @@ +# Disable warnings as errors on compression code since it currently +# doesn't pass those tests +--- +Checks: '-*,clang-analyzer-core.*,clang-diagnostic-*' +WarningsAsErrors: 'clang-analyzer-unix.*' +HeaderFilterRegex: '' +AnalyzeTemporaryDtors: false +...