[Scons-users] What is the best approach with SConstruct calling SConscript

Bill Deegan bill at baddogconsulting.com
Thu Nov 3 23:13:52 EDT 2016


On Thu, Nov 3, 2016 at 4:40 PM, Pierre-Luc Boily <pierreluc.boily at gmail.com>
wrote:

> I have a philosophical question.
>
> How should I call my 160 SConscript?
>
> 1 - Call all 160 one by one, hard-coded?
> 2 - Have a function that find them and iterate over it?
>

Whichever works best for you...


>
> Right now, we are using idea number 2, it looks like that :
>
> |def buildSpeech(common_env):
> |    ListOfSConscriptFiles, ListOfRelativePaths = findAllSconscriptFiles()
> |    i = 0
> |    for file in ListOfSConscriptFiles:
> |        variantDir =  os.path.join(common_env['ENV']['VARIANTDIRROOT'],
> ListOfRelativePaths[i][2:], common_env['ENV']['CONFIG'])
> |        sconsScript = os.path.join(ListOfRelativePaths[i], file)
> |        SConscript(sconsScript, {'common_env' : common_env},
> variant_dir=variantDir, duplicate=0)
> |        i = i+1
> |
> |common_env = environmentCreator.EnvironmentCreator().get_env()
>
> But soon, I will need other environments.  I might need to do something
> line
> this :
>
> |def buildSpeech(common_env):
> |    ListOfSConscriptFiles, ListOfRelativePaths = findAllSconscriptFiles()
> |    i = 0
> |    for file in ListOfSConscriptFiles:
> |        variantDir =  os.path.join(win32_env['ENV']['VARIANTDIRROOT'],
> ListOfRelativePaths[i][2:], win32_env['ENV']['CONFIG'])
> |        sconsScript = os.path.join(ListOfRelativePaths[i], file)
> |        SConscript(sconsScript,
> |                   {'win32_env' : win32_env, 'win64_env' : win64_env,
> 'java_env' : java_env},
> |                   variant_dir=variantDir,
> |                   duplicate=0)
> |        i = i+1
> |
> |win32_env = environmentCreator.EnvironmentCreator('win32')
> |win64_env = environmentCreator.EnvironmentCreator('win64')
> |java_env = environmentCreator.EnvironmentCreator('java')
>
> I can cleary see a problem with this approach with my variantDir not
> correct
> for all environment.  There is 2 solutions:
> a - List manually all SConscript and passing them the correct varianDir and
> correct environment.  Like this :
>
> |        variantDir =  os.path.join(win32_env['ENV']['VARIANTDIRROOT'],
> other_path, win32_env['ENV']['CONFIG'])
> |        SConscript(sconsScriptA, {'env' : win32_env},variantDir,0)
> |        variantDir =  os.path.join(win64_env['ENV']['VARIANTDIRROOT'],
> other_path, win64_env['ENV']['CONFIG'])
> |        SConscript(sconsScriptA, {'env' : win64_env},variantDir,0)
>
> b - Still  iterate over all of them like before, but set the variantDir
> inside the SConscript (but I see somewhere else that it is not recommended
> to set variantDir inside SConscript)
>
> Which approach should I favor?
>

It really depends on what's going to be easiest for you to maintain.
If you know all subdirs of a given tree are win32, and another are win64,
perhaps you can still find all the SConscripts under those trees and loop
through them as appropriate.

How do you know now which SConscripts need which variantdir and
Environment()?


>
> One last thing.  I would like to create my environment like this :
>
> |win32_env = environmentCreator.EnvironmentCreator('win32')
>
> Doing this means that EnvironmentCreator has to inheritate from
> SCons.Environement (Or SCons.Base, I am not sure)
>
> Can I do this?  If yes, from which class should I need to inherit?
>

Why would it need to inherit from Environment?
It only has to return an Environment().
No need to inherit from it.

Also, why use env['ENV']['YOUR_VARIABLE_HERE'], instead of
env['YOUR_VARIABLE_HERE'] ?

-Bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20161103/e3483ea2/attachment-0001.html>


More information about the Scons-users mailing list