Please note:The SCons wiki is now restored from the attack in March 2013. All old passwords have been invalidated. Please reset your password if you have an account. If you note missing pages, please report them to webmaster@scons.org. Also, new account creation is currently disabled due to an ongoing spam flood (2013/08/27).

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:

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

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


   1 def DumpEnv( env, key = None, header = None, footer = None ):
   2     """
   3     Using the standard Python pretty printer, dump the contents of the
   4     scons build environment to stdout.
   5 
   6     If the key passed in is anything other than 'env', then that will
   7     be used as an index into the build environment dictionary and
   8     whatever is found there will be fed into the pretty printer. Note
   9     that this key is case sensitive.
  10 
  11     The header and footer are simple mechanisms to allow printing a
  12     prefix and suffix to the contents that are dumped out. They are
  13     handy when using DumpEnv to dump multiple portions of the
  14     environment.
  15     """
  16     import pprint
  17     pp = pprint.PrettyPrinter( indent = 2 )
  18     if key:
  19         dict = env.Dictionary( key )
  20     else:
  21         dict = env.Dictionary()
  22     if header:
  23         print header
  24     pp.pprint( dict )
  25     if footer:
  26         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

Put:

DumpEnv( env )

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

scons: Reading SConscript files ...
{ 'AR': 'ar',
  'ARCOM': '$AR $ARFLAGS $TARGET $SOURCES\n$RANLIB $RANLIBFLAGS $TARGET',
  'ARFLAGS': 'r',
  'AS': 'as',
  'ASCOM': '$AS $ASFLAGS -o $TARGET $SOURCES',
  'ASFLAGS': '',
  'ASPPCOM': '$CC $ASFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES',
  'BIBTEX': 'bibtex',
  'BIBTEXCOM': '$BIBTEX $BIBTEXFLAGS $SOURCES',
  'BIBTEXFLAGS': '',
  'BUILDERS': {'ExpandVersion': <SCons.Builder.BuilderBase instance at 0x404890cc>},
  'CC': 'gcc',
  'CCCOM': '$CC $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES',
  'CCFLAGS': '',
  'CFILESUFFIX': '.c',
  'CPPDEFPREFIX': '-D',
  'CPPDEFSUFFIX': '',
  'CVS': 'cvs',
  'CVSCOFLAGS': '',
  'CVSCOM': '$CVS $CVSFLAGS co $CVSCOFLAGS ${TARGET.posix}',
  'CVSFLAGS': '-d $CVSREPOSITORY',
  'CXX': 'g++',
  'CXXCOM': '$CXX $CXXFLAGS $CPPFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES',
  'CXXFILESUFFIX': '.cc',
  'CXXFLAGS': '$CCFLAGS',
  'CXXVERSION': '3.2.2',
  'DEV': '/home/peterk/tmp/emitter',
  'DVIPDF': 'dvipdf',
  'DVIPDFCOM': '$DVIPDF $DVIPDFFLAGS $SOURCES $TARGET',
  'DVIPDFFLAGS': '',
  'DVIPS': 'dvips',
  'DVIPSFLAGS': '',
  'ENV': {'PATH': '/usr/local/bin:/bin:/usr/bin'},
  'ESCAPE': <function escape at 0x4045fb1c>,
  'F77': 'g77',
  'F77COM': '$F77 $F77FLAGS $_F77INCFLAGS -c -o $TARGET $SOURCES',
  'F77FLAGS': '',
  'F77PPCOM': '$F77 $F77FLAGS $CPPFLAGS $_CPPDEFFLAGS $_F77INCFLAGS -c -o $TARGET $SOURCES',
  'GS': 'gs',
  'GSCOM': '$GS $GSFLAGS -sOutputFile=$TARGET $SOURCES',
  'GSFLAGS': '-dNOPAUSE -dBATCH -sDEVICE=pdfwrite',
  'INCPREFIX': '-I',
  'INCSUFFIX': '',
  'INSTALL': <function copyFunc at 0x4041c7d4>,
  'JAR': 'jar',
  'JARCOM': '$JAR $_JARFLAGS $TARGET $_JARMANIFEST $_JARCHDIR $_JARSOURCES',
  'JARFLAGS': 'cf',
  'JARSUFFIX': '.jar',
  'JAVAC': 'javac',
  'JAVACCOM': '$JAVAC $JAVACFLAGS -d ${TARGET.attributes.java_classdir} -sourcepath ${SOURCE.dir.rdir()} $SOURCES',
  'JAVACFLAGS': '',
  'JAVACLASSSUFFIX': '.class',
  'JAVAH': 'javah',
  'JAVAHCOM': '$JAVAH $JAVAHFLAGS $_JAVAHOUTFLAG -classpath ${SOURCE.attributes.java_classdir} ${SOURCES.attributes.java_classname}',
  'JAVAHFLAGS': '',
  'JAVASUFFIX': '.java',
  'LATEX': 'latex',
  'LATEXCOM': '$LATEX $LATEXFLAGS $SOURCES',
  'LATEXFLAGS': '',
  'LEX': 'flex',
  'LEXCOM': '$LEX $LEXFLAGS -t $SOURCES > $TARGET',
  'LEXFLAGS': '',
  'LIBDIRPREFIX': '-L',
  'LIBDIRSUFFIX': '',
  'LIBLINKPREFIX': '-l',
  'LIBLINKSUFFIX': '',
  'LIBPREFIX': 'lib',
  'LIBPREFIXES': '$LIBPREFIX',
  'LIBSUFFIX': '.a',
  'LIBSUFFIXES': ['$LIBSUFFIX', '$SHLIBSUFFIX'],
  'LINK': '$SMARTLINK',
  'LINKCOM': '$LINK $LINKFLAGS -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS',
  'LINKFLAGS': '',
  'M4': 'm4',
  'M4COM': 'cd ${SOURCE.srcdir} && $M4 $M4FLAGS < ${SOURCE.file} > ${TARGET.abspath}',
  'M4FLAGS': '-E',
  'OBJPREFIX': '',
  'OBJSUFFIX': '.o',
  'PDFCOM': '$DVIPDFCOM',
  'PDFLATEX': 'pdflatex',
  'PDFLATEXCOM': '$PDFLATEX $PDFLATEXFLAGS $SOURCES $TARGET',
  'PDFLATEXFLAGS': '',
  'PDFPREFIX': '',
  'PDFSUFFIX': '.pdf',
  'PDFTEX': 'pdftex',
  'PDFTEXCOM': '$PDFTEX $PDFTEXFLAGS $SOURCES $TARGET',
  'PDFTEXFLAGS': '',
  'PLATFORM': 'posix',
  'PROGPREFIX': '',
  'PROGSUFFIX': '',
  'PSCOM': '$DVIPS $DVIPSFLAGS -o $TARGET $SOURCES',
  'PSPAWN': <function piped_env_spawn at 0x4045f95c>,
  'PSPREFIX': '',
  'PSSUFFIX': '.ps',
  'RANLIB': 'ranlib',
  'RANLIBFLAGS': '',
  'RCS': 'rcs',
  'RCS_CO': 'co',
  'RCS_COCOM': '$RCS_CO $RCS_COFLAGS $TARGET',
  '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',
  'SHCCCOM': '$SHCC $SHCCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES',
  'SHCCFLAGS': '$CCFLAGS -fPIC',
  'SHCXX': '$CXX',
  'SHCXXCOM': '$SHCXX $SHCXXFLAGS $CPPFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES',
  'SHCXXFLAGS': '$CXXFLAGS -fPIC',
  'SHELL': 'sh',
  'SHF77': '$F77',
  'SHF77COM': '$SHF77 $SHF77FLAGS $_F77INCFLAGS -c -o $TARGET $SOURCES',
  'SHF77FLAGS': '$F77FLAGS',
  'SHF77PPCOM': '$SHF77 $SHF77FLAGS $CPPFLAGS $_CPPDEFFLAGS $_F77INCFLAGS -c -o $TARGET $SOURCES',
  'SHLIBEMITTER': None,
  'SHLIBPREFIX': '$LIBPREFIX',
  'SHLIBSUFFIX': '.so',
  'SHLINK': '$LINK',
  'SHLINKCOM': '$SHLINK $SHLINKFLAGS -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS',
  'SHLINKFLAGS': '$LINKFLAGS -shared',
  'SHOBJPREFIX': '$OBJPREFIX',
  'SHOBJSUFFIX': '.os',
  'SMARTLINK': <function smart_link at 0x4046f144>,
  'SPAWN': <function spawn_spawn at 0x4045f844>,
  'STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME': 0,
  'SWIG': 'swig',
  'SWIGCFILESUFFIX': '_wrap$CFILESUFFIX',
  'SWIGCOM': '$SWIG $SWIGFLAGS -o $TARGET $SOURCES',
  'SWIGCXXFILESUFFIX': '_wrap$CXXFILESUFFIX',
  'SWIGFLAGS': '',
  'TAR': 'tar',
  'TARCOM': '$TAR $TARFLAGS -f $TARGET $SOURCES',
  'TARFLAGS': '-c',
  'TARSUFFIX': '.tar',
  'TEMPFILE': <class SCons.Defaults.NullCmdGenerator at 0x40414dac>,
  'TEX': 'tex',
  'TEXCOM': '$TEX $TEXFLAGS $SOURCES',
  'TEXFLAGS': '',
  'TOOLS': [ 'default',
             'gnulink',
             'gcc',
             'g++',
             'g77',
             'gas',
             'ar',
             'CVS',
             'dvipdf',
             'dvips',
             'gs',
             'jar',
             'javac',
             'javah',
             'latex',
             'lex',
             'm4',
             'pdflatex',
             'pdftex',
             'RCS',
             'rmic',
             'swig',
             'tar',
             'tex',
             'yacc',
             'zip'],
  'YACC': 'bison',
  'YACCCOM': '$YACC $YACCFLAGS -o $TARGET $SOURCES',
  'YACCFLAGS': '',
  'ZIP': 'zip',
  'ZIPCOM': <SCons.Action.FunctionAction instance at 0x404af5ec>,
  'ZIPFLAGS': '',
  'ZIPSUFFIX': '.zip',
  '_CPPDEFFLAGS': '${_defines(CPPDEFPREFIX, CPPDEFINES, CPPDEFSUFFIX, __env__)}',
  '_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)} $)',
  '_LIBFLAGS': '${_stripixes(LIBLINKPREFIX, LIBS, LIBLINKSUFFIX, LIBPREFIX, LIBSUFFIX, __env__)}',
  '_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',
  'gnulink',
  'gcc',
  'g++',
  'g77',
  'gas',
  'ar',
  'CVS',
  'dvipdf',
  'dvips',
  'gs',
  'jar',
  'javac',
  'javah',
  'latex',
  'lex',
  'm4',
  'pdflatex',
  'pdftex',
  'RCS',
  'rmic',
  'swig',
  'tar',
  'tex',
  'yacc',
  'zip']
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:

   1 if 'dump' in ARGUMENTS:
   2     env_key = ARGUMENTS[ 'dump' ]
   3     if env_key == 'env':
   4         prefix = 'env.Dictionary()'
   5         env_key = None
   6     else:
   7         prefix = 'env.Dictionary( ' + env_key + ' )'
   8     DumpEnv( env,
   9              key = env_key,
  10              header = prefix + ' - start',
  11              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:

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

This requires scons 0.92 or later.

DumpEnv (last edited 2009-11-29 05:26:46 by adsl-71-141-112-117)