From 3fb46a5e0562ef9ee61026a1b7bd13c8fa8bdc49 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Mon, 30 Aug 2004 21:46:36 +0000 Subject: [PATCH] Add an Environment.Dump() method. (Gary Oberbrunner) git-svn-id: http://scons.tigris.org/svn/scons/trunk@1048 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- doc/man/scons.1 | 34 ++++++++++++++++++++++++++++ src/CHANGES.txt | 9 ++++++++ src/engine/SCons/Environment.py | 18 +++++++++++++++ src/engine/SCons/EnvironmentTests.py | 7 ++++++ 4 files changed, 68 insertions(+) diff --git a/doc/man/scons.1 b/doc/man/scons.1 index 54a76abc..a08b151d 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -2625,6 +2625,40 @@ Directory Nodes have attributes and methods that are useful in many situations; see "File and Directory Nodes," below. +'\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +.TP +.RI env.Dump([ key ]) +Returns a pretty printable representation of the environment. +.IR key , +if not +.IR None , +should be a string containing the name of the variable of interest. + +This SConstruct: +.ES +env=Environment() +print env.Dump('CCCOM') +.EE +will print: +.ES +'$CC $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES' +.EE + +.ES +env=Environment() +print env.Dump() +.EE +will print: +.ES +{ 'AR': 'ar', + 'ARCOM': '$AR $ARFLAGS $TARGET $SOURCES\n$RANLIB $RANLIBFLAGS $TARGET', + 'ARFLAGS': ['r'], + 'AS': 'as', + 'ASCOM': '$AS $ASFLAGS -o $TARGET $SOURCES', + 'ASFLAGS': [], + ... +.EE + '\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .TP .RI EnsurePythonVersion( major ", " minor ) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index b8a36281..f3b5778f 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -10,6 +10,15 @@ RELEASE 0.97 - XXX + From Gary Oberbrunner: + + - Add an Environment.Dump() method to print the contents of a + construction environment. + + + +RELEASE 0.96.1 - XXX + From Craig Bachelor: - Handle white space in the executable Python path name within in MSVS diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index 32fa1e63..03f2e38a 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -663,6 +663,24 @@ class Base: dlist = dlist[0] return dlist + def Dump(self, key = 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 None, 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. + """ + import pprint + pp = pprint.PrettyPrinter(indent=2) + if key: + dict = self.Dictionary(key) + else: + dict = self.Dictionary() + return pp.pformat(dict) + def FindIxes(self, paths, prefix, suffix): """ Search a list of paths for something that matches the prefix and suffix. diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index 810f3077..a6b86455 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -1994,6 +1994,13 @@ class EnvironmentTestCase(unittest.TestCase): d = env.Dir('${BAR}_$BAR') assert d == 'Dir(bardir_bardir)', d + def test_Dump(self): + """Test the Dump() method""" + + env = Environment(FOO = 'foo') + assert env.Dump('FOO') == "'foo'", env.Dump('FOO') + assert len(env.Dump()) > 200, env.Dump() # no args version + def test_Environment(self): """Test the Environment() method""" env = Environment(FOO = 'xxx', BAR = 'yyy') -- 2.26.2