aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/markdown/Feature-autodetection.md2
-rw-r--r--docs/markdown/Unit-tests.md2
-rw-r--r--mesonbuild/environment.py6
-rw-r--r--mesonbuild/scripts/coverage.py29
4 files changed, 18 insertions, 21 deletions
diff --git a/docs/markdown/Feature-autodetection.md b/docs/markdown/Feature-autodetection.md
index f865174..9ee2e3e 100644
--- a/docs/markdown/Feature-autodetection.md
+++ b/docs/markdown/Feature-autodetection.md
@@ -16,4 +16,4 @@ If you do not wish to use CCache for some reason, just specify your compiler wit
Coverage
--
-When doing a code coverage build, Meson will check the existence of binaries `gcovr`, `lcov` and `genhtml`. If the first one is found, it will create targets called *coverage-text* and *coverage-xml*. If the latter two or a new enough `gcovr` is found, it generates the target *coverage-html*. You can then generate coverage reports just by calling e.g. `ninja coverage-xml`.
+When doing a code coverage build, Meson will check for existence of the binaries `gcovr`, `lcov` and `genhtml`. If version 3.3 or higher of the first is found, targets called *coverage-text*, *coverage-xml* and *coverage-html* are generated. Alternatively, if the latter two are found, only the target *coverage-html* is generated. Coverage reports can then be produced simply by calling e.g. `ninja coverage-xml`. As a convenience, a high-level *coverage* target is also generated which will produce all 3 coverage report types, if possible.
diff --git a/docs/markdown/Unit-tests.md b/docs/markdown/Unit-tests.md
index 9e61739..694c190 100644
--- a/docs/markdown/Unit-tests.md
+++ b/docs/markdown/Unit-tests.md
@@ -30,7 +30,7 @@ Note how you need to specify multiple values as an array.
Coverage
--
-If you enable coverage measurements by giving Meson the command line flag `-Db_coverage=true`, you can generate coverage reports. Meson will autodetect what coverage generator tools you have installed and will generate the corresponding targets. These targets are `coverage-xml` and `coverage-text` which are both provided by [Gcovr](http://gcovr.com) and `coverage-html`, which requires [Lcov](https://ltp.sourceforge.io/coverage/lcov.php) and [GenHTML](https://linux.die.net/man/1/genhtml) or [Gcovr](http://gcovr.com) with html support.
+If you enable coverage measurements by giving Meson the command line flag `-Db_coverage=true`, you can generate coverage reports. Meson will autodetect what coverage generator tools you have installed and will generate the corresponding targets. These targets are `coverage-xml` and `coverage-text` which are both provided by [Gcovr](http://gcovr.com) (version 3.3 or higher) and `coverage-html`, which requires [Lcov](https://ltp.sourceforge.io/coverage/lcov.php) and [GenHTML](https://linux.die.net/man/1/genhtml) or [Gcovr](http://gcovr.com). As a convenience, a high-level `coverage` target is also generated which will produce all 3 coverage report types, if possible.
The output of these commands is written to the log directory `meson-logs` in your build directory.
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index c296573..3d5d3ab 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -83,7 +83,7 @@ from .compilers import (
build_filename = 'meson.build'
-def detect_gcovr(version='3.1', log=False):
+def detect_gcovr(min_version='3.3', new_rootdir_version='4.2', log=False):
gcovr_exe = 'gcovr'
try:
p, found = Popen_safe([gcovr_exe, '--version'])[0:2]
@@ -91,10 +91,10 @@ def detect_gcovr(version='3.1', log=False):
# Doesn't exist in PATH or isn't executable
return None, None
found = search_version(found)
- if p.returncode == 0:
+ if p.returncode == 0 and mesonlib.version_compare(found, '>=' + min_version):
if log:
mlog.log('Found gcovr-{} at {}'.format(found, shlex.quote(shutil.which(gcovr_exe))))
- return gcovr_exe, mesonlib.version_compare(found, '>=' + version)
+ return gcovr_exe, mesonlib.version_compare(found, '>=' + new_rootdir_version)
return None, None
def find_coverage_tools():
diff --git a/mesonbuild/scripts/coverage.py b/mesonbuild/scripts/coverage.py
index 0e203f9..4bd41fe 100644
--- a/mesonbuild/scripts/coverage.py
+++ b/mesonbuild/scripts/coverage.py
@@ -22,35 +22,33 @@ def coverage(outputs, source_root, subproject_root, build_root, log_dir):
(gcovr_exe, gcovr_new_rootdir, lcov_exe, genhtml_exe) = environment.find_coverage_tools()
- # gcovr >= 3.1 interprets rootdir differently
+ # gcovr >= 4.2 requires a different syntax for out of source builds
if gcovr_new_rootdir:
- gcovr_rootdir = build_root
+ gcovr_base_cmd = [gcovr_exe, '-r', source_root, build_root]
else:
- gcovr_rootdir = source_root
+ gcovr_base_cmd = [gcovr_exe, '-r', build_root]
if not outputs or 'xml' in outputs:
if gcovr_exe:
- subprocess.check_call([gcovr_exe,
- '-x',
- '-r', gcovr_rootdir,
+ subprocess.check_call(gcovr_base_cmd +
+ ['-x',
'-e', subproject_root,
'-o', os.path.join(log_dir, 'coverage.xml'),
])
outfiles.append(('Xml', pathlib.Path(log_dir, 'coverage.xml')))
elif outputs:
- print('gcovr needed to generate Xml coverage report')
+ print('gcovr >= 3.3 needed to generate Xml coverage report')
exitcode = 1
if not outputs or 'text' in outputs:
if gcovr_exe:
- subprocess.check_call([gcovr_exe,
- '-r', gcovr_rootdir,
- '-e', subproject_root,
+ subprocess.check_call(gcovr_base_cmd +
+ ['-e', subproject_root,
'-o', os.path.join(log_dir, 'coverage.txt'),
])
outfiles.append(('Text', pathlib.Path(log_dir, 'coverage.txt')))
elif outputs:
- print('gcovr needed to generate text coverage report')
+ print('gcovr >= 3.3 needed to generate text coverage report')
exitcode = 1
if not outputs or 'html' in outputs:
@@ -101,21 +99,20 @@ def coverage(outputs, source_root, subproject_root, build_root, log_dir):
'--branch-coverage',
covinfo])
outfiles.append(('Html', pathlib.Path(htmloutdir, 'index.html')))
- elif gcovr_exe and gcovr_new_rootdir:
+ elif gcovr_exe:
htmloutdir = os.path.join(log_dir, 'coveragereport')
if not os.path.isdir(htmloutdir):
os.mkdir(htmloutdir)
- subprocess.check_call([gcovr_exe,
- '--html',
+ subprocess.check_call(gcovr_base_cmd +
+ ['--html',
'--html-details',
'--print-summary',
- '-r', build_root,
'-e', subproject_root,
'-o', os.path.join(htmloutdir, 'index.html'),
])
outfiles.append(('Html', pathlib.Path(htmloutdir, 'index.html')))
elif outputs:
- print('lcov/genhtml or gcovr >= 3.2 needed to generate Html coverage report')
+ print('lcov/genhtml or gcovr >= 3.3 needed to generate Html coverage report')
exitcode = 1
if not outputs and not outfiles: