[Scons-users] Changing VariantDir in an SConscript file
Luke Tunmer
luke.tunmer at gmail.com
Tue Nov 16 05:19:23 EST 2021
Thanks Bill, that's quite helpful.
I have done it this way (with some attempts to minimise typing), which
seems to work:
Import('env')
env_A = env.Clone()
env_A.Append(VDIR='A')
env_A.Append(CCFLAGS=' -DVAR_A')
env_A.VariantDir('A', '.', duplicate=0)
env_B = env.Clone()
env_B.Append(VDIR='B')
env_B.Append(CCFLAGS=' -DVAR_B')
env_B.VariantDir('B', '.', duplicate=0)
subsystem1_A = env_A.Library('$VDIR/subsystem1_A', ['$VDIR/src/common.c',
'src/impl_A.c'])
subsystem1_B = env_B.Library('$VDIR/subsystem1_B', ['$VDIR/src/common.c',
'src/impl_B.c'])
I use an env var to make it more straightforward. The files that do not
need to be built two ways can just be listed by their source location. This
is actually a good practice - engineers should know which of their source
files are affected by the variant (i.e. use the VAR_A or VAR_B definitions
in this idealized example), and be able to mark them in the SConscript file.
I will wrap some more abstractions around this to make the idea clear to my
engineers how they manage local variants within their subsystems and
libraries. The bigger picture here is that these two libraries are linked
into two different elf files which are targeted at two different cores
within the SOC, and they should both be built in a single run of SCons.
This is done in a parent SConscript.
Seems to all work, so thanks again.
Regards,
Luke
On Mon, 15 Nov 2021 at 16:38, Bill Deegan <bill at baddogconsulting.com> wrote:
> Luke,
>
> VariantDir()'s seem to be one of the harder to grasp concepts in SCons so
> you're in good company.
> Assuming your Library() statements are in the same SConscript, you'd need
> to change them as follows
>
> lib_A = env_A.Library('Build/A/lib_A', ['Build/A/src/common.c', 'Build/A/
> src/impl_A.c'])
> lib_B = env_B.Library('Build/B/lib_B', ['Build/A/src/common.c', 'Build/A/
> src/impl_B.c'])
>
> Just adding a VariantDir() to an Environment() doesn't do anything to any
> builders you use with that environment.
>
> All you're doing with any VariantDir() statement is telling SCons that for
> example Build/A should be treated as if it was '.'.
> So any files you reference relative to Build/A, if they don't exist in
> Build/A, SCons should also look in .
>
> So for Build/A/src/common.c SCons should first look at that location, then
> it should look at ./src/commmon.c
>
> Is that any clearer?
> -Bill
>
>
> On Mon, Nov 15, 2021 at 9:54 AM Luke Tunmer <luke.tunmer at gmail.com> 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.
>>
>> My top level SConstruct file started the ball rolling with a variant_dir
>> that encapsulates all the different configurations that this system can be
>> built to ensure each configuration is built into a unique build folder
>> location (I turn duplicate off).
>>
>> Deep down in the tree in a particular SConscript file I need to compile
>> some C files two different ways which target the C compiler optimizer for
>> the particular CPU on which it will run (the embedded system is a multicore
>> one with at least 5 different CPU types). Some of these C files will be
>> running on different cores.
>>
>> I thought I could clone the environment two ways and modify the
>> VariantDir of each:
>>
>> Import('env')
>>
>> env_A = env.Clone()
>> env_A.VariantDir('build/A', '.', duplicate=0)
>> # add various CC flags to env_A
>>
>> env_B = env.Clone()
>> env_B.VariantDir('build/B', '.', duplicate=0)
>> # add different CC flags to env_B
>>
>> And then I would like to be able to specify the two different libraries
>> that need to be built at this level in the tree:
>>
>> lib_A = env_A.Library('lib_A', ['src/common.c', 'src/impl_A.c'])
>> lib_B = env_B.Library('lib_B', ['src/common.c', 'src/impl_B.c'])
>>
>> and then common.c will be compiled two ways into different build folders,
>> and the appropriate one included in each library. However, the change to
>> the VariantDir of each environment seems to make no difference at all: it
>> uses the build folder specified right at the top of the tree for both the
>> .o files and for the .lib files that it makes.
>>
>> Any help in my understanding of how VariantDir is supposed to work, and
>> what it is actually doing is appreciated. Or, of course, any information on
>> the proper way to achieve this result would be great.
>>
>> Regards,
>> Luke
>>
>> _______________________________________________
>> Scons-users mailing list
>> Scons-users at scons.org
>> https://pairlist4.pair.net/mailman/listinfo/scons-users
>>
> _______________________________________________
> 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/20211116/51ccd594/attachment.htm>
More information about the Scons-users
mailing list