Clone wiki

SCons / DumpEnv

The SCons wiki has moved to

Table of Contents

Dumping the Construction Environment

There are times when it's very helpful to be able to see the contents of the construction environment. Most of the time, dumping the contents of the environment allows you to easily see what's going on inside with the tools being used. And that's a pretty handy task when debugging issues with scons.

_NOTE: _since 0.96.90, the code below is no longer needed. Environments have a method Dump() built-in. Just call:

    print env.Dump()  # dump whole env
    print env.Dump('CCFLAGS') # dump just one key

But if you're using an older version of scons, read on...

def DumpEnv( env, key = None, header = None, footer = None ):
    Using the standard Python pretty printer, dump the contents of the
    scons build environment to stdout.

    If the key passed in is anything other than 'env', then that will
    be used as an index into the build environment dictionary and
    whatever is found there will be fed into the pretty printer. Note
    that this key is case sensitive.

    The header and footer are simple mechanisms to allow printing a
    prefix and suffix to the contents that are dumped out. They are
    handy when using DumpEnv to dump multiple portions of the
    import pprint
    pp = pprint.PrettyPrinter( indent = 2 )
    if key:
        dict = env.Dictionary( key )
        dict = env.Dictionary()
    if header:
        print header
    pp.pprint( dict )
    if footer:
        print footer

Using DumpEnv

Stick the DumpEnv function someplace easy to access, like in the SConstruct file and then call it.

Dumping the Entire Environment


DumpEnv( env )

in the SConstruct file. Then running scons will show something like:

