A few months ago, I encountered an issue with Scons and the SubstInFile2 tool. When it is used in a variant dir, when the emitter is called, the variant dir is not yet populated. Unfortunately, the emitter tries to open the file in the variant dir, so this does not work.

The only thing to do is to use the source node in the emitter instead of the variant node. So line 112:

keys = subst_keys(str(s.srcnode()))

And this is it!