From e3116a7d1c679ed56afd2becb58270e300131006 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Wed, 26 Jun 2024 15:39:00 +0200 Subject: [PATCH] Add plugin/CMakeLists.txt Support for BRO_PLUGIN_BASE has been removed, resulting in the ZeekPluginDynamic.cmake code to pick-up ${CMAKE_CURRENT_SOURCE_DIR}/scripts as the plugin's script. For the package-template's generated skeleton, these are however the extra scripts usually installed via zkg. Propose creation of another CMakeLists.txt within plugin/ to prevent this. The main wart here is that zeek-plugin-create-package.sh contains assumption about the location of additional DIST_FILES (../ relative to the build directory), so we copy these at configure time into build/ to fix this. I'm liking this more than re-introducing support for BRO_PLUGIN_BASE, but not sure it's overly great. Closes #35 --- features/plugin/CMakeLists.txt | 28 ++--------------- features/plugin/plugin/CMakeLists.txt | 30 +++++++++++++++++++ .../features.plugin-init-preload/output | 10 +++++++ .../features.plugin-license-github_ci/output | 1 + tests/features/plugin-init-preload | 24 +++++++++++++++ 5 files changed, 67 insertions(+), 26 deletions(-) create mode 100644 features/plugin/plugin/CMakeLists.txt create mode 100644 tests/Baseline/features.plugin-init-preload/output create mode 100644 tests/features/plugin-init-preload diff --git a/features/plugin/CMakeLists.txt b/features/plugin/CMakeLists.txt index 196cab2..a8405a7 100644 --- a/features/plugin/CMakeLists.txt +++ b/features/plugin/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.15.0 FATAL_ERROR) project(ZeekPlugin@NAME@) -# Establish version numbers in config.h +# Establish version numbers file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" VERSION LIMIT_COUNT 1) string(REGEX REPLACE "[.-]" " " version_numbers ${VERSION}) @@ -13,34 +13,10 @@ list(GET version_numbers 0 VERSION_MAJOR) list(GET version_numbers 1 VERSION_MINOR) list(GET version_numbers 2 VERSION_PATCH) -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/plugin/src/config.h.in" - "${CMAKE_CURRENT_BINARY_DIR}/config.h" @ONLY) - # Process any package-specific customizations include(plugin.cmake OPTIONAL) -# Our plugin source and scripts are in a subdirectory -set(BRO_PLUGIN_BASE "${CMAKE_CURRENT_SOURCE_DIR}/plugin") - -# Workaround to make header files in plugin sources available to BiFs. -include_directories("${BRO_PLUGIN_BASE}/src") - -include(ZeekPlugin) - -zeek_plugin_begin(@NS@ @NAME@) - -file(GLOB cc_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "plugin/src/*.cc") -foreach(file ${cc_files}) - zeek_plugin_cc(${file}) -endforeach () - -file(GLOB bif_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "plugin/src/*.bif") -foreach(file ${bif_files}) - zeek_plugin_bif(${file}) -endforeach () - -zeek_plugin_dist_files(README CHANGES COPYING VERSION) -zeek_plugin_end() +add_subdirectory(plugin) if ("${PROJECT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") # Allows building rpm/deb packages via "make package" in build dir. diff --git a/features/plugin/plugin/CMakeLists.txt b/features/plugin/plugin/CMakeLists.txt new file mode 100644 index 0000000..6341196 --- /dev/null +++ b/features/plugin/plugin/CMakeLists.txt @@ -0,0 +1,30 @@ +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/config.h" @ONLY) + +include(ZeekPlugin) + +zeek_plugin_begin(@NS@ @NAME@) + +file(GLOB cc_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "src/*.cc") +foreach(file ${cc_files}) + zeek_plugin_cc(${file}) +endforeach () + +file(GLOB bif_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "src/*.bif") +foreach(file ${bif_files}) + zeek_plugin_bif(${file}) +endforeach () + +# Copy the dist files to package with the tarball into the top-level +# build directory to fulfill zeek-plugin-create-package.sh assumptions +# about them being located in the parent directory. +set(dist_files README CHANGES COPYING VERSION) +foreach(file ${dist_files}) + if ( EXISTS ../${file} ) + file(COPY ../${file} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/../) + endif() +endforeach () + +zeek_plugin_dist_files(${dist_files}) + +zeek_plugin_end() diff --git a/tests/Baseline/features.plugin-init-preload/output b/tests/Baseline/features.plugin-init-preload/output new file mode 100644 index 0000000..1757af5 --- /dev/null +++ b/tests/Baseline/features.plugin-init-preload/output @@ -0,0 +1,10 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +=== without test/scripts +plugin/scripts/__load__.zeek +plugin/scripts/__preload__.zeek +=== with test/scripts +plugin/scripts/__load__.zeek +plugin/scripts/__preload__.zeek +scripts/__load__.zeek +scripts/main.zeek +Hello world! diff --git a/tests/Baseline/features.plugin-license-github_ci/output b/tests/Baseline/features.plugin-license-github_ci/output index 8470d25..6a2ffe3 100644 --- a/tests/Baseline/features.plugin-license-github_ci/output +++ b/tests/Baseline/features.plugin-license-github_ci/output @@ -12,6 +12,7 @@ test/COPYING test/plugin test/plugin.cmake test/plugin/.gitignore +test/plugin/CMakeLists.txt test/plugin/scripts test/plugin/scripts/types.zeek test/plugin/scripts/__load__.zeek diff --git a/tests/features/plugin-init-preload b/tests/features/plugin-init-preload new file mode 100644 index 0000000..becfa1b --- /dev/null +++ b/tests/features/plugin-init-preload @@ -0,0 +1,24 @@ +# A test to verify that plugin/scripts/ is used as the plugin's script +# directory rather than the top-level scripts/ directory. +# +# Regression test for #35. +# +# @TEST-REQUIRES: make --version +# @TEST-REQUIRES: cmake --help | grep -q '^* Unix Makefiles' +# +# @TEST-EXEC: bash %INPUT +# +# @TEST-EXEC: cd test && ./configure 1>&2 +# @TEST-EXEC: make -C test/build/ -j`nproc` 1>&2 +# @TEST-EXEC: echo "=== without test/scripts" >>output +# @TEST-EXEC: ZEEK_PLUGIN_PATH=./test/build zeek >output +# @TEST-EXEC: echo "=== with test/scripts" >>output +# @TEST-EXEC: ZEEK_PLUGIN_PATH=./test/build zeek ./test/scripts >>output +# @TEST-EXEC: btest-diff output + +${SCRIPTS}/zkg create --packagedir=test --features plugin --user-var name=Name --user-var namespace=Namespace + +echo 'event zeek_init() &priority=40 { print "plugin/scripts/__load__.zeek"; }' >> test/plugin/scripts/__load__.zeek +echo 'event zeek_init() &priority=30 { print "plugin/scripts/__preload__.zeek"; }' >> test/plugin/scripts/__preload__.zeek +echo 'event zeek_init() &priority=20 { print "scripts/__load__.zeek"; }' >> test/scripts/__load__.zeek +echo 'event zeek_init() &priority=10 { print "scripts/main.zeek"; }' >> test/scripts/main.zeek