Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZeekPluginDynamic: Handle DIST_FILES in CMake #116

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading