From 5ca3421906f263bd9fe539ad0b737b307ad1a0fa Mon Sep 17 00:00:00 2001 From: Manuel Date: Wed, 4 Dec 2024 16:56:12 +0100 Subject: [PATCH] feat: add building types mechanism to better modularize building procedure --- packages/macos/generate_wazuh_packages.sh | 50 +++++++++++++++++------ packages/macos/package_files/build.sh | 15 +++---- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/packages/macos/generate_wazuh_packages.sh b/packages/macos/generate_wazuh_packages.sh index 5a5b7de417..0dee34df76 100755 --- a/packages/macos/generate_wazuh_packages.sh +++ b/packages/macos/generate_wazuh_packages.sh @@ -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. @@ -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 @@ -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 @@ -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." @@ -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 @@ -463,13 +470,30 @@ 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) + echo "Building package with previously generated binaries" + build_package + ;; + 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]" + 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 @@ -478,7 +502,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 diff --git a/packages/macos/package_files/build.sh b/packages/macos/package_files/build.sh index cfcffd1f86..b8c2678b5b 100755 --- a/packages/macos/package_files/build.sh +++ b/packages/macos/package_files/build.sh @@ -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(){ @@ -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)"