Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

genhtml (2.0) dies with source files in top directory #245

Closed
entrope opened this issue Nov 4, 2023 · 6 comments
Closed

genhtml (2.0) dies with source files in top directory #245

entrope opened this issue Nov 4, 2023 · 6 comments

Comments

@entrope
Copy link

entrope commented Nov 4, 2023

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 to File::Spec->catdir() and $rel_dir is empty.

Adding unshift @$short_path, '.' if $#$short_path == 0; before the call to catdir() 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.

@henry2cox
Copy link
Collaborator

better if you could attach a testcase.
Other question is what happens when your remove the --prefix option.
Thanks.

@entrope
Copy link
Author

entrope commented Nov 5, 2023

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)

@henry2cox
Copy link
Collaborator

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

@entrope
Copy link
Author

entrope commented Nov 7, 2023

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.

henry2cox added a commit that referenced this issue Nov 8, 2023
files.  See #245

Signed-off-by:  Henry Cox <henry.cox@mediatek.com>
@henry2cox
Copy link
Collaborator

should be fixed in the above commit: bf135ca

@henry2cox
Copy link
Collaborator

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

thesamesam added a commit to thesamesam/meson that referenced this issue Aug 19, 2024
Hack for linux-test-project/lcov#245. I tried
to backport linux-test-project/lcov@bf135ca
but had no luck (worked in one container but didn'y apply in another, whatever).

This fixes the coverage unittests.

>=lcov-2.1-beta works fine. The beta has landed in a beta version of
Ubuntu too.

Bug: linux-test-project/lcov#245
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants