From 64e2fccc2bae567f6b0f5186ee21996a8d0d6d11 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Wed, 16 Apr 2025 14:52:45 -0700 Subject: [PATCH 1/3] Make sure clang-tidy and iwyu are added to all targets --- CMakeLists.txt | 27 +++++++++++++++++++++++++++ cmake | 2 +- src/CMakeLists.txt | 19 ++----------------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8bcb86bd1f..3e5274b6e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -208,6 +208,20 @@ include(cmake/CheckCompilerArch.cmake) string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER) +if (ENABLE_IWYU) + find_program(ZEEK_IWYU_PATH NAMES include-what-you-use iwyu) + if (NOT ZEEK_IWYU_PATH) + message(FATAL_ERROR "Could not find the program include-what-you-use") + endif () +endif () + +if (ENABLE_CLANG_TIDY) + find_program(ZEEK_CLANG_TIDY_PATH NAMES clang-tidy) + if (NOT ZEEK_CLANG_TIDY_PATH) + message(FATAL_ERROR "Could not find the program clang-tidy") + endif () +endif () + # ############################################################################## # Main targets and utilities. @@ -307,6 +321,16 @@ function (zeek_target_link_libraries lib_target) endforeach () endfunction () +function (zeek_target_add_linters lib_target) + if (ZEEK_IWYU_PATH) + set_target_properties(${lib_target} PROPERTIES CXX_INCLUDE_WHAT_YOU_USE ${ZEEK_IWYU_PATH}) + endif () + + if (ZEEK_CLANG_TIDY_PATH) + set_target_properties(${lib_target} PROPERTIES CXX_CLANG_TIDY ${ZEEK_CLANG_TIDY_PATH}) + endif () +endfunction () + function (zeek_include_directories) foreach (name zeek_exe zeek_lib zeek_fuzzer_shared) if (TARGET ${name}) @@ -414,6 +438,9 @@ function (zeek_add_subdir_library name) # Feed into the main Zeek target(s). zeek_target_link_libraries(${target_name}) + + # Add IWYU and clang-tidy to the target if enabled. + zeek_target_add_linters(${target_name}) endfunction () # ############################################################################## diff --git a/cmake b/cmake index b4998425fb..04a714605d 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit b4998425fb00402967792311ec7c2cf391eb0ca5 +Subproject commit 04a714605d2af055dd35152aeffc1874447ca616 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 67347bafca..7810ce6191 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -562,23 +562,8 @@ target_compile_definitions(zeek_objs PRIVATE ZEEK_CONFIG_SKIP_VERSION_H) add_dependencies(zeek_objs zeek_autogen_files) zeek_target_link_libraries(zeek_objs) -if (ENABLE_IWYU) - find_program(IWYU_PATH NAMES include-what-you-use iwyu) - if (NOT IWYU_PATH) - message(FATAL_ERROR "Could not find the program include-what-you-use") - endif () - - set_target_properties(zeek_objs PROPERTIES CXX_INCLUDE_WHAT_YOU_USE ${IWYU_PATH}) -endif () - -if (ENABLE_CLANG_TIDY) - find_program(CLANG_TIDY_PATH NAMES clang-tidy) - if (NOT CLANG_TIDY_PATH) - message(FATAL_ERROR "Could not find the program clang-tidy") - endif () - - set_target_properties(zeek_objs PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY_PATH}) -endif () +# Add IWYU and clang-tidy to the target if enabled. +zeek_target_add_linters(zeek_objs) if (HAVE_SPICY) target_link_libraries(zeek_objs PRIVATE hilti spicy) From 7111d6a143095b05027f3c30e283d869d019c11f Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Wed, 16 Apr 2025 10:31:44 -0700 Subject: [PATCH 2/3] Disable linting for files generated by bison These files will report lots of findings in the code that we have no control over. --- src/CMakeLists.txt | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7810ce6191..d2532d75cf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -92,17 +92,20 @@ replace_yy_prefix_target(${CMAKE_CURRENT_BINARY_DIR}/p.cc ${CMAKE_CURRENT_BINARY flex_target(Scanner scan.l ${CMAKE_CURRENT_BINARY_DIR}/scan.cc COMPILE_FLAGS "-Pzeek") set_property(SOURCE scan.cc APPEND_STRING PROPERTY COMPILE_FLAGS "${SIGN_COMPARE_FLAG}") +set(zeek_bison_generated_files + ${CMAKE_CURRENT_BINARY_DIR}/parse.cc + ${CMAKE_CURRENT_BINARY_DIR}/re-parse.cc + ${CMAKE_CURRENT_BINARY_DIR}/re-parse.h + ${CMAKE_CURRENT_BINARY_DIR}/re-scan.cc + ${CMAKE_CURRENT_BINARY_DIR}/rule-parse.cc + ${CMAKE_CURRENT_BINARY_DIR}/rule-parse.h + ${CMAKE_CURRENT_BINARY_DIR}/rule-scan.cc + ${CMAKE_CURRENT_BINARY_DIR}/scan.cc) + +set_source_files_properties(${zeek_bison_generated_files} PROPERTIES SKIP_LINTING ON) + # Add a dependency for the generated files to zeek_autogen_files. -add_custom_target( - zeek_bison_outputs - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/parse.cc - ${CMAKE_CURRENT_BINARY_DIR}/re-parse.cc - ${CMAKE_CURRENT_BINARY_DIR}/re-parse.h - ${CMAKE_CURRENT_BINARY_DIR}/re-scan.cc - ${CMAKE_CURRENT_BINARY_DIR}/rule-parse.cc - ${CMAKE_CURRENT_BINARY_DIR}/rule-parse.h - ${CMAKE_CURRENT_BINARY_DIR}/rule-scan.cc - ${CMAKE_CURRENT_BINARY_DIR}/scan.cc) +add_custom_target(zeek_bison_outputs DEPENDS ${zeek_bison_generated_files}) add_dependencies(zeek_autogen_files zeek_bison_outputs) # ############################################################################## From 94d742d3148e979ab5daa60f6fc740ceec5fcbdb Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Thu, 17 Apr 2025 09:26:23 -0700 Subject: [PATCH 3/3] Update src/3rdparty submodule to disable clang-format --- src/3rdparty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/3rdparty b/src/3rdparty index c48d4fac92..46ad4968b6 160000 --- a/src/3rdparty +++ b/src/3rdparty @@ -1 +1 @@ -Subproject commit c48d4fac922cc476e758da98baac454d047d2636 +Subproject commit 46ad4968b63604842cca58c7a18b92e9cbc184c3