From 64ecc531db5c79fe9bbd873fa256eb940024d100 Mon Sep 17 00:00:00 2001 From: Jeroen Koekkoek Date: Fri, 28 Jan 2022 10:15:07 +0100 Subject: [PATCH 1/2] Replace Codecov by Azure Pipelines Code Coverage Signed-off-by: Jeroen Koekkoek --- .azure/codecov.yml | 79 ---------------- .azure/templates/build-test.yml | 18 ++++ CMakeLists.txt | 1 - README.md | 2 +- azure-pipelines.yml | 1 + cmake/Modules/Codecov.cmake | 45 ---------- cmake/Modules/Codecov/codecov.cmake | 135 ---------------------------- 7 files changed, 20 insertions(+), 261 deletions(-) delete mode 100644 .azure/codecov.yml delete mode 100644 cmake/Modules/Codecov.cmake delete mode 100644 cmake/Modules/Codecov/codecov.cmake diff --git a/.azure/codecov.yml b/.azure/codecov.yml deleted file mode 100644 index 0d8fc50e..00000000 --- a/.azure/codecov.yml +++ /dev/null @@ -1,79 +0,0 @@ -# -# Copyright(c) 2021 ADLINK Technology Limited and others -# -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License v. 2.0 which is available at -# http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License -# v. 1.0 which is available at -# http://www.eclipse.org/org/documents/edl-v10.php. -# -# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause -# - -# -# Azure Pipeline specifically for building and submitting to Codecov -# - -trigger: none -pr: none - -schedules: - - cron: "0 12 * * 0" - branches: - include: [ master ] - always: false - -strategy: - matrix: - 'Ubuntu 20.04 LTS with GCC 10 (Debug, x86_64)': - image: ubuntu-20.04 - cc: gcc-10 - cxx: g++-10 - coverage: on - -pool: - vmImage: $(image) - -steps: - - template: /.azure/templates/build-test.yml - - bash: | - set -e -x - cd build - slug=$(echo "${BUILD_REPOSITORY_URI}" | sed -nE 's#.*/([^/]+/[^\]+)#\1#p') - commit="${BUILD_SOURCEVERSION}" - if [ -n "$pr" ] && [ "$pr" != false ]; then - mc=$(git show --no-patch --format="%P" 2>/dev/null || echo "") - if [[ "$mc" =~ ^[a-z0-9]{40}[[:space:]][a-z0-9]{40}$ ]]; then - mc=$(echo "$mc" | cut -d ' ' -f2) - commit=$mc - fi - fi - query=$(curl -Gso /dev/null -w "%{url_effective}" "" \ - --data-urlencode "package=cmake-codecov.io" \ - --data-urlencode "token=${token}" \ - --data-urlencode "branch=${BUILD_SOURCEBRANCH#/refs/heads/}" \ - --data-urlencode "commit=${commit}" \ - --data-urlencode "build=${BUILD_BUILDNUMBER}" \ - --data-urlencode "build_url=${SYSTEM_TEAMFOUNDATIONSERVERURI}${SYSTEM_TEAMPROJECT}/_build/results?buildId=${BUILD_BUILDID}" \ - --data-urlencode "tag=" \ - --data-urlencode "slug=${slug}" \ - --data-urlencode "service=azure_pipelines" \ - --data-urlencode "flags=" \ - --data-urlencode "pr=${SYSTEM_PULLREQUEST_PULLREQUESTNUMBER:-$SYSTEM_PULLREQUEST_PULLREQUESTID}" \ - --data-urlencode "job=${BUILD_BUILDID}" \ - --data-urlencode "project=${SYSTEM_TEAMPROJECT}" \ - --data-urlencode "server_uri=${SYSTEM_TEAMFOUNDATIONSERVERURI}" \ - 2>/dev/null | cut -c 3- | sed -e 's/%0A//') - cmake --build . --target codecov - code=$(curl -X POST -w "%{http_code}" \ - --data-binary @"codecov.tar.gz" \ - --retry 5 --retry-delay 2 --connect-timeout 2 \ - -H 'Content-Type: text/plain' \ - -H 'Content-Encoding: gzip' \ - -H 'X-Content-Encoding: gzip' \ - -H 'Accept: text/plain' \ - "https://codecov.io/upload/v2?$query") - [[ "${code}" =~ "success" ]] || (echo "cURL exited with ${code}" 1>&2 && exit 1) - name: submit_to_codecov - env: - token: $(CODECOV_TOKEN) diff --git a/.azure/templates/build-test.yml b/.azure/templates/build-test.yml index 9c2452c6..443c01d8 100644 --- a/.azure/templates/build-test.yml +++ b/.azure/templates/build-test.yml @@ -84,6 +84,11 @@ steps: conan profile update settings.compiler.libcxx=libstdc++11 default condition: eq(variables['Agent.OS'], 'Linux') name: update_conan_cxx_library + - bash: | + set -e -x + pip install gcovr --user --upgrade + condition: eq(variables['coverage'], 'on') + name: install_gcovr - bash: | set -e -x sudo apt-get install libacl1-dev libncurses5-dev pkg-config @@ -147,3 +152,16 @@ steps: -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ ${GENERATOR:+-G} "${GENERATOR}" "${INSTALLPREFIX}/share/CycloneDDS-CXX/examples/helloworld" name: test + - bash: | + set -e -x + cd build + cmake --build . --config ${BUILD_TYPE} --target gcov -- ${BUILD_TOOL_OPTIONS} + gcovr --exclude '.*/tests/.*' --root "${BUILD_SOURCESDIRECTORY}" --xml-pretty --output coverage.xml . + condition: eq(variables['coverage'], 'on') + name: generate_code_coverage + - task: PublishCodeCoverageResults@1 + inputs: + codeCoverageTool: 'Cobertura' + summaryFileLocation: $(Build.SourcesDirectory)/build/coverage.xml + condition: eq(variables['coverage'], 'on') + name: publish_code_coverage diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a738e7e..69411928 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -180,7 +180,6 @@ if(SANITIZER) endif() find_package(codecov) -include(Codecov) # Build all executables and libraries into the top-level /bin and /lib folders. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") diff --git a/README.md b/README.md index da9c889a..f35f975f 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ tier-1 middleware for the Robot Operating System [ROS 2][6]. [![Build Status](https://dev.azure.com/eclipse-cyclonedds/cyclonedds-cxx/_apis/build/status/Pull%20requests?branchName=master)](https://dev.azure.com/eclipse-cyclonedds/cyclonedds-cxx/_build/latest?definitionId=4&branchName=master) [![Coverity Status](https://scan.coverity.com/projects/21579/badge.svg)](https://scan.coverity.com/projects/eclipse-cyclonedds-cyclonedds-cxx) -[![Codecov](https://codecov.io/gh/eclipse-cyclonedds/cyclonedds-cxx/branch/master/graphs/badge.svg?branch=master)](https://codecov.io/github/eclipse-cyclonedds/cyclonedds-cxx?branch=master) +[![Coverage](https://img.shields.io/azure-devops/coverage/eclipse-cyclonedds/cyclonedds-cxx/9/master)](https://dev.azure.com/eclipse-cyclonedds/cyclonedds-cxx/_build/latest?definitionId=9&branchName=master) [![License](https://img.shields.io/badge/License-EPL%202.0-blue)](https://choosealicense.com/licenses/epl-2.0/) [![License](https://img.shields.io/badge/License-EDL%201.0-blue)](https://choosealicense.com/licenses/edl-1.0/) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 60cac96e..278f539d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -29,6 +29,7 @@ strategy: cxx: g++-10 'Ubuntu 18.04 LTS with GCC 7 (Debug, x86_64)': image: ubuntu-18.04 + coverage: on conanfile: conanfile102.txt cc: gcc-7 gxx: g++-7 diff --git a/cmake/Modules/Codecov.cmake b/cmake/Modules/Codecov.cmake deleted file mode 100644 index 7ddce68a..00000000 --- a/cmake/Modules/Codecov.cmake +++ /dev/null @@ -1,45 +0,0 @@ -# -# Copyright(c) 2020 ADLINK Technology Limited and others -# -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License v. 2.0 which is available at -# http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License -# v. 1.0 which is available at -# http://www.eclipse.org/org/documents/edl-v10.php. -# -# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause -# - -# This module is meant to be used in conjuntion with CMake-codecov -# https://github.com/RWTH-HPC/CMake-codecov -# -# A codecov target is added if ENABLE_COVERAGE is on. -# Generate a codecov.io submission file with cmake --build . --target codecov. -# Submit the file to codecov.io by putting the proper commands in .travis.yml. -# See https://codecov.io/bash for details. - -if(ENABLE_COVERAGE) - if(NOT TARGET gcov) - add_custom_target(gcov) - endif() - if(NOT TARGET codecov) - set(CODECOV_FILE codecov.dump) - set(CODECOV_ARCHIVE codecov.tar.gz) - add_custom_target(codecov) - add_dependencies(codecov gcov) - add_custom_command( - TARGET codecov - POST_BUILD - BYPRODUCTS - "${CMAKE_BINARY_DIR}/${CODECOV_FILE}" - "${CMAKE_BINARY_DIR}/${CODECOV_ARCHIVE}" - COMMAND ${CMAKE_COMMAND} ARGS - -DPROJECT_ROOT="${CMAKE_SOURCE_DIR}" - -DCODECOV_FILE="${CODECOV_FILE}" - -P ${CMAKE_CURRENT_LIST_DIR}/Codecov/codecov.cmake - COMMAND ${CMAKE_COMMAND} ARGS - -E tar czf ${CODECOV_ARCHIVE} -- ${CODECOV_FILE} - COMMENT "Generating ${CODECOV_ARCHIVE}" - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) - endif() -endif() diff --git a/cmake/Modules/Codecov/codecov.cmake b/cmake/Modules/Codecov/codecov.cmake deleted file mode 100644 index 598630e6..00000000 --- a/cmake/Modules/Codecov/codecov.cmake +++ /dev/null @@ -1,135 +0,0 @@ -# -# Copyright(c) 2020 ADLINK Technology Limited and others -# -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License v. 2.0 which is available at -# http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License -# v. 1.0 which is available at -# http://www.eclipse.org/org/documents/edl-v10.php. -# -# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause -# - -# CMake script to produce a codecov.io submission file. -# Should be compatible with https://codecov.io/bash. - -if(NOT PROJECT_ROOT) - message(FATAL_ERROR "PROJECT_ROOT is not set") -endif() - -if(NOT CODECOV_FILE) - message(FATAL_ERROR "CODECOV_FILE is not set") -endif() - -function(read_adjustments ROOT SOURCEFILE ADJUSTMENTS) - file(READ "${SOURCEFILE}" _source) - # replace semicolons by colons - string(REPLACE ";" ":" _source "${_source}") - # replace newlines by semicolons - # space is inserted to ensure blank lines are picked up - string(REPLACE "\n" " ;" _source "${_source}") - - # include matching lines in adjustments - set(_line_number 0) - foreach(_line ${_source}) - math(EXPR _line_number "${_line_number} + 1") - # empty_line='^[[:space:]]*$' - if(_line MATCHES "^[ \t]*$") - list(APPEND _adjustments ${_line_number}) - # syntax_bracket='^[[:space:]]*[\{\}][[:space:]]*(//.*)?$' - elseif(_line MATCHES "^[ \t]*[{}][ \t]*(//.*)?") - list(APPEND _adjustments ${_line_number}) - # //LCOV_EXCL - elseif(_line MATCHES "// LCOV_EXCL") - list(APPEND _adjustments ${_line_number}) - endif() - endforeach() - - if(_adjustments) - string(REPLACE ";" "," _adjustments "${_adjustments}") - set(${ADJUSTMENTS} "${SOURCEFILE}:${_adjustments}\n" PARENT_SCOPE) - endif() -endfunction() - -function(read_and_reduce_gcov ROOT GCOVFILE SOURCEFILE GCOV) - file(READ "${GCOVFILE}" _gcov) - # grab first line - string(REGEX MATCH "^[^\n]*" _source "${_gcov}") - - # reduce gcov - # 1. remove source code - # 2. remove ending bracket lines - # 3. remove whitespace - string(REGEX REPLACE " *([^ \n:]*): *([^ \n:]*):?[^\n]*" "\\1:\\2:" _gcov "${_gcov}") - # 4. remove contextual lines - string(REGEX REPLACE "-+[^\n]*\n" "" _gcov "${_gcov}") - # 5. remove function names - - string(REPLACE "${ROOT}" "" _path "${GCOVFILE}") - string(REGEX REPLACE "^/+" "" _path "${_path}") - string(PREPEND _gcov "# path=${_path}.reduced\n${_source}\n") - string(APPEND _gcov "<<<<<< EOF\n") - - # capture source file - string(REGEX REPLACE "^.*:Source:(.*)$" "\\1" _source "${_source}") - - set(${SOURCEFILE} "${_source}" PARENT_SCOPE) - set(${GCOV} "${_gcov}" PARENT_SCOPE) -endfunction() - -set(project_dir "${PROJECT_ROOT}") -set(build_dir "${CMAKE_CURRENT_BINARY_DIR}") - -# Codecov supports .codecov.yml files to configure the service. The location -# of the first .codecov.yml found by the bash uploader is in included in the -# the list of files submitted to the service. -file(GLOB_RECURSE yaml_files RELATIVE "${PROJECT_ROOT}" "${PROJECT_ROOT}/*codecov.y*ml") -if(yaml_files) - list(GET yaml_files 0 yaml_file) -endif() - -set(network_block "${yaml_file}\n") -set(gcov_block "") -set(adjustments_block "") - -# Codecov uses "git ls-files" and falls back to find, but having no -# dependencies is preferred (for now). Globbing rules are very likely to -# produce the same result -file(GLOB_RECURSE source_files "${PROJECT_ROOT}/*.[hH]" - "${PROJECT_ROOT}/*.[Cc]" - "${PROJECT_ROOT}/*.[Hh][Pp][Pp]" - "${PROJECT_ROOT}/*.[Cc][Pp][Pp]" - "${PROJECT_ROOT}/*.[Cc][Xx][Xx]") - -file(GLOB_RECURSE gcov_files "${CMAKE_CURRENT_BINARY_DIR}/*.gcov") -foreach(gcov_file ${gcov_files}) - read_and_reduce_gcov("${PROJECT_ROOT}" "${gcov_file}" source_file gcov) - list(APPEND source_files "${source_file}") - string(APPEND gcov_block "${gcov}") -endforeach() - -list(REMOVE_DUPLICATES source_files) -foreach(source_file ${source_files}) - # ignore any files located in the build directory - string(FIND "${source_file}" "${build_dir}/" in_build_dir) - if(in_build_dir GREATER_EQUAL 0) - continue() - endif() - # ignore paths with /CMakeFiles/ - if(source_file MATCHES "/CMakeFiles/") - continue() - endif() - read_adjustments("${PROJECT_ROOT}" "${source_file}" adjustments) - string(APPEND adjustments_block "${adjustments}") - string(REPLACE "${PROJECT_ROOT}" "" source_file "${source_file}") - string(REGEX REPLACE "^/+" "" source_file "${source_file}") - string(APPEND network_block "${source_file}\n") -endforeach() - -string(PREPEND adjustments_block "# path=fixes\n") -string(APPEND adjustments_block "<<<<<< EOF") -string(APPEND network_block "<<<<<< network\n") - -file(WRITE ${CODECOV_FILE} "${network_block}") -file(APPEND ${CODECOV_FILE} "${gcov_block}") -file(APPEND ${CODECOV_FILE} "${adjustments_block}") From 80bb11890e69e2f0c72e6e0fc0f61f819ea204ca Mon Sep 17 00:00:00 2001 From: Jeroen Koekkoek Date: Fri, 28 Jan 2022 14:15:35 +0100 Subject: [PATCH 2/2] Publish tests results in Azure Pipelines Signed-off-by: Jeroen Koekkoek --- .azure/templates/build-test.yml | 9 +++++++++ azure-pipelines.yml | 1 + 2 files changed, 10 insertions(+) diff --git a/.azure/templates/build-test.yml b/.azure/templates/build-test.yml index 443c01d8..c0d760b2 100644 --- a/.azure/templates/build-test.yml +++ b/.azure/templates/build-test.yml @@ -165,3 +165,12 @@ steps: summaryFileLocation: $(Build.SourcesDirectory)/build/coverage.xml condition: eq(variables['coverage'], 'on') name: publish_code_coverage + - task: PublishTestResults@2 + inputs: + testRunner: CTest + testResultsFiles: '**/Test.xml' + searchFolder: $(System.DefaultWorkingDirectory)/build/Testing + platform: $(arch) + configuration: $(build_type) + condition: eq(variables['tests'], 'on') + name: publish_test_results diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 278f539d..d95e577c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -30,6 +30,7 @@ strategy: 'Ubuntu 18.04 LTS with GCC 7 (Debug, x86_64)': image: ubuntu-18.04 coverage: on + tests: on conanfile: conanfile102.txt cc: gcc-7 gxx: g++-7