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 Also, new account creation is currently disabled due to an ongoing spam flood (2013/08/27).
Differences between revisions 18 and 19
Revision 18 as of 2005-07-15 04:58:54
Size: 2626
Editor: dsl-61-29-35-206
Revision 19 as of 2008-03-12 02:47:04
Size: 2626
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

SCons attempts to be a clean build tool and only generates the environment for build operations that is necessary for success of those build operations. This is the philosophical other end of the scale from make, where all of the environment variables of the process are automatically active within the build statements.

This is a good thing, since it prevents hidden dependencies and other problems (even trojan horses) from affecting the build environment from one user or platform to another.

However, sometimes you do want to import settings from your environment (see the ExternalTools example).

/!\ First, you should think about importing ONLY those settings you want:

env = Environment()
env.Append(CCACHEDIR = os.environ['CCACHEDIR'])

If this is too awkward, /!\ think again, and again!

Do you really want to open this Pandora's box?!

If you still do, then you could use the simple method shown in ExternalTools:

env = Environment(ENV = os.environ)

but this is likely to break for some platforms (e.g. Win32) because the Platform initialization of SCons may have already prepared some settings (like paths, etc.) that would be overwritten and lost by the above substitution. The following method is a little more involved, but makes sure that combinative elements like paths are correctly concatenated rather than replaced:

def ENV_update(tgt_ENV, src_ENV):
    for K in src_ENV.keys():
        if K in tgt_ENV.keys() and K in [ 'PATH', 'LD_LIBRARY_PATH',
                                          'LIB', 'INCLUDE' ]:
            tgt_ENV[K]=SCons.Util.AppendPath(tgt_ENV[K], src_ENV[K])

env = Environment()
ENV_update(env, os.environ)

I tried the above and got the following error

AttributeError: SConsEnvironment instance has no attribute 'keys':
  File "SConstruct", line 14:
    ENV_update(env, os.environ)
  File "SConstruct", line 7:
    if K in tgt_ENV.keys() and K in [ 'PATH', 'LD_LIBRARY_PATH',

I suspect ENV_update is supposed to be called as follows

ENV_update(env['ENV'], os.environ)

SCons 0.96.1; Python 2.4.1; WinXP; - TomHoward

Sorry to ruin this page. I run scons 0.95 on Windows ME with VC6. I alway get the anonying messages of 'Bad command or filename' when invoking cl.exe or link.exe, and my environment is OK. Finally, I change

args = [sh, '/C', escape(string.join(args))]

in Platform\ to

args = [sh, '/E:4096 /C', string.join(args)]

Everything seems right then. That's all.

ImportingEnvironmentSettings (last edited 2008-03-12 02:47:04 by localhost)