How to prevent Waf from renaming object files?
Asked Answered
P

2

6

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?
Plaza answered 13/8, 2012 at 14:20 Comment(0)
D
8

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)

Delacruz answered 26/2, 2013 at 12:40 Comment(2)
This was really tricky to get working despite the clear answer. Apparently there's a bug in the master revision of gcovr that causes it to read each character of the --root argument as a separate path in a list. So given that $(pwd) starts with '/' it begins by searching your entire filesystem for .gcno files and hangs. I changed line 1828 where it calls get_datafiles to pass "[options.root]" instead and got it to work.Sech
@Sech The "[options.root]" bug is fixed in gcovr 3.2.Veronique
S
0

Have you tried modifying Waf's configuration with something like

bld.program(
  obj_ext  = '.o',
  source   = 'test.c',
  target   = 'test1')
Shiksa answered 13/8, 2012 at 14:43 Comment(2)
Anyway, from Waf's F.A.Q : Q: why does foo.cpp compile to foo.cpp.<n>.o where <n> is some number? A: else the same files might be compiled in different contexts and overwritten Shiksa
Unfortunately, adding obj_ext does not help. But thanks for pointing me to the unsatisfactory explanation from the FAQ (I wonder why they didn't include this important information in the Waf book).Plaza

© 2022 - 2024 — McMap. All rights reserved.