Skip to content

Commit

Permalink
Merge pull request #2226 from bitshares/fix-sonar-coverage
Browse files Browse the repository at this point in the history
Fix sonar-scanner test coverage and warnings
  • Loading branch information
abitmore authored Jul 4, 2020
2 parents 4f5d6fd + a7cf23f commit 4bc70a4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion programs/build_helpers/scan_with_sonar_step_1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ programs/build_helpers/buildstep -s 3500
ccache -s
programs/build_helpers/buildstep Prepare 1 "sed -i '/tests/d' libraries/fc/CMakeLists.txt"
programs/build_helpers/buildstep cmake 5 "cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS=--coverage -DCMAKE_CXX_FLAGS=--coverage -DBoost_USE_STATIC_LIBS=OFF -DCMAKE_CXX_OUTPUT_EXTENSION_REPLACE=ON ."
programs/build_helpers/buildstep make.programs 1800 "programs/build_helpers/make_with_sonar bw-output -j 2 witness_node cli_wallet js_operation_serializer get_dev_key network_mapper"
programs/build_helpers/buildstep make.programs 1800 "programs/build_helpers/make_with_sonar bw-output -j 2 witness_node cli_wallet js_operation_serializer get_dev_key network_mapper app_test chain_test cli_test"
set -o pipefail
programs/build_helpers/buildstep prepare.sonar 20 "find libraries/[acdenptuw]*/CMakeFiles/*.dir programs/[cdgjsw]*/CMakeFiles/*.dir -type d -print | while read d; do gcov -o \"\$d\" \"\${d/CMakeFiles*.dir//}\"/*.cpp; done >/dev/null; programs/build_helpers/set_sonar_branch sonar-project.properties"
du -hs sonar_cache
Expand Down
2 changes: 1 addition & 1 deletion programs/build_helpers/scan_with_sonar_step_2
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ programs/build_helpers/buildstep -s 3500
ccache -s
programs/build_helpers/buildstep Prepare 1 "sed -i '/tests/d' libraries/fc/CMakeLists.txt"
programs/build_helpers/buildstep cmake 5 "cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS=--coverage -DCMAKE_CXX_FLAGS=--coverage -DBoost_USE_STATIC_LIBS=OFF -DCMAKE_CXX_OUTPUT_EXTENSION_REPLACE=ON ."
programs/build_helpers/buildstep make.programs 1800 "programs/build_helpers/make_with_sonar bw-output -j 2 witness_node cli_wallet js_operation_serializer get_dev_key network_mapper"
programs/build_helpers/buildstep make.programs 1800 "programs/build_helpers/make_with_sonar bw-output -j 2 witness_node cli_wallet js_operation_serializer get_dev_key network_mapper app_test chain_test cli_test"
set -o pipefail
programs/build_helpers/buildstep prepare.sonar 20 "find libraries/[acdenptuw]*/CMakeFiles/*.dir programs/[cdgjsw]*/CMakeFiles/*.dir -type d -print | while read d; do gcov -o \"\$d\" \"\${d/CMakeFiles*.dir//}\"/*.cpp; done >/dev/null; programs/build_helpers/set_sonar_branch sonar-project.properties"
du -hs sonar_cache
Expand Down
7 changes: 5 additions & 2 deletions programs/build_helpers/scan_with_sonar_step_3
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ programs/build_helpers/buildstep -s 3500
ccache -s
programs/build_helpers/buildstep Prepare 1 "sed -i '/tests/d' libraries/fc/CMakeLists.txt"
programs/build_helpers/buildstep cmake 5 "cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS=--coverage -DCMAKE_CXX_FLAGS=--coverage -DBoost_USE_STATIC_LIBS=OFF -DCMAKE_CXX_OUTPUT_EXTENSION_REPLACE=ON ."
programs/build_helpers/buildstep make.programs 1800 "programs/build_helpers/make_with_sonar bw-output -j 2 witness_node cli_wallet js_operation_serializer get_dev_key network_mapper"
programs/build_helpers/buildstep make.programs 1800 "programs/build_helpers/make_with_sonar bw-output -j 2 witness_node cli_wallet js_operation_serializer get_dev_key network_mapper app_test chain_test cli_test"
set -o pipefail
programs/build_helpers/buildstep run.chain_test 600 "libraries/fc/tests/run-parallel-tests.sh tests/chain_test"
programs/build_helpers/buildstep run.cli_test 180 "libraries/fc/tests/run-parallel-tests.sh tests/cli_test"
programs/build_helpers/buildstep run.app_test 180 "tests/app_test"
programs/build_helpers/buildstep prepare.sonar 20 "find libraries/[acdenptuw]*/CMakeFiles/*.dir programs/[cdgjsw]*/CMakeFiles/*.dir -type d -print | while read d; do gcov -o \"\$d\" \"\${d/CMakeFiles*.dir//}\"/*.cpp; done >/dev/null; programs/build_helpers/set_sonar_branch sonar-project.properties"
du -hs sonar_cache
# The first pass is skipped here
Expand All @@ -15,7 +18,7 @@ programs/build_helpers/buildstep prepare.sonar.part2 1 "cp sonar-project.propert
programs/build_helpers/buildstep run.sonar.part2 1500 "which sonar-scanner && sonar-scanner"
programs/build_helpers/buildstep prepare.sonar.full 1 "cp sonar-project.properties.bak sonar-project.properties"
du -hs sonar_cache
# The second pass, scan all files
# The third pass, scan all files
programs/build_helpers/buildstep run.sonar.full 1500 "which sonar-scanner && sonar-scanner"
du -hs sonar_cache
programs/build_helpers/buildstep end 0
Expand Down
26 changes: 10 additions & 16 deletions programs/build_helpers/set_sonar_branch
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,18 @@ ORIGINAL_TARGET="$( grep 'sonar\.branch\.target' "$1" | sed 's=^.*[:=] *==' )"

