Skip to content

Commit b4acf6c

Browse files
Merge tag '2.2.7'
2.2.7: - report covergae on sonarcloud (#203) - fixed some code smells (#128) - fixed bugs: #129, #130, #31, #134, #135
2 parents 000b3a3 + c16abd4 commit b4acf6c

17 files changed

+227
-67
lines changed

.travis.yml

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ compiler: gcc
1111
env:
1212
CODECOV_TOKEN="6fa05a9c-1a01-4123-b726-d493275017cd"
1313

14+
# Travis CI uses shallow clone to speed up build times, but a truncated SCM history may cause issues
15+
# when SonarCloud computes blame data.
16+
git:
17+
depth: false
18+
1419
# Run travis on these branches only...
1520
branches:
1621
only:
@@ -26,26 +31,8 @@ addons:
2631
- doxygen
2732
- graphviz
2833

29-
matrix:
30-
include:
31-
- name: coverage jobs
32-
env:
33-
BUILD_DIRECTORY=cmake-gcov-build
34-
CMAKE_COMMAND_LINE_ARGS="-DGCOV=yes"
35-
MAKE_TARGETS="all test"
36-
- name: sonar code quality checks
37-
env:
38-
BUILD_DIRECTORY=cmake-sonar-build
39-
CMAKE_COMMAND_LINE_ARGS="-DSONAR=yes"
40-
MAKE_TARGETS="code-quality"
41-
- name: default
42-
env:
43-
BUILD_DIRECTORY=cmake-default-build
44-
CMAKE_COMMAND_LINE_ARGS="-DCMAKE_BUILD_TYPE=Release"
45-
MAKE_TARGETS="all doxygen package"
46-
4734
script:
48-
- mkdir $BUILD_DIRECTORY && cd $BUILD_DIRECTORY && cmake $CMAKE_COMMAND_LINE_ARGS .. && make $MAKE_TARGETS
35+
- ./BUILD -S
4936

5037
after_success:
5138
# create gcov files

BUILD

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env bash
2+
3+
# does actual build.
4+
#
5+
cmake_build(){
6+
7+
echo "cd cmake-build && cmake $cmake_args .. && make $make_args "
8+
[ -d cmake-build ] && ( cd cmake-build && cmake $cmake_args .. && make $make_args )
9+
10+
}
11+
12+
# build command usage message
13+
#
14+
usage(){
15+
echo "usage: `basename $0` [-G] [-S] [-T <build_type>]"
16+
echo
17+
echo "Build this module."
18+
echo
19+
echo "-S setup things to run SONAR"
20+
echo "-G setup things to compile with coverage options and libs"
21+
echo "-T build type (Release, Debug, ...)"
22+
echo
23+
24+
exit 99
25+
}
26+
27+
set_current_branch(){
28+
if [ -z "$TRAVIS_BRANCH" ]
29+
then
30+
current_branch=`git rev-parse --abbrev-ref HEAD -- | head -1`
31+
else
32+
if [ -z "$TRAVIS_TAG" ]
33+
then
34+
[ -z "$TRAVIS_PULL_REQUEST_BRANCH" ] && current_branch=$TRAVIS_BRANCH || current_branch=$TRAVIS_PULL_REQUEST_BRANCH
35+
else
36+
current_branch="master"
37+
fi
38+
fi
39+
}
40+
41+
set_current_branch
42+
43+
if [ "$current_branch" == "master" ]
44+
then
45+
cmake_build_type="-DCMAKE_BUILD_TYPE=Release"
46+
else
47+
cmake_build_type="-DCMAKE_BUILD_TYPE=Debug"
48+
fi
49+
50+
make_args="all test"
51+
52+
while getopts "SGT:" option
53+
do
54+
case $option in
55+
S) cmake_sonar_option="-DSONAR=yes" ; cmake_gcov_option="-DCOVERAGE=yes" ; make_args="code-quality";;
56+
G) cmake_gcov_option="-DCOVERAGE=yes" ; make_args="$make_args coverage";;
57+
T) cmake_build_type="-DCMAKE_BUILD_TYPE=$OPTARG" ;;
58+
*) usage ;; # display usage and exit
59+
esac
60+
done
61+
62+
cmake_args="$cmake_build_type $cmake_gcov_option $cmake_sonar_option"
63+
64+
echo "##############################################################################"
65+
echo "#"
66+
[ ! -z "$TRAVIS_BRANCH" ] && echo -e "# Running on Travis (TRAVIS_BRANCH: $TRAVIS_BRANCH, TRAVIS_TAG: $TRAVIS_TAG, TRAVIS_PULL_REQUEST_BRANCH: $TRAVIS_PULL_REQUEST_BRANCH)\n#"
67+
echo "# Project: cpp-pthread"
68+
echo "# Build date: `date`"
69+
echo "# Build directory: cmake-build"
70+
echo "# Build options: $cmake_args"
71+
echo "# GIT current branch: [$current_branch]"
72+
echo "#"
73+
echo "##############################################################################"
74+
75+
[ -d cmake-build ] && (rm -Rf cmake-build/* && cmake_build ) || ( mkdir cmake-build && cmake_build )
76+

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2.2.7:
2+
- report covergae on sonarcloud (#203)
3+
- fixed some code smells (#128)
4+
- fixed bugs: #129, #130, #31, #134, #135
15
2.2.6
26
- Remove extern "C" (#127)
37
- Remove commented out code (#126)

CMakeLists.txt

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ cmake_minimum_required(VERSION 3.11)
66

77
project(
88
cpp-logger
9-
VERSION 2.2.6
10-
DESCRIPTION "Simple C++ logger (${GIT_LOG})")
9+
VERSION 2.2.7
10+
DESCRIPTION "Simple C++ logger")
1111

1212
option(GCOV "Activate GCOV options")
1313

@@ -20,33 +20,35 @@ if ( GCOV )
2020
endif()
2121
endif()
2222

23-
#find_package(Git CONFIG)
24-
#find_package(Conan)
25-
find_package(GTestExt PATHS cmake)
26-
27-
# This part MUST be executed before the loading of the CMake package
28-
set(SONAR_PROPERTIES_FILE ${CMAKE_CURRENT_BINARY_DIR}/sonar-project.properties)
29-
message(STATUS "Generating SONAR properties file ${SONAR_PROPERTIES_FILE}")
30-
configure_file(${CMAKE_CURRENT_LIST_DIR}/sonar-project.properties.in ${SONAR_PROPERTIES_FILE})
31-
32-
find_package(SonarCloud PATHS cmake)
23+
find_package(Coverage PATHS cmake)
24+
find_package(GTestExt PATHS cmake)
3325

3426
# Versionning infos -----------------------------------------
3527
#
3628
if( CMAKE_BUILD_TYPE MATCHES Release )
3729
if( GIT_LOG )
38-
add_definitions( -DCPP_LOGGER_VERSION="${PROJECT_VERSION} - ${GIT_LOG}")
30+
set(CPP_LOGGER_VERSION "${PROJECT_VERSION} - ${GIT_LOG}")
3931
else()
40-
add_definitions( -DCPP_LOGGER_VERSION="${PROJECT_VERSION}")
32+
set(CPP_LOGGER_VERSION "${PROJECT_VERSION}")
4133
endif()
4234
else()
4335
if( GIT_LOG )
44-
add_definitions( -DCPP_LOGGER_VERSION="${PROJECT_VERSION}-${GIT_LOG}-SNAPSHOT")
36+
set(CPP_LOGGER_VERSION "${PROJECT_VERSION}-${GIT_LOG}-SNAPSHOT")
4537
else()
46-
add_definitions( -DCPP_LOGGER_VERSION="${PROJECT_VERSION}-SNAPSHOT")
38+
set(CPP_LOGGER_VERSION "${PROJECT_VERSION}-SNAPSHOT")
4739
endif()
4840
endif()
4941

42+
message(STATUS "Building ${PROJECT_NAME} version ${CPP_LOGGER_VERSION}")
43+
add_definitions( -DCPP_LOGGER_VERSION="${CPP_LOGGER_VERSION}")
44+
45+
# This part MUST be executed before the loading of the CMake package
46+
set(SONAR_PROPERTIES_FILE ${CMAKE_CURRENT_BINARY_DIR}/sonar-project.properties)
47+
message(STATUS "Generating SONAR properties file ${SONAR_PROPERTIES_FILE}")
48+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/sonar-project.properties.in ${SONAR_PROPERTIES_FILE})
49+
50+
find_package(SonarCloud PATHS cmake)
51+
5052
# targets --------------------------------------------------
5153
#
5254
# project's public headers
@@ -92,9 +94,10 @@ endif()
9294
#
9395
find_package(Doxygen REQUIRED dot OPTIONAL_COMPONENTS mscgen dia)
9496
if (Doxygen_FOUND)
97+
set(DOXYGEN_PROJECT_NUMBER ${CPP_LOGGER_VERSION})
9598
set(DOXYGEN_EXAMPLE_PATH tests)
9699
set(DOXYGEN_EXTRACT_ALL yes)
97-
set(DOXYGEN_PROJECT_BRIEF ${PROJECT_DESCRUPTION})
100+
set(DOXYGEN_PROJECT_BRIEF ${PROJECT_DESCRIPTION})
98101
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "${CMAKE_SOURCE_DIR}/README.md")
99102
doxygen_add_docs(doxygen README.md src include COMMENT "generate on-line documentation")
100103
endif()

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## cpp-logger
22

3-
[![Build Status](https://travis-ci.com/HerbertKoelman/cpp-logger.svg?branch=master)](https://travis-ci.com/HerbertKoelman/cpp-logger) [![codecov](https://codecov.io/gh/HerbertKoelman/cpp-logger/branch/master/graph/badge.svg)](https://codecov.io/gh/HerbertKoelman/cpp-logger) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=HerbertKoelman_cpp-logger&metric=alert_status)](https://sonarcloud.io/dashboard?id=HerbertKoelman_cpp-logger)
3+
[![Build Status](https://travis-ci.com/HerbertKoelman/cpp-logger.svg?branch=master)](https://travis-ci.com/HerbertKoelman/cpp-logger) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=HerbertKoelman_cpp-logger&metric=alert_status)](https://sonarcloud.io/dashboard?id=HerbertKoelman_cpp-logger)
4+
[![codecov](https://codecov.io/gh/HerbertKoelman/cpp-logger/branch/master/graph/badge.svg)](https://codecov.io/gh/HerbertKoelman/cpp-logger)
45

56
### What it does
67

cmake/CMakeLists.txt.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ project(googletest-download VERSION 1.8.1)
88
include(ExternalProject)
99
ExternalProject_Add(googletest
1010
GIT_REPOSITORY https://github.com/google/googletest.git
11-
GIT_TAG release-1.8.1
11+
GIT_TAG v1.10.x
1212
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
1313
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
1414
CONFIGURE_COMMAND ""

cmake/CoverageConfig.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
option(COVERAGE "Activate coverage")
2+
3+
if (COVERAGE)
4+
5+
# Handle coverage with GNU compilers
6+
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
7+
message(STATUS "Detecting LCOV")
8+
find_program(LCOV lcov)
9+
if ( LCOV )
10+
11+
message(STATUS "Detecting LCOV [${LCOV}] - done")
12+
add_custom_target( coverage
13+
COMMAND ${CMAKE_CURRENT_LIST_DIR}/LCOV
14+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
15+
COMMENT "Coverage report (${CMAKE_CURRENT_LIST_DIR}/LCOV)"
16+
VERBATIM
17+
)
18+
message(STATUS "Added custom build target [coverage]...")
19+
20+
endif()
21+
22+
message(STATUS "Setting GCOV --coverage compiler option")
23+
add_compile_options(--coverage)
24+
if (CMAKE_VERSION VERSION_GREATER "3.13.5")
25+
message(STATUS "Setting GCOV --coverage linker option")
26+
add_link_options(--coverage)
27+
else ()
28+
message(STATUS "Setting GCOV --coverage option in linker related variables CMAKE_EXE_LINKER_FLAGS and CMAKE_SHARED_LINKER_FLAGS")
29+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
30+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
31+
endif ()
32+
endif ()
33+
endif ()

cmake/FGCOV

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env sh
2+
3+
# author: herbert koelman
4+
#
5+
# This shell script makes sure to handle only files that have produced coverage data. It comes with the
6+
# SonarConfig.cmake module
7+
#
8+
9+
for source_gcda_file in $(find ./ -type f -name "*.gcda")
10+
do
11+
source_file=`basename $source_gcda_file .gcda`
12+
source_dir=`dirname $source_gcda_file`
13+
source_gcno_file=$source_dir/$source_file.gcno
14+
15+
echo "Handling file [$source_gcno_file]------------------------"
16+
[ -f $source_gcno_file ] && gcov -m $source_gcno_file
17+
echo "Done -----------------------------------------------------"
18+
echo
19+
done

cmake/GTestExtConfig.cmake

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@ if (BUILD_TESTS)
2828
# Add googletest directly to our build. This adds
2929
# the following targets: gtest, gtest_main, gmock
3030
# and gmock_main
31-
add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src"
32-
"${CMAKE_BINARY_DIR}/googletest-build")
31+
add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src" "${CMAKE_BINARY_DIR}/googletest-build")
3332

3433
# The gtest/gmock targets carry header search path
3534
# dependencies automatically when using CMake 2.8.11 or
3635
# later. Otherwise we have to add them here ourselves.
3736
if(CMAKE_VERSION VERSION_LESS 2.8.11)
38-
message(STATUS "GoogleTest include directory ${gtest_SOURCE_DIR}/include ${gmock_SOURCE_DIR}/include)")
39-
include_directories("${gtest_SOURCE_DIR}/include"
40-
"${gmock_SOURCE_DIR}/include")
37+
message(STATUS "GoogleTest include directory ${gtest_SOURCE_DIR}/include ${gmock_SOURCE_DIR}/include)")
38+
include_directories("${gtest_SOURCE_DIR}/include" "${gmock_SOURCE_DIR}/include")
4139
endif()
4240

4341
add_library(GTest::GTest ALIAS gtest)
@@ -53,4 +51,4 @@ if (BUILD_TESTS)
5351
endif()
5452
else()
5553
message(STATUS "Disabled unit testing (BUILD_TESTS is ${BUILD_TESTS})")
56-
endif()
54+
endif()

cmake/LCOV

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#8/usr/bin/env bash
2+
3+
initialize_coverage_file=""
4+
5+
for directory in $(find ./ -type f -name "*.gcda" -exec dirname {} \; | sort -u)
6+
do
7+
echo "Handling directory [$directory]"
8+
9+
if [ "${initialize_coverage_file}" == "" ]
10+
then
11+
echo "Initializing [coverage.info] file"
12+
lcov --quiet --directory $directory --capture --output-file coverage.info
13+
initialize_coverage_file="`date`"
14+
else
15+
coverage_info=$(mktemp --suffix=.coverage)
16+
lcov --quiet --directory $directory --capture --output-file $coverage_info
17+
echo "Adding tracefile [$coverage_info] to [coverage.info]"
18+
lcov --quiet --add-tracefile $coverage_info --add-tracefile coverage.info --output-file coverage.info
19+
fi
20+
done
21+
lcov --quiet --remove coverage.info '/usr/*' --output-file coverage.info
22+
lcov --quiet --remove coverage.info '*/googletest/*' --output-file coverage.info
23+
lcov --list coverage.info

0 commit comments

Comments
 (0)