[Scons-users] Per target env variables

Hua Yanghao huayanghao at gmail.com
Mon Sep 10 10:40:34 EDT 2018


Not sure how Object(CFLAGS = old + new) is handled, but I have
verified that definitely going to customize for each and every object,
and no clash seen.
If this, behind the scene is also using a Clone() somehow I starts to
understand why my build startup is a bit slow (totally acceptable
though, e.g. for a build that creates 22 different target, a few
hundred C files each), around 9 seconds before the first build prints
on screen.
On Mon, Sep 10, 2018 at 2:40 PM Petteri Hintsanen <petterih at iki.fi> wrote:
>
> 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
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users


More information about the Scons-users mailing list