Skip to content

Commit

Permalink
Add dev warnings as errors flag to catch issues in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pfultz2 committed Aug 4, 2023
1 parent 5c9623b commit d678ff8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
20 changes: 16 additions & 4 deletions share/rocm/cmake/ROCMClangTidy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ else()
message(STATUS "Clang tidy found: ${CLANG_TIDY_VERSION}")
endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")

set(CLANG_TIDY_CACHE
"${CMAKE_BINARY_DIR}/tidy-cache"
Expand Down Expand Up @@ -90,16 +90,28 @@ cmake_dependent_option(ROCM_ENABLE_CLANG_TIDY "Enable Clang-Tidy checks" ON CLAN

macro(rocm_enable_clang_tidy)
if(ROCM_ENABLE_CLANG_TIDY)
set(options ALL ANALYZE_TEMPORARY_DTORS ENABLE_ALPHA_CHECKS)
set(options ALL ANALYZE_TEMPORARY_DTORS ENABLE_ALPHA_CHECKS DEV_WARNINGS_AS_ERRORS)
set(oneValueArgs HEADER_FILTER)
set(multiValueArgs CHECKS ERRORS EXTRA_ARGS CLANG_ARGS)

cmake_parse_arguments(PARSE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
string(REPLACE ";" "," CLANG_TIDY_CHECKS "${PARSE_CHECKS}")
string(REPLACE ";" "," CLANG_TIDY_ERRORS "${PARSE_ERRORS}")

if(PARSE_UNPARSED_ARGUMENTS)
message(
FATAL_ERROR "Unknown keywords given to rocm_enable_clang_tidy(): \"${PARSE_UNPARSED_ARGUMENTS}\"")
endif()

message(STATUS "Clang tidy checks: ${CLANG_TIDY_CHECKS}")

set(CLANG_TIDY_DEV_WARNINGS_AS_ERRORS)
set(CLANG_TIDY_DEV_WARNING_MODE WARNING)
if(PARSE_DEV_WARNINGS_AS_ERRORS)
set(CLANG_TIDY_DEV_WARNING_MODE FATAL_ERROR)
set(CLANG_TIDY_DEV_WARNINGS_AS_ERRORS -Werror=dev)
endif()

set(CLANG_TIDY_ALL)
if(PARSE_ALL)
set(CLANG_TIDY_ALL ALL)
Expand Down Expand Up @@ -209,7 +221,7 @@ function(rocm_clang_tidy_check TARGET)
OUTPUT_VARIABLE PP_OUT
RESULT_VARIABLE RESULT1)
if(NOT RESULT1 EQUAL 0)
message(WARNING \"Could not preprocess ${SOURCE} -> ${BASE_SOURCE}.i\")
message(${CLANG_TIDY_DEV_WARNING_MODE} \"Could not preprocess ${SOURCE} -> ${BASE_SOURCE}.i\")
execute_process(
COMMAND
\${CLANG_TIDY_COMMAND_LIST}
Expand Down Expand Up @@ -281,7 +293,7 @@ function(rocm_clang_tidy_check TARGET)
")
add_custom_target(
${tidy_target}
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/${tidy_target}.cmake
COMMAND ${CMAKE_COMMAND} ${CLANG_TIDY_DEV_WARNINGS_AS_ERRORS} -P ${CMAKE_CURRENT_BINARY_DIR}/${tidy_target}.cmake
COMMENT "clang-tidy: Running clang-tidy on target ${SOURCE}...")
else()
add_custom_target(
Expand Down
16 changes: 9 additions & 7 deletions test/analyze/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@ include(ROCMInstallTargets)
include(ROCMAnalyzers)
include(ROCMSetupVersion)

rocm_setup_version(VERSION 1.0.0)

configure_file(simple2.cpp.in simple2.cpp)

add_library(simple simple.cpp ${CMAKE_CURRENT_BINARY_DIR}/simple2.cpp)
rocm_install_targets(TARGETS simple INCLUDE include)

include(ROCMClangTidy)
rocm_enable_clang_tidy(
DEV_WARNINGS_AS_ERRORS
CHECKS
*
-llvmlibc-*
Expand All @@ -46,4 +40,12 @@ rocm_enable_cppcheck(
threadsafety
)

rocm_setup_version(VERSION 1.0.0)

configure_file(simple2.cpp.in simple2.cpp)

add_library(simple simple.cpp ${CMAKE_CURRENT_BINARY_DIR}/simple2.cpp)
rocm_install_targets(TARGETS simple INCLUDE include)


rocm_clang_tidy_check(simple)

0 comments on commit d678ff8

Please sign in to comment.