From c5eac1504b67980f98989a9ec3b996d6ffe939db Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Thu, 27 Jun 2024 11:03:37 +0200 Subject: [PATCH 1/2] ZeekPluginDynamic: Handle DIST_FILES in CMake Move path wrangling of DIST files from zeek-plugin-create-package.sh into CMake logic. New logic: Location of files in dist is based relative to the PROJECT_SOURCE_DIR. This removes the assumption of having build/ located within the source directory (and zeek-plugin-create-package.sh running from build/). --- ZeekPluginDynamic.cmake | 35 +++++++++++++++++++++++++++++++++-- zeek-plugin-create-package.sh | 12 ++---------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/ZeekPluginDynamic.cmake b/ZeekPluginDynamic.cmake index 7283cba..c6bda10 100644 --- a/ZeekPluginDynamic.cmake +++ b/ZeekPluginDynamic.cmake @@ -143,17 +143,48 @@ function (zeek_add_dynamic_plugin ns name) endif () # Create the binary install package. + set(dist_tarball_dir ${CMAKE_CURRENT_BINARY_DIR}/dist/${canon_name}) set(dist_tarball_name ${canon_name}.tgz) set(dist_tarball_path ${CMAKE_CURRENT_BINARY_DIR}/${dist_tarball_name}) message(STATUS "Install prefix for plugin ${canon_name}: ${install_dir}") message(STATUS "Tarball path for plugin ${canon_name}: ${dist_tarball_path}") + add_custom_command(OUTPUT ${dist_tarball_path} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Building binary plugin package: ${dist_tarball_path}") + + # Handle dist files: Pre-place user provided dist files into the + # directory that zeek-plugin-create-package.sh will tar up. Previously, + # the zeek-plugin-create-package.sh script had done this itself. + # + # This computes the relative path of individual DIST_FILES to the + # PROJECT_SOURCE_DIR (last project() invocation) and uses the + # resulting path in the tarball. + foreach (df ${FN_ARGS_DIST_FILES}) + # set(df_src ${CMAKE_CURRENT_SOURCE_DIR}/${df}) + get_filename_component(df_src "${df}" REALPATH) + + if (NOT EXISTS "${df_src}") + # This was silently ignored previously. + message(WARNING "The file ${df} (${df_src}) given to DIST_FILES does not exist") + continue() + endif () + + file(RELATIVE_PATH df_dist ${PROJECT_SOURCE_DIR} ${df_src}) + + add_custom_command( + OUTPUT ${dist_tarball_path} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${df} + ${dist_tarball_dir}/${df_dist} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${df} + APPEND) + endforeach () + add_custom_command( OUTPUT ${dist_tarball_path} COMMAND ${ZEEK_PLUGIN_SCRIPTS_PATH}/zeek-plugin-create-package.sh ${canon_name} - ${FN_ARGS_DIST_FILES} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${target_name} ${FN_ARGS_SCRIPT_FILES} - COMMENT "Building binary plugin package: ${dist_tarball_path}") + APPEND) + add_custom_target(${target_name}_tarball ALL DEPENDS ${dist_tarball_path}) # Tell CMake to install our tarball. Note: This usually runs from our diff --git a/zeek-plugin-create-package.sh b/zeek-plugin-create-package.sh index 041120d..12eb059 100755 --- a/zeek-plugin-create-package.sh +++ b/zeek-plugin-create-package.sh @@ -6,27 +6,19 @@ # Called from ZeekPluginDynamic.cmake. Current directory is the plugin # build directory. -if [ $# = 0 ]; then - echo "usage: $(basename "$0") []" +if [ $# -ne 1 ]; then + echo "usage: $(basename "$0") " exit 1 fi name=$1 shift -addl=$* DIST=dist/${name} mkdir -p "${DIST}" # Copy files to be distributed to temporary location. cp -RL __zeek_plugin__ lib scripts "${DIST}" -for i in ${addl}; do - if [ -e "../$i" ]; then - dir=$(dirname "$i") - mkdir -p "${DIST}/${dir}" - cp -p "../$i" "${DIST}/${dir}" - fi -done tgz=${name}-$( (test -e ../VERSION && head -1 ../VERSION) || echo 0.0).tar.gz From cc9de7b4e8f84cea31e284fe0028a595f2c720d6 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Tue, 2 Jul 2024 19:34:25 +0200 Subject: [PATCH 2/2] ZeekPluginDynamic: Use absolute-but-non-realpath for dist files There's a pattern of README -> README.md symlinking. Using README as dist file should not package the README.md file. --- ZeekPluginDynamic.cmake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ZeekPluginDynamic.cmake b/ZeekPluginDynamic.cmake index c6bda10..85d290b 100644 --- a/ZeekPluginDynamic.cmake +++ b/ZeekPluginDynamic.cmake @@ -159,8 +159,7 @@ function (zeek_add_dynamic_plugin ns name) # PROJECT_SOURCE_DIR (last project() invocation) and uses the # resulting path in the tarball. foreach (df ${FN_ARGS_DIST_FILES}) - # set(df_src ${CMAKE_CURRENT_SOURCE_DIR}/${df}) - get_filename_component(df_src "${df}" REALPATH) + get_filename_component(df_src "${df}" ABSOLUTE) if (NOT EXISTS "${df_src}") # This was silently ignored previously.