From 34823f96ab46f60bea45173611b6e4c0637e75b7 Mon Sep 17 00:00:00 2001 From: lqx Date: Sun, 26 Nov 2023 17:58:30 +0800 Subject: [PATCH 1/5] CI add Gtest --- .github/workflows/pikiwidb.yml | 8 +++++++- build.sh | 28 ++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pikiwidb.yml b/.github/workflows/pikiwidb.yml index ce822fcff..67bdfe9dc 100644 --- a/.github/workflows/pikiwidb.yml +++ b/.github/workflows/pikiwidb.yml @@ -13,4 +13,10 @@ jobs: - name: Build run: | - sh build.sh \ No newline at end of file + sh build.sh + + - name: GTest + working-directory: ${{ github.workspace }}/build + # Execute tests defined by the CMake configuration. + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest \ No newline at end of file diff --git a/build.sh b/build.sh index cbe0e124d..b343d2705 100755 --- a/build.sh +++ b/build.sh @@ -1,11 +1,28 @@ #!/bin/bash +#color code +C_RED="\033[31m" +C_GREEN="\033[32m" + +C_END="\033[0m" + BUILD_TIME=$(git log -1 --format=%ai) BUILD_TIME=${BUILD_TIME: 0: 10} COMMIT_ID=$(git rev-parse HEAD) SHORT_COMMIT_ID=${COMMIT_ID: 0: 8} +if [ ! -f "/proc/cpuinfo" ];then + CPU_CORE=$(sysctl -n hw.ncpu) +else + CPU_CORE=$(cat /proc/cpuinfo| grep "processor"| wc -l) +fi +if [ ${CPU_CORE} -eq 0 ]; then + CPU_CORE=1 +fi + +echo "cpu core ${CPU_CORE}" + if [ -z "$SHORT_COMMIT_ID" ]; then echo "no git commit id" SHORT_COMMIT_ID="pikiwidb" @@ -14,5 +31,12 @@ fi echo "BUILD_TIME:" $BUILD_TIME echo "COMMIT_ID:" $SHORT_COMMIT_ID -cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TIME=$BUILD_TIME -DGIT_COMMIT_ID=$SHORT_COMMIT_ID -S . -B build -cmake --build build -- -j 32 +cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_TIME=$BUILD_TIME -DGIT_COMMIT_ID=$SHORT_COMMIT_ID -S . -B build +cmake --build build -- -j ${CPU_CORE} pikiwidb + +if [ $? -eq 0 ]; then + echo -e "pika compile complete, output file ${C_GREEN} ${BUILD_DIR}/pika ${C_END}" +else + echo -e "${C_RED} pika compile fail ${C_END}" + exit 1 +fi From 42c33a14d5259c1263418d724d7a1a3da45dd3ef Mon Sep 17 00:00:00 2001 From: lqx Date: Sun, 26 Nov 2023 18:13:41 +0800 Subject: [PATCH 2/5] fix gtest out dir --- src/pstd/tests/CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pstd/tests/CMakeLists.txt b/src/pstd/tests/CMakeLists.txt index e78536cec..0320de8a5 100644 --- a/src/pstd/tests/CMakeLists.txt +++ b/src/pstd/tests/CMakeLists.txt @@ -16,7 +16,7 @@ foreach (pstd_test_source ${PSTD_TEST_SOURCE}) get_filename_component(pstd_test_filename ${pstd_test_source} NAME) string(REPLACE ".cc" "" pstd_test_name ${pstd_test_filename}) - set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) +# set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) add_executable(${pstd_test_name} ${pstd_test_source}) target_include_directories(${pstd_test_name} PUBLIC ${PROJECT_SOURCE_DIR}/src @@ -27,6 +27,5 @@ foreach (pstd_test_source ${PSTD_TEST_SOURCE}) PUBLIC pstd PUBLIC gtest ) - gtest_discover_tests(${pstd_test_name} - WORKING_DIRECTORY .) + gtest_discover_tests(${pstd_test_name}) endforeach () From 95c32e11d3c98f4b6383637c1bfce095a70998cd Mon Sep 17 00:00:00 2001 From: lqx Date: Sun, 26 Nov 2023 18:38:12 +0800 Subject: [PATCH 3/5] closs other test --- build.sh | 2 +- cmake/double-conversion.cmake | 5 +++-- cmake/gflags.cmake | 1 + cmake/glog.cmake | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index b343d2705..612d2c4f2 100755 --- a/build.sh +++ b/build.sh @@ -32,7 +32,7 @@ echo "BUILD_TIME:" $BUILD_TIME echo "COMMIT_ID:" $SHORT_COMMIT_ID cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_TIME=$BUILD_TIME -DGIT_COMMIT_ID=$SHORT_COMMIT_ID -S . -B build -cmake --build build -- -j ${CPU_CORE} pikiwidb +cmake --build build -- -j ${CPU_CORE} if [ $? -eq 0 ]; then echo -e "pika compile complete, output file ${C_GREEN} ${BUILD_DIR}/pika ${C_END}" diff --git a/cmake/double-conversion.cmake b/cmake/double-conversion.cmake index c14726f13..88b69768e 100644 --- a/cmake/double-conversion.cmake +++ b/cmake/double-conversion.cmake @@ -11,5 +11,6 @@ FetchContent_DeclareGitHubWithMirror(double-conversion google/double-conversion v3.3.0 SHA256=4080014235f90854ffade6d1c423940b314bbca273a338235f049da296e47183 ) - -FetchContent_MakeAvailableWithArgs(double-conversion) +FetchContent_MakeAvailableWithArgs(double-conversion + BUILD_TESTING=OFF +) diff --git a/cmake/gflags.cmake b/cmake/gflags.cmake index b069674d9..410b1b067 100644 --- a/cmake/gflags.cmake +++ b/cmake/gflags.cmake @@ -18,6 +18,7 @@ FetchContent_MakeAvailableWithArgs(gflags BUILD_SHARED_LIBS=OFF BUILD_gflags_LIB=ON BUILD_gflags_nothreads_LIB=OFF + BUILD_TESTING=OFF ) find_package(Threads REQUIRED) diff --git a/cmake/glog.cmake b/cmake/glog.cmake index b6a8497e4..fbbde6fe9 100644 --- a/cmake/glog.cmake +++ b/cmake/glog.cmake @@ -16,7 +16,7 @@ FetchContent_Declare(glog FetchContent_MakeAvailableWithArgs(glog CMAKE_MODULE_PATH=${PROJECT_SOURCE_DIR}/cmake/modules/glog WITH_GFLAGS=ON - WITH_GTEST=OFF + BUILD_TESTING=OFF BUILD_SHARED_LIBS=OFF WITH_UNWIND=ON ) From 26e84c2402b939742a2994a0e36ce835e26fbe99 Mon Sep 17 00:00:00 2001 From: lqx Date: Sun, 26 Nov 2023 19:09:03 +0800 Subject: [PATCH 4/5] fix release compile error --- CMakeLists.txt | 2 +- build.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6ada246d..f46a87f7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,7 @@ ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Linux") set(CMAKE_THREAD_LIBS_INIT "-lpthread") ELSEIF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") SET(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") - SET(CMAKE_CXX_FLAGS "-pthread -Wl,--no-as-needed -ldl") + SET(CMAKE_CXX_FLAGS "-pthread -Wl,--no-as-needed -ldl -Wno-restrict") ENDIF () ADD_DEFINITIONS(-DOS_LINUX) ELSE () diff --git a/build.sh b/build.sh index 612d2c4f2..fe835ccfc 100755 --- a/build.sh +++ b/build.sh @@ -31,7 +31,7 @@ fi echo "BUILD_TIME:" $BUILD_TIME echo "COMMIT_ID:" $SHORT_COMMIT_ID -cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_TIME=$BUILD_TIME -DGIT_COMMIT_ID=$SHORT_COMMIT_ID -S . -B build +cmake -DCMAKE_BUILD_TYPE=release -DBUILD_TIME=$BUILD_TIME -DGIT_COMMIT_ID=$SHORT_COMMIT_ID -S . -B build cmake --build build -- -j ${CPU_CORE} if [ $? -eq 0 ]; then From cd138d969425a6ce15a128c4d5ffe0c090e01537 Mon Sep 17 00:00:00 2001 From: lqx Date: Mon, 27 Nov 2023 20:10:56 +0800 Subject: [PATCH 5/5] add build.sh read prams,add ci on ubuntu --- .github/workflows/pikiwidb.yml | 16 +++++++++++ build.sh | 51 ++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pikiwidb.yml b/.github/workflows/pikiwidb.yml index 67bdfe9dc..97441c5fe 100644 --- a/.github/workflows/pikiwidb.yml +++ b/.github/workflows/pikiwidb.yml @@ -15,6 +15,22 @@ jobs: run: | sh build.sh + - name: GTest + working-directory: ${{ github.workspace }}/build + # Execute tests defined by the CMake configuration. + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest + + build_on_ubuntu: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Build + run: | + bash build.sh + - name: GTest working-directory: ${{ github.workspace }}/build # Execute tests defined by the CMake configuration. diff --git a/build.sh b/build.sh index fe835ccfc..102f35325 100755 --- a/build.sh +++ b/build.sh @@ -12,6 +12,49 @@ BUILD_TIME=${BUILD_TIME: 0: 10} COMMIT_ID=$(git rev-parse HEAD) SHORT_COMMIT_ID=${COMMIT_ID: 0: 8} +BUILD_TYPE=release +VERBOSE=0 +CMAKE_FLAGS="" +MAKE_FLAGS="" +PREFIX="build" + +ARGS=`getopt -a -o h -l help,debug,verbose,prefix: -- "$@"` +function show_help() { + echo " + -h --help show help + --debug compile with debug + --verbose compile with verbose + --prefix compile output path + " + exit 0 +} + +eval set -- "${ARGS}" +while true +do + case "$1" in + -h|--help) + show_help + ;; + --debug) + BUILD_TYPE=debug + ;; + --verbose) + CMAKE_FLAGS="${CMAKE_FLAGS} -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" + MAKE_FLAGS="${MAKE_FLAGS} VERBOSE=1" + ;; + --prefix) + PREFIX=$2 + shift + ;; + --) + shift + break + ;; + esac +shift +done + if [ ! -f "/proc/cpuinfo" ];then CPU_CORE=$(sysctl -n hw.ncpu) else @@ -31,8 +74,12 @@ fi echo "BUILD_TIME:" $BUILD_TIME echo "COMMIT_ID:" $SHORT_COMMIT_ID -cmake -DCMAKE_BUILD_TYPE=release -DBUILD_TIME=$BUILD_TIME -DGIT_COMMIT_ID=$SHORT_COMMIT_ID -S . -B build -cmake --build build -- -j ${CPU_CORE} +echo "BUILD_TYPE:" $BUILD_TYPE +echo "CMAKE_FLAGS:" $CMAKE_FLAGS +echo "MAKE_FLAGS:" $MAKE_FLAGS + +cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DBUILD_TIME=$BUILD_TIME -DGIT_COMMIT_ID=$SHORT_COMMIT_ID ${CMAKE_FLAGS} -S . -B ${PREFIX} +cmake --build ${PREFIX} -- ${MAKE_FLAGS} -j ${CPU_CORE} if [ $? -eq 0 ]; then echo -e "pika compile complete, output file ${C_GREEN} ${BUILD_DIR}/pika ${C_END}"