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 ...
  File "/home/my/project/SConstruct", line 2

    print env.Dump()

            ^

SyntaxError: invalid syntax

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

C:\>scons
scons: Reading SConscript files ...
  File "/home/my/project/SConstruct", line 2

    print env.Dump()

            ^

SyntaxError: invalid syntax

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 ...
  File "/home/my/project/SConstruct", line 2

    print env.Dump('ENV')

            ^

SyntaxError: invalid syntax

And the following when executed on a Windows system:

C:\>scons
scons: Reading SConscript files ...
  File "/home/my/project/SConstruct", line 2

    print env.Dump('ENV')

            ^

SyntaxError: invalid syntax