Skip to content

Commit

Permalink
馃殾 Add coverage workflow
Browse files Browse the repository at this point in the history
This adds a Github workflow for adding coveralls code coverage support.

In order for this change to be effective, the GCC/clang attribute for
preventing instrumentation has been removed when performing coverage
builds.
  • Loading branch information
bitwizeshift committed Jan 31, 2021
1 parent 2d2b492 commit 35340ad
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 10 deletions.
106 changes: 106 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: "Code Coverage"

on:
push:
paths:
- 'include/**.hpp'
- 'test/**.cpp'
- '**.cmake'
- 'conanfile.py'
- 'CMakeLists.txt'
- 'test/CMakeLists.txt'
- '.github/workflows/coverage.yml'
pull_request:
paths:
- 'include/**.hpp'
- 'test/**.cpp'
- '**.cmake'
- 'conanfile.py'
- 'CMakeLists.txt'
- 'test/CMakeLists.txt'
- '.github/workflows/coverage.yml'

jobs:
coverage:
name: Ubuntu ${{matrix.compiler.cc}} Coverage
runs-on: ubuntu-20.04

env:
build-directory: build

strategy:
matrix:
compiler:
- { cc: gcc, cxx: g++, version: "10" }
- { cc: clang, cxx: clang++, version: "10" }

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.7

- name: Prepare Environment
run: |
sudo apt-get install -y ${{matrix.compiler.cxx}}-${{matrix.compiler.version}}
if [["${{matrix.compiler.cc}}" = "clang"]]; then
sudo apt-get install -y llvm-${{matrix.compiler.version}}
fi
sudo apt-get install lcov
python -m pip install --upgrade pip
pip install conan
cmake -E make_directory ${{env.build-directory}}
cmake -E chdir ${{env.build-directory}} conan install ..
- name: Configure
working-directory: ${{env.build-directory}}
env:
CC: ${{matrix.compiler.cc}}-${{matrix.compiler.version}}
CXX: ${{matrix.compiler.cxx}}-${{matrix.compiler.version}}
run: |
cmake .. -DCMAKE_BUILD_TYPE=Debug \
-DBACKPORT_COMPILE_UNIT_TESTS=On \
-DCMAKE_CXX_FLAGS="--coverage -DBPSTD_INLINE_VISIBILITY=" \
- name: Build
working-directory: ${{env.build-directory}}
run: cmake --build .

- name: Test
working-directory: ${{env.build-directory}}
run: ctest --output-on-failure

- name: Process Coverage Data
working-directory: ${{env.build-directory}}
run: |
# Create a script for which gcov to use (needed for lcov)
echo "#!/bin/bash" > gcov-executable.sh
if [[ "${{matrix.compiler.cc}}" =~ "gcc" ]]; then
echo 'gcov $@' >> gcov-executable.sh
else
echo 'llvm-cov-${{matrix.compiler.version}} gcov $@' >> gcov-executable.sh
fi
chmod +x gcov-executable.sh
./gcov-executable.sh $(find $(pwd) -name '*.o' -type f)
# Generate coverage information
lcov --capture \
--gcov-tool $(pwd)/gcov-executable.sh \
--directory . \
--output-file coverage_unfiltered.info
# Strip symbols from 'test' directory
lcov --remove coverage_unfiltered.info -o coverage.info \
--gcov-tool $(pwd)/gcov-executable.sh \
"$(cd ..; pwd)/test/*" \
"${HOME}/.conan/*" \
"/usr/*" \
- name: Generate Coverage
uses: coverallsapp/github-action@v1.1.2
with:
github-token: ${{secrets.GITHUB_TOKEN}}
path-to-lcov: ${{env.build-directory}}/coverage.info
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
[![macOS Build Status](https://github.com/bitwizeshift/BackportCpp/workflows/macOS/badge.svg?branch=master)](https://github.com/bitwizeshift/BackportCpp/actions?query=workflow%3AmacOS)
[![Windows Build Status](https://github.com/bitwizeshift/BackportCpp/workflows/Windows/badge.svg?branch=master)](https://github.com/bitwizeshift/BackportCpp/actions?query=workflow%3AWindows)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/64b1ffd7f95b488eb70a11ee21eb1792)](https://www.codacy.com/manual/bitwizeshift/BackportCpp?utm_source=github.com&utm_medium=referral&utm_content=bitwizeshift/BackportCpp&utm_campaign=Badge_Grade)
[![Coverage Status](https://coveralls.io/repos/github/bitwizeshift/BackportCpp/badge.svg?branch=master)](https://coveralls.io/github/bitwizeshift/BackportCpp?branch=master)
[![Github Issues](https://img.shields.io/github/issues/bitwizeshift/BackportCpp.svg)](http://github.com/bitwizeshift/BackportCpp/issues)
<br>
[![Github Releases](https://img.shields.io/github/v/release/bitwizeshift/BackportCpp.svg?include_prereleases)](https://github.com/bitwizeshift/BackportCpp/releases)
[![Bintray Releases](https://api.bintray.com/packages/bitwizeshift/public-conan/Backport%3Abackport/images/download.svg) ](https://bintray.com/bitwizeshift/public-conan/Backport%3Abackport/_latestVersion)

------------------------------

**Backport** is an ongoing effort to bring modern C++ utilities to be compatible
with C++11.

Expand Down
22 changes: 12 additions & 10 deletions include/bpstd/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,25 @@
# define BPSTD_MAY_ALIAS
#endif // defined __clang__ || defined __GNUC__

#if !defined(BPSTD_INLINE_VISIBILITY)
// When using 'clang-cl', don't forceinline -- since it results in code generation
// failures in 'variant'
#if defined(__clang__) && defined(_MSC_VER)
# define BPSTD_INLINE_VISIBILITY __attribute__((visibility("hidden"), no_instrument_function))
#elif defined(__clang__) || defined(__GNUC__)
# define BPSTD_INLINE_VISIBILITY __attribute__((visibility("hidden"), always_inline, no_instrument_function))
#elif defined(_MSC_VER)
# define BPSTD_INLINE_VISIBILITY __forceinline
#else
# define BPSTD_INLINE_VISIBILITY
#endif
# if defined(__clang__) && defined(_MSC_VER)
# define BPSTD_INLINE_VISIBILITY __attribute__((visibility("hidden"), no_instrument_function))
# elif defined(__clang__) || defined(__GNUC__)
# define BPSTD_INLINE_VISIBILITY __attribute__((visibility("hidden"), always_inline, no_instrument_function))
# elif defined(_MSC_VER)
# define BPSTD_INLINE_VISIBILITY __forceinline
# else
# define BPSTD_INLINE_VISIBILITY
# endif
#endif // !defined(BPSTD_INLINE_VISIBILITY)

#if defined(_MSC_VER)
# define BPSTD_COMPILER_DIAGNOSTIC_PREAMBLE \
__pragma(warning(push)) \
__pragma(warning(disable:4714)) \
__pragma(warning(disable:4100))
__pragma(warning(disable:4100))
#else
# define BPSTD_COMPILER_DIAGNOSTIC_PREAMBLE
#endif
Expand Down

0 comments on commit 35340ad

Please sign in to comment.