Skip to content

Commit

Permalink
Merge tag '2.2.7'
Browse files Browse the repository at this point in the history
2.2.7:
- report covergae on sonarcloud (#203)
- fixed some code smells (#128)
- fixed bugs: #129, #130, #31, #134, #135
  • Loading branch information
HerbertKoelman committed Oct 27, 2019
2 parents 000b3a3 + c16abd4 commit b4acf6c
Show file tree
Hide file tree
Showing 17 changed files with 227 additions and 67 deletions.
25 changes: 6 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ compiler: gcc
env:
CODECOV_TOKEN="6fa05a9c-1a01-4123-b726-d493275017cd"

# Travis CI uses shallow clone to speed up build times, but a truncated SCM history may cause issues
# when SonarCloud computes blame data.
git:
depth: false

# Run travis on these branches only...
branches:
only:
Expand All @@ -26,26 +31,8 @@ addons:
- doxygen
- graphviz

matrix:
include:
- name: coverage jobs
env:
BUILD_DIRECTORY=cmake-gcov-build
CMAKE_COMMAND_LINE_ARGS="-DGCOV=yes"
MAKE_TARGETS="all test"
- name: sonar code quality checks
env:
BUILD_DIRECTORY=cmake-sonar-build
CMAKE_COMMAND_LINE_ARGS="-DSONAR=yes"
MAKE_TARGETS="code-quality"
- name: default
env:
BUILD_DIRECTORY=cmake-default-build
CMAKE_COMMAND_LINE_ARGS="-DCMAKE_BUILD_TYPE=Release"
MAKE_TARGETS="all doxygen package"

script:
- mkdir $BUILD_DIRECTORY && cd $BUILD_DIRECTORY && cmake $CMAKE_COMMAND_LINE_ARGS .. && make $MAKE_TARGETS
- ./BUILD -S

after_success:
# create gcov files
Expand Down
76 changes: 76 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bash

# does actual build.
#
cmake_build(){

echo "cd cmake-build && cmake $cmake_args .. && make $make_args "
[ -d cmake-build ] && ( cd cmake-build && cmake $cmake_args .. && make $make_args )

}

# build command usage message
#
usage(){
echo "usage: `basename $0` [-G] [-S] [-T <build_type>]"
echo
echo "Build this module."
echo
echo "-S setup things to run SONAR"
echo "-G setup things to compile with coverage options and libs"
echo "-T build type (Release, Debug, ...)"
echo

exit 99
}

set_current_branch(){
if [ -z "$TRAVIS_BRANCH" ]
then
current_branch=`git rev-parse --abbrev-ref HEAD -- | head -1`
else
if [ -z "$TRAVIS_TAG" ]
then
[ -z "$TRAVIS_PULL_REQUEST_BRANCH" ] && current_branch=$TRAVIS_BRANCH || current_branch=$TRAVIS_PULL_REQUEST_BRANCH
else
current_branch="master"
fi
fi
}

set_current_branch

if [ "$current_branch" == "master" ]
then
cmake_build_type="-DCMAKE_BUILD_TYPE=Release"
else
cmake_build_type="-DCMAKE_BUILD_TYPE=Debug"
fi

make_args="all test"

while getopts "SGT:" option
do
case $option in
S) cmake_sonar_option="-DSONAR=yes" ; cmake_gcov_option="-DCOVERAGE=yes" ; make_args="code-quality";;
G) cmake_gcov_option="-DCOVERAGE=yes" ; make_args="$make_args coverage";;
T) cmake_build_type="-DCMAKE_BUILD_TYPE=$OPTARG" ;;
*) usage ;; # display usage and exit
esac
done

cmake_args="$cmake_build_type $cmake_gcov_option $cmake_sonar_option"

