Home > Mobile >  gcovr with Cobertura XML output gives absolute path of production files
gcovr with Cobertura XML output gives absolute path of production files

Time:07-17

I have managed to show code coverage data with Cobertura XML in Jenkins. Its works well, but I wants to see the source code in Jenkins, too. I accidentally saw, that Jenkins is referring for the source files at my windows harddrive, but the files are on a Jenkins server (different PC). This happens maybe, because in Cobertura output XML, the "filename" refers to an absolute path and not relative from directory. The XML attribute looks like filename="C:/Users/PathToMySources".

How I can change filenames in Cobertura XML to be relative?

gcovr.exe is invoked like this:

gcovr.exe --filter ../MySources/ --branches --html-details Test.html --cobertura Test.xml

My Project look like this:

MyProject
|
|---Library A (has subfolders)
|
|---Library B (has subfolders)
|
|---TestFolder for Library A and B (has subfolders)

This Layout is like this because Library A, B and Testfolders are externals in svn for sharing the library to everyone in the company. With gcovr I refered for example to Library B. In Library B, I have subfolders. Some Subfolders contains only headers because of template classes in C . Now I saw another issue. With --filter, the header only classes are included in coverage output, with --root they are not included!

CodePudding user response:

In this instance, you can fix things by changing --filter to --root.

Gcovr has a concept of a “root” directory which defaults to the current working directory. The root is used for various purposes like serving as a default filter, but also for deciding how file names are presented in reports.

  • If a file path is within the root directory, a path relative from the root directory is shown.
  • Otherwise, an absolute path is shown

It is unusual to ever see an absolute path in a gcovr report, unless you're trying to include coverage for a library outside of your project directory, or if you're using the --html-absolute-paths option.

  • Related