28.2. What's in That Construction Environment? the Dump Method

When you create a construction environment, SCons populates it with construction variables that are set up for various compilers, linkers and utilities that it finds on your system. Although this is usually helpful and what you want, it might be frustrating if SCons doesn't set certain variables that you expect to be set. In situations like this, it's sometimes helpful to use the construction environment Dump method to print all or some of the construction variables. Note that the Dump method returns the representation of the variables in the environment for you to print (or otherwise manipulate):


         env = Environment()
         print env.Dump()
    

On a POSIX system with gcc installed, this might generate:


      % scons
      scons: Reading SConscript files ...
      { 'BUILDERS': {'_InternalInstall': <function InstallBuilderWrapper at 0x700000>, '_InternalInstallAs': <function InstallAsBuilderWrapper at 0x700000>},
        'CONFIGUREDIR': '#/.sconf_temp',
        'CONFIGURELOG': '#/config.log',
        'CPPSUFFIXES': [ '.c',
                         '.C',
                         '.cxx',
                         '.cpp',
                         '.c++',
                         '.cc',
                         '.h',
                         '.H',
                         '.hxx',
                         '.hpp',
                         '.hh',
                         '.F',
                         '.fpp',
                         '.FPP',
                         '.m',
                         '.mm',
                         '.S',
                         '.spp',
                         '.SPP',
                         '.sx'],
        'DSUFFIXES': ['.d'],
        'Dir': <SCons.Defaults.Variable_Method_Caller object at 0x700000>,
        'Dirs': <SCons.Defaults.Variable_Method_Caller object at 0x700000>,
        'ENV': { 'PATH': '/usr/local/bin:/opt/bin:/bin:/usr/bin'},
        'ESCAPE': <function escape at 0x700000>,
        'File': <SCons.Defaults.Variable_Method_Caller object at 0x700000>,
        'HOST_ARCH': None,
        'HOST_OS': None,
        'IDLSUFFIXES': ['.idl', '.IDL'],
        'INSTALL': <function copyFunc at 0x700000>,
        'LIBPREFIX': 'lib',
        'LIBPREFIXES': ['$LIBPREFIX'],
        'LIBSUFFIX': '.a',
        'LIBSUFFIXES': ['$LIBSUFFIX', '$SHLIBSUFFIX'],
        'MAXLINELENGTH': 128072,
        'OBJPREFIX': '',
        'OBJSUFFIX': '.o',
        'PLATFORM': 'posix',
        'PROGPREFIX': '',
        'PROGSUFFIX': '',
        'PSPAWN': <function piped_env_spawn at 0x700000>,
        'RDirs': <SCons.Defaults.Variable_Method_Caller object at 0x700000>,
        'SCANNERS': [],
        'SHELL': 'sh',
        'SHLIBPREFIX': '$LIBPREFIX',
        'SHLIBSUFFIX': '.so',
        'SHOBJPREFIX': '$OBJPREFIX',
        'SHOBJSUFFIX': '$OBJSUFFIX',
        'SPAWN': <function spawnvpe_spawn at 0x700000>,
        'TARGET_ARCH': None,
        'TARGET_OS': None,
        'TEMPFILE': <class 'SCons.Platform.TempFileMunge'>,
        'TEMPFILEPREFIX': '@',
        'TOOLS': ['install', 'install'],
        '_CPPDEFFLAGS': '${_defines(CPPDEFPREFIX, CPPDEFINES, CPPDEFSUFFIX, __env__)}',
        '_CPPINCFLAGS': '$( ${_concat(INCPREFIX, CPPPATH, INCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)',
        '_LIBDIRFLAGS': '$( ${_concat(LIBDIRPREFIX, LIBPATH, LIBDIRSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)',
        '_LIBFLAGS': '${_concat(LIBLINKPREFIX, LIBS, LIBLINKSUFFIX, __env__)}',
        '__RPATH': '$_RPATH',
        '_concat': <function _concat at 0x700000>,
        '_defines': <function _defines at 0x700000>,
        '_stripixes': <function _stripixes at 0x700000>}
      scons: done reading SConscript files.
      scons: Building targets ...
      scons: `.' is up to date.
      scons: done building targets.
    

On a Windows system with Visual C++ the output might look like:


      C:\>scons
      scons: Reading SConscript files ...
      { 'BUILDERS': {'_InternalInstall': <function InstallBuilderWrapper at 0x700000>, 'Object': <SCons.Builder.CompositeBuilder object at 0x700000>, 'PCH': <SCons.Builder.BuilderBase object at 0x700000>, 'RES': <SCons.Builder.BuilderBase object at 0x700000>, 'SharedObject': <SCons.Builder.CompositeBuilder object at 0x700000>, 'StaticObject': <SCons.Builder.CompositeBuilder object at 0x700000>, '_InternalInstallAs': <function InstallAsBuilderWrapper at 0x700000>},
        'CC': 'cl',
        'CCCOM': <SCons.Action.FunctionAction object at 0x700000>,
        'CCFLAGS': ['/nologo'],
        'CCPCHFLAGS': ['${(PCH and "/Yu%s \\"/Fp%s\\""%(PCHSTOP or "",File(PCH))) or ""}'],
        'CCPDBFLAGS': ['${(PDB and "/Z7") or ""}'],
        'CFILESUFFIX': '.c',
        'CFLAGS': [],
        'CONFIGUREDIR': '#/.sconf_temp',
        'CONFIGURELOG': '#/config.log',
        'CPPDEFPREFIX': '/D',
        'CPPDEFSUFFIX': '',
        'CPPSUFFIXES': [ '.c',
                         '.C',
                         '.cxx',
                         '.cpp',
                         '.c++',
                         '.cc',
                         '.h',
                         '.H',
                         '.hxx',
                         '.hpp',
                         '.hh',
                         '.F',
                         '.fpp',
                         '.FPP',
                         '.m',
                         '.mm',
                         '.S',
                         '.spp',
                         '.SPP',
                         '.sx'],
        'CXX': '$CC',
        'CXXCOM': '${TEMPFILE("$CXX $_MSVC_OUTPUT_FLAG /c $CHANGED_SOURCES $CXXFLAGS $CCFLAGS $_CCCOMCOM")}',
        'CXXFILESUFFIX': '.cc',
        'CXXFLAGS': ['$(', '/TP', '$)'],
        'DSUFFIXES': ['.d'],
        'Dir': <SCons.Defaults.Variable_Method_Caller object at 0x700000>,
        'Dirs': <SCons.Defaults.Variable_Method_Caller object at 0x700000>,
        'ENV': { 'PATH': 'C:\\WINDOWS\\System32',
                 'PATHEXT': '.COM;.EXE;.BAT;.CMD',
                 'SystemRoot': 'C:\\WINDOWS'},
        'ESCAPE': <function escape at 0x700000>,
        'File': <SCons.Defaults.Variable_Method_Caller object at 0x700000>,
        'HOST_ARCH': '',
        'HOST_OS': 'win32',
        'IDLSUFFIXES': ['.idl', '.IDL'],
        'INCPREFIX': '/I',
        'INCSUFFIX': '',
        'INSTALL': <function copyFunc at 0x700000>,
        'LIBPREFIX': '',
        'LIBPREFIXES': ['$LIBPREFIX'],
        'LIBSUFFIX': '.lib',
        'LIBSUFFIXES': ['$LIBSUFFIX'],
        'MAXLINELENGTH': 2048,
        'MSVC_SETUP_RUN': True,
        'OBJPREFIX': '',
        'OBJSUFFIX': '.obj',
        'PCHCOM': '$CXX /Fo${TARGETS[1]} $CXXFLAGS $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c $SOURCES /Yc$PCHSTOP /Fp${TARGETS[0]} $CCPDBFLAGS $PCHPDBFLAGS',
        'PCHPDBFLAGS': ['${(PDB and "/Yd") or ""}'],
        'PLATFORM': 'win32',
        'PROGPREFIX': '',
        'PROGSUFFIX': '.exe',
        'PSPAWN': <function piped_spawn at 0x700000>,
        'RC': 'rc',
        'RCCOM': <SCons.Action.FunctionAction object at 0x700000>,
        'RCFLAGS': [],
        'RCSUFFIXES': ['.rc', '.rc2'],
        'RDirs': <SCons.Defaults.Variable_Method_Caller object at 0x700000>,
        'SCANNERS': [],
        'SHCC': '$CC',
        'SHCCCOM': <SCons.Action.FunctionAction object at 0x700000>,
        'SHCCFLAGS': ['$CCFLAGS'],
        'SHCFLAGS': ['$CFLAGS'],
        'SHCXX': '$CXX',
        'SHCXXCOM': '${TEMPFILE("$SHCXX $_MSVC_OUTPUT_FLAG /c $CHANGED_SOURCES $SHCXXFLAGS $SHCCFLAGS $_CCCOMCOM")}',
        'SHCXXFLAGS': ['$CXXFLAGS'],
        'SHELL': None,
        'SHLIBPREFIX': '',
        'SHLIBSUFFIX': '.dll',
        'SHOBJPREFIX': '$OBJPREFIX',
        'SHOBJSUFFIX': '$OBJSUFFIX',
        'SPAWN': <function spawn at 0x700000>,
        'STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME': 1,
        'TARGET_ARCH': '',
        'TARGET_OS': 'win32',
        'TEMPFILE': <class 'SCons.Platform.TempFileMunge'>,
        'TEMPFILEPREFIX': '@',
        'TOOLS': ['msvc', 'install', 'install'],
        '_CCCOMCOM': '$CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS $CCPCHFLAGS $CCPDBFLAGS',
        '_CPPDEFFLAGS': '${_defines(CPPDEFPREFIX, CPPDEFINES, CPPDEFSUFFIX, __env__)}',
        '_CPPINCFLAGS': '$( ${_concat(INCPREFIX, CPPPATH, INCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)',
        '_LIBDIRFLAGS': '$( ${_concat(LIBDIRPREFIX, LIBPATH, LIBDIRSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)',
        '_LIBFLAGS': '${_concat(LIBLINKPREFIX, LIBS, LIBLINKSUFFIX, __env__)}',
        '_MSVC_OUTPUT_FLAG': <function msvc_output_flag at 0x700000>,
        '_concat': <function _concat at 0x700000>,
        '_defines': <function _defines at 0x700000>,
        '_stripixes': <function _stripixes at 0x700000>}
      scons: done reading SConscript files.
      scons: Building targets ...
      scons: `.' is up to date.
      scons: done building targets.
    

The construction environments in these examples have actually been restricted to just gcc and Visual C++, respectively. In a real-life situation, the construction environments will likely contain a great many more variables. Also note that we've massaged the example output above to make the memory address of all objects a constant 0x700000. In reality, you would see a different hexadecimal number for each object.

To make it easier to see just what you're interested in, the Dump method allows you to specify a specific constrcution variable that you want to disply. For example, it's not unusual to want to verify the external environment used to execute build commands, to make sure that the PATH and other environment variables are set up the way they should be. You can do this as follows:


         env = Environment()
         print env.Dump('ENV')
    

Which might display the following when executed on a POSIX system:


      % scons
      scons: Reading SConscript files ...
      { 'PATH': '/usr/local/bin:/opt/bin:/bin:/usr/bin'}
      scons: done reading SConscript files.
      scons: Building targets ...
      scons: `.' is up to date.
      scons: done building targets.
    

And the following when executed on a Windows system:


      C:\>scons
      scons: Reading SConscript files ...
      { 'PATH': 'C:\\WINDOWS\\System32',
        'PATHEXT': '.COM;.EXE;.BAT;.CMD',
        'SystemRoot': 'C:\\WINDOWS'}
      scons: done reading SConscript files.
      scons: Building targets ...
      scons: `.' is up to date.
      scons: done building targets.