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

Dirk Bächle tshortik at gmx.de
Sun May 4 21:07:37 EDT 2014


On 05.05.2014 01:35, Vinnie Falco wrote:

>> 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)

Thanks a lot for the example:

1.) Your list "outputs" is empty, at least on my side. Try to add a:

outputs = base.Protoc([],
PROTOCPROTOPATH=[os.path.dirname(source)],
PROTOCOUTDIR='build',
PROTOCPYTHONOUTDIR=None)
print map(str, outputs)

env = base.Clone()

and you should see it too.


> The problem line is the call to env.Object.

2.) Correct, that's a problem. Because you're trying to pass a File
object to the os.path.join(). You'll have to use

objects = env.Object(os.path.join('build', str(outputs[0])))

instead.

3.) You're specifying "build" as the output dir for the protoc Builder.
So you get this folder prepended to the actual targets, resulting in

['build/src/test.pb.cc', 'build/src/test.pb.h']


Finally, here's a SConstruct that seems to work, based on the suggestion
by Carl Cerecke:

import os

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


Funnily, I didn't have to change anything about the VariantDir() call. ;)

Dirk



More information about the Scons-users mailing list