[Scons-users] Changing VariantDir in an SConscript file

Mats Wichmann mats at wichmann.us
Mon Nov 15 15:44:03 EST 2021


On 11/15/21 07:54, Luke Tunmer wrote:
> Hi all,
> 
> I'm trying to understand why calling VariantDir on my environment within 
> an SConstript file doesn't do what I thought it would. I suspect it's my 
> understanding that is broken, and if so, I'm looking for advice for how 
> to do this properly.

To pile on to what Bill said: the mental model is variant directories 
are "an alternate place to build", not "a place where build artifacts 
go" - yes they're different.  Your subsidiary SConscript that tries to 
understand multiple build flavors is going to get called once for each 
build, so your logic isn't going to be "set up for A, then set up for B" 
but "set up for this build" but with some kind of awareness of which 
build it is.  You can pass information down which tells you which build 
it is, or you can do something like in this example from the docs (using 
the usually-preferred variant_dir kwarg instead of the VariantDir function):

opts = { 'CPPDEFINES' : ['DEBUG'], 'CCFLAGS' : '-pgdb' }
SConscript('src/SConscript', variant_dir='debug', duplicate=0, exports=opts)
opts = { 'CPPDEFINES' : ['NODEBUG'], 'CCFLAGS' : '-O' }
SConscript('src/SConscript', variant_dir='prod', duplicate=0, exports=opts)

And the called SConscript does

Import("opts")

If you expect to do all the builds in a single SCons run you have to be 
pretty careful about keeping the environments straight.  The place I 
dealt with such a setup we drove our CI with a script which built the 
different flavors sequentially and kind of dodged that concern, as in

scons {args} linux
scons {args} linux_unsecured
scons {args} linux_with_java
scons {args} android_universal
etc.


Somehow this mental model isn't particularly intuitive. Past generations 
of SCons developers have spent hours of effort writing up explanations - 
you can find some of these on the wiki, often festooned with another 
developer's comment "this isn't quite right", "it's confusing to also 
mention X", "it's incomplete if you don't mention Y".  Sorry about that...

Feel free to ask further!



More information about the Scons-users mailing list