From fbdedbf21b721c7d32aa8a95b05c3367e0caf692 Mon Sep 17 00:00:00 2001 From: "yizhe.wcm" Date: Sun, 23 Feb 2020 19:36:33 +0800 Subject: [PATCH 1/2] =?UTF-8?q?Modification=20item:=20=EF=BC=881=EF=BC=89D?= =?UTF-8?q?eclare=20variables=20explicitly,=20and=20clarify=20variable=20t?= =?UTF-8?q?ypes.=20=EF=BC=882=EF=BC=89Format=20the=20code=20style.=20?= =?UTF-8?q?=EF=BC=883=EF=BC=89Add=20asan=20support=20for=20memory=20addres?= =?UTF-8?q?s=20out=20of=20range=20checking.=20=EF=BC=884=EF=BC=89Add=20lsa?= =?UTF-8?q?n=20support=20for=20memory=20leak=20checking.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 14 +++++++++ build.sh | 80 +++++++++++++++++++++++++++++++++----------------- 2 files changed, 67 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a5647142..a2b178c63 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,6 +173,20 @@ ELSE () string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CXX_FLAGS}") string(REPLACE ";" " " CMAKE_C_FLAGS "${C_FLAGS}") + option(ENABLE_ASAN "Enable asan reporting" OFF) + if (ENABLE_ASAN) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer -static-libasan") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer -static-libasan") + message(STATUS "** ENABLE_ASAN: ${ENABLE_ASAN} Enable asan reporting") + endif () + + option(ENABLE_LSAN "Enable lsan reporting" OFF) + if (ENABLE_LSAN) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=leak -fno-omit-frame-pointer -static-liblsan") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=leak -fno-omit-frame-pointer -static-liblsan") + message(STATUS "** ENABLE_LSAN: ${ENABLE_LSAN} Enable lsan reporting") + endif () + set(CMAKE_CXX_FLAGS_DEBUG "-O0 -DDEBUG") set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") diff --git a/build.sh b/build.sh index 20a2426ca..1d0034499 100755 --- a/build.sh +++ b/build.sh @@ -19,16 +19,16 @@ basepath=$( cd $(dirname $0) pwd ) -down_dir="${basepath}/tmp_down_dir" -build_dir="${basepath}/tmp_build_dir" -packet_dir="${basepath}/tmp_packet_dir" -install_lib_dir="${basepath}/bin" -fname_libevent="libevent*.zip" -fname_jsoncpp="jsoncpp*.zip" -fname_boost="boost*.tar.gz" -fname_libevent_down="release-2.1.11-stable.zip" -fname_jsoncpp_down="0.10.6.zip" -fname_boost_down="1.58.0/boost_1_58_0.tar.gz" +declare down_dir="${basepath}/tmp_down_dir" +declare build_dir="${basepath}/tmp_build_dir" +declare packet_dir="${basepath}/tmp_packet_dir" +declare install_lib_dir="${basepath}/bin" +declare fname_libevent="libevent*.zip" +declare fname_jsoncpp="jsoncpp*.zip" +declare fname_boost="boost*.tar.gz" +declare fname_libevent_down="release-2.1.11-stable.zip" +declare fname_jsoncpp_down="0.10.6.zip" +declare fname_boost_down="1.58.0/boost_1_58_0.tar.gz" PrintParams() { echo "=========================================one key build help============================================" @@ -38,13 +38,15 @@ PrintParams() { echo "" } -need_build_jsoncpp=1 -need_build_libevent=1 -need_build_boost=1 -test=0 -verbose=1 -codecov=0 -cpu_num=4 +declare need_build_jsoncpp=1 +declare need_build_libevent=1 +declare need_build_boost=1 +declare enable_asan=0 +declare enable_lsan=0 +declare verbose=1 +declare codecov=0 +declare cpu_num=4 +declare test=0 pasres_arguments() { for var in "$@"; do @@ -58,6 +60,12 @@ pasres_arguments() { noBoost) need_build_boost=0 ;; + asan) + enable_asan=1 + ;; + lsan) + enable_lsan=1 + ;; noVerbose) verbose=0 ;; @@ -80,18 +88,26 @@ PrintParams() { else echo "need build libevent lib" fi - if [ $need_build_jsoncpp -eq 0 ]; then echo "no need build jsoncpp lib" else echo "need build jsoncpp lib" fi - if [ $need_build_boost -eq 0 ]; then echo "no need build boost lib" else echo "need build boost lib" fi + if [ $enable_asan -eq 1 ]; then + echo "enable asan reporting" + else + echo "disable asan reporting" + fi + if [ $enable_lsan -eq 1 ]; then + echo "enable lsan reporting" + else + echo "disable lsan reporting" + fi if [ $test -eq 1 ]; then echo "build unit tests" else @@ -289,15 +305,27 @@ BuildBoost() { BuildRocketMQClient() { cd ${build_dir} echo "============start to build rocketmq client cpp.=========" - if [ $test -eq 0 ]; then - cmake .. - else + local ROCKETMQ_CMAKE_FLAG="" + if [ $test -eq 1 ]; then if [ $codecov -eq 1 ]; then - cmake .. -DRUN_UNIT_TEST=ON -DCODE_COVERAGE=ON + ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DRUN_UNIT_TEST=ON -DCODE_COVERAGE=ON" else - cmake .. -DRUN_UNIT_TEST=ON + ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DRUN_UNIT_TEST=ON -DCODE_COVERAGE=OFF" fi + else + ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DRUN_UNIT_TEST=OFF -DCODE_COVERAGE=OFF" fi + if [ $enable_asan -eq 1 ]; then + ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DENABLE_ASAN=ON" + else + ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DENABLE_ASAN=OFF" + fi + if [ $enable_lsan -eq 1 ]; then + ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DENABLE_LSAN=ON" + else + ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DENABLE_LSAN=OFF" + fi + cmake .. $ROCKETMQ_CMAKE_FLAG if [ $verbose -eq 0 ]; then echo "build rocketmq without detail log." make -j $cpu_num >buildclient.txt 2>&1 @@ -317,12 +345,10 @@ BuildGoogleTest() { echo "no need build google test lib" return 0 fi - if [ -f ./bin/lib/libgtest.a ]; then echo "libgteest already exist no need build test" return 0 fi - cd ${down_dir} if [ -e release-1.8.1.tar.gz ]; then echo "${fname_boost} is exist" @@ -333,7 +359,7 @@ BuildGoogleTest() { tar -zxvf release-1.8.1.tar.gz >googletest.txt 2>&1 fi cd googletest-release-1.8.1 - mkdir build + mkdir -p build cd build echo "build googletest static #####################" if [ $verbose -eq 0 ]; then From b1530391b3e760c5b2ffe70b77a0236acf812f08 Mon Sep 17 00:00:00 2001 From: "yizhe.wcm" Date: Sun, 23 Feb 2020 20:07:09 +0800 Subject: [PATCH 2/2] Simplify redirection semantics for easy understanding. --- build.sh | 24 ++++++++++++------------ distribution/deploy.sh | 2 +- format.sh | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/build.sh b/build.sh index 1d0034499..25015ed17 100755 --- a/build.sh +++ b/build.sh @@ -181,7 +181,7 @@ BuildLibevent() { else wget https://github.com/libevent/libevent/archive/${fname_libevent_down} -O libevent-${fname_libevent_down} fi - unzip -o ${fname_libevent} >unziplibevent.txt 2>&1 + unzip -o ${fname_libevent} &> unziplibevent.txt if [ $? -ne 0 ]; then exit 1 fi @@ -197,7 +197,7 @@ BuildLibevent() { fi echo "build libevent static #####################" if [ $verbose -eq 0 ]; then - ./configure --disable-openssl --enable-static=yes --enable-shared=no CFLAGS=-fPIC CPPFLAGS=-fPIC --prefix=${install_lib_dir} >libeventconfig.txt 2>&1 + ./configure --disable-openssl --enable-static=yes --enable-shared=no CFLAGS=-fPIC CPPFLAGS=-fPIC --prefix=${install_lib_dir} &> libeventconfig.txt else ./configure --disable-openssl --enable-static=yes --enable-shared=no CFLAGS=-fPIC CPPFLAGS=-fPIC --prefix=${install_lib_dir} fi @@ -206,7 +206,7 @@ BuildLibevent() { fi if [ $verbose -eq 0 ]; then echo "build libevent without detail log." - make -j $cpu_num >libeventbuild.txt 2>&1 + make -j $cpu_num &> libeventbuild.txt else make -j $cpu_num fi @@ -230,7 +230,7 @@ BuildJsonCPP() { else wget https://github.com/open-source-parsers/jsoncpp/archive/${fname_jsoncpp_down} -O jsoncpp-${fname_jsoncpp_down} fi - unzip -o ${fname_jsoncpp} >unzipjsoncpp.txt 2>&1 + unzip -o ${fname_jsoncpp} &> unzipjsoncpp.txt if [ $? -ne 0 ]; then exit 1 fi @@ -244,7 +244,7 @@ BuildJsonCPP() { echo "build jsoncpp static ######################" if [ $verbose -eq 0 ]; then echo "build jsoncpp without detail log." - cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir} >jsoncppbuild.txt 2>&1 + cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir} &> jsoncppbuild.txt else cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir} fi @@ -252,7 +252,7 @@ BuildJsonCPP() { exit 1 fi if [ $verbose -eq 0 ]; then - make -j $cpu_num >jsoncppbuild.txt 2>&1 + make -j $cpu_num &> jsoncppbuild.txt else make -j $cpu_num fi @@ -279,7 +279,7 @@ BuildBoost() { else wget http://sourceforge.net/projects/boost/files/boost/${fname_boost_down} fi - tar -zxvf ${fname_boost} >unzipboost.txt 2>&1 + tar -zxvf ${fname_boost} &> unzipboost.txt boost_dir=$(ls | grep ^boost | grep .*[^gz]$) cd ${boost_dir} if [ $? -ne 0 ]; then @@ -293,7 +293,7 @@ BuildBoost() { pwd if [ $verbose -eq 0 ]; then echo "build boost without detail log." - ./b2 -j$cpu_num cflags=-fPIC cxxflags=-fPIC --with-atomic --with-thread --with-system --with-chrono --with-date_time --with-log --with-regex --with-serialization --with-filesystem --with-locale --with-iostreams threading=multi link=static release install --prefix=${install_lib_dir} >boostbuild.txt 2>&1 + ./b2 -j$cpu_num cflags=-fPIC cxxflags=-fPIC --with-atomic --with-thread --with-system --with-chrono --with-date_time --with-log --with-regex --with-serialization --with-filesystem --with-locale --with-iostreams threading=multi link=static release install --prefix=${install_lib_dir} &> boostbuild.txt else ./b2 -j$cpu_num cflags=-fPIC cxxflags=-fPIC --with-atomic --with-thread --with-system --with-chrono --with-date_time --with-log --with-regex --with-serialization --with-filesystem --with-locale --with-iostreams threading=multi link=static release install --prefix=${install_lib_dir} fi @@ -328,7 +328,7 @@ BuildRocketMQClient() { cmake .. $ROCKETMQ_CMAKE_FLAG if [ $verbose -eq 0 ]; then echo "build rocketmq without detail log." - make -j $cpu_num >buildclient.txt 2>&1 + make -j $cpu_num &> buildclient.txt else make -j $cpu_num fi @@ -356,7 +356,7 @@ BuildGoogleTest() { wget https://github.com/abseil/googletest/archive/release-1.8.1.tar.gz fi if [ ! -d "googletest-release-1.8.1" ]; then - tar -zxvf release-1.8.1.tar.gz >googletest.txt 2>&1 + tar -zxvf release-1.8.1.tar.gz &> googletest.txt fi cd googletest-release-1.8.1 mkdir -p build @@ -364,7 +364,7 @@ BuildGoogleTest() { echo "build googletest static #####################" if [ $verbose -eq 0 ]; then echo "build googletest without detail log." - cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir} >googletestbuild.txt 2>&1 + cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir} &> googletestbuild.txt else cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir} fi @@ -372,7 +372,7 @@ BuildGoogleTest() { exit 1 fi if [ $verbose -eq 0 ]; then - make -j $cpu_num >gtestbuild.txt 2>&1 + make -j $cpu_num &> gtestbuild.txt else make -j $cpu_num fi diff --git a/distribution/deploy.sh b/distribution/deploy.sh index c213d9a14..d257c6d38 100755 --- a/distribution/deploy.sh +++ b/distribution/deploy.sh @@ -40,7 +40,7 @@ cp -rf ${CWD_DIR}/../README.md ${DEPLOY_BUILD_HOME}/ cp -rf ${CWD_DIR}/../LICENSE ${DEPLOY_BUILD_HOME}/LICENSE cp -rf ${CWD_DIR}/../NOTICE ${DEPLOY_BUILD_HOME}/NOTICE -cd ${CWD_DIR} && tar -cvzf ./${PKG_NAME}-${VERSION}-bin-release.tar.gz ./${PKG_NAME} >/dev/null 2>&1 +cd ${CWD_DIR} && tar -cvzf ./${PKG_NAME}-${VERSION}-bin-release.tar.gz ./${PKG_NAME} &> /dev/null rm -rf ${DEPLOY_BUILD_HOME} # # ##==================================================================== #make clean diff --git a/format.sh b/format.sh index f46c5f296..7aa812efe 100755 --- a/format.sh +++ b/format.sh @@ -26,7 +26,7 @@ function Usage } #Setp1 check clang-format support -if ! which clang-format &>/dev/null; then +if ! which clang-format &> /dev/null; then echo -e "\033[32m !!!!!!please install clang-format \033[0m" exit 1 fi