Closed entrope closed 7 months ago
better if you could attach a testcase.
Other question is what happens when your remove the --prefix
option.
Thanks.
This was on macOS 14.1 (Sonoma) using Apple's version of LLVM 15 as cc, but should translate well to Linux. (I reproduced my original case, which uses Meson as a build system, in a Kali Linux VM because that was what had lcov 2.0).
% echo "int main() { return 0; }" > main.c
% cc -Wall -Wextra --coverage ../main.c
% ./a.out
% lcov -c -d `pwd` -o lcov.info
[...]
% genhtml -o html --prefix `pwd` lcov.info
Found 1 entries.
Using user-specified filename prefix "/Users/mdpoole/src/tmp"
Generating output.
genhtml: ERROR: file error for main.c
Meson automatically adds --prefix, so it is not easy for my original case to remove it. Without --prefix in the test case above, it finds the parent directory as the prefix:
% genhtml -o html lcov.info
Found 1 entries.
Found common filename prefix "/Users/mdpoole/src"
Generating output.
Processing file tmp/main.c
lines=1 hit=1 functions=1 hit=1
Overall coverage rate:
lines......: 100.0% (1 of 1 line)
functions......: 100.0% (1 of 1 function)
Thanks.
I suspect that your actual case is not quite so simple :-) Probably contains code in subdirectories of 'prefix' as well as in the top-level directory.
I also wanted to test that my somewhat hacky fix handles --flat
and --hierarchical
report formats.
In any event: I seem to have a fix which I will push along with some other changes/enhancements - once local tests are complete and things seem to have stabilized.
Henry
My actual case is almost that simple -- I have multiple source files, but all were in the top-level directory. (I have since restructured it to have subdirectories, to clarify library vs executable code.)
I am happy to test your fix on my original test case once you think it is worth sharing. Thank you for the quick responses.
should be fixed in the above commit: bf135ca
Closing this issue as I think that it is fixed. If there is still a problem, please either reopen this issue or file a new one. Please include a testcase which illustrates the problem if at all possible. Henry
When there is a source file in the top-level directory of a project (one of the directories passed with --prefix), the
die("file error for " ...)
call gets triggered: @$short_path has only one element, so nothing gets passed toFile::Spec->catdir()
and$rel_dir
is empty.Adding
unshift @$short_path, '.' if $#$short_path == 0;
before the call tocatdir()
avoids the crash but generates an HTML coverage report with no way to access the source files because the top-level directory has a zero-length (or no?) hyperlink to the per-directory report file.With lcov 1.16, this would give the name "root" to the top-level directory.