Both of these options are not well documented, so the main source of knowledge is source code.
a) what is --exclude-directories for since it seems like you (should) be able to exclude a directory with the right regex passed to --exclude?
--exclude-directories
option used by gcovr to skip directories by it's name, not fullpath. It can be verified if you check the gcovr's source code. Magic is done in def link_walker(path)
function:
for root, dirs, files in os.walk(
os.path.abspath(path), followlinks=True
):
for exc in options.exclude_dirs:
for d in dirs:
m = exc.search(d)
According to the os.walk
documentation, dirs
is a list of the names of the subdirectories. E.g. to skip all directories starts with MyMod
use --exclude-directories='MyMod.*'
.
b) Any suggestions about why the --excludes do not work as expected? Perhaps these are not the right kind/style of regular expressions?
Your regular expression is correct. It's typical Python's regex.
To understand what is going on at --exclude
option it's useful to enable -v
output. With this option enabled, output should have lots of lines:
currdir /cygdrive/f/test/path/to/source
gcov_fname myfile.cpp.gcov
[' -', ' 0', 'Source', 'myfile.cpp\n']
source_fname /cygdrive/f/test/path/to/source/myfile.gcda
root /cygdrive/f/test/path/to/source
fname /cygdrive/f/test/path/to/source/myfile.cpp
Parsing coverage data for file /cygdrive/f/test/path/to/source/myfile.cpp
This output produced by def process_gcov_data(data_fname, covdata, source_fname, options)
function. If you check the source code you will see the following:
for exc in options.exclude:
if (filtered_fname is not None and exc.match(filtered_fname)) or \
exc.match(fname) or \
exc.match(os.path.abspath(fname))
Exclude filter applies to fname
printed above. It's the absolute filepath. Also it applies to all files which have coverage data. If file was excluded the following line should be in output (-v
option required):
Excluding coverage data for file /cygdrive/f/test/path/to/source/myfile.cpp
--exclude='.*/MyMod.*'
and--exclude-directories='MyMod.*'
? 2) Can you explain the difference between--exclude
and--gcov-exclude=
? – Daphnedaphnis