Buildd-setup faffing around with __FILE__ breaks my unit tests.

Sune Vuorela sune at debian.org
Sat Feb 9 18:54:16 GMT 2019


(Please keep me CC'ed. Not subscribed)

The latest incarnations of the reproducible build  autobuilder setup passes 
some options to gcc to not let __FILE__ actualy be the full file path, but some 
relative path.

This breaks at least some of my unit tests.

In this case, it is src:kookbook, but they are as such not doing anything 
magical. Just using Qt's QFINDTESTDATA macro, which I will explain in a moment 
how it is put together.

A relevant file structure could look like:
footest.cpp
data/file1

and then in the relevant place in footest.cpp do
QString filepath = QFINDTESTDATA("data/file1");

(and open the filepath and do whatever)

What QFINDTESTDATA in this case does behind the scene is, in pseudocode,

#define QFINDTESTDATA(filename) basedir(__FILE__) + filename
(It is a bit more convoluted than this, but this is the important part of it)

All of this is combined with a out-of-tree build, meaning that if __FILE__ 
isn't a absolute path any longer, these tests starts to fail.


Note that this is unit tests, so recording the source file path into the 
executable is not going to give reproducibility issues for shipped files.

So, how to ensure that unit tests still works and can load test data placed 
next to the sources?

My suggestion is to not change the meaning of __FILE__ and instead fix the 
programs that uses __FILE__ for something they shouldn't.

/Sune
-- 
I didn’t stop pretending when I became an adult, it’s just that when I was a 
kid I was pretending that I fit into the rules and structures of this world. 
And now that I’m an adult, I pretend that those rules and structures exist.
   - zefrank





More information about the Reproducible-builds mailing list