echo "##############################################################################"
echo "#"
[ ! -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#"
echo "# Project: cpp-pthread"
echo "# Build date: `date`"
echo "# Build directory: cmake-build"
echo "# Build options: $cmake_args"
echo "# GIT current branch: [$current_branch]"
echo "#"
echo "##############################################################################"

[ -d cmake-build ] && (rm -Rf cmake-build/* && cmake_build ) || ( mkdir cmake-build && cmake_build )

4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2.2.7:
- report covergae on sonarcloud (#203)
- fixed some code smells (#128)
- fixed bugs: #129, #130, #31, #134, #135
2.2.6
- Remove extern "C" (#127)
- Remove commented out code (#126)
Expand Down
37 changes: 20 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ cmake_minimum_required(VERSION 3.11)

project(
cpp-logger
VERSION 2.2.6
DESCRIPTION "Simple C++ logger (${GIT_LOG})")
VERSION 2.2.7
DESCRIPTION "Simple C++ logger")

option(GCOV "Activate GCOV options")

Expand All @@ -20,33 +20,35 @@ if ( GCOV )
endif()
endif()

#find_package(Git CONFIG)
#find_package(Conan)
find_package(GTestExt PATHS cmake)

# This part MUST be executed before the loading of the CMake package
set(SONAR_PROPERTIES_FILE ${CMAKE_CURRENT_BINARY_DIR}/sonar-project.properties)
message(STATUS "Generating SONAR properties file ${SONAR_PROPERTIES_FILE}")
configure_file(${CMAKE_CURRENT_LIST_DIR}/sonar-project.properties.in ${SONAR_PROPERTIES_FILE})

find_package(SonarCloud PATHS cmake)
find_package(Coverage PATHS cmake)
find_package(GTestExt PATHS cmake)

# Versionning infos -----------------------------------------
#
if( CMAKE_BUILD_TYPE MATCHES Release )
if( GIT_LOG )
add_definitions( -DCPP_LOGGER_VERSION="${PROJECT_VERSION} - ${GIT_LOG}")
set(CPP_LOGGER_VERSION "${PROJECT_VERSION} - ${GIT_LOG}")
else()
add_definitions( -DCPP_LOGGER_VERSION="${PROJECT_VERSION}")
set(CPP_LOGGER_VERSION "${PROJECT_VERSION}")
endif()
else()
if( GIT_LOG )
add_definitions( -DCPP_LOGGER_VERSION="${PROJECT_VERSION}-${GIT_LOG}-SNAPSHOT")
set(CPP_LOGGER_VERSION "${PROJECT_VERSION}-${GIT_LOG}-SNAPSHOT")
else()
add_definitions( -DCPP_LOGGER_VERSION="${PROJECT_VERSION}-SNAPSHOT")
set(CPP_LOGGER_VERSION "${PROJECT_VERSION}-SNAPSHOT")
endif()
endif()

message(STATUS "Building ${PROJECT_NAME} version ${CPP_LOGGER_VERSION}")
add_definitions( -DCPP_LOGGER_VERSION="${CPP_LOGGER_VERSION}")

# This part MUST be executed before the loading of the CMake package
set(SONAR_PROPERTIES_FILE ${CMAKE_CURRENT_BINARY_DIR}/sonar-project.properties)
message(STATUS "Generating SONAR properties file ${SONAR_PROPERTIES_FILE}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/sonar-project.properties.in ${SONAR_PROPERTIES_FILE})

find_package(SonarCloud PATHS cmake)

# targets --------------------------------------------------
#
# project's public headers
Expand Down Expand Up @@ -92,9 +94,10 @@ endif()
#
find_package(Doxygen REQUIRED dot OPTIONAL_COMPONENTS mscgen dia)
if (Doxygen_FOUND)
set(DOXYGEN_PROJECT_NUMBER ${CPP_LOGGER_VERSION})
set(DOXYGEN_EXAMPLE_PATH tests)
set(DOXYGEN_EXTRACT_ALL yes)
set(DOXYGEN_PROJECT_BRIEF ${PROJECT_DESCRUPTION})
set(DOXYGEN_PROJECT_BRIEF ${PROJECT_DESCRIPTION})
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "${CMAKE_SOURCE_DIR}/README.md")
doxygen_add_docs(doxygen README.md src include COMMENT "generate on-line documentation")
endif()
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## cpp-logger

[![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)
[![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)
[![codecov](https://codecov.io/gh/HerbertKoelman/cpp-logger/branch/master/graph/badge.svg)](https://codecov.io/gh/HerbertKoelman/cpp-logger)

### What it does

Expand Down
2 changes: 1 addition & 1 deletion cmake/CMakeLists.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ project(googletest-download VERSION 1.8.1)
include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.8.1
GIT_TAG v1.10.x
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
Expand Down
33 changes: 33 additions & 0 deletions cmake/CoverageConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
option(COVERAGE "Activate coverage")

if (COVERAGE)

# Handle coverage with GNU compilers
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
message(STATUS "Detecting LCOV")
find_program(LCOV lcov)
if ( LCOV )

message(STATUS "Detecting LCOV [${LCOV}] - done")
add_custom_target( coverage
COMMAND ${CMAKE_CURRENT_LIST_DIR}/LCOV
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Coverage report (${CMAKE_CURRENT_LIST_DIR}/LCOV)"
VERBATIM
)
message(STATUS "Added custom build target [coverage]...")

endif()

message(STATUS "Setting GCOV --coverage compiler option")
add_compile_options(--coverage)
if (CMAKE_VERSION VERSION_GREATER "3.13.5")
message(STATUS "Setting GCOV --coverage linker option")
add_link_options(--coverage)
else ()
message(STATUS "Setting GCOV --coverage option in linker related variables CMAKE_EXE_LINKER_FLAGS and CMAKE_SHARED_LINKER_FLAGS")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
endif ()
endif ()
endif ()
19 changes: 19 additions & 0 deletions cmake/FGCOV
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env sh

# author: herbert koelman
#
# This shell script makes sure to handle only files that have produced coverage data. It comes with the
# SonarConfig.cmake module
#

for source_gcda_file in $(find ./ -type f -name "*.gcda")
do
source_file=`basename $source_gcda_file .gcda`
source_dir=`dirname $source_gcda_file`
source_gcno_file=$source_dir/$source_file.gcno

echo "Handling file [$source_gcno_file]------------------------"
[ -f $source_gcno_file ] && gcov -m $source_gcno_file
echo "Done -----------------------------------------------------"
echo
done
10 changes: 4 additions & 6 deletions cmake/GTestExtConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ if (BUILD_TESTS)
# Add googletest directly to our build. This adds
# the following targets: gtest, gtest_main, gmock
# and gmock_main
add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src"
"${CMAKE_BINARY_DIR}/googletest-build")
add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src" "${CMAKE_BINARY_DIR}/googletest-build")

# The gtest/gmock targets carry header search path
# dependencies automatically when using CMake 2.8.11 or
# later. Otherwise we have to add them here ourselves.
if(CMAKE_VERSION VERSION_LESS 2.8.11)
message(STATUS "GoogleTest include directory ${gtest_SOURCE_DIR}/include ${gmock_SOURCE_DIR}/include)")
include_directories("${gtest_SOURCE_DIR}/include"
"${gmock_SOURCE_DIR}/include")
message(STATUS "GoogleTest include directory ${gtest_SOURCE_DIR}/include ${gmock_SOURCE_DIR}/include)")
include_directories("${gtest_SOURCE_DIR}/include" "${gmock_SOURCE_DIR}/include")
endif()

add_library(GTest::GTest ALIAS gtest)
Expand All @@ -53,4 +51,4 @@ if (BUILD_TESTS)
endif()
else()
message(STATUS "Disabled unit testing (BUILD_TESTS is ${BUILD_TESTS})")
endif()
endif()
23 changes: 23 additions & 0 deletions cmake/LCOV
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#8/usr/bin/env bash

initialize_coverage_file=""

for directory in $(find ./ -type f -name "*.gcda" -exec dirname {} \; | sort -u)
do
echo "Handling directory [$directory]"

if [ "${initialize_coverage_file}" == "" ]
then
echo "Initializing [coverage.info] file"
lcov --quiet --directory $directory --capture --output-file coverage.info
initialize_coverage_file="`date`"
else
coverage_info=$(mktemp --suffix=.coverage)
lcov --quiet --directory $directory --capture --output-file $coverage_info
echo "Adding tracefile [$coverage_info] to [coverage.info]"
lcov --quiet --add-tracefile $coverage_info --add-tracefile coverage.info --output-file coverage.info
fi
done
lcov --quiet --remove coverage.info '/usr/*' --output-file coverage.info
lcov --quiet --remove coverage.info '*/googletest/*' --output-file coverage.info
lcov --list coverage.info
20 changes: 18 additions & 2 deletions cmake/SonarCloudConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,30 @@ if ( SONAR )
find_program(SONAR_BUILD_WRAPPER build-wrapper-linux-x86-64)
if ( SONAR_BUILD_WRAPPER )
add_custom_target( build-wrapper
COMMAND ${SONAR_BUILD_WRAPPER} --out-dir ${SONAR_WRAPPER_OUTPUT_DIR} make clean all
COMMAND ${SONAR_BUILD_WRAPPER} --out-dir ${SONAR_WRAPPER_OUTPUT_DIR} make clean all test
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "run SONAR's ${SONAR_BUILD_WRAPPER}"
)
message(STATUS "Added custom target [build-wrapper]...")
add_dependencies(code-quality build-wrapper)
endif()

find_program(SONAR_GCOV gcov)
if(SONAR_GCOV)
add_custom_target( sonar-gcov-report
# COMMAND find ./CMakeFiles/ -type f -name "*.gcno" -exec ${SONAR_GCOV} {} -m \; > /dev/null 2>&1
COMMAND ${CMAKE_CURRENT_LIST_DIR}/FGCOV
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
# COMMENT "Built sonar GCOV report (${SONAR_GCOV})"
COMMENT "Built sonar GCOV report (${CMAKE_CURRENT_LIST_DIR}/FGCOV)"
VERBATIM
)
message(STATUS "Added custom target [sonar-gcov-report]...")

add_dependencies(sonar-gcov-report build-wrapper )
add_dependencies(code-quality sonar-gcov-report)
else()
add_dependencies(code-quality build-wrapper)
endif()

else()
message(SEND_ERROR "Failed to find the program [sonar_scanner], make sure sonar tools are installed.")
Expand Down
3 changes: 1 addition & 2 deletions include/logger/definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ namespace logger {
constexpr short MAXECIDLEN = 64;//!< execution ID maximum size/length
constexpr char const *LOGGER_LOG_PATTERN = "<%d>1 %s %s %s.%d.%d - %-16s";

const long HOST_NAME_MAX = sysconf(_SC_HOST_NAME_MAX); //!< hostname max size/length
//if (host_name_max <= 0) host_name_max = _POSIX_HOST_NAME_MAX;
const long HOST_NAME_MAX = sysconf(_SC_HOST_NAME_MAX); //!< hostname max size/length

class logger;

Expand Down
Loading

0 comments on commit b4acf6c

Please sign in to comment.