From d68e7e2966fda1ca3fc73a060f623e37dc0cf491 Mon Sep 17 00:00:00 2001 From: fruffy Date: Mon, 20 Nov 2023 09:18:40 -0500 Subject: [PATCH] Review comments. --- cmake/Linters.cmake | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/cmake/Linters.cmake b/cmake/Linters.cmake index 8cc3343848d..62c5a042fd7 100644 --- a/cmake/Linters.cmake +++ b/cmake/Linters.cmake @@ -57,8 +57,7 @@ endif() add_clang_format_files(${P4C_SOURCE_DIR} "${P4C_LINT_LIST}") find_program(CLANG_FORMAT_CMD clang-format) - -if(NOT ${CLANG_FORMAT_CMD}) +if(CLANG_FORMAT_CMD) # Retrieve the global clang-format property. get_property(CLANG_FORMAT_FILES GLOBAL PROPERTY CLANG_FORMAT-files) if(DEFINED CLANG_FORMAT_FILES) @@ -67,7 +66,6 @@ if(NOT ${CLANG_FORMAT_CMD}) set(CLANG_FORMAT_TXT_FILE ${P4C_BINARY_DIR}/clang_format_files.txt) list(SORT CLANG_FORMAT_FILES) file(WRITE ${CLANG_FORMAT_TXT_FILE} "${CLANG_FORMAT_FILES}") - set(CLANG_FORMAT_CMD clang-format) add_custom_target( clang-format COMMAND xargs -a ${CLANG_FORMAT_TXT_FILE} -r -d '\;' ${CLANG_FORMAT_CMD} --verbose --Werror --dry-run -i -- @@ -82,7 +80,7 @@ if(NOT ${CLANG_FORMAT_CMD}) ) endif() else() - message(WARNING "clang-format executable not found. Disabling clang-format checks. clang-format can be installed with \"pip3 install --user --upgrade clang-format\"") + message(WARNING "clang-format executable not found. Disabling clang-format checks. clang-format can be installed with \"pip3 install --user --upgrade clang-format\" or your distribution's package manager.") endif() @@ -96,31 +94,35 @@ endif() find_program(CLANG_TIDY_CMD clang-tidy) -if(NOT ${CLANG_TIDY_CMD}) +if(CLANG_TIDY_CMD) + if (NOT CMAKE_EXPORT_COMPILE_COMMANDS) + message(WARNING "CMAKE_EXPORT_COMPILE_COMMANDS is not set ON, clang-tidy remains disabled.") + endif() + # Retrieve the global clang-tidy property. get_property(CLANG_TIDY_FILES GLOBAL PROPERTY CLANG_TIDY-files) - if(DEFINED CLANG_TIDY_FILES) + if(DEFINED CLANG_TIDY_FILES AND CMAKE_EXPORT_COMPILE_COMMANDS) + # Write the list to a file. # We need to do this as too many files will reach the shell argument limit. set(CLANG_TIDY_TXT_FILE ${P4C_BINARY_DIR}/clang_tidy_files.txt) list(SORT CLANG_TIDY_FILES) file(WRITE ${CLANG_TIDY_TXT_FILE} "${CLANG_TIDY_FILES}") - set(CLANG_TIDY_CMD clang-tidy) add_custom_target( clang-tidy - COMMAND xargs -a ${CLANG_TIDY_TXT_FILE} -r -d '\;' ${CLANG_TIDY_CMD} -extra-arg=-std=c++17 -p ${CMAKE_BINARY_DIR} + COMMAND xargs -a ${CLANG_TIDY_TXT_FILE} -r -d '\;' ${CLANG_TIDY_CMD} -p ${CMAKE_BINARY_DIR} WORKING_DIRECTORY ${P4C_SOURCE_DIR} COMMENT "Applying clang-tidy analysis." ) add_custom_target( clang-tidy-fix-errors - COMMAND xargs -a ${CLANG_TIDY_TXT_FILE} -r -d '\;' ${CLANG_TIDY_CMD} -extra-arg=-std=c++17 -p ${CMAKE_BINARY_DIR} --fix + COMMAND xargs -a ${CLANG_TIDY_TXT_FILE} -r -d '\;' ${CLANG_TIDY_CMD} -p ${CMAKE_BINARY_DIR} --fix WORKING_DIRECTORY ${P4C_SOURCE_DIR} COMMENT "Applying clang-tidy fix-its." ) endif() else() - message(WARNING "clang-tidy executable not found. Disabling clang-tidy checks. clang-tidy can be installed with \"pip3 install --user --upgrade clang-tidy\"") + message(WARNING "clang-tidy executable not found. Disabling clang-tidy checks. clang-tidy can be installed with \"pip3 install --user --upgrade clang-tidy\" or your distribution's package manager.") endif() @@ -141,7 +143,7 @@ find_program(BLACK_CMD black) find_program(ISORT_CMD isort) # Black and isort share the same files and should be run together. -if(NOT ${BLACK_CMD} OR NOT (NOT ${ISORT_CMD})) +if(BLACK_CMD AND ISORT_CMD) # Retrieve the global black property. get_property(BLACK_FILES GLOBAL PROPERTY BLACK-files) if(DEFINED BLACK_FILES) @@ -177,5 +179,5 @@ if(NOT ${BLACK_CMD} OR NOT (NOT ${ISORT_CMD})) ) endif() else() - message(WARNING "black or isort executable not found. Disabling black/isort checks. black/isort can be installed with \"pip3 install --user --upgrade black\" and \"pip3 install --user --upgrade isort\" ") + message(WARNING "black or isort executable not found. Disabling black/isort checks. black/isort can be installed with \"pip3 install --user --upgrade black\" and \"pip3 install --user --upgrade isort\" or your distribution's package manager. ") endif()