Skip to content

Commit c8691eb

Browse files
committed
🚦 Add coverage workflow
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.
1 parent 8dc2b13 commit c8691eb

File tree

3 files changed

+121
-10
lines changed

3 files changed

+121
-10
lines changed

.github/workflows/coverage.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: "Code Coverage"
2+
3+
on:
4+
push:
5+
paths:
6+
- 'include/**.hpp'
7+
- 'test/**.cpp'
8+
- '**.cmake'
9+
- 'conanfile.py'
10+
- 'CMakeLists.txt'
11+
- 'test/CMakeLists.txt'
12+
- '.github/workflows/coverage.yml'
13+
pull_request:
14+
paths:
15+
- 'include/**.hpp'
16+
- 'test/**.cpp'
17+
- '**.cmake'
18+
- 'conanfile.py'
19+
- 'CMakeLists.txt'
20+
- 'test/CMakeLists.txt'
21+
- '.github/workflows/coverage.yml'
22+
23+
jobs:
24+
coverage:
25+
name: Ubuntu ${{matrix.compiler.cc}} Coverage
26+
runs-on: ubuntu-20.04
27+
28+
env:
29+
build-directory: build
30+
31+
strategy:
32+
matrix:
33+
compiler:
34+
- { cc: gcc, cxx: g++, version: "10" }
35+
- { cc: clang, cxx: clang++, version: "10" }
36+
37+
steps:
38+
- name: Checkout repository
39+
uses: actions/checkout@v2
40+
41+
- name: Set up Python
42+
uses: actions/setup-python@v1
43+
with:
44+
python-version: 3.7
45+
46+
- name: Prepare Environment
47+
run: |
48+
sudo apt-get install -y ${{matrix.compiler.cxx}}-${{matrix.compiler.version}}
49+
if [["${{matrix.compiler.cc}}" = "clang"]]; then
50+
sudo apt-get install -y llvm-${{matrix.compiler.version}}
51+
fi
52+
sudo apt-get install lcov
53+
python -m pip install --upgrade pip
54+
pip install conan
55+
cmake -E make_directory ${{env.build-directory}}
56+
cmake -E chdir ${{env.build-directory}} conan install ..
57+
58+
- name: Configure
59+
working-directory: ${{env.build-directory}}
60+
env:
61+
CC: ${{matrix.compiler.cc}}-${{matrix.compiler.version}}
62+
CXX: ${{matrix.compiler.cxx}}-${{matrix.compiler.version}}
63+
run: |
64+
cmake .. -DCMAKE_BUILD_TYPE=Debug \
65+
-DBACKPORT_COMPILE_UNIT_TESTS=On \
66+
-DCMAKE_CXX_FLAGS="--coverage -DBPSTD_INLINE_VISIBILITY=" \
67+
68+
- name: Build
69+
working-directory: ${{env.build-directory}}
70+
run: cmake --build .
71+
72+
- name: Test
73+
working-directory: ${{env.build-directory}}
74+
run: ctest --output-on-failure
75+
76+
- name: Process Coverage Data
77+
working-directory: ${{env.build-directory}}
78+
run: |
79+
# Create a script for which gcov to use (needed for lcov)
80+
echo "#!/bin/bash" > gcov-executable.sh
81+
if [[ "${{matrix.compiler.cc}}" =~ "gcc" ]]; then
82+
echo 'gcov $@' >> gcov-executable.sh
83+
else
84+
echo 'llvm-cov-${{matrix.compiler.version}} gcov $@' >> gcov-executable.sh
85+
fi
86+
chmod +x gcov-executable.sh
87+
./gcov-executable.sh $(find $(pwd) -name '*.o' -type f)
88+
89+
# Generate coverage information
90+
lcov --capture \
91+
--gcov-tool $(pwd)/gcov-executable.sh \
92+
--directory . \
93+
--output-file coverage_unfiltered.info
94+
95+
# Strip symbols from 'test' directory
96+
lcov --remove coverage_unfiltered.info -o coverage.info \
97+
--gcov-tool $(pwd)/gcov-executable.sh \
98+
"$(cd ..; pwd)/test/*" \
99+
"${HOME}/.conan/*" \
100+
"/usr/*" \
101+
102+
- name: Generate Coverage
103+
uses: coverallsapp/github-action@v1.1.2
104+
with:
105+
github-token: ${{secrets.GITHUB_TOKEN}}
106+
path-to-lcov: ${{env.build-directory}}/coverage.info

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
[![macOS Build Status](https://github.com/bitwizeshift/BackportCpp/workflows/macOS/badge.svg?branch=master)](https://github.com/bitwizeshift/BackportCpp/actions?query=workflow%3AmacOS)
55
[![Windows Build Status](https://github.com/bitwizeshift/BackportCpp/workflows/Windows/badge.svg?branch=master)](https://github.com/bitwizeshift/BackportCpp/actions?query=workflow%3AWindows)
66
[![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)
7+
[![Coverage Status](https://coveralls.io/repos/github/bitwizeshift/BackportCpp/badge.svg?branch=master)](https://coveralls.io/github/bitwizeshift/BackportCpp?branch=master)
78
[![Github Issues](https://img.shields.io/github/issues/bitwizeshift/BackportCpp.svg)](http://github.com/bitwizeshift/BackportCpp/issues)
89
<br>
910
[![Github Releases](https://img.shields.io/github/v/release/bitwizeshift/BackportCpp.svg?include_prereleases)](https://github.com/bitwizeshift/BackportCpp/releases)
1011
[![Bintray Releases](https://api.bintray.com/packages/bitwizeshift/public-conan/Backport%3Abackport/images/download.svg) ](https://bintray.com/bitwizeshift/public-conan/Backport%3Abackport/_latestVersion)
1112

13+
------------------------------
14+
1215
**Backport** is an ongoing effort to bring modern C++ utilities to be compatible
1316
with C++11.
1417

include/bpstd/detail/config.hpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,25 @@
7070
# define BPSTD_MAY_ALIAS
7171
#endif // defined __clang__ || defined __GNUC__
7272

73+
#if !defined(BPSTD_INLINE_VISIBILITY)
7374
// When using 'clang-cl', don't forceinline -- since it results in code generation
7475
// failures in 'variant'
75-
#if defined(__clang__) && defined(_MSC_VER)
76-
# define BPSTD_INLINE_VISIBILITY __attribute__((visibility("hidden"), no_instrument_function))
77-
#elif defined(__clang__) || defined(__GNUC__)
78-
# define BPSTD_INLINE_VISIBILITY __attribute__((visibility("hidden"), always_inline, no_instrument_function))
79-
#elif defined(_MSC_VER)
80-
# define BPSTD_INLINE_VISIBILITY __forceinline
81-
#else
82-
# define BPSTD_INLINE_VISIBILITY
83-
#endif
76+
# if defined(__clang__) && defined(_MSC_VER)
77+
# define BPSTD_INLINE_VISIBILITY __attribute__((visibility("hidden"), no_instrument_function))
78+
# elif defined(__clang__) || defined(__GNUC__)
79+
# define BPSTD_INLINE_VISIBILITY __attribute__((visibility("hidden"), always_inline, no_instrument_function))
80+
# elif defined(_MSC_VER)
81+
# define BPSTD_INLINE_VISIBILITY __forceinline
82+
# else
83+
# define BPSTD_INLINE_VISIBILITY
84+
# endif
85+
#endif // !defined(BPSTD_INLINE_VISIBILITY)
8486

8587
#if defined(_MSC_VER)
8688
# define BPSTD_COMPILER_DIAGNOSTIC_PREAMBLE \
8789
__pragma(warning(push)) \
8890
__pragma(warning(disable:4714)) \
89-
__pragma(warning(disable:4100))
91+
__pragma(warning(disable:4100))
9092
#else
9193
# define BPSTD_COMPILER_DIAGNOSTIC_PREAMBLE
9294
#endif

0 commit comments

Comments
 (0)