[Scons-users] Overriding Object to force global dependency

Pawel Tomulik ptomulik at meil.pw.edu.pl
Fri Jun 29 06:32:46 EDT 2012


W dniu 27.06.2012 19:04, Greg Ward pisze:

> Hi all --

>

> I want to force every single *.o file in my build to artificially

> depend on something. (We have a homebrew tool that downloads and

> unpacks specific versions of all third-party dependencies -- GCC,

> C/C++ libraries, Java libraries, etc. This tool must run first, and

> everything else should depend on its output.)

>

> The obvious thing to do is override env.Object(), but I'm not sure how

> to do that. I tried it with env.AddMethod, and that only half worked.

> Here's my override:

>

> _Object = env.Object

> def Object(env, *args, **kwargs):

> global _Object, dummy

> print('Object override: args=%s' % map(str, args))

> obj = _Object(*args, **kwargs)

> env.Depends(obj, dummy)

> return obj

>

> env.AddMethod(Object, 'Object')

>

> ('dummy' is the output of that homebrew dependency tool.)

>

> This works as long as I only ever use one env object. But as soon as I

> do

>

> env = env.Clone()

>

> it stops working. The clone has the original Object() method, not

> mine. ;-(

>

> Is there a good way to do this?

>


Hi Greg,

It may be possible to use emitter for your purpose, I think.
Dee API docs for SCons.Builder.BuilderBase, especially add_emitter()
method. Try something like:

def my_emitter(target, source, env):
env.Depends(target, 'foo.txt')
return target, source

env = Environment()

env['BUILDERS']['StaticObject'].add_emitter('.c', my_emitter)
ob = env.Object('a.c')

Regards!
--
Paweł Tomulik




More information about the Scons-users mailing list