Skip to content

Commit

Permalink
ci: Update to gcovr=6.0 and remove bundled-version support (#2629)
Browse files Browse the repository at this point in the history
Addresses and closes Issue #1211 
----------------------------------
The supposed problem was "Parallel processing of gcov data. ([#%s592](gcovr/gcovr#592))" in gcov 5.1. This was already fixed in 5.2.

We need to add `--exclude-noncode-lines` due to a breaking change in gcovr 6.0, otherwise our coverage would change a lot (-0.33%):
New [--exclude-noncode-lines](https://gcovr.com/en/stable/manpage.html#cmdoption-gcovr-exclude-noncode-lines) to exclude noncode lines. Noncode lines are not excluded by default anymore. ([#%s704](gcovr/gcovr#704), [#%s705](gcovr/gcovr#705))

Closes #1211

Update the gcovr-call
----------------------
- remove use of local bundled version (files were removed some years ago)
- remove outdated exclude of folder `/Legacy/`
- remind user to update gcovr to at least `v5.0`
- assert if `v5.1` is used
- black
  • Loading branch information
AJPfleger authored Nov 5, 2023
1 parent ee82495 commit f185bad
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 96 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ jobs:
&& du -sh build
- name: Coverage
run: >
pip3 install gcovr==5.0
pip3 install gcovr==6.0
&& cd build
&& /usr/bin/python3 ../CI/test_coverage
&& /usr/bin/python3 ../CI/test_coverage.py
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
Expand Down
94 changes: 0 additions & 94 deletions CI/test_coverage

This file was deleted.

86 changes: 86 additions & 0 deletions CI/test_coverage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env python
import sys
import os
import subprocess
import argparse
import multiprocessing as mp
import re


if not os.path.exists("CMakeCache.txt"):
print("Not in CMake build dir. Not executing")
sys.exit(1)


def check_output(*args, **kwargs):
p = subprocess.Popen(
*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kwargs
)
p.wait()
stdout, stderr = p.communicate()
stdout = stdout.decode("utf-8")
return (p.returncode, stdout.strip())


# call helper function
def call(cmd):
print(" ".join(cmd))
try:
subprocess.check_call(cmd)
except subprocess.CalledProcessError as e:
print("Failed, output: ", e.output)
raise e


p = argparse.ArgumentParser()
p.add_argument("--gcov", default=check_output(["which", "gcov"])[1])
args = p.parse_args()

ret, gcovr_exe = check_output(["which", "gcovr"])
assert ret == 0, "gcovr not installed. Use 'pip install gcovr'."

ret, gcovr_version_text = check_output(["gcovr", "--version"])
gcovr_version = tuple(
map(int, re.match("gcovr (\d+\.\d+)", gcovr_version_text).group(1).split("."))
)

extra_flags = []

print(f"Found gcovr version {gcovr_version[0]}.{gcovr_version[1]}")
if gcovr_version < (5,):
print("Consider upgrading to a newer gcovr version.")
elif gcovr_version == (5, 1):
assert False and "Version 5.1 does not support parallel processing of gcov data"
elif gcovr_version >= (6,):
extra_flags += ["--exclude-noncode-lines"]

gcovr = [gcovr_exe]

script_dir = os.path.dirname(__file__)
source_dir = os.path.abspath(os.path.join(script_dir, ".."))
coverage_dir = os.path.abspath("coverage")

if not os.path.exists(coverage_dir):
os.makedirs(coverage_dir)

excludes = ["-e", "../Tests/", "-e", ".*json\.hpp"]

# create the html report
call(
gcovr
+ ["-r", source_dir]
+ ["--gcov-executable", args.gcov]
+ ["-j", str(mp.cpu_count())]
+ excludes
+ extra_flags
+ ["--xml", "-o", "coverage/cov.xml"]
)

call(
gcovr
+ ["-r", source_dir]
+ ["-j", str(mp.cpu_count())]
+ ["--gcov-executable", args.gcov]
+ excludes
+ extra_flags
)

0 comments on commit f185bad

Please sign in to comment.