From 737dd9b65221320fec574979b001c261b6a7d90e Mon Sep 17 00:00:00 2001 From: Wu Tao Date: Wed, 26 Sep 2018 11:56:09 +0800 Subject: [PATCH] misc: refactor cmake scripts to support gcov (#165) --- CMakeLists.txt | 43 +++- bin/compiler_info.cmake | 1 + bin/dsn.cmake | 226 ++++++------------ run.sh | 8 +- scripts/linux/build.sh | 69 +----- scripts/linux/misc.sh | 154 ------------ src/dist/cli/shell/CMakeLists.txt | 2 +- src/dist/nfs/test/main.cpp | 3 +- .../test/meta_test/unit_test/CMakeLists.txt | 5 +- 9 files changed, 120 insertions(+), 391 deletions(-) delete mode 100755 scripts/linux/misc.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 595dc64557..f85f4b79bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,22 +1,39 @@ cmake_minimum_required(VERSION 2.8.8) +project(dsn C CXX) + include(bin/dsn.cmake) -project(dsn C CXX) set(DSN_BUILD_RUNTIME TRUE) add_definitions(-DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=0) -if(DEFINED WARNING_ALL) - #add_compile_options("-Wall") - SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall") - SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall") -endif() -OPTION(ENABLE_GCOV "Enable gcov (debug, Linux builds only)" OFF) -if(ENABLE_GCOV AND UNIX) - #add_compile_options("-fprofile-arcs" "-ftest-coverage") - SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -DENABLE_GCOV") - SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -DENABLE_GCOV") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -lgcov") -endif() dsn_common_setup() +# add custom target for gcov +if(ENABLE_GCOV) + find_program(GCOV_PATH gcov) + find_program(GCOVR_PATH gcovr) + + if(NOT GCOV_PATH) + message(FATAL_ERROR "gcov not found! Aborting...") + endif() # NOT GCOV_PATH + + if(NOT GCOVR_PATH) + message(FATAL_ERROR "gcovr not found! Aborting...") + endif() # NOT GCOVR_PATH + + if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading") + endif() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug" + + set(COVERAGE_COMPILER_FLAGS "-g -O0 --coverage -fprofile-arcs -ftest-coverage" CACHE INTERNAL "") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}") + message(STATUS "Appending code coverage compiler flags: ${COVERAGE_COMPILER_FLAGS}") + + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov") +endif() + +# install rdsn/include to ${CMAKE_INCLUDE_PREFIX}/include +install(DIRECTORY include/ DESTINATION include) + add_subdirectory(src) diff --git a/bin/compiler_info.cmake b/bin/compiler_info.cmake index dbec3e7c97..896243a572 100644 --- a/bin/compiler_info.cmake +++ b/bin/compiler_info.cmake @@ -18,6 +18,7 @@ # Sets COMPILER_FAMILY to 'clang' or 'gcc' # Sets COMPILER_VERSION to the version +include(CMakeDetermineCXXCompiler) message("Running rdsn/bin/compiler_info.cmake") execute_process(COMMAND env LANG=C "${CMAKE_CXX_COMPILER}" -v ERROR_VARIABLE COMPILER_VERSION_FULL) diff --git a/bin/dsn.cmake b/bin/dsn.cmake index e2257d2c0a..8c1944ea34 100644 --- a/bin/dsn.cmake +++ b/bin/dsn.cmake @@ -1,54 +1,56 @@ include(${CMAKE_CURRENT_LIST_DIR}/compiler_info.cmake) + # Always generate the compilation database file (compile_commands.json) for use # with various development tools, such as IWYU and Vim's YouCompleteMe plugin. # See http://clang.llvm.org/docs/JSONCompilationDatabase.html set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) -function(ms_add_project PROJ_TYPE PROJ_NAME PROJ_SRC PROJ_INC_PATH PROJ_LIBS PROJ_LIB_PATH PROJ_BINPLACES PROJ_BINDIRS DO_INSTALL) - if(DEFINED DSN_DEBUG_CMAKE) - message(STATUS "PROJ_TYPE = ${PROJ_TYPE}") - message(STATUS "PROJ_NAME = ${PROJ_NAME}") - message(STATUS "PROJ_SRC = ${PROJ_SRC}") - message(STATUS "PROJ_INC_PATH = ${PROJ_INC_PATH}") - message(STATUS "PROJ_LIBS = ${PROJ_LIBS}") - message(STATUS "PROJ_LIB_PATH = ${PROJ_LIB_PATH}") - message(STATUS "PROJ_BINPLACES = ${PROJ_BINPLACES}") - message(STATUS "DO_INSTALL = ${DO_INSTALL}") + +# Set DSN_ROOT to ${PROJECT_BINARY_DIR}/output, this is where targets will be installed. +# Users don't have to configure CMAKE_INSTALL_PREFIX unless they want to customize +# the destination. +set(DSN_ROOT ${PROJECT_BINARY_DIR}/output) +message(STATUS "DSN_ROOT = ${DSN_ROOT}") +set(CMAKE_INSTALL_PREFIX ${DSN_ROOT} CACHE STRING "" FORCE) +message (STATUS "Installation directory: CMAKE_INSTALL_PREFIX = " ${CMAKE_INSTALL_PREFIX}) + +# Set DSN_THIRDPARTY_ROOT to rdsn/thirdparty +set(RDSN_PROJECT_DIR ${CMAKE_CURRENT_LIST_DIR}) +get_filename_component(RDSN_PROJECT_DIR ${RDSN_PROJECT_DIR} DIRECTORY) +set(DSN_THIRDPARTY_ROOT ${RDSN_PROJECT_DIR}/thirdparty) +message(STATUS "DSN_THIRDPARTY_ROOT = ${DSN_THIRDPARTY_ROOT}") + + +# Install this target into ${CMAKE_INSTALL_PREFIX}/lib +function(dsn_install_library) + install(TARGETS ${MY_PROJ_NAME} DESTINATION "lib") +endfunction() + +# Install this target into ${CMAKE_INSTALL_PREFIX}/bin/${PROJ_NAME} +function(dsn_install_executable) + set(MY_PROJ_TYPE "EXECUTABLE") + set(INSTALL_DIR "bin/${MY_PROJ_NAME}") + install(TARGETS ${MY_PROJ_NAME} DESTINATION "${INSTALL_DIR}") + + # install the extra files together with the executable + if(NOT (MY_BINPLACES STREQUAL "")) + foreach(BF ${MY_BINPLACES}) + install(FILES ${BF} DESTINATION "${INSTALL_DIR}") + endforeach() endif() +endfunction() +function(ms_add_project PROJ_TYPE PROJ_NAME PROJ_SRC PROJ_INC_PATH PROJ_LIBS PROJ_LIB_PATH PROJ_BINPLACES) if(NOT((PROJ_TYPE STREQUAL "STATIC") OR (PROJ_TYPE STREQUAL "SHARED") OR (PROJ_TYPE STREQUAL "EXECUTABLE") OR (PROJ_TYPE STREQUAL "OBJECT"))) - #"MODULE" is not used yet message(FATAL_ERROR "Invalid project type.") endif() - if(PROJ_NAME STREQUAL "") - message(FATAL_ERROR "Invalid project name.") - endif() - if(PROJ_SRC STREQUAL "") message(FATAL_ERROR "No source files.") endif() - set(INSTALL_DIR "lib") - if(PROJ_TYPE STREQUAL "EXECUTABLE") - set(INSTALL_DIR "bin/${PROJ_NAME}") - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJ_NAME}") - set(OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") - execute_process(COMMAND sh -c "echo ${PROJ_NAME} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR}/${INSTALL_DIR} ' ' >> ${CMAKE_SOURCE_DIR}/.matchfile") - elseif(PROJ_TYPE STREQUAL "STATIC") - set(OUTPUT_DIRECTORY "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}") - execute_process(COMMAND sh -c "echo ${PROJ_NAME} ${CMAKE_CURRENT_SOURCE_DIR} ${OUTPUT_DIRECTORY} ' ' >> ${CMAKE_SOURCE_DIR}/.matchfile") - elseif(PROJ_TYPE STREQUAL "SHARED") - set(OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") - execute_process(COMMAND sh -c "echo ${PROJ_NAME} ${CMAKE_CURRENT_SOURCE_DIR} ${OUTPUT_DIRECTORY} ' ' >> ${CMAKE_SOURCE_DIR}/.matchfile") - endif() - - if(DEFINED DSN_DEBUG_CMAKE) - message(STATUS "OUTPUT_DIRECTORY = ${OUTPUT_DIRECTORY}") - endif() - if(NOT (PROJ_INC_PATH STREQUAL "")) include_directories(${PROJ_INC_PATH}) endif() @@ -72,60 +74,21 @@ function(ms_add_project PROJ_TYPE PROJ_NAME PROJ_SRC PROJ_INC_PATH PROJ_LIBS PRO endif() target_link_libraries(${PROJ_NAME} "${LINK_MODE}" ${PROJ_LIBS}) endif() - - if(DO_INSTALL) - install(TARGETS ${PROJ_NAME} DESTINATION "${INSTALL_DIR}") - endif() - - if((PROJ_TYPE STREQUAL "EXECUTABLE") AND (NOT (PROJ_BINPLACES STREQUAL ""))) - foreach(BF ${PROJ_BINPLACES}) - get_filename_component(BF "${BF}" ABSOLUTE) - add_custom_command( - TARGET ${PROJ_NAME} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy ${BF} "${OUTPUT_DIRECTORY}/" - ) - if(DO_INSTALL) - install(FILES ${BF} DESTINATION "${INSTALL_DIR}") - endif() - endforeach() - endif() - - if((PROJ_TYPE STREQUAL "EXECUTABLE") AND (NOT (PROJ_BINDIRS STREQUAL ""))) - foreach(BF ${PROJ_BINDIRS}) - get_filename_component(BF "${BF}" ABSOLUTE) - add_custom_command( - TARGET ${PROJ_NAME} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory ${BF} "${OUTPUT_DIRECTORY}/" - ) - if(DO_INSTALL) - install(FILES ${BF} DESTINATION "${INSTALL_DIR}") - endif() - endforeach() - endif() endfunction(ms_add_project) -macro(ms_find_source_files SOURCE_DIR GLOB_OPTION PROJ_SRC) - set(TEMP_PROJ_SRC "") - file(${GLOB_OPTION} - TEMP_PROJ_SRC - "${SOURCE_DIR}/*.cpp" - "${SOURCE_DIR}/*.cc" - "${SOURCE_DIR}/*.c" - "${SOURCE_DIR}/*.h" - "${SOURCE_DIR}/*.hpp" - ) - - if(DEFINED DSN_DEBUG_CMAKE) - message(STATUS "SOURCE_DIR = ${SOURCE_DIR}") - message(STATUS "GLOB_OPTION = ${GLOB_OPTION}") - message(STATUS "PROJ_SRC = ${${PROJ_SRC}}") - endif() - - set(${PROJ_SRC} ${${PROJ_SRC}} ${TEMP_PROJ_SRC}) -endmacro(ms_find_source_files) +# Parameters: +# - MY_PROJ_TYPE +# - MY_PROJ_NAME +# - MY_SRC_SEARCH_MODE +# Search mode for source files under current project directory +# "GLOB_RECURSE" for recursive search +# "GLOB" for non-recursive search +# - MY_PROJ_SRC +# - MY_PROJ_INC_PATH +# - MY_PROJ_LIB_PATH TODO(wutao1): remove this +# - MY_BINPLACES +# - MY_BOOST_PACKAGES function(dsn_add_project) if((NOT DEFINED MY_PROJ_TYPE) OR (MY_PROJ_TYPE STREQUAL "")) message(FATAL_ERROR "MY_PROJ_TYPE is empty.") @@ -136,12 +99,19 @@ function(dsn_add_project) if(NOT DEFINED MY_SRC_SEARCH_MODE) set(MY_SRC_SEARCH_MODE "GLOB") endif() + + # find source files from current directory if(NOT DEFINED MY_PROJ_SRC) set(MY_PROJ_SRC "") endif() set(TEMP_SRC "") - ms_find_source_files("${CMAKE_CURRENT_SOURCE_DIR}" ${MY_SRC_SEARCH_MODE} TEMP_SRC) + # We restrict the file suffix to keep our codes consitent. + file(${MY_SRC_SEARCH_MODE} TEMP_SRC + "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/*.c" + ) set(MY_PROJ_SRC ${TEMP_SRC} ${MY_PROJ_SRC}) + if(NOT DEFINED MY_PROJ_INC_PATH) set(MY_PROJ_INC_PATH "") endif() @@ -151,24 +121,12 @@ function(dsn_add_project) if(NOT DEFINED MY_PROJ_LIB_PATH) set(MY_PROJ_LIB_PATH "") endif() - if(NOT DEFINED MY_PROJ_BINPLACES) - set(MY_PROJ_BINPLACES "") - endif() - if(NOT DEFINED MY_PROJ_BINDIRS) - set(MY_PROJ_BINDIRS "") + if(NOT DEFINED MY_BINPLACES) + set(MY_BINPLACES "") endif() if(NOT DEFINED MY_BOOST_PACKAGES) set(MY_BOOST_PACKAGES "") endif() - if(NOT DEFINED MY_DO_INSTALL) - if(MY_PROJ_TYPE STREQUAL "OBJECT") - set(MY_DO_INSTALL FALSE) - elseif(DSN_BUILD_RUNTIME AND (MY_PROJ_TYPE STREQUAL "EXECUTABLE")) - set(MY_DO_INSTALL FALSE) - else() - set(MY_DO_INSTALL TRUE) - endif() - endif() set(MY_BOOST_LIBS "") if(NOT (MY_BOOST_PACKAGES STREQUAL "")) @@ -181,41 +139,24 @@ function(dsn_add_project) else() set(TEMP_LIBS dsn_runtime) endif() - set(MY_PROJ_LIBS ${MY_PROJ_LIBS} ${TEMP_LIBS} ${MY_BOOST_LIBS} -ltcmalloc) - if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") - set(MY_PROJ_LIBS ${MY_PROJ_LIBS} ${DSN_SYSTEM_LIBS}) - else() - set(MY_PROJ_LIBS ${DSN_SYSTEM_LIBS} ${MY_PROJ_LIBS}) - endif() + set(MY_PROJ_LIBS ${MY_PROJ_LIBS} ${TEMP_LIBS} ${MY_BOOST_LIBS} -ltcmalloc ${DSN_SYSTEM_LIBS}) endif() list(APPEND MY_PROJ_LIBS thrift) - if(DEFINED DSN_DEBUG_CMAKE) - message(STATUS "MY_PROJ_TYPE = ${MY_PROJ_TYPE}") - message(STATUS "MY_PROJ_NAME = ${MY_PROJ_NAME}") - message(STATUS "MY_PROJ_SRC = ${MY_PROJ_SRC}") - message(STATUS "MY_SRC_SEARCH_MODE = ${MY_SRC_SEARCH_MODE}") - message(STATUS "MY_PROJ_INC_PATH = ${MY_PROJ_INC_PATH}") - message(STATUS "MY_PROJ_LIBS = ${MY_PROJ_LIBS}") - message(STATUS "MY_PROJ_LIB_PATH = ${MY_PROJ_LIB_PATH}") - message(STATUS "MY_PROJ_BINPLACES = ${MY_PROJ_BINPLACES}") - message(STATUS "MY_PROJ_BINDIRS = ${MY_PROJ_BINDIRS}") - message(STATUS "MY_DO_INSTALL = ${MY_DO_INSTALL}") - message(STATUS "MY_BOOST_PACKAGES = ${MY_BOOST_PACKAGES}") - message(STATUS "MY_BOOST_LIBS = ${MY_BOOST_LIBS}") - endif() - ms_add_project("${MY_PROJ_TYPE}" "${MY_PROJ_NAME}" "${MY_PROJ_SRC}" "${MY_PROJ_INC_PATH}" "${MY_PROJ_LIBS}" "${MY_PROJ_LIB_PATH}" "${MY_BINPLACES}" "${MY_PROJ_BINDIRS}" "${MY_DO_INSTALL}") + ms_add_project("${MY_PROJ_TYPE}" "${MY_PROJ_NAME}" "${MY_PROJ_SRC}" "${MY_PROJ_INC_PATH}" "${MY_PROJ_LIBS}" "${MY_PROJ_LIB_PATH}" "${MY_BINPLACES}") endfunction(dsn_add_project) function(dsn_add_static_library) set(MY_PROJ_TYPE "STATIC") dsn_add_project() + dsn_install_library() endfunction(dsn_add_static_library) function(dsn_add_shared_library) set(MY_PROJ_TYPE "SHARED") dsn_add_project() + dsn_install_library() endfunction(dsn_add_shared_library) function(dsn_add_executable) @@ -229,15 +170,26 @@ function(dsn_add_object) endfunction(dsn_add_object) option(BUILD_TEST "build unit test" ON) +option(ENABLE_GCOV "Enable gcov (for code coverage analysis)" OFF) function(dsn_add_test) if(${BUILD_TEST}) + set(MY_EXECUTABLE_IS_TEST TRUE) dsn_add_executable() + + file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/bin") + execute_process(COMMAND ln -sf ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR}/bin/${MY_PROJ_NAME}) + + # copy the extra files together with the executable + if(NOT (MY_BINPLACES STREQUAL "")) + foreach(BF ${MY_BINPLACES}) + FILE(COPY ${BF} DESTINATION "${CMAKE_BINARY_DIR}/bin/${MY_PROJ_NAME}") + endforeach() + endif() endif() endfunction() function(dsn_setup_compiler_flags) if(CMAKE_BUILD_TYPE STREQUAL "Debug") - add_definitions(-D_DEBUG) add_definitions(-DDSN_BUILD_TYPE=Debug) else() add_definitions(-g) @@ -266,7 +218,7 @@ function(dsn_setup_compiler_flags) if ("${COMPILER_FAMILY}" STREQUAL "clang") add_compile_options(-Qunused-arguments) endif() - message("use ccache to speed up compilation") + message(STATUS "use ccache to speed up compilation") endif(CCACHE_FOUND) set(CMAKE_EXE_LINKER_FLAGS @@ -283,10 +235,6 @@ function(dsn_setup_compiler_flags) endfunction(dsn_setup_compiler_flags) macro(ms_setup_boost STATIC_LINK PACKAGES BOOST_LIBS) - if(DEFINED DSN_DEBUG_CMAKE) - message(STATUS "BOOST_PACKAGES = ${PACKAGES}") - endif() - set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_LIBS OFF) set(Boost_USE_STATIC_RUNTIME OFF) @@ -343,12 +291,6 @@ function(dsn_setup_packages) ) endfunction(dsn_setup_packages) -function(dsn_set_output_path) - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin CACHE STRING "" FORCE) - set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib CACHE STRING "" FORCE) - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib CACHE STRING "" FORCE) -endfunction(dsn_set_output_path) - function(dsn_setup_include_path) if(DEFINED BOOST_ROOT) include_directories(${BOOST_ROOT}/include) @@ -376,17 +318,8 @@ function(dsn_setup_link_path) endif() endfunction(dsn_setup_link_path) -function(dsn_setup_install) - if(DSN_BUILD_RUNTIME) - install(DIRECTORY include/ DESTINATION include) - install(DIRECTORY bin/ DESTINATION bin USE_SOURCE_PERMISSIONS) - install(DIRECTORY ${PROJECT_BINARY_DIR}/lib/ DESTINATION lib) - endif() -endfunction(dsn_setup_install) - function(dsn_common_setup) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(notdir $(abspath $<))\"'") - execute_process(COMMAND sh -c "rm -rf ${CMAKE_SOURCE_DIR}/.matchfile") if(NOT (UNIX)) message(FATAL_ERROR "Only Unix are supported.") @@ -400,25 +333,16 @@ function(dsn_common_setup) set(DSN_BUILD_RUNTIME FALSE) endif() - message (STATUS "Installation directory: CMAKE_INSTALL_PREFIX = " ${CMAKE_INSTALL_PREFIX}) - set(DSN_ROOT2 "$ENV{DSN_ROOT}") - if((NOT (DSN_ROOT2 STREQUAL "")) AND (EXISTS "${DSN_ROOT2}/")) - set(CMAKE_INSTALL_PREFIX ${DSN_ROOT2} CACHE STRING "" FORCE) - message (STATUS "Installation directory redefined w/ ENV{DSN_ROOT}: " ${CMAKE_INSTALL_PREFIX}) - endif() - set(BUILD_SHARED_LIBS OFF) include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++1y" COMPILER_SUPPORTS_CXX1Y) - if(NOT ${COMPILER_SUPPORTS_CXX11}) + if(NOT ${COMPILER_SUPPORTS_CXX1Y}) message(FATAL_ERROR "You need a compiler with C++1y support.") endif() dsn_setup_packages() dsn_setup_compiler_flags() dsn_setup_include_path() - dsn_set_output_path() dsn_setup_link_path() - dsn_setup_install() endfunction(dsn_common_setup) diff --git a/run.sh b/run.sh index a83f09fcf4..8909c0222c 100755 --- a/run.sh +++ b/run.sh @@ -58,7 +58,6 @@ function usage_build() echo " default is \"gcc,g++\"" echo " -j|--jobs the number of jobs to run simultaneously, default 8" echo " -b|--boost_dir specify customized boost directory, use system boost if not set" - echo " -w|--warning_all open all warnings when build, default no" echo " --enable_gcov generate gcov code coverage report, default no" echo " -v|--verbose build in verbose mode, default no" echo " --notest build without building unit tests, default no" @@ -77,7 +76,6 @@ function run_build() CLEAR_THIRDPARTY=NO JOB_NUM=8 BOOST_DIR="" - WARNING_ALL=NO ENABLE_GCOV=NO RUN_VERBOSE=NO NO_TEST=NO @@ -118,11 +116,9 @@ function run_build() BOOST_DIR="$2" shift ;; - -w|--warning_all) - WARNING_ALL=YES - ;; --enable_gcov) ENABLE_GCOV=YES + BUILD_TYPE="debug" ;; -v|--verbose) RUN_VERBOSE=YES @@ -179,7 +175,7 @@ function run_build() fi C_COMPILER="$C_COMPILER" CXX_COMPILER="$CXX_COMPILER" BUILD_TYPE="$BUILD_TYPE" \ ONLY_BUILD="$ONLY_BUILD" CLEAR="$CLEAR" JOB_NUM="$JOB_NUM" \ - BOOST_DIR="$BOOST_DIR" WARNING_ALL="$WARNING_ALL" ENABLE_GCOV="$ENABLE_GCOV" \ + BOOST_DIR="$BOOST_DIR" ENABLE_GCOV="$ENABLE_GCOV" \ RUN_VERBOSE="$RUN_VERBOSE" TEST_MODULE="$TEST_MODULE" NO_TEST="$NO_TEST" $scripts_dir/build.sh } diff --git a/scripts/linux/build.sh b/scripts/linux/build.sh index 8bd00399f0..b4e194048a 100755 --- a/scripts/linux/build.sh +++ b/scripts/linux/build.sh @@ -9,7 +9,6 @@ # CXX_COMPILER # ONLY_BUILD YES|NO # RUN_VERBOSE YES|NO -# WARNING_ALL YES|NO # ENABLE_GCOV YES|NO # BOOST_DIR |"" # TEST_MODULE " ..." @@ -18,8 +17,6 @@ # -DCMAKE_C_COMPILER=gcc|clang # -DCMAKE_CXX_COMPILER=g++|clang++ # [-DCMAKE_BUILD_TYPE=Debug] -# [-DDSN_GIT_SOURCE=github|xiaomi] -# [-DWARNING_ALL=TRUE] # [-DENABLE_GCOV=TRUE] # [-DBoost_NO_BOOST_CMAKE=ON -DBOOST_ROOT=$BOOST_DIR -DBoost_NO_SYSTEM_PATHS=ON] @@ -27,8 +24,6 @@ ROOT=`pwd` REPORT_DIR=$ROOT/test_reports BUILD_DIR="$ROOT/builder" GCOV_DIR="$ROOT/gcov_report" -GCOV_TMP="$ROOT/.gcov_tmp" -GCOV_PATTERN=`find $ROOT/include $ROOT/src -name '*.h' -o -name '*.cpp'` TIME=`date --rfc-3339=seconds` echo "C_COMPILER=$C_COMPILER" @@ -68,14 +63,6 @@ else echo "RUN_VERBOSE=NO" fi -if [ "$WARNING_ALL" == "YES" ] -then - echo "WARNING_ALL=YES" - CMAKE_OPTIONS="$CMAKE_OPTIONS -DWARNING_ALL=TRUE" -else - echo "WARNING_ALL=NO" -fi - if [ "$ENABLE_GCOV" == "YES" ] then echo "ENABLE_GCOV=YES" @@ -181,43 +168,16 @@ then exit 0 fi -echo "#############################################################################" +echo "################################# start testing ################################" -############################################## -## Supported test module: -## - dsn.core.tests -## - dsn.tests -## - dsn.rep_tests.simple_kv -## - dsn.replication.simple_kv -############################################## if [ -z "$TEST_MODULE" ] then + # supported test module TEST_MODULE="dsn.core.tests,dsn.tests,dsn_nfs_test,dsn.replication.simple_kv,dsn.rep_tests.simple_kv,dsn.meta.test,dsn.replica.test" fi echo "TEST_MODULE=$TEST_MODULE" -if [ "$ENABLE_GCOV" == "YES" ] -then - echo "Initializing gcov..." - cd $ROOT - rm -rf $GCOV_TMP &>/dev/null - mkdir -p $GCOV_TMP - lcov -q -d $BUILD_DIR -z - lcov -q -d $BUILD_DIR -b $ROOT --no-external --initial -c -o $GCOV_TMP/initial.info - if [ $? -ne 0 ] - then - echo "ERROR: lcov init failed, maybe need to run again with --clear option" - exit 1 - fi - lcov -q -e $GCOV_TMP/initial.info $GCOV_PATTERN -o $GCOV_TMP/initial.extract.info - if [ $? -ne 0 ] - then - echo "ERROR: lcov init extract failed" - exit 1 - fi -fi - if [ ! -d "$REPORT_DIR" ] then mkdir -p $REPORT_DIR @@ -233,7 +193,7 @@ for MODULE in `echo $TEST_MODULE | sed 's/,/ /g'`; do fi if [ ! -f "$MODULE_DIR/run.sh" ] then - echo "ERROR: module test entrance script $MODULE_DIR/run.sh not exist" + echo "ERROR: module test entrance script $MODULE_DIR/run.sh doesn't exist" exit 1 fi cd $MODULE_DIR @@ -250,28 +210,15 @@ if [ "$ENABLE_GCOV" == "YES" ] then echo "Generating gcov report..." cd $ROOT - lcov -q -d $BUILD_DIR -b $ROOT --no-external -c -o $GCOV_TMP/gcov.info - if [ $? -ne 0 ] - then - echo "ERROR: lcov generate failed" - exit 1 - fi - lcov -q -e $GCOV_TMP/gcov.info $GCOV_PATTERN -o $GCOV_TMP/gcov.extract.info - if [ $? -ne 0 ] - then - echo "ERROR: lcov extract failed" - exit 1 - fi - genhtml $GCOV_TMP/*.extract.info --show-details --legend --title "GCOV report at $TIME" -o $GCOV_TMP/report + mkdir -p $GCOV_DIR + + echo "Running gcovr to produce HTML code coverage report." + gcovr --html --html-details -r $ROOT --object-directory=$BUILD_DIR \ + -o $GCOV_DIR/index.html if [ $? -ne 0 ] then - echo "ERROR: gcov genhtml failed" exit 1 fi - rm -rf $GCOV_DIR &>/dev/null - mv $GCOV_TMP/report $GCOV_DIR - rm -rf $GCOV_TMP - echo "View gcov report: firefox $GCOV_DIR/index.html" fi echo "Test succeed" diff --git a/scripts/linux/misc.sh b/scripts/linux/misc.sh deleted file mode 100755 index 340f363e28..0000000000 --- a/scripts/linux/misc.sh +++ /dev/null @@ -1,154 +0,0 @@ -# This script defines some useful function to help switch between directories of the project. -# To use it, just import this script using 'source misc.sh'. - -function find_matchfile() -{ - dir=`pwd` - while [ "$dir" != "/" ]; do - if [ -f "$dir/.matchfile" ]; then - echo "$dir/.matchfile" - return - fi - dir=`dirname $dir` - done -} - -function goto_dest_dir() -{ - all_params=$* - dst_dir=`echo $all_params | awk '{print $3}'` - cd $dst_dir -} - -function goto_source_dir() -{ - all_params=$* - src_dir=`echo $all_params | awk '{print $2}'` - cd $src_dir -} - -function g() -{ - matchfile=`find_matchfile` - if [ -z $matchfile ]; then - echo "You need to be in rDSN project and build the project first" - return - fi - - proj_dir=`pwd` - result=`cat $matchfile | grep -F "$proj_dir " | wc -l` - if [ $result -ne 1 ]; then - echo "You are not in any module src/binary dir, try 'lst' command to list modules" - else - proj_line=`cat $matchfile | grep -F "$proj_dir "` - src_dir=`echo $proj_line | awk '{print $2}'` - if [ "$proj_dir" = "$src_dir" ]; then - goto_dest_dir $proj_line - else - goto_source_dir $proj_line - fi - fi -} - -function src() -{ - matchfile=`find_matchfile` - if [ -z $matchfile ]; then - echo "You need to be in rDSN project and build the project first" - return - fi - - result=`cat $matchfile | grep -F "$1 " | wc -l` - if [ $result -eq 1 ]; then - proj_line=`cat $matchfile | grep -F "$1 "` - goto_source_dir $proj_line - return - fi - - result=`cat $matchfile | grep -F $1 | wc -l` - if [ $result -ne 1 ]; then - echo "Can not identify unique module name, candidates are:" - cat $matchfile | grep -F $1 - else - proj_line=`cat $matchfile | grep -F $1` - goto_source_dir $proj_line - fi -} - -function dst() -{ - matchfile=`find_matchfile` - if [ -z $matchfile ]; then - echo "You need to be in rDSN project and build the project first" - return - fi - - result=`cat $matchfile | grep -F "$1 " | wc -l` - if [ $result -eq 1 ]; then - proj_line=`cat $matchfile | grep -F "$1 "` - goto_dest_dir $proj_line - return - fi - - result=`cat $matchfile | grep -F $1 | wc -l` - if [ $result -ne 1 ]; then - echo "Can not identify unique module name, candidates are:" - cat $matchfile | grep -F $1 - else - proj_line=`cat $matchfile | grep -F $1` - goto_dest_dir $proj_line - fi -} - -function gcp() -{ - matchfile=`find_matchfile` - if [ -z $matchfile ]; then - echo "You need to be in rDSN project and build the project first" - return - fi - - if [ $# -gt 0 ]; then - proj_dir=`pwd` - result=`cat $matchfile | grep -F "$proj_dir " | wc -l` - if [ $result -ne 1 ]; then - echo "You are not in any module src/binary dir, try 'lst' command to list modules" - else - proj_line=`cat $matchfile | grep -F "$proj_dir "` - src_dir=`echo $proj_line | awk '{print $2}'` - dest_dir=`echo $proj_line | awk '{print $3}'` - if [ "$proj_dir" = "$src_dir" ]; then - cp -v $* $dest_dir - else - cp -v $* $src_dir - fi - fi - else - echo "No file specified to copy" - fi -} - -function r() -{ - matchfile=`find_matchfile` - if [ -z $matchfile ]; then - echo "You need to be in rDSN project and build the project first" - return - fi - - cd `dirname $matchfile` -} - -function lst() -{ - matchfile=`find_matchfile` - if [ -z $matchfile ]; then - echo "You need to be in rDSN project and build the project first" - return - fi - - cat $matchfile | awk '{print $1}' - echo - echo "Try 'src ' or 'dst ' command to go to src/binary dirtory" -} - diff --git a/src/dist/cli/shell/CMakeLists.txt b/src/dist/cli/shell/CMakeLists.txt index cd73320b3a..8190ec2988 100644 --- a/src/dist/cli/shell/CMakeLists.txt +++ b/src/dist/cli/shell/CMakeLists.txt @@ -24,5 +24,5 @@ set(MY_BOOST_PACKAGES system filesystem) # Extra files that will be installed set(MY_BINPLACES "${CMAKE_CURRENT_SOURCE_DIR}/config.ini") -set(MY_DO_INSTALL TRUE) dsn_add_executable() +dsn_install_executable() diff --git a/src/dist/nfs/test/main.cpp b/src/dist/nfs/test/main.cpp index 611424db72..bceaec4393 100644 --- a/src/dist/nfs/test/main.cpp +++ b/src/dist/nfs/test/main.cpp @@ -146,6 +146,5 @@ GTEST_API_ int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); dsn_run_config("config.ini", false); - int ans = RUN_ALL_TESTS(); - dsn_exit(ans); + return RUN_ALL_TESTS(); } diff --git a/src/dist/replication/test/meta_test/unit_test/CMakeLists.txt b/src/dist/replication/test/meta_test/unit_test/CMakeLists.txt index 116e105897..6ffa62cb53 100644 --- a/src/dist/replication/test/meta_test/unit_test/CMakeLists.txt +++ b/src/dist/replication/test/meta_test/unit_test/CMakeLists.txt @@ -2,15 +2,14 @@ set(MY_PROJ_NAME dsn.meta.test) # Source files under CURRENT project directory will be automatically included. # You can manually set MY_PROJ_SRC to include source files under other directories. -set(MY_PROJ_SRC ../misc/misc.cpp) +file(GLOB MY_PROJ_SRC ${PROJECT_SOURCE_DIR}/src/dist/replication/meta_server/*.cpp) +set(MY_PROJ_SRC ${MY_PROJ_SRC} ../misc/misc.cpp) # Search mode for source files under CURRENT project directory? # "GLOB_RECURSE" for recursive search # "GLOB" for non-recursive search set(MY_SRC_SEARCH_MODE "GLOB") -ms_find_source_files("${CMAKE_CURRENT_SOURCE_DIR}/../../../meta_server" "GLOB" MY_PROJ_SRC) - set(MY_PROJ_INC_PATH "") set(MY_PROJ_LIBS dsn.replication.zookeeper_provider