Skip to content

Commit e7a4f67

Browse files
authored
Simplify code coverage builds (PyVRP#557)
* Simplify code coverage builds * Try clang, using Meson's coverage-xml target * Add gcovr configuration * Exclude throw branches
1 parent 87c2c79 commit e7a4f67

File tree

6 files changed

+16
-23
lines changed

6 files changed

+16
-23
lines changed

.github/workflows/CI.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,16 @@ jobs:
8989
run: |
9090
poetry install --only-root
9191
poetry run python build_extensions.py --build_type debug --clean
92-
- name: Run tests
93-
run: poetry run pytest
94-
- if: matrix.compiler == 'gcc'
95-
# Clang does not generate accurate coverage reports, so there is no
96-
# point in uploading those.
97-
uses: codecov/codecov-action@v4
92+
- name: Run tests and generate coverage reports
93+
run: |
94+
poetry run pytest
95+
poetry run ninja coverage-xml -C build
96+
- uses: codecov/codecov-action@v4
9897
with:
9998
fail_ci_if_error: true
10099
token: ${{ secrets.CODECOV_TOKEN }}
101-
plugins: gcov, pycoverage
100+
plugins: pycoverage
101+
files: build/meson-logs/coverage.xml
102102
- if: matrix.compiler == 'gcc'
103103
name: Install Valgrind
104104
run: sudo apt install valgrind

build_extensions.py

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def configure(
9393
f"-Dpython.platlibdir={cwd.absolute()}",
9494
f"-Dproblem={problem}",
9595
f"-Dstrip={'true' if build_type == 'release' else 'false'}",
96+
f"-Db_coverage={'true' if build_type != 'release' else 'false'}",
9697
*additional,
9798
# fmt: on
9899
]

gcovr.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exclude-unreachable-branches = yes
2+
exclude-throw-branches = yes
3+
filter = pyvrp/

meson.build

-13
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,6 @@ project(
1111
]
1212
)
1313

14-
if get_option('buildtype') == 'debug'
15-
compiler = meson.get_compiler('cpp')
16-
17-
if compiler.has_argument('-fprofile-abs-path')
18-
# clang does not have this particular flag, so we only add it when
19-
# compiling with gcc. It's helpful in determining code coverage.
20-
add_project_arguments('-fprofile-abs-path', language: 'cpp')
21-
endif
22-
23-
add_project_arguments('--coverage', language: 'cpp')
24-
add_project_link_arguments('--coverage', language: 'cpp')
25-
endif
26-
2714
if get_option('problem') == 'cvrp'
2815
# CVRP does not have time windows, so we set a flag that compiles time
2916
# window stuff out of the extension modules.

pyproject.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ pytest-cov = ">=2.6.1"
8888
codecov = "*"
8989

9090
# These are used in the build script: for compiling the library (meson, ninja)
91-
# and for generating doc or type stubs (docblock, mypy).
91+
# and for generating docs (docblock), type stubs (mypy), and coverage reports
92+
# (gcovr).
9293
meson = "^1.0.0"
9394
ninja = "^1.11.1"
95+
gcovr = "^7.2"
9496
mypy = "^0.991"
9597
docblock = "^0.1.5"
9698

pyvrp/cpp/search/SwapTails.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ pyvrp::Cost SwapTails::evaluate(Route::Node *U,
2020

2121
// We're going to incur fixed cost if a route is currently empty but
2222
// becomes non-empty due to the proposed move.
23-
if (uRoute->empty() && U->isDepot() && !n(V)->isDepot())
23+
if (uRoute->empty() && !n(V)->isDepot())
2424
deltaCost += uRoute->fixedVehicleCost();
2525

26-
if (vRoute->empty() && V->isDepot() && !n(U)->isDepot())
26+
if (vRoute->empty() && !n(U)->isDepot())
2727
deltaCost += vRoute->fixedVehicleCost();
2828

2929
// We lose fixed cost if a route becomes empty due to the proposed move.

0 commit comments

Comments
 (0)