From 0e07f1a8963c75b57bbe445821c7291f81d1e10b Mon Sep 17 00:00:00 2001 From: Henk van der Laan Date: Mon, 5 Feb 2018 19:48:30 +0100 Subject: Remove all files outside the source directory from the coverage report Cuurently, a set of directories is filtered out from the output based on the location of system includes on most common linux distro's. This commit does away with the blacklist and implements a whitelist approach: only the files inside the source root are shown. --- mesonbuild/scripts/coverage.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'mesonbuild/scripts/coverage.py') diff --git a/mesonbuild/scripts/coverage.py b/mesonbuild/scripts/coverage.py index d1fad11..47f4cda 100644 --- a/mesonbuild/scripts/coverage.py +++ b/mesonbuild/scripts/coverage.py @@ -16,11 +16,6 @@ from mesonbuild import environment import sys, os, subprocess, pathlib -def remove_dir_from_trace(lcov_command, covfile, dirname): - tmpfile = covfile + '.tmp' - subprocess.check_call([lcov_command, '--remove', covfile, dirname, '-o', tmpfile]) - os.replace(tmpfile, covfile) - def coverage(source_root, build_root, log_dir): (gcovr_exe, lcov_exe, genhtml_exe) = environment.find_coverage_tools() if gcovr_exe: @@ -38,6 +33,7 @@ def coverage(source_root, build_root, log_dir): covinfo = os.path.join(log_dir, 'coverage.info') initial_tracefile = covinfo + '.initial' run_tracefile = covinfo + '.run' + raw_tracefile = covinfo + '.raw' subprocess.check_call([lcov_exe, '--directory', build_root, '--capture', @@ -55,11 +51,12 @@ def coverage(source_root, build_root, log_dir): subprocess.check_call([lcov_exe, '-a', initial_tracefile, '-a', run_tracefile, - '-o', covinfo]) - remove_dir_from_trace(lcov_exe, covinfo, '/usr/include/*') - remove_dir_from_trace(lcov_exe, covinfo, '/usr/local/include/*') - remove_dir_from_trace(lcov_exe, covinfo, '/usr/src/*') - remove_dir_from_trace(lcov_exe, covinfo, '/usr/lib/llvm-*/include/*') + '-o', raw_tracefile]) + # Remove all directories outside the source_root from the covinfo + subprocess.check_call([lcov_exe, + '--extract', raw_tracefile, + os.path.join(source_root, '*'), + '--output-file', covinfo]) subprocess.check_call([genhtml_exe, '--prefix', build_root, '--output-directory', htmloutdir, -- cgit v1.1