mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-22 22:11:29 +08:00
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.
This commit is contained in:
parent
1c1b3c856e
commit
1dd9314f4d
@ -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)
|
||||
|
8
tsl/src/compression/.clang-tidy
Normal file
8
tsl/src/compression/.clang-tidy
Normal file
@ -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
|
||||
...
|
Loading…
x
Reference in New Issue
Block a user