Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/topic/awelzel/dynamic-plugin-dis…
Browse files Browse the repository at this point in the history
…t-files'

* origin/topic/awelzel/dynamic-plugin-dist-files:
  ZeekPluginDynamic: Use absolute-but-non-realpath for dist files
  ZeekPluginDynamic: Handle DIST_FILES in CMake
  • Loading branch information
awelzel committed Jul 2, 2024
2 parents 2df3b8e + cc9de7b commit d996924
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
34 changes: 32 additions & 2 deletions ZeekPluginDynamic.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,47 @@ 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})
get_filename_component(df_src "${df}" ABSOLUTE)

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
Expand Down
12 changes: 2 additions & 10 deletions zeek-plugin-create-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,19 @@
# Called from ZeekPluginDynamic.cmake. Current directory is the plugin
# build directory.

if [ $# = 0 ]; then
echo "usage: $(basename "$0") <canonical plugin name> [<additional files to include into binary distribution>]"
if [ $# -ne 1 ]; then
echo "usage: $(basename "$0") <canonical plugin name>"
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

Expand Down

0 comments on commit d996924

Please sign in to comment.