[Scons-users] SCons code generation (e.g. protobuf) and VariantDir

Vinnie Falco vinnie at ripple.com
Sun May 4 19:35:39 EDT 2014



> Maybe you can help out with a simple, self-contained example, that

> demonstrates how things go wrong?


base = Environment(tools=['default', 'protoc'])
source = os.path.join('src', 'test.proto')
outputs = base.Protoc([],
PROTOCPROTOPATH=[os.path.dirname(source)],
PROTOCOUTDIR='build',
PROTOCPYTHONOUTDIR=None)
env = base.Clone()
env.VariantDir('build', 'src')
objects = env.Object(os.path.join('build', outputs[0])) # Problem
env.Default(objects)

You will need
build/
src/test.proto
The protoc.py which contains the protobuf Builder (in site_scons)

The problem line is the call to env.Object. It passes
'build/test.pb.cc' which is what you normally do when using
VariantDirs. But SCons can't figure out that in order to build that
derived file it has to run protoc. Oddly, when the implicit dependency
scanner sees that file it does know how to build it. You can
demonstrate this by creating a .cpp file that has #include
"test.pb.cc" in it and adding the .cpp to the build. SCons finds
test.pb.cc as an implicit dependency and with a tree dump you will see
both the .proto and the protoc executable as children in the
dependencies.


More information about the Scons-users mailing list