BRANCH=
TARGET="$ORIGINAL_TARGET"
FETCH=

if [ -n "$TRAVIS_PULL_REQUEST" -a "$TRAVIS_PULL_REQUEST" != false ]; then
if [ -n "$TRAVIS_PULL_REQUEST" -a "$TRAVIS_PULL_REQUEST" != "false" ]; then
# PRs work per default, remove sonar.branch.* since they only work with sonar.pullrequest.*
echo "Detected PR '$TRAVIS_PULL_REQUEST'"
TARGET=
FETCH="$TRAVIS_BRANCH"
elif [ -n "$TRAVIS_TAG" ]; then
# Tag build is either master or testnet
echo "Detected tag '$TRAVIS_TAG'"
BRANCH="$TRAVIS_BRANCH"
case "$TRAVIS_TAG" in
*test*) TARGET=testnet; FETCH=testnet; ;;
*) TARGET=master; FETCH=master; ;;
*test*) TARGET=testnet; ;;
*) TARGET=master; ;;
esac
else
BRANCH="$TRAVIS_BRANCH"
Expand All @@ -48,29 +46,31 @@ else
# Long-lived branches stand for themselves, no target
echo "Detected long-lived branch '$TRAVIS_BRANCH'"
TARGET=
FETCH="$TRAVIS_BRANCH"
;;
*test*release*)
# Testnet release branch will be merged into testnet
echo "Detected testnet release branch '$TRAVIS_BRANCH'"
TARGET=testnet
FETCH=testnet
;;
*release*)
# Release branch will be merged into default (master)
echo "Detected release branch '$TRAVIS_BRANCH'"
TARGET=master
FETCH=master
;;
*)
# All other branches should have sonar.branch.target in their
# sonar.properties, leave it unchanged
echo "Detected normal branch '$TRAVIS_BRANCH'"
FETCH="$TARGET"
esac
fi

echo "Branch '$BRANCH', target '$TARGET', fetch target '$FETCH'"
echo "Branch '$BRANCH', target '$TARGET'"

git fetch --no-tags --unshallow
git fetch --no-tags origin +refs/heads/$TRAVIS_BRANCH:refs/remotes/origin/$TRAVIS_BRANCH
if [ -n "$TARGET" ]; then
git fetch --no-tags origin +refs/heads/$TARGET:refs/remotes/origin/$TARGET
fi

if [ "x$TARGET" != "x$ORIGINAL_TARGET" ]; then
clear_branch "$1"
Expand All @@ -81,11 +81,5 @@ fi
if [ -n "$BRANCH" ]; then
echo "sonar.branch.name=$BRANCH" >>"$1"
fi
#if [ -n "$FETCH" ]; then
# Unfortunately this leads to sonar failing. Apparently it needs a full
# clone, not a shallow one. Since our repo is somewhat large and this is
# only required for blame annotations, disabled for now.
#git fetch --depth=50 origin "$FETCH:$FETCH"
#fi

exit 0

0 comments on commit 4bc70a4

Please sign in to comment.