scons: Reading SConscript files ...
{ 'AR': 'ar',
  'ARFLAGS': 'r',
  'AS': 'as',
  'ASFLAGS': '',
  'BIBTEX': 'bibtex',
  'BUILDERS': {'ExpandVersion': <SCons.Builder.BuilderBase instance at 0x404890cc>},
  'CC': 'gcc',
  'CCFLAGS': '',
  'CFILESUFFIX': '.c',
  'CVS': 'cvs',
  'CXX': 'g++',
  'CXXVERSION': '3.2.2',
  'DEV': '/home/peterk/tmp/emitter',
  'DVIPDF': 'dvipdf',
  'DVIPS': 'dvips',
  'ENV': {'PATH': '/usr/local/bin:/bin:/usr/bin'},
  'ESCAPE': <function escape at 0x4045fb1c>,
  'F77': 'g77',
  'F77COM': '$F77 $F77FLAGS $_F77INCFLAGS -c -o $TARGET $SOURCES',
  'F77FLAGS': '',
  'GS': 'gs',
  'GSFLAGS': '-dNOPAUSE -dBATCH -sDEVICE=pdfwrite',
  'INCPREFIX': '-I',
  'INCSUFFIX': '',
  'INSTALL': <function copyFunc at 0x4041c7d4>,
  'JAR': 'jar',
  'JARFLAGS': 'cf',
  'JARSUFFIX': '.jar',
  'JAVAC': 'javac',
  'JAVACCOM': '$JAVAC $JAVACFLAGS -d ${TARGET.attributes.java_classdir} -sourcepath ${SOURCE.dir.rdir()} $SOURCES',
  'JAVACLASSSUFFIX': '.class',
  'JAVAH': 'javah',
  'JAVAHCOM': '$JAVAH $JAVAHFLAGS $_JAVAHOUTFLAG -classpath ${SOURCE.attributes.java_classdir} ${SOURCES.attributes.java_classname}',
  'JAVASUFFIX': '.java',
  'LATEX': 'latex',
  'LEX': 'flex',
  'LEXFLAGS': '',
  'LIBPREFIX': 'lib',
  'LIBSUFFIX': '.a',
  'LINKFLAGS': '',
  'M4': 'm4',
  'M4COM': 'cd ${SOURCE.srcdir} && $M4 $M4FLAGS < ${SOURCE.file} > ${TARGET.abspath}',
  'M4FLAGS': '-E',
  'OBJPREFIX': '',
  'OBJSUFFIX': '.o',
  'PDFLATEX': 'pdflatex',
  'PDFPREFIX': '',
  'PDFSUFFIX': '.pdf',
  'PDFTEX': 'pdftex',
  'PLATFORM': 'posix',
  'PSPAWN': <function piped_env_spawn at 0x4045f95c>,
  'PSPREFIX': '',
  'PSSUFFIX': '.ps',
  'RANLIB': 'ranlib',
  'RCS': 'rcs',
  'RCS_CO': 'co',
  'RCS_COFLAGS': '',
  'RMIC': 'rmic',
  'RMICCOM': '$RMIC $RMICFLAGS -d ${TARGET.attributes.java_lookupdir} -classpath ${SOURCE.attributes.java_classdir} ${SOURCES.attributes.java_classname}',
  'RMICFLAGS': '',
  'SCANNERS': [ <SCons.Scanner.ClassicCPP instance at 0x4041e8cc>,
                <SCons.Scanner.Classic instance at 0x4041e58c>],
  'SHCC': '$CC',
  'SHCXX': '$CXX',
  'SHELL': 'sh',
  'SHF77': '$F77',
  'SHF77FLAGS': '$F77FLAGS',
  'SHLIBSUFFIX': '.so',
  'SHLINK': '$LINK',
  'SHOBJSUFFIX': '.os',
  'SMARTLINK': <function smart_link at 0x4046f144>,
  'SPAWN': <function spawn_spawn at 0x4045f844>,
  'SWIG': 'swig',
  'SWIGFLAGS': '',
  'TAR': 'tar',
  'TARFLAGS': '-c',
  'TARSUFFIX': '.tar',
  'TEMPFILE': <class SCons.Defaults.NullCmdGenerator at 0x40414dac>,
  'TEX': 'tex',
  'TEXFLAGS': '',
  'TOOLS': [ 'default',
  'YACC': 'bison',
  'YACCFLAGS': '',
  'ZIP': 'zip',
  'ZIPCOM': <SCons.Action.FunctionAction instance at 0x404af5ec>,
  'ZIPFLAGS': '',
  'ZIPSUFFIX': '.zip',
  '_CPPINCFLAGS': '$( ${_concat(INCPREFIX, CPPPATH, INCSUFFIX, __env__, RDirs)} $)',
  '_F77INCFLAGS': '$( ${_concat(INCPREFIX, F77PATH, INCSUFFIX, __env__, RDirs)} $)',
  '_JARCHDIR': <function jarChdir at 0x4046ff0c>,
  '_JARFLAGS': <function jarFlags at 0x4046fed4>,
  '_JARMANIFEST': <function jarManifest at 0x4046fe9c>,
  '_JARSOURCES': <function jarSources at 0x4046faac>,
  '_JAVAHOUTFLAG': <function JavaHOutFlagGenerator at 0x40479764>,
  '_LIBDIRFLAGS': '$( ${_concat(LIBDIRPREFIX, LIBPATH, LIBDIRSUFFIX, __env__, RDirs)} $)',
  '_concat': <function _concat at 0x4041c844>,
  '_defines': <function _defines at 0x4041c8b4>,
  '_stripixes': <function _stripixes at 0x4041c87c>}
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.

Dumping a Portion of the Environment

DumpEnv( env, key = 'TOOLS' )

Note that the key is case sensitive! Then running scons will show something like:

scons: Reading SConscript files ...
[ 'default',
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.

Optionally Calling DumpEnv

While it's handy to be able to peek into the environment, it can be annoying to dump the contents out every time. To get around that, add the following to the SConstruct file:

if 'dump' in ARGUMENTS:
    env_key = ARGUMENTS[ 'dump' ]
    if env_key == 'env':
        prefix = 'env.Dictionary()'
        env_key = None
        prefix = 'env.Dictionary( ' + env_key + ' )'
    DumpEnv( env,
             key = env_key,
             header = prefix + ' - start',
             footer = prefix + ' - end' )

To dump the environment, you now have to specify an additional argument on the command line:

scons dump=env

Without the dump=env, the environment will not be written out.

The contents of specific portions of the environment can also be specified. For example, to write out the contents of the TOOLS portion of the environment, use:

scons dump=TOOLS

Passing Around DumpEnv

Sometimes, is would be nice to be able to dump the environment when in a SConscript file someplace in the bowels of a complex build hierarchy. The easiest way to do this is to modify the environment in the SConstruct file by adding the DumpEnv to it.

    env[ 'DumpEnv' ] = DumpEnv

Then from within a SConscript file, use:

   env[ 'DumpEnv' ]( env )

to dump the contents of the environment at that point.

Another way to do this is to make Dump a method of the Environment class. Put this after your definition of DumpEnv:

   from SCons.Script.SConscript import SConsEnvironment
   SConsEnvironment.DumpEnv = DumpEnv

Then for any environment you can do this in your SConscript:

   # or
   env.DumpEnv(key = 'TOOLS')

This requires scons 0.92 or later.