[Scons-dev] Tool initialization is called twice

anatoly techtonik techtonik at gmail.com
Wed May 28 03:39:20 EDT 2014


Hi,

I found that SCons calls tool initialization twice for this simple
SConstruct:

    env = Environment()
    env.Program(target='flite', source=[])

Double check is an obvious performance killer.
Here is the log with inserted print for call stack in one of the default
tools.

---[cut]---------------------------------------------------------------------
E:\flite>E:\scons\src\script\scons.py
scons: Reading SConscript files ...
False
['E:\\scons\\src\\script\\scons.py:199(<module>)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Script\\Main.py:1361(main)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Script\\Main.py:1324(_exec_main)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Script\\Main.py:994(_main)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Script\\SConscript.py:260(_SConscript)',
 'E:\\flite\\SConstruct:1(<module>)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Environment.py:1003(__init__)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Environment.py:107(apply_tools)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Environment.py:1787(Tool)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Tool\\__init__.py:183(__call__)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Tool\\default.py:41(generate)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Tool\\__init__.py:183(__call__)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Tool\\mslink.py:303(generate)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Tool\\MSCommon\\vc.py:375(msvc_setup_env_once)']

scons: warning: No version of Visual Studio compiler found - C/C++
compilers most likely not set correctly
File "E:\flite\SConstruct", line 1, in <module>
scons: done reading SConscript files.
False
['E:\\scons\\src\\script\\scons.py:199(<module>)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Script\\Main.py:1361(main)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Script\\Main.py:1324(_exec_main)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Script\\Main.py:1034(_main)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Defaults.py:88(DefaultEnvironment)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Environment.py:1003(__init__)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Environment.py:107(apply_tools)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Environment.py:1787(Tool)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Tool\\__init__.py:183(__call__)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Tool\\default.py:41(generate)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Tool\\__init__.py:183(__call__)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Tool\\mslink.py:303(generate)',
 'E:\\scons\\src\\script\\..\\engine\\SCons\\Tool\\MSCommon\\vc.py:375(msvc_setup_env_once)']

scons: warning: No version of Visual Studio compiler found - C/C++
compilers most likely not set correctly
File "E:\scons\src\script\scons.py", line 199, in <module>
scons: Building targets ...
link /nologo /OUT:flite.exe
'link' is not recognized as an internal or external command,
operable program or batch file.
scons: *** [flite.exe] Error 1
scons: building terminated because of errors.
---[cut]---------------------------------------------------------------------


The Environment constructor is called twice, and hence tool
initialization too. Guilty lines are SCons.Script.Main:994 and
SCons.Script.Main:1034

    progress_display("scons: Reading SConscript files ...")

    start_time = time.time()
    try:
        for script in scripts:
994:        SCons.Script._SConscript._SConscript(fs, script)
    except SCons.Errors.StopError, e:
        ...
    if not options.help:
 1034:
SCons.SConf.CreateConfigHBuilder(SCons.Defaults.DefaultEnvironment())


So far I see two ways to fix this:
1. Environment should explicitly invoke DefaultEnvironment somehow
    (this way DefaultEnvironment will be invoked during "Reading SConscript
     files..." phase - in _SConscript._SConscript)

    I am actually puzzled why Environment call completely skips
    DefaultEnvironment settings.

2. Cache tool discovery phase. This needs to be optional, so that people who
    rely on setting up paths to their tools in SConstruct files can prevent
this
    caching.

-- 
anatoly t.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/scons-dev/attachments/20140528/b5a7d34b/attachment.html>


More information about the Scons-dev mailing list