28.2. What's in That Construction Environment? the `Dump` Method
Prev | Chapter 28. Troubleshooting | Next

## 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>,
                    '_InternalInstallVersionedLib': <function InstallVersionedBuilderWrapper 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:/snap/bin'},
      'ESCAPE': <function escape at 0x700000>,
      'File': <SCons.Defaults.Variable_Method_Caller object at 0x700000>,
      'HOST_ARCH': 'arm64',
      'HOST_OS': 'posix',
      'IDLSUFFIXES': ['.idl', '.IDL'],
      'INSTALL': <function copyFunc at 0x700000>,
      'INSTALLVERSIONEDLIB': <function copyFuncVersionedLib at 0x700000>,
      'LIBLITERALPREFIX': '',
      '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': [<SCons.Scanner.ScannerBase object at 0x700000>],
      'SHELL': 'sh',
      'SHLIBPREFIX': '$LIBPREFIX',
      'SHLIBSUFFIX': '.so',
      'SHOBJPREFIX': '$OBJPREFIX',
      'SHOBJSUFFIX': '$OBJSUFFIX',
      'SPAWN': <function subprocess_spawn at 0x700000>,
      'TARGET_ARCH': None,
      'TARGET_OS': None,
      'TEMPFILE': <class 'SCons.Platform.TempFileMunge'>,
      'TEMPFILEARGESCFUNC': <function quote_spaces at 0x700000>,
      'TEMPFILEARGJOIN': ' ',
      'TEMPFILEPREFIX': '@',
      'TOOLS': ['install'],
      '_CPPDEFFLAGS': '${_defines(CPPDEFPREFIX, CPPDEFINES, CPPDEFSUFFIX, __env__, '
                      'TARGET, SOURCE)}',
      '_CPPINCFLAGS': '${_concat(INCPREFIX, CPPPATH, INCSUFFIX, __env__, RDirs, '
                      'TARGET, SOURCE, affect_signature=False)}',
      '_LIBDIRFLAGS': '${_concat(LIBDIRPREFIX, LIBPATH, LIBDIRSUFFIX, __env__, '
                      'RDirs, TARGET, SOURCE, affect_signature=False)}',
      '_LIBFLAGS': '${_concat(LIBLINKPREFIX, LIBS, LIBLINKSUFFIX, __env__)}',
      '__DRPATH': '$_DRPATH',
      '__DSHLIBVERSIONFLAGS': '${__libversionflags(__env__,"DSHLIBVERSION","_DSHLIBVERSIONFLAGS")}',
      '__LDMODULEVERSIONFLAGS': '${__libversionflags(__env__,"LDMODULEVERSION","_LDMODULEVERSIONFLAGS")}',
      '__RPATH': '$_RPATH',
      '__SHLIBVERSIONFLAGS': '${__libversionflags(__env__,"SHLIBVERSION","_SHLIBVERSIONFLAGS")}',
      '__lib_either_version_flag': <function __lib_either_version_flag at 0x700000>,
      '__libversionflags': <function __libversionflags 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.

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

    C:\>scons
    scons: Reading SConscript files ...
    { 'BUILDERS': { '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>,
                    '_InternalInstall': <function InstallBuilderWrapper at 0x700000>,
                    '_InternalInstallAs': <function InstallAsBuilderWrapper at 0x700000>,
                    '_InternalInstallVersionedLib': <function InstallVersionedBuilderWrapper at 0x700000>},
      'CC': 'cl',
      'CCCOM': <SCons.Action.FunctionAction object at 0x700000>,
      'CCDEPFLAGS': '/showIncludes',
      'CCFLAGS': ['/nologo'],
      'CCPCHFLAGS': <function gen_ccpchflags at 0x700000>,
      '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","$CXXCOMSTR")}',
      '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': 'arm64',
      'HOST_OS': 'win32',
      'IDLSUFFIXES': ['.idl', '.IDL'],
      'INCPREFIX': '/I',
      'INCSUFFIX': '',
      'INSTALL': <function copyFunc at 0x700000>,
      'INSTALLVERSIONEDLIB': <function copyFuncVersionedLib at 0x700000>,
      'LEXUNISTD': ['--nounistd'],
      'LIBLITERALPREFIX': '',
      'LIBPREFIX': '',
      'LIBPREFIXES': ['$LIBPREFIX'],
      'LIBSUFFIX': '.lib',
      'LIBSUFFIXES': ['$LIBSUFFIX'],
      'MAXLINELENGTH': 2048,
      'MSVC_SETUP_RUN': True,
      'NINJA_DEPFILE_PARSE_FORMAT': 'msvc',
      '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': ['/nologo'],
      'RCSUFFIXES': ['.rc', '.rc2'],
      'RDirs': <SCons.Defaults.Variable_Method_Caller object at 0x700000>,
      'SCANNERS': [<SCons.Scanner.ScannerBase object at 0x700000>],
      '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","$SHCXXCOMSTR")}',
      'SHCXXFLAGS': ['$CXXFLAGS'],
      'SHELL': 'command',
      'SHLIBPREFIX': '',
      'SHLIBSUFFIX': '.dll',
      'SHOBJPREFIX': '$OBJPREFIX',
      'SHOBJSUFFIX': '$OBJSUFFIX',
      'SPAWN': <function spawn at 0x700000>,
      'STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME': 1,
      'TARGET_ARCH': None,
      'TARGET_OS': None,
      'TEMPFILE': <class 'SCons.Platform.TempFileMunge'>,
      'TEMPFILEARGESCFUNC': <function quote_spaces at 0x700000>,
      'TEMPFILEARGJOIN': '\n',
      'TEMPFILEPREFIX': '@',
      'TOOLS': ['msvc', 'install'],
      '_CCCOMCOM': '$CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS $CCPCHFLAGS $CCPDBFLAGS',
      '_CPPDEFFLAGS': '${_defines(CPPDEFPREFIX, CPPDEFINES, CPPDEFSUFFIX, __env__, '
                      'TARGET, SOURCE)}',
      '_CPPINCFLAGS': '${_concat(INCPREFIX, CPPPATH, INCSUFFIX, __env__, RDirs, '
                      'TARGET, SOURCE, affect_signature=False)}',
      '_LIBDIRFLAGS': '${_concat(LIBDIRPREFIX, LIBPATH, LIBDIRSUFFIX, __env__, '
                      'RDirs, TARGET, SOURCE, affect_signature=False)}',
      '_LIBFLAGS': '${_concat(LIBLINKPREFIX, LIBS, LIBLINKSUFFIX, __env__)}',
      '_MSVC_OUTPUT_FLAG': <function msvc_output_flag at 0x700000>,
      '__DSHLIBVERSIONFLAGS': '${__libversionflags(__env__,"DSHLIBVERSION","_DSHLIBVERSIONFLAGS")}',
      '__LDMODULEVERSIONFLAGS': '${__libversionflags(__env__,"LDMODULEVERSION","_LDMODULEVERSIONFLAGS")}',
      '__SHLIBVERSIONFLAGS': '${__libversionflags(__env__,"SHLIBVERSION","_SHLIBVERSIONFLAGS")}',
      '__lib_either_version_flag': <function __lib_either_version_flag at 0x700000>,
      '__libversionflags': <function __libversionflags 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 Microsoft 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 construction 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 ...
    {'ENV': {'PATH': '/usr/local/bin:/opt/bin:/bin:/usr/bin:/snap/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 ...
    { 'ENV': { 'PATH': 'C:\\WINDOWS\\System32:/usr/bin',
               '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.

Prev | Up | Next
Chapter 28. Troubleshooting | Home | 28.3. What Dependencies Does SCons Know About? the `--tree` Option