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

Gabe Black gabe.black at gmail.com
Mon Jul 26 18:12:46 EDT 2021

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

> On 7/25/21 9:05 AM, Gabe Black wrote:
> > 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().
> I think that's just an ordering thing, as the substitution is done when
> this line runs, not when SCons actually performs the build... if you
> move the Append above the Object call does it change?

I suspect it would, but unfortunately that order doesn't really fit with
the structure of our SConscripts. One aspect of that (but not the only) I
mentioned in another thread, where we have several environments with
different options for different flavors of builds, and we want to build
different object files from the same .cc for each. If we moved the Append
above the Object, then we would create one of those environments, and if we
did that for each environment symmetrically, then we'd need to (as far as I
can see) call Object for each of those environments one after the other,
rather than just the once.

> By the way, normally it's suggested to use CPPDEFINES for preprocessor
> macros (where you don't include the -D, SCons will fill that in for the
> target compiler) instead of CCFLAGS.

Yep, I just defaulted to CCFLAGS as something easy to change, and -DFOO as
a flag I could see in the command line but which would otherwise have no
effect. In a "real" SConscript I'd use CPPDEFINES :-).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20210726/547af593/attachment.htm>

More information about the Scons-users mailing list