From d678ff84e31020b3cb2723583e3713dd2ee0dbcd Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 4 Aug 2023 17:10:34 -0500 Subject: [PATCH] Add dev warnings as errors flag to catch issues in tests --- share/rocm/cmake/ROCMClangTidy.cmake | 20 ++++++++++++++++---- test/analyze/CMakeLists.txt | 16 +++++++++------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/share/rocm/cmake/ROCMClangTidy.cmake b/share/rocm/cmake/ROCMClangTidy.cmake index daf76113..dd93c857 100644 --- a/share/rocm/cmake/ROCMClangTidy.cmake +++ b/share/rocm/cmake/ROCMClangTidy.cmake @@ -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" @@ -90,7 +90,7 @@ 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) @@ -98,8 +98,20 @@ macro(rocm_enable_clang_tidy) 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) @@ -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} @@ -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( diff --git a/test/analyze/CMakeLists.txt b/test/analyze/CMakeLists.txt index 0881e8aa..96d67a40 100755 --- a/test/analyze/CMakeLists.txt +++ b/test/analyze/CMakeLists.txt @@ -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-* @@ -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)