mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2026-11-26 05:31:36 +00:00
feat(tidy): build the checks as a clang-tidy plugin
- Add the MODULE library fairmq-tidy-plugin, installed as libfairmq-tidy-checks.so. It adds the fairmq-* checks to a stock clang-tidy of the same LLVM release via --load. - Do not link the LLVM libraries into the plugin: the loading clang-tidy has them. - Run every check test also through the plugin, if a clang-tidy of the found LLVM installation exists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -64,3 +64,19 @@ install(TARGETS ${target}
|
|||||||
EXPORT ${PROJECT_EXPORT_SET}
|
EXPORT ${PROJECT_EXPORT_SET}
|
||||||
RUNTIME DESTINATION ${PROJECT_INSTALL_BINDIR}
|
RUNTIME DESTINATION ${PROJECT_INSTALL_BINDIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# libfairmq-tidy-checks: the fairmq-* checks as a plugin for a clang-tidy of
|
||||||
|
# the same LLVM release, e.g. `clang-tidy --load=libfairmq-tidy-checks.so`.
|
||||||
|
# It does not link the LLVM libraries: the clang-tidy executable has them.
|
||||||
|
set(target fairmq-tidy-plugin)
|
||||||
|
add_library(${target} MODULE $<TARGET_OBJECTS:fairmq-tidy-module>)
|
||||||
|
add_library("${PROJECT_NAME}::${target}" ALIAS ${target})
|
||||||
|
set_target_properties(${target} PROPERTIES OUTPUT_NAME fairmq-tidy-checks)
|
||||||
|
if(APPLE)
|
||||||
|
target_link_options(${target} PRIVATE -undefined dynamic_lookup)
|
||||||
|
endif()
|
||||||
|
install(TARGETS ${target}
|
||||||
|
EXPORT ${PROJECT_EXPORT_SET}
|
||||||
|
LIBRARY DESTINATION ${PROJECT_INSTALL_LIBDIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -29,18 +29,42 @@ $<$<BOOL:${incs}>:-isystem\n$<JOIN:${incs},\n-isystem\n>>
|
|||||||
$<$<BOOL:${defs}>:-D$<JOIN:${defs},\n-D>>
|
$<$<BOOL:${defs}>:-D$<JOIN:${defs},\n-D>>
|
||||||
")
|
")
|
||||||
|
|
||||||
|
# The plugin needs a clang-tidy of the same LLVM release.
|
||||||
|
find_program(FAIRMQ_TIDY_CLANG_TIDY NAMES clang-tidy clang-tidy-${LLVM_VERSION_MAJOR}
|
||||||
|
HINTS "${LLVM_TOOLS_BINARY_DIR}" NO_DEFAULT_PATH
|
||||||
|
DOC "clang-tidy executable for the fairmq-tidy plugin tests"
|
||||||
|
)
|
||||||
|
if(NOT FAIRMQ_TIDY_CLANG_TIDY)
|
||||||
|
message(STATUS "clang-tidy not found in ${LLVM_TOOLS_BINARY_DIR}. "
|
||||||
|
"Skipping the fairmq-tidy plugin tests.")
|
||||||
|
endif()
|
||||||
|
|
||||||
file(GLOB inputs CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/fairmq-*.cxx")
|
file(GLOB inputs CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/fairmq-*.cxx")
|
||||||
foreach(input IN LISTS inputs)
|
foreach(input IN LISTS inputs)
|
||||||
get_filename_component(check "${input}" NAME_WE)
|
get_filename_component(check "${input}" NAME_WE)
|
||||||
add_test(NAME "tidy.${check}"
|
set(args
|
||||||
COMMAND ${CMAKE_COMMAND}
|
|
||||||
"-DTIDY=$<TARGET_FILE:FairMQ::fairmq-tidy>"
|
|
||||||
"-DFILECHECK=${FAIRMQ_TIDY_FILECHECK}"
|
"-DFILECHECK=${FAIRMQ_TIDY_FILECHECK}"
|
||||||
"-DCHECK=${check}"
|
"-DCHECK=${check}"
|
||||||
"-DINPUT=${input}"
|
"-DINPUT=${input}"
|
||||||
"-DFLAGS=${CMAKE_CURRENT_BINARY_DIR}/flags.txt"
|
"-DFLAGS=${CMAKE_CURRENT_BINARY_DIR}/flags.txt"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_test(NAME "tidy.${check}"
|
||||||
|
COMMAND ${CMAKE_COMMAND} ${args}
|
||||||
|
"-DTIDY=$<TARGET_FILE:FairMQ::fairmq-tidy>"
|
||||||
"-DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${check}"
|
"-DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${check}"
|
||||||
-P "${CMAKE_CURRENT_SOURCE_DIR}/RunCheck.cmake"
|
-P "${CMAKE_CURRENT_SOURCE_DIR}/RunCheck.cmake"
|
||||||
)
|
)
|
||||||
set_tests_properties("tidy.${check}" PROPERTIES TIMEOUT 120)
|
set_tests_properties("tidy.${check}" PROPERTIES TIMEOUT 120)
|
||||||
|
|
||||||
|
if(FAIRMQ_TIDY_CLANG_TIDY)
|
||||||
|
add_test(NAME "tidy.plugin.${check}"
|
||||||
|
COMMAND ${CMAKE_COMMAND} ${args}
|
||||||
|
"-DTIDY=${FAIRMQ_TIDY_CLANG_TIDY}"
|
||||||
|
"-DLOAD=$<TARGET_FILE:FairMQ::fairmq-tidy-plugin>"
|
||||||
|
"-DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/plugin/${check}"
|
||||||
|
-P "${CMAKE_CURRENT_SOURCE_DIR}/RunCheck.cmake"
|
||||||
|
)
|
||||||
|
set_tests_properties("tidy.plugin.${check}" PROPERTIES TIMEOUT 120)
|
||||||
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|||||||
@@ -16,7 +16,8 @@
|
|||||||
# Any warning or error without a CHECK-MESSAGES line fails the test.
|
# Any warning or error without a CHECK-MESSAGES line fails the test.
|
||||||
#
|
#
|
||||||
# Usage: cmake -DTIDY=<exe> -DFILECHECK=<exe> -DCHECK=<name> -DINPUT=<file>
|
# Usage: cmake -DTIDY=<exe> -DFILECHECK=<exe> -DCHECK=<name> -DINPUT=<file>
|
||||||
# -DFLAGS=<file with one compiler flag per line> -DWORKDIR=<dir> -P RunCheck.cmake
|
# -DFLAGS=<file with one compiler flag per line> -DWORKDIR=<dir>
|
||||||
|
# [-DLOAD=<clang-tidy plugin>] -P RunCheck.cmake
|
||||||
|
|
||||||
foreach(var IN ITEMS TIDY FILECHECK CHECK INPUT FLAGS WORKDIR)
|
foreach(var IN ITEMS TIDY FILECHECK CHECK INPUT FLAGS WORKDIR)
|
||||||
if(NOT DEFINED ${var})
|
if(NOT DEFINED ${var})
|
||||||
@@ -35,8 +36,12 @@ string(REGEX REPLACE "// *CHECK-[A-Z-]+:[^\n]*" "//" content "${content}")
|
|||||||
file(WRITE "${fixed}" "${content}")
|
file(WRITE "${fixed}" "${content}")
|
||||||
|
|
||||||
file(STRINGS "${FLAGS}" flags)
|
file(STRINGS "${FLAGS}" flags)
|
||||||
|
set(load)
|
||||||
|
if(LOAD)
|
||||||
|
set(load "--load=${LOAD}")
|
||||||
|
endif()
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND "${TIDY}" "--checks=-*,${CHECK}" --fix "${fixed}" -- ${flags}
|
COMMAND "${TIDY}" ${load} "--checks=-*,${CHECK}" --fix "${fixed}" -- ${flags}
|
||||||
OUTPUT_FILE "${messages}"
|
OUTPUT_FILE "${messages}"
|
||||||
ERROR_VARIABLE stderr
|
ERROR_VARIABLE stderr
|
||||||
RESULT_VARIABLE result
|
RESULT_VARIABLE result
|
||||||
|
|||||||
Reference in New Issue
Block a user