[Scons-users] persistent but local tweaks to a node's environment

Gabe Black gabe.black at gmail.com
Sun Jul 25 11:05:17 EDT 2021


Sure. Here is an example SConstruct I was playing with:

'''
env = Environment()

foo_o = env.Object('foo.c', CCFLAGS='${CCFLAGS} -DFOO=foo')

env.Append(CCFLAGS=['-DBAR=bar'])
foo = env.Program('foo', foo_o)

Default(foo)
'''

When that builds foo.o, it always uses -DFOO=foo, and never -DFOO=bar, so
the env.Append line seems to be clobbered by the override in env.Object().

Thinking about what you said though, I tried a little experiment which
seemed to work more like what I would expect

'''
env = Environment()

env.Append(CCFLAGS=['${CCFLAGS_extra}'])
foo_o = env.Object('foo.c', CCFLAGS_extra='-DFOO=foo')

env.Append(CCFLAGS=['-DBAR=bar'])
foo = env.Program('foo', foo_o)

Default(foo)
'''

With that I get both -DFOO=bar and -DFOO=foo. I can probably work with that
since everything I'd need to add is local to env.Object, and I might even
be able to wrap it in something to make it a little less cumbersome.

Related to this, I know you can override a variable using FOO='bar' in a
builder, but is there a way to Append? I usually want to, for instance, add
extra compiler flags without clobbering everything that's already there.
That's what I was *hoping* to achieve with the CCFLAGS='${CCFLAGS} ...',
but I don't think that's what it ended up doing!

Gabe

On Sun, Jul 25, 2021 at 6:52 AM Mats Wichmann <mats at wichmann.us> wrote:

> On 7/24/21 4:18 AM, Gabe Black wrote:
> > Hi! The project I work on builds several different versions of its
> > outputs, like a debug version, an optimized version, etc. Also, some
> > files in the project, for instance automatically generated files, need
> > to have slightly customized build flags, like disabling certain warnings
> > that are false positives and/or are in source we can't change.
> >
> > Right now we handle that by creating an environment for each build,
> > which I think is the standard approach. Unfortunately, we then have to
> > have a separate step which goes through and generates new environments
> > based on those for each file that needs its slightly customized build
> flags.
> >
> > What I would *like* to do, is to be able to specify for any given node
> > that it should build using the flags that would be implied by the
> > environment that's pulling it in, except that they should be tweaked
> > just a little bit. Something like:
> >
> > Object('foo.cc', '-Wno-deprecated-copy')
> >
> > and then:
> >
> > opt.Program('foo.opt', 'foo.cc', CCFLAGS='${CCFLAGS} -O3')
> > debug.Program('foo.debug', 'foo.cc', CCFLAGS='${CCFLAGS} -g',
> > OBJSUFFIX='.do')
> > etc
> >
> > and then have foo.do build with "-Wno-deprecated-copy -g", and foo.o
> > build with "-Wno-deprecated-copy -O3"
> >
> > The problem is, that as soon as I tell SCons to use custom variables, it
> > Clone-s the underlying environment and disassociates from the underlying
> > environment.
>
> could you explain what you're seeing a little further?
>
> In the case of construction variable overrides in a builder call, it
> doesn't Clone, as that's considered expensive, it just builds an
> override dictionary, and it doesn't disassociate - it retains the
> underlying construction environment and only applies the override dict
> if there were any overrides - so it's supposed to be a kind of
> copy-on-write setup.  Since this doesn't seem to match what you're
> seeing it would be good to figure out what's actually happening.
>
>
>
>
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20210725/95dadc67/attachment.htm>


More information about the Scons-users mailing list