Skip to content

Commit a2392c4

Browse files
committed
[cmake][ci] Enable codecov.
Fixes #27.
1 parent fc5bd09 commit a2392c4

File tree

3 files changed

+56
-11
lines changed

3 files changed

+56
-11
lines changed

.github/workflows/main.yml

+41-10
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ jobs:
2121
strategy:
2222
fail-fast: false
2323
matrix:
24-
os: [ubuntu-latest, macos-latest]
24+
include:
25+
- name: ubu
26+
os: ubuntu-latest
27+
- name: ubu-analyzers
28+
os: ubuntu-latest
29+
coverage: true
30+
extra_cmake_flags: -DCMAKE_BUILD_TYPE=Debug
31+
- name: osx
32+
os: macos-latest
2533

2634
steps:
2735
- uses: actions/checkout@v2
@@ -40,28 +48,30 @@ jobs:
4048
- name: cmake configure
4149
shell: bash -l {0}
4250
run: |
43-
mkdir -p bld
44-
cd bld
51+
mkdir -p build
52+
cd build
4553
cmake .. \
4654
-DCMAKE_PREFIX_PATH=$CONDA_PREFIX \
47-
-DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX
55+
-DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX \
56+
-DXEUS_CPP_ENABLE_CODE_COVERAGE=${{ matrix.coverage }} \
57+
${{ matrix.extra_cmake_flags }}
4858
4959
- name: build
5060
shell: bash -l {0}
5161
run: |
52-
cd bld
62+
cd build
5363
make -j8
5464
5565
- name: install
5666
shell: bash -l {0}
5767
run: |
58-
cd bld
68+
cd build
5969
make install
6070
6171
- name: Test xeus-cpp C++
6272
shell: bash -l {0}
6373
run: |
64-
cd bld/test
74+
cd build/test
6575
./test_xeus_cpp
6676
timeout-minutes: 4
6777

@@ -71,6 +81,27 @@ jobs:
7181
cd test
7282
pytest . --reruns 5
7383
84+
- name: Prepare code coverage report
85+
if: ${{ success() && (matrix.coverage == true) }}
86+
shell: bash -l {0}
87+
run: |
88+
# Create lcov report
89+
# Find the current compiler version.
90+
CC=$(realpath `which c++`)
91+
vers="${CC##*-}"
92+
sudo apt install lcov
93+
# capture coverage info
94+
lcov --directory build/ --capture --output-file coverage.info --gcov-tool $CONDA_PREFIX/bin/gcov
95+
lcov --remove coverage.info '/usr/*' "${HOME}"'/.cache/*' ${{ github.workspace }}'/llvm-project/*' ${{ github.workspace }}'/test/*' --output-file coverage.info
96+
# output coverage data for debugging (optional)
97+
lcov --list coverage.info
98+
99+
- name: Upload to codecov.io
100+
if: ${{ success() && (matrix.coverage == true) }}
101+
uses: codecov/codecov-action@v3
102+
with:
103+
file: ./coverage.info
104+
74105
win:
75106

76107
runs-on: ${{ matrix.os }}
@@ -98,15 +129,15 @@ jobs:
98129
shell: cmd
99130
run: |
100131
call C:\Users\runneradmin\micromamba-root\condabin\micromamba.bat activate xeus-cpp
101-
mkdir -p bld
102-
cd bld
132+
mkdir -p build
133+
cd build
103134
cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DXEUS_BUILD_TESTS=ON -DDEPENDENCY_SEARCH_PREFIX="%CONDA_PREFIX%\Library" -DCMAKE_PREFIX_PATH="%CONDA_PREFIX%\Library" -DCMAKE_INSTALL_PREFIX="%CONDA_PREFIX%"
104135
105136
- name: build
106137
shell: cmd
107138
run: |
108139
call C:\Users\runneradmin\micromamba-root\condabin\micromamba.bat activate xeus-cpp
109-
cd bld
140+
cd build
110141
set CL=/MP
111142
nmake install
112143

CMakeLists.txt

+14-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ OPTION(XEUS_CPP_USE_SHARED_XEUS_CPP "Link xcpp with the xeus shared library (in
5252

5353
# Test options
5454
OPTION(XEUS_CPP_BUILD_TESTS "xeus-cpp test suite" ON)
55+
OPTION(XEUS_CPP_ENABLE_CODE_COVERAGE "xeus-cpp test suite" OFF)
56+
if(XEUS_CPP_ENABLE_CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
57+
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
58+
if(NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
59+
message(FATAL_ERROR "CodeCov enabled on non-debug build!")
60+
endif()
61+
set(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage")
62+
set(GCC_COVERAGE_LINK_FLAGS "--coverage")
63+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
64+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
65+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHAREDLINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
66+
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
67+
endif()
5568

5669
if(EMSCRIPTEN)
5770
add_compile_definitions(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
@@ -418,4 +431,4 @@ endif ()
418431

419432
if(XEUS_CPP_INCLUDE_DOCS)
420433
add_subdirectory(docs)
421-
endif()
434+
endif()

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![Build Status](https://github.com/compiler-research/xeus-cpp/actions/workflows/main.yml/badge.svg)](https://github.com/compiler-research/xeus-cpp/actions/workflows/main.yml)
44
[![Documentation Status](http://readthedocs.org/projects/xeus-cpp/badge/?version=latest)](https://xeus-cppreadthedocs.io/en/latest/?badge=latest)
55
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/compiler-research/xeus-cpp/main?urlpath=/lab/tree/notebooks/xeus-cpp.ipynb)
6+
[![codecov]( https://codecov.io/gh/compiler-research/xeus-cpp/branch/main/graph/badge.svg)](https://codecov.io/gh/compiler-research/xeus-cpp)
67

78
`xeus-cpp` is a Jupyter kernel for cpp based on the native implementation of the
89
Jupyter protocol [xeus](https://github.com/jupyter-xeus/xeus).

0 commit comments

Comments
 (0)