From 1868ae32372128b632f57951114f2265d78b4c41 Mon Sep 17 00:00:00 2001 From: "qiufengshuo.qfs" Date: Tue, 16 Jul 2024 11:08:35 +0000 Subject: [PATCH] fix --- core/CMakeLists.txt | 42 +++++++++++++++++----------------- core/common/common.cmake | 5 +--- core/dependencies.cmake | 12 ++-------- core/flusher/flusher.cmake | 7 ++---- core/input/input.cmake | 5 +--- core/processor/links.cmake | 2 +- core/processor/processor.cmake | 11 ++------- core/unittest/CMakeLists.txt | 42 +++++++++++++++------------------- scripts/gen_build_scripts.sh | 4 ++-- 9 files changed, 51 insertions(+), 79 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 2506b3c240..1a533d5b25 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -30,12 +30,12 @@ option(ENABLE_ENTERPRISE "enable enterprise feature") cmake_dependent_option(ENABLE_COMPATIBLE_MODE "Build Logtail in compatible mode (for low version Linux)" OFF "LINUX" OFF) cmake_dependent_option(ENABLE_STATIC_LINK_CRT "Build Logtail by linking CRT statically" OFF "LINUX" OFF) option(WITHOUTGDB "Build Logtail without gdb") -option(WITHOUTSPL "Link Logtail without SPL") +option(WITHSPL "Link Logtail with SPL" ON) option(BUILD_LOGTAIL_UT "Build unit test for Logtail") -if (BUILD_LOGTAIL_SHARED_LIBRARY AND NOT WITHOUTSPL) - set(WITHOUTSPL ON) - message(WARNING, "generating logtail shared library is not supported with SPL. WITHOUTSPL has been set to ON.") +if (BUILD_LOGTAIL_SHARED_LIBRARY AND WITHSPL) + message(FATEL_ERROR, "Generating logtail shared library is not supported to be linked with SPL. WITHSPL should be set OFF.") + return() endif() set(UT_LINK OFF) @@ -49,7 +49,7 @@ else () include(${CMAKE_CURRENT_SOURCE_DIR}/options.cmake) endif () -if (WITHOUTSPL) +if (NOT WITHSPL) add_definitions(-D__EXCLUDE_SPL__) endif() @@ -95,8 +95,8 @@ endif () include(${CMAKE_CURRENT_SOURCE_DIR}/utils.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/dependencies.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/links.cmake) -set(SUBDIR_SOURCE_FILES "") -set(NOSPL_SUBDIR_SOURCE_FILES "") +set(SUBDIR_SOURCE_FILES_CORE "") +set(SUBDIR_SOURCE_FILES_SPL "") include(${CMAKE_CURRENT_SOURCE_DIR}/common/common.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/common/links.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/input/input.cmake) @@ -131,7 +131,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories("/opt/logtail_spl/include") if (LINUX) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/observer) - if (NOT WITHOUTSPL) + if (WITHSPL) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/spl) endif() endif() @@ -157,8 +157,6 @@ if(MSVC) # remove linux event listener file(GLOB REMOVE_EVENT_LISTENER_SOURCES event_listener/*_Linux.cpp event_listener/*_Linux.h) list(REMOVE_ITEM SOURCE_FILES_LIST ${REMOVE_EVENT_LISTENER_SOURCES}) - set(WINDOWS_SOURCE_FILES ${SOURCE_FILES_LIST} ${SUBDIR_SOURCE_FILES}) - set(NOSPL_WINDOWS_SOURCE_FILES ${SOURCE_FILES_LIST} ${NOSPL_SUBDIR_SOURCE_FILES}) elseif(UNIX) # remove windows event listener file(GLOB REMOVE_EVENT_LISTENER_SOURCES event_listener/*_Windows.cpp event_listener/*_Windows.h) @@ -167,14 +165,16 @@ elseif(UNIX) # observer file(GLOB_RECURSE APPEND_OBSERVER_SOURCES observer/*) list(APPEND SOURCE_FILES_LIST ${APPEND_OBSERVER_SOURCES}) + if (WITHSPL) + set(SRC_FILES ${SUBDIR_SOURCE_FILES_SPL}) + endif() endif() - set(UNIX_SOURCE_FILES ${SOURCE_FILES_LIST} ${SUBDIR_SOURCE_FILES}) - set(NOSPL_UNIX_SOURCE_FILES ${SOURCE_FILES_LIST} ${NOSPL_SUBDIR_SOURCE_FILES}) endif() +set(SRC_FILES ${SRC_FILES} ${SOURCE_FILES_LIST} ${SUBDIR_SOURCE_FILES_CORE}) # Generate SPL library. if (LINUX) - if (NOT WITHOUTSPL) + if (WITHSPL) add_subdirectory(spl) endif() endif() @@ -183,15 +183,15 @@ endif() if (BUILD_LOGTAIL) if (ENABLE_ENTERPRISE) if (UNIX) - add_executable(${LOGTAIL_TARGET} enterprise_logtail.cpp ${UNIX_SOURCE_FILES}) + add_executable(${LOGTAIL_TARGET} enterprise_logtail.cpp ${SRC_FILES}) elseif (MSVC) - add_executable(${LOGTAIL_TARGET} enterprise_logtail_windows.cpp ${WINDOWS_SOURCE_FILES}) + add_executable(${LOGTAIL_TARGET} enterprise_logtail_windows.cpp ${SRC_FILES}) endif () else () if (UNIX) - add_executable(${LOGTAIL_TARGET} logtail.cpp ${UNIX_SOURCE_FILES}) + add_executable(${LOGTAIL_TARGET} logtail.cpp ${SRC_FILES}) elseif (MSVC) - add_executable(${LOGTAIL_TARGET} logtail_windows.cpp ${WINDOWS_SOURCE_FILES}) + add_executable(${LOGTAIL_TARGET} logtail_windows.cpp ${SRC_FILES}) endif () endif() endif() @@ -199,15 +199,15 @@ endif() if (BUILD_LOGTAIL_SHARED_LIBRARY) if (ENABLE_ENTERPRISE) if (UNIX) - add_library(${LOGTAIL_TARGET} SHARED enterprise_logtail.cpp ${UNIX_SOURCE_FILES}) + add_library(${LOGTAIL_TARGET} SHARED enterprise_logtail.cpp ${SRC_FILES}) elseif (MSVC) - add_library(${LOGTAIL_TARGET} SHARED enterprise_logtail_windows.cpp ${WINDOWS_SOURCE_FILES}) + add_library(${LOGTAIL_TARGET} SHARED enterprise_logtail_windows.cpp ${SRC_FILES}) endif () else () if (UNIX) - add_library(${LOGTAIL_TARGET} SHARED logtail.cpp ${UNIX_SOURCE_FILES}) + add_library(${LOGTAIL_TARGET} SHARED logtail.cpp ${SRC_FILES}) elseif (MSVC) - add_library(${LOGTAIL_TARGET} SHARED logtail_windows.cpp ${WINDOWS_SOURCE_FILES}) + add_library(${LOGTAIL_TARGET} SHARED logtail_windows.cpp ${SRC_FILES}) endif () endif() endif () diff --git a/core/common/common.cmake b/core/common/common.cmake index 81bf05c989..ce999a9c6b 100644 --- a/core/common/common.cmake +++ b/core/common/common.cmake @@ -45,7 +45,4 @@ elseif(UNIX) endif() # Set source files to parent -set(SUBDIR_SOURCE_FILES ${SUBDIR_SOURCE_FILES} ${THIS_SOURCE_FILES_LIST}) - -# for NOSPL UT -set(NOSPL_SUBDIR_SOURCE_FILES ${NOSPL_SUBDIR_SOURCE_FILES} ${THIS_SOURCE_FILES_LIST}) +set(SUBDIR_SOURCE_FILES_CORE ${SUBDIR_SOURCE_FILES_CORE} ${THIS_SOURCE_FILES_LIST}) diff --git a/core/dependencies.cmake b/core/dependencies.cmake index 231986560e..40775951e9 100644 --- a/core/dependencies.cmake +++ b/core/dependencies.cmake @@ -242,11 +242,7 @@ macro(link_lz4 target_name) if (lz4_${LINK_OPTION_SUFFIX}) target_link_libraries(${target_name} "${lz4_${LINK_OPTION_SUFFIX}}") elseif (UNIX) - if (WITHOUTSPL) - target_link_libraries(${target_name} "${lz4_${LIBRARY_DIR_SUFFIX}}/liblz4.so") - else () - target_link_libraries(${target_name} "${lz4_${LIBRARY_DIR_SUFFIX}}/liblz4.so") - endif () + target_link_libraries(${target_name} "${lz4_${LIBRARY_DIR_SUFFIX}}/liblz4.so") elseif (MSVC) target_link_libraries(${target_name} debug "liblz4_staticd" @@ -310,11 +306,7 @@ macro(link_unwind target_name) elseif (ANDROID) # target_link_libraries(${target_name} "${unwind_${LIBRARY_DIR_SUFFIX}}/libunwindstack.a") elseif (UNIX) - if (WITHOUTSPL) - target_link_libraries(${target_name} "${unwind_${LIBRARY_DIR_SUFFIX}}/libunwind.so") - else () - target_link_libraries(${target_name} "${unwind_${LIBRARY_DIR_SUFFIX}}/libunwind.so") - endif () + target_link_libraries(${target_name} "${unwind_${LIBRARY_DIR_SUFFIX}}/libunwind.so") elseif (MSVC) target_link_libraries(${target_name} debug "breakpad_commond.lib" diff --git a/core/flusher/flusher.cmake b/core/flusher/flusher.cmake index e967a5705b..6e6c6356a6 100644 --- a/core/flusher/flusher.cmake +++ b/core/flusher/flusher.cmake @@ -17,10 +17,7 @@ include_directories(flusher) # Add source files -file(GLOB THIS_SOURCE_FILES ${CMAKE_SOURCE_DIR}/flusher/*.c ${CMAKE_SOURCE_DIR}/flusher/*.cc ${CMAKE_SOURCE_DIR}/flusher/*.cpp ${CMAKE_SOURCE_DIR}/flusher/*.h) +file(GLOB THIS_SOURCE_FILES_LIST ${CMAKE_SOURCE_DIR}/flusher/*.c ${CMAKE_SOURCE_DIR}/flusher/*.cc ${CMAKE_SOURCE_DIR}/flusher/*.cpp ${CMAKE_SOURCE_DIR}/flusher/*.h) # Set source files to parent -set(SUBDIR_SOURCE_FILES ${SUBDIR_SOURCE_FILES} ${THIS_SOURCE_FILES}) - -# for NOSPL UT -set(NOSPL_SUBDIR_SOURCE_FILES ${NOSPL_SUBDIR_SOURCE_FILES} ${THIS_SOURCE_FILES}) +set(SUBDIR_SOURCE_FILES_CORE ${SUBDIR_SOURCE_FILES_CORE} ${THIS_SOURCE_FILES_LIST}) diff --git a/core/input/input.cmake b/core/input/input.cmake index 4afddb1afb..8206cdcde6 100644 --- a/core/input/input.cmake +++ b/core/input/input.cmake @@ -38,7 +38,4 @@ elseif(UNIX) endif() # Set source files to parent -set(SUBDIR_SOURCE_FILES ${SUBDIR_SOURCE_FILES} ${THIS_SOURCE_FILES_LIST}) - -# for NOSPL UT -set(NOSPL_SUBDIR_SOURCE_FILES ${NOSPL_SUBDIR_SOURCE_FILES} ${THIS_SOURCE_FILES_LIST}) +set(SUBDIR_SOURCE_FILES_CORE ${SUBDIR_SOURCE_FILES_CORE} ${THIS_SOURCE_FILES_LIST}) diff --git a/core/processor/links.cmake b/core/processor/links.cmake index 3e9e073002..f35edd013e 100644 --- a/core/processor/links.cmake +++ b/core/processor/links.cmake @@ -22,7 +22,7 @@ macro(processor_link target_name ut_link ut_link_need_spl) target_link_libraries(${target_name} spl) endif() else () - if (LINUX AND NOT WITHOUTSPL) + if (LINUX AND WITHSPL) link_spl(${target_name}) target_link_libraries(${target_name} spl) endif () diff --git a/core/processor/processor.cmake b/core/processor/processor.cmake index 0fe5ce6ef6..966d8ea5d8 100644 --- a/core/processor/processor.cmake +++ b/core/processor/processor.cmake @@ -26,14 +26,7 @@ list(APPEND THIS_SOURCE_FILES_LIST ${THIS_SOURCE_FILES}) file(GLOB THIS_SOURCE_FILES ${CMAKE_SOURCE_DIR}/processor/inner/*.c ${CMAKE_SOURCE_DIR}/processor/inner/*.cc ${CMAKE_SOURCE_DIR}/processor/inner/*.cpp ${CMAKE_SOURCE_DIR}/processor/inner/*.h) list(APPEND THIS_SOURCE_FILES_LIST ${THIS_SOURCE_FILES}) -if(NOT LINUX OR WITHOUTSPL) - # remove spl related files in processor - list(REMOVE_ITEM THIS_SOURCE_FILES_LIST ${CMAKE_SOURCE_DIR}/processor/ProcessorSPL.cpp ${CMAKE_SOURCE_DIR}/processor/ProcessorSPL.h) -endif() - # Set source files to parent -set(SUBDIR_SOURCE_FILES ${SUBDIR_SOURCE_FILES} ${THIS_SOURCE_FILES_LIST}) - -# for NOSPL UT, remove ProcessorSPL.cpp and ProcessorSPL.h list(REMOVE_ITEM THIS_SOURCE_FILES_LIST ${CMAKE_SOURCE_DIR}/processor/ProcessorSPL.cpp ${CMAKE_SOURCE_DIR}/processor/ProcessorSPL.h) -set(NOSPL_SUBDIR_SOURCE_FILES ${NOSPL_SUBDIR_SOURCE_FILES} ${THIS_SOURCE_FILES_LIST}) +set(SUBDIR_SOURCE_FILES_CORE ${SUBDIR_SOURCE_FILES_CORE} ${THIS_SOURCE_FILES_LIST}) +set(SUBDIR_SOURCE_FILES_SPL ${SUBDIR_SOURCE_FILES_SPL} ${CMAKE_SOURCE_DIR}/processor/ProcessorSPL.cpp ${CMAKE_SOURCE_DIR}/processor/ProcessorSPL.h) diff --git a/core/unittest/CMakeLists.txt b/core/unittest/CMakeLists.txt index df86f0e708..e59b6d755a 100644 --- a/core/unittest/CMakeLists.txt +++ b/core/unittest/CMakeLists.txt @@ -29,7 +29,7 @@ include(${CMAKE_SOURCE_DIR}/processor/links.cmake) include(${CMAKE_SOURCE_DIR}/input/links.cmake) include(${CMAKE_SOURCE_DIR}/flusher/links.cmake) -macro(add_nospl_subdir) +macro(add_core_subdir) add_subdirectory(app_config) add_subdirectory(batch) add_subdirectory(checkpoint) @@ -75,38 +75,34 @@ macro(ut_link need_spl) common_link(${UT_BASE_TARGET}) endmacro() +set(SOURCE_FILES_CORE ${SOURCE_FILES_LIST} ${SUBDIR_SOURCE_FILES_CORE}) +set(SOURCE_FILES_CORE_WITHSPL ${SOURCE_FILES_CORE} ${SUBDIR_SOURCE_FILES_SPL}) + if (UNIX) if (LINUX) - if (WITHOUTSPL) - # add nospl subdir - set(UT_BASE_TARGET "unittest_base") - add_library(${UT_BASE_TARGET} SHARED ${NOSPL_UNIX_SOURCE_FILES}) - target_compile_options(${UT_BASE_TARGET} PRIVATE -Werror) - add_nospl_subdir() - set(UT_LINK_NEED_SPL OFF) - ut_link(${UT_LINK_NEED_SPL}) - else () + if (WITHSPL) # add spl subdir - set(UT_BASE_TARGET "unittest_base_static") - add_library(${UT_BASE_TARGET} STATIC ${UNIX_SOURCE_FILES}) + set(UT_BASE_TARGET "unittest_base_withspl") + add_library(${UT_BASE_TARGET} STATIC ${SOURCE_FILES_CORE_WITHSPL}) target_compile_options(${UT_BASE_TARGET} PRIVATE -Werror) add_spl_subdir() set(UT_LINK_NEED_SPL ON) ut_link(${UT_LINK_NEED_SPL}) - # add nospl subdir - set(UT_BASE_TARGET "unittest_base") - add_definitions(-D__EXCLUDE_SPL__) - add_library(${UT_BASE_TARGET} SHARED ${NOSPL_UNIX_SOURCE_FILES}) - target_compile_options(${UT_BASE_TARGET} PRIVATE -Werror) - add_nospl_subdir() - set(UT_LINK_NEED_SPL OFF) - ut_link(${UT_LINK_NEED_SPL}) endif() + # add core subdir + set(UT_BASE_TARGET "unittest_base") + add_definitions(-D__EXCLUDE_SPL__) + add_library(${UT_BASE_TARGET} SHARED ${SOURCE_FILES_CORE}) + target_compile_options(${UT_BASE_TARGET} PRIVATE -Werror) + add_core_subdir() + set(UT_LINK_NEED_SPL OFF) + ut_link(${UT_LINK_NEED_SPL}) else () - set(UT_BASE_TARGET "unittest_base_static") - add_library(${UT_BASE_TARGET} STATIC ${NOSPL_UNIX_SOURCE_FILES}) + # add core subdir + set(UT_BASE_TARGET "unittest_base") + add_library(${UT_BASE_TARGET} STATIC ${SOURCE_FILES_CORE}) target_compile_options(${UT_BASE_TARGET} PRIVATE -Werror) - add_nospl_subdir() + add_core_subdir() set(UT_LINK_NEED_SPL OFF) ut_link(${UT_LINK_NEED_SPL}) endif () diff --git a/scripts/gen_build_scripts.sh b/scripts/gen_build_scripts.sh index bc702a44c5..4ae5847e47 100755 --- a/scripts/gen_build_scripts.sh +++ b/scripts/gen_build_scripts.sh @@ -38,7 +38,7 @@ BUILD_LOGTAIL_UT=${BUILD_LOGTAIL_UT:-OFF} ENABLE_COMPATIBLE_MODE=${ENABLE_COMPATIBLE_MODE:-OFF} ENABLE_STATIC_LINK_CRT=${ENABLE_STATIC_LINK_CRT:-OFF} WITHOUTGDB==${WITHOUTGDB:-OFF} -WITHOUTSPL=${WITHOUTSPL:-OFF} +WITHSPL=${WITHSPL:-ON} BUILD_SCRIPT_FILE=$GENERATED_HOME/gen_build.sh COPY_SCRIPT_FILE=$GENERATED_HOME/gen_copy_docker.sh MAKE_JOBS=${MAKE_JOBS:-$(nproc)} @@ -83,7 +83,7 @@ EOF if [ $CATEGORY = "plugin" ]; then echo "mkdir -p core/build && cd core/build && cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DLOGTAIL_VERSION=${VERSION} .. && cd plugin && make -s PluginAdapter && cd ../../.. && ./scripts/upgrade_adapter_lib.sh && ./scripts/plugin_build.sh mod c-shared ${OUT_DIR} ${VERSION} ${PLUGINS_CONFIG_FILE} ${GO_MOD_FILE}" >>$BUILD_SCRIPT_FILE elif [ $CATEGORY = "core" ]; then - echo "mkdir -p core/build && cd core/build && cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DLOGTAIL_VERSION=${VERSION} -DBUILD_LOGTAIL=${BUILD_LOGTAIL} -DBUILD_LOGTAIL_UT=${BUILD_LOGTAIL_UT} -DENABLE_COMPATIBLE_MODE=${ENABLE_COMPATIBLE_MODE} -DENABLE_STATIC_LINK_CRT=${ENABLE_STATIC_LINK_CRT} -DWITHOUTGDB=${WITHOUTGDB} -DWITHOUTSPL=${WITHOUTSPL} .. && make -sj${MAKE_JOBS}" >>$BUILD_SCRIPT_FILE + echo "mkdir -p core/build && cd core/build && cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DLOGTAIL_VERSION=${VERSION} -DBUILD_LOGTAIL=${BUILD_LOGTAIL} -DBUILD_LOGTAIL_UT=${BUILD_LOGTAIL_UT} -DENABLE_COMPATIBLE_MODE=${ENABLE_COMPATIBLE_MODE} -DENABLE_STATIC_LINK_CRT=${ENABLE_STATIC_LINK_CRT} -DWITHOUTGDB=${WITHOUTGDB} -DWITHSPL=${WITHSPL} .. && make -sj${MAKE_JOBS}" >>$BUILD_SCRIPT_FILE elif [ $CATEGORY = "all" ]; then echo "mkdir -p core/build && cd core/build && cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DLOGTAIL_VERSION=${VERSION} -DBUILD_LOGTAIL_UT=${BUILD_LOGTAIL_UT} -DENABLE_COMPATIBLE_MODE=${ENABLE_COMPATIBLE_MODE} -DENABLE_STATIC_LINK_CRT=${ENABLE_STATIC_LINK_CRT} -DWITHOUTGDB=${WITHOUTGDB} .. && make -sj\$nproc && cd - && ./scripts/upgrade_adapter_lib.sh && ./scripts/plugin_build.sh mod c-shared ${OUT_DIR} ${VERSION} ${PLUGINS_CONFIG_FILE} ${GO_MOD_FILE}" >>$BUILD_SCRIPT_FILE elif [ $CATEGORY = "e2e" ]; then