-
Notifications
You must be signed in to change notification settings - Fork 283
--html-details cannot locate sources #368
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
Comments
The problem occurs for me as well, if I have my source directory at /src with other paths e.g. /workingdir or /home/username/src it works Actually I think it occurs, when you have a repetition of your source folder name in in the file path, at least this seems to be the problem in my case. /src/path/to/lib/src/something.cpp as it seems to replace the /src in the path (but that's only a first guess, I did not look into it) |
I fully believe that something is broken here, because gcovr's path handling depends a lot on guesses and heuristics. And those guesses often get it wrong. So thank you for adding these useful data points :)
What might help here is running gcovr from your build dir, especially if you are using cmake:
cd src/build/debug; gcovr -r ../.. --html-details -o ../../../coverage.html ...
Do you at least get the correct files in other report formats, e.g. the default text report?
Running gcovr from the build dir did not fix the problem. As for the text report, I do get a summary (as for the HTML report), but as you can't browse the source file, I do not know if it is relevant. Maybe I did not specify that I do get an HTML report with per-file coverage statistics. The only problem is that I cannot browse the files because the paths are not correct. |
I think I have a hunch. Assuming that you are using gcovr 4.2, could you try editing the file data['ROWS'] = []
- currdir = os.getcwd()
- os.chdir(options.root_dir)
- with io.open(data['FILENAME'], 'r', encoding=options.source_encoding,
+ with io.open(f, 'r', encoding=options.source_encoding,
errors='replace') as INPUT:
for ctr, line in enumerate(INPUT, 1):
data['ROWS'].append(
source_row(ctr, line.rstrip(), cdata.lines.get(ctr))
)
- os.chdir(currdir) Background: the Even if this isn't the exact problem, I think the root cause has to be nearby. It would be helpful to have a small test case that reproduces the problem (hello world style source code plus a script or makefile to run gcc & gcovr), but if this is too Windows-specific that might be difficult. |
Unfortunately no change, no matter if gcovr is run from the root dir or the build dir. Before 8000 the patch:
After the patch:
So the file is still searched in the build dir. the difference is only on the stripped 'root' prefix |
Thank you for helping investigate this, that was really helpful in ruling out some problem areas, although I still don't know what the actual problem is. If you can reproduce the issue in a small sample project this would make it possible to do deeper debugging, but I won't promise any timeline. If you need a workaround: use gcovr to output JSON data, write a script to fix the path names in the JSON, and then use gcovr to turn the JSON into the HTML report. Alternatively, please consider other coverage tools such as lcov. |
I use a two step process for a workaround for this issue. The first step uses the 'gcov' to map the data to the c file and then at root i use the gcovr to generate HTML from that data. This is possible because during my build process i isolate the files and create a batch file for the same. This happens automatically for me. What i fail to understand is how is gcovr guessing the path and from where? |
Hi @k10blogger! Running the gcov tool manually tends to work very well, except when multiple object files contain coverage data for the same source file, e.g. inline functions in header files. Gcovr needs to figure out from which directory the gcov tool should be executed. Generally, this should be exactly the directory from which the compiler (gcc) was invoked. I'm not entirely sure why this is necessary, but it seems that the gcno files contain relative pathnames to the source files. Gcovr uses a brute-force approach and just tries out lots of directories until gcov successfully produces output, see the Line 514 in 1f17d44
This issue indicates that although the gcov tool produces correct output, gcovr misunderstands the source file name as reported by gcov. This is likely an error at the gcov–gcovr interface, which won't be fixed by giving a source path to gcovr. GCC 9 added working-directory metadata to the gcov reports which might fix the issue, but gcovr doesn't make use of it yet. |
I have something similar. In my case I have proper sources in the root directory and unittests in a subdirectory. I'm sending objects to a subdirectory In the textual output I get references to source files from the unittests but with the
Those do not exists, so that's probably why the HTML output fails. Small example: From this example you can see that I'm running gcovr 4.2 on WSL 4.4.0-18362-Microsoft. |
@thoni56 You are using two different root directories for compiling but only one for running gcovr. The files produced by gcov contains the path used when compiling and the guessing of the path use the wrong root. Lines 186 to 211 in 39f5a82
If you don't change to the sub directory for compiling unit but give the files with the sub directory everything is fine.
|
@Spacetown Fair enough, is there any other way to merge the two data sets? I really don't want to bring up all my unittest compilation into the top level Makefile... |
You can create a JSON for each executable using the Sam working directory as the compiler. This JSONs can be merged to one HTML report. |
Say what?!? I'm guessing that by "using the Sam working directory as the compiler" you mean that I should create two separate Json reports in the two directories where the compiles are run, right? Then those JSON files can be merged into a single report? Ok, I'lll try that. |
Sorry for my bad English but you got it. |
I'm hitting the same problem of original reporter of this bug... since indeed I have a similar tree structure for my project... |
@Spacetown any help we can provide on fixing this problem? What's the status? is there a work-in-progress MR perhaps? Any hint on where to start the debugging? I would like to help if I can... Thanks a lot! |
@f18m Can someone check if the generation of two separate JSON files and merging thme together will work? |
Hi @Spacetown I tried something like that: instead of running
I tried using:
but it fails as well - I think the coverage.json file contains wrong source file paths and thus the html output generator will keep looking for the wrong source files also in this case. |
I've created a test, there you can see the commands and from which directory the have to be called. |
Hi @Spacetown ,
Sorry it's not clear to me what you mean. You're saying that I should invoke gcovr in every single subfolder of my project that contains source code? that's going to be quite cumbersome... also I think that --html-details should work out of the box in a single run, without the need to combine together multiple --json output files, right? Also gcov >= 9.1 has a "current_working_directory" JSON entry in gcov JSON output (https://gcc.gnu.org/onlinedocs/gcc/Invoking-Gcov.html#Invoking-Gcov) that could be used to avoid such issue, right?
But just to understand: in your feature branch you did not change gcovr internal path handling but just added a test to show that gcovr works if it's invoked multiple times from different folders, right? Thanks!! |
Not in each source directory. You have to call gcovr for each executable from a common base directory giving the root directory used for compiling the executable.
We use the text output and support also old versions of gcc. At work we use 4.5 and 4.8.
Yes |
I'm also hitting the same issue. Any tips how to overcome this? |
@ribtoks Run gcovr in the same directory than GCC. The |
@Spacetown Thanks for the suggestion, but it does not work. I have a following codebase structure:
When I'm running
Note: missing After I try: Of course it's not found, it's missing |
6D40
Sorry, |
@Spacetown , |
@ribtoks Yes, you have to run gcovr for each directory in the src directory and generate a trace file. This trace files can be merged together with a separate call. Or can you configure qmake to keep the working directory? |
@Spacetown No, I doubt I can tweak |
For anybody looking for solution in future: I did not come up with anything convenient. Manually searching for correct directories (with |
@ribtoks Do you have a solution how to guess the correct working directory of the Line 196 in c0f1da2
|
@Spacetown no, this I don't know. But maybe you can use a file search from root directory and hope that there will be no similarly named files in the same file tree. It does not necessarily have to be a solution that covers 100% of cases of everybody. If it would cover 90%, already would make life better for many people. |
I've prepared a quick test branch (https://github.com/Spacetown/gcovr/tree/recursive_search_file), please can you check if this is working? |
@Spacetown My gcovr setup runs in CI/CD. I will try your branch, but it will take me a bit to replicate the setup locally. Thanks a lot for your help and prompt changes! I will be back sometime soon. |
I just added Is |
@blackliner Yes, GCC creates .gcno files along the .o object files. Information in the .gcno is used to associate coverage data with source code locations. Changing the location of these files will break gcov/gcovr, though it might be possible to work around some of the issues with gcov's “cross-profiling” feature (aka GCOV_PREFIX). See also #481 (comment). |
But I did not change any location, just Ah, you mean that could lead to a different invocation of |
Seems my issue relates to ccache/ccache#219 |
We just hit this bug too. The weird thing is that it happened by updating CMake 3.20 to 3.22. We use CMake and ninja to instrument the compiler to generate coverage information and then call gcovr. With CMake 3.20, --html-details works fine. With CMake 3.22, we get the same error, because gcov is looking for cpp files in the build tree instead of the source tree. The --root option is correctly set but this doesn't help. It is still a mistery why the bug is triggered. |
@ocroquette Which version of gcovr are you using? |
Hi @Spacetown I can reproduce the issue with 4.2 and 5.0 |
In cmake 3.21 there is one change mentioned which maybe change the behaviour of
If you use latest master branch, can you upload the build log where |
Canc you try the LATEST master branch because we changed with #525 the heuristic to find the correct working director. See #525 (comment) for details. |
Quick update...
Related CMake changes:
I cannot send a log file for now sorry, I need to create a minimal example without internal information first. |
Is it possible to strip the log to the gcov file which reference the file which isn't found? Maybe you can also send the file via mail if this is possible for you. You can also try the option |
@Spacetown I sent the log files to your GMX address. -fprofile-abs-path does not help, gcovr still fails with the same error. |
@Spacetown found the issue. We were setting "--source-prefix" without a good reason, which, combined with the CMake update, led to the issue. Everything is fine without "--source-prefix", even with 4.2. Now I wonder if this Github issue should still be open? |
Can this be checked with the branch of #597? |
No progress for a while. If the problem persist, please reopen. |
Hello @Spacetown, I think I face the same or a very similar problem on Windows using Cygwin for my catch2 UnitTests.
I run It searches for the source files in this directory: How to tell gcovr which dir it should use? |
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I have a problem with the --html-details options. It seems like gcovr tries to search for sources inside the build dir.
Here is my dir structure:
the build dir is inside the src/ dir
gcda and gcno files are located inside src/build/debug/{lib|test}
with --html-details options, gcovr seems to search for source files inside src/build/debug/{lib|test}.
I have the following exception:
the command line run from root/:
'''
gcovr.exe --html --html-details -r . -o coverage.html --gcov-executable /c/Qt/Tools/mingw730_32/bin/gcov.exe -v
'''
Can you please help with this ?
Thanks
The text was updated successfully, but these errors were encountered: