[Scons-users] Per target env variables

Petteri Hintsanen petterih at iki.fi
Mon Sep 10 08:39:45 EDT 2018


On Wed, Sep 05, 2018 at 11:57:38PM -0400, Bill Deegan wrote:
> Here's the caveat.
> Don't make a gazillion Clone's they're not lightweight.
> If you make 100, it won't kill you, if you make 1000's you may start seeing
> memory and speed impacted.

This is news to me.  I have always thought that cloning is relatively
cheap.

We use simple wrappers around standard SCons functions Library and
Program to simplify dependency handling, mostly for linking against
static libraries and importing packages via pkg-config.  Greatly
simplified, it looks something like this:

link_envs = []

def build_bin(env, target, sources, libs, pkgs):
    # Import packages
    if pkgs:
        env = env.Clone()
        # use pkg-config to bring CFLAGS into env 
        # and append pkg-config --libs into libs
        import_pkgs(env, pkgs, libs)

    # Compile
    objs = env.StaticObject(sources)

    # Link
    link_env = env
    if libs:
        link_env = env.Clone()
        link_envs.append([link_env, libs])

    program = link_env.Program(target, objs)

link_envs contain all (cloned) environments that have link-time
dependencies.  They are augmented by link_env.Append(LIBS = ...)
after all SConscripts have been read, so that programs will be linked
against libraries they depend on.  [To do that we use a dictionary
which maps between strings and Library nodes (we refer to libraries
by their names, ie.  strings).]

This is done after all SConscritps have been read because that way we
do not need to worry about the evaluation order of various
SConscripts which define the said libraries.  Nor do we need to
Export("mylib") in SConscript that builds "mylib" or Import("mylib")
in SConscripts that refer to "mylib".

But in this scheme we clone a lot.  Maybe this is too heavyweight?

Regards,
Petteri


More information about the Scons-users mailing list