Skip to content

Commit

Permalink
Review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
fruffy committed Nov 20, 2023
1 parent 8044d7c commit d68e7e2
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions cmake/Linters.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 --
Expand All @@ -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()


Expand All @@ -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()


Expand All @@ -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)
Expand Down Expand Up @@ -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()

0 comments on commit d68e7e2

Please sign in to comment.