Skip to content

Commit

Permalink
feat: add building types mechanism to better modularize building proc…
Browse files Browse the repository at this point in the history
…edure
  • Loading branch information
mjcr99 committed Dec 5, 2024
1 parent 0e5a54b commit 7774907
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 22 deletions.
55 changes: 42 additions & 13 deletions packages/macos/generate_wazuh_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ VERBOSE="no" # Enables the full log by using `set -exf`
DEBUG="no" # Enables debug symbols while compiling.
CHECKSUM="no" # Enables the checksum generation.
IS_STAGE="no" # Enables release package naming.
MAKE_COMPILATION="yes" # Set whether or not to compile the code
BUILD_TYPE="full_package" # Set build type
CERT_APPLICATION_ID="" # Apple Developer ID certificate to sign Apps and binaries.
CERT_INSTALLER_ID="" # Apple Developer ID certificate to sign pkg.
KEYCHAIN="" # Keychain where the Apple Developer ID certificate is.
Expand Down Expand Up @@ -138,7 +138,7 @@ function prepare_building_folder() {
mkdir -p $DESTINATION
}

function build_package() {
function build_package_binaries() {

# Download source code
if [ -n "$BRANCH_TAG" ]; then
Expand All @@ -164,8 +164,11 @@ function build_package() {

prepare_building_folder $VERSION $pkg_name

${WAZUH_PACKAGES_PATH}/package_files/build.sh "${PACKAGED_DIRECTORY}" "${WAZUH_PATH}" ${JOBS} ${MAKE_COMPILATION} ${VCPKG_KEY}
${WAZUH_PACKAGES_PATH}/package_files/build.sh "${PACKAGED_DIRECTORY}" "${WAZUH_PATH}" ${JOBS} ${VCPKG_KEY}

}

function build_package() {
# sign the binaries and the libraries
sign_binaries

Expand Down Expand Up @@ -202,7 +205,7 @@ function help() {
echo " -d, --debug [Optional] Build the binaries with debug symbols. By default: no."
echo " -c, --checksum [Optional] Generate checksum on the store path."
echo " --is_stage [Optional] Use release name in package"
echo " -nc, --not-compile [Optional] Set whether or not to compile the code."
echo " -bt, --build-type [Optional] Set building type, binaries, package, or full_package [binaries,package,full_package]. By Default: full."
echo " --vcpkg-binary-caching-key [Optional] VCPK remote binary caching repository key."
echo " -h, --help [ Util ] Show this help."
echo " -i, --install-deps [ Util ] Install build dependencies."
Expand Down Expand Up @@ -367,9 +370,13 @@ function main() {
IS_STAGE="yes"
shift 1
;;
"-nc"|"--not-compile")
MAKE_COMPILATION="no"
shift 1
"-bt"|"--build-type")
if [ -n "$2" ]; then
BUILD_TYPE="$2"
shift 2
else
help 1
fi
;;
"--vcpkg-binary-caching-key")
if [ -n "$2" ]; then
Expand Down Expand Up @@ -463,13 +470,35 @@ function main() {
fi

testdep

check_root
build_package
${CURRENT_PATH}/uninstall.sh

if [ "${NOTARIZE}" = "yes" ]; then

case "$BUILD_TYPE" in
binaries)
echo "Building only the binaries for the package."
build_package_binaries
;;
package)
if [[ -d $PACKAGED_DIRECTORY]]
echo "Building package with previously generated binaries."
build_package
else
echo "Binaries have not been created, existing."
clean_and_exit 1
fi
;;
full_package)
echo "Building binaries and packaging them."
build_package_binaries
build_package
;;
*)
echo "Error: BUILD_TYPE mus't be one of: [binaries, package, full_package]"
clean_and_exit 1
;;
esac

if [ "${NOTARIZE}" = "yes" ] && { [ "${BUILD_TYPE}" = "package" ] || [ "${BUILD_TYPE}" = "full_package" ]; }; then

notarization_path="${DESTINATION}/${pkg_name}.pkg"

if [ -z "${notarization_path}" ]; then
Expand All @@ -478,7 +507,7 @@ function main() {
fi
notarize_pkg "${notarization_path}"
else
echo "Notarization has not been selected."
echo "Notarization has not been selected or was not available for the selected building type"
fi

return 0
Expand Down
15 changes: 6 additions & 9 deletions packages/macos/package_files/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ set -e
DESTINATION_PATH=$1
WAZUH_PATH=$2
BUILD_JOBS=$3
MAKE_COMPILATION=$4
VCPKG_KEY=$5
VCPKG_KEY=$4
SOURCES_DIR=${WAZUH_PATH}/src

set_vcpkg_remote_binary_cache(){
Expand All @@ -38,14 +37,12 @@ set_vcpkg_remote_binary_cache(){

function build() {

if [ "${MAKE_COMPILATION}" == "yes" ]; then
if [ ! -z "${VCPKG_KEY}" ]; then
set_vcpkg_remote_binary_cache $VCPKG_KEY
fi
git submodule update --init --recursive
cmake -S $SOURCES_DIR -B $SOURCES_DIR/build -DINSTALL_ROOT=$DESTINATION_PATH
make -C $SOURCES_DIR/build -j $BUILD_JOBS
if [ ! -z "${VCPKG_KEY}" ]; then
set_vcpkg_remote_binary_cache $VCPKG_KEY
fi
git submodule update --init --recursive
cmake -S $SOURCES_DIR -B $SOURCES_DIR/build -DINSTALL_ROOT=$DESTINATION_PATH
make -C $SOURCES_DIR/build -j $BUILD_JOBS

EXECUTABLE_FILES=$(find "${SOURCES_DIR}" -maxdepth 1 -type f ! -name "*.py" -exec file {} + | grep 'executable' | cut -d: -f1)
EXECUTABLE_FILES+=" $(find "${SOURCES_DIR}" -type f ! -name "*.py" ! -path "${SOURCES_DIR}/external/*" ! -path "${SOURCES_DIR}/symbols/*" -name "*.dylib" -print 2>/dev/null)"
Expand Down

0 comments on commit 7774907

Please sign in to comment.