Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Waf from renaming object files?

Tags:

c

gcov

waf

I am using Waf to build a C project and gcov to have some test code coverage. However, Waf calls gcc in a way that produces foo.c.1.o from source file foo.c that confuses gcov when searching for the generated files:

$ gcov foo.c
$ foo.gcno:cannot open graph file

Fortunately, gcov has the -o option with which it is possible to specify the corresponding object file. Nevertheless, this is not convenient and executing lcov still fails. Therefore, my questions are:

  1. Why does Waf rename the object files?
  2. How can this behaviour be disabled or ...
  3. How can gcov/lcov work around this issue?
like image 615
matthias Avatar asked Aug 13 '12 14:08

matthias


1 Answers

You can use gcovr instead of directly running gcov.

gcovr does not rely on file name magic, but parses gcov's coverage files.
It then calls gcov with the appropriate parameters.
This works great with Waf's object file renaming.

You can run gcovr from Waf's build subdirectory:

cd build
gcovr --root=$(pwd) --keep
lcov --capture --directory $(pwd) --base-directory $(pwd) --output-file coverage.info
genhtml coverage.info --output-directory out

The --root option removes the current directory prefix
The --keep option keeps gcov's temporary files, used by lcov/genhtml.

You can also use gcovr's --xml option to produce Cobertura-compatible xml output.
It can then be used by various formatters (I use it with Jenkins' Cobertura Plugin)

like image 192
Laurent Doré Avatar answered Sep 21 '22 17:09

Laurent Doré