Skip to content

Commit

Permalink
ZeekPluginDynamic: Handle DIST_FILES in CMake
Browse files Browse the repository at this point in the history
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/).
  • Loading branch information
awelzel committed Jun 27, 2024
1 parent 2df3b8e commit c5eac15
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
35 changes: 33 additions & 2 deletions ZeekPluginDynamic.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 c5eac15

Please sign in to comment.