[Scons-users] Transparently interposing on builders?

Andrew C. Morrow andrew.c.morrow at gmail.com
Mon Jul 21 14:25:39 EDT 2014


I'm interested in understanding better how to properly and transparently
interpose on Program, SharedLibrary, and other builders, such that the
interposed builders still appear to be 'real' builders (e.g. one could
access the 'target_scanner' of the interposed builder, and get the scanner
of the underlying builder).

Furthermore, I want these interposed builders to be able to be stacked
arbitrarily deep and retain the above property.

The approach documented here http://scons.org/wiki/MsvcIncrementalLinking
has some fragility w.r.t. naming, and the resulting Program builder does
not respond properly to attribute requests.

Is it possible to wrap and stack builders? One thought was to use the
SCons.Util.Proxy class, but I could not get it to work properly. My attempt
was as follows:

def PushBuilder(env, builderName, BuilderType):
    baseBuilder = env['BUILDERS'][builderName]
    newBuilder = BuilderType(env, baseBuilder)
    env['BUILDERS'][builderName] = newBuilder
env.AddMethod(PushBuilder, 'PushBuilder')

class LoggingProgramBuilder(SCons.Util.Proxy):
    def __init__(self, env, base_builder):
        SCons.Util.Proxy.__init__(self, base_builder)
        self.base_builder = base_builder

    def __call__(self, env, target, source, **kwargs):
        print("Running 'Program'")
        result = self.base_builder(env, target, source, **kwargs)
        print("Finished running 'Program'")
        return result

env.PushBuilder('Program', LoggingProgramBuilder)

This sort of worked, in that the resulting builder appeared to still expose
the attributes of the underlying builder, but at build time something was
clearly very broken, since the build skipped directly to attempting to link
the program without first compiling its dependent .o files.

My motivation here is that I want to be able to write SConscript files
normally, using the names Program, SharedLibrary, etc. but I want to be
able to conditionally inject several other behaviors into the meaning of
those terms, in complex ways depending on build options.

What is the proper way to transparently interpose on builders?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://four.pairlist.net/pipermail/scons-users/attachments/20140721/2747b0df/attachment.html>


More information about the Scons-users mailing list