diff options
author | Gary Oberbrunner <garyo@oberbrunner.com> | 2009-04-29 01:18:14 (GMT) |
---|---|---|
committer | Gary Oberbrunner <garyo@oberbrunner.com> | 2009-04-29 01:18:14 (GMT) |
commit | f336f13ec93285dc4f5caf00d79a7f2086e5786a (patch) | |
tree | 888a5686bbe5c770cfbe3b454e874f58e8d02e66 /src | |
parent | 74c4ae42c9361c1e32ff1c80946ce65370a5d273 (diff) | |
download | SCons-f336f13ec93285dc4f5caf00d79a7f2086e5786a.zip SCons-f336f13ec93285dc4f5caf00d79a7f2086e5786a.tar.gz SCons-f336f13ec93285dc4f5caf00d79a7f2086e5786a.tar.bz2 |
fix for bug #2393. Instead of just 'import'ing
site_scons/site_init.py, I now load that file directly into the
SCons.Script namespace using exec ... in. This allows site_init.py to
define tools in the way users expect.
Diffstat (limited to 'src')
-rw-r--r-- | src/engine/SCons/Script/Main.py | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/engine/SCons/Script/Main.py b/src/engine/SCons/Script/Main.py index f7ea9c0..926cf5c 100644 --- a/src/engine/SCons/Script/Main.py +++ b/src/engine/SCons/Script/Main.py @@ -701,17 +701,30 @@ def _load_site_scons_dir(topdir, site_dir_name=None): try: fp, pathname, description = imp.find_module(site_init_modname, [site_dir]) + # Load the file into SCons.Script namespace. This is + # opaque and clever; m is the module object for the + # SCons.Script module, and the exec ... in call executes a + # file (or string containing code) in the context of the + # module's dictionary, so anything that code defines ends + # up adding to that module. This is really short, but all + # the error checking makes it longer. try: - imp.load_module(site_init_modname, fp, pathname, description) - finally: - if fp: - fp.close() + m=sys.modules['SCons.Script'] + except Exception, e: + raise SCons.Errors.InternalError, \ + "can't import site_init.py: missing SCons.Script module, %s"%str(e) + try: + # This is the magic. + exec fp in m.__dict__ + except Exception, e: + sys.stderr.write("*** Error loading site_init file %s:\n"%site_init_file) + raise except ImportError, e: - sys.stderr.write("Can't import site init file '%s': %s\n"%(site_init_file, e)) - raise - except Exception, e: - sys.stderr.write("Site init file '%s' raised exception: %s\n"%(site_init_file, e)) + sys.stderr.write("Can't import site init file '%s':\n"%site_init_file) raise + finally: + if fp: + fp.close() if os.path.exists(site_tools_dir): SCons.Tool.DefaultToolpath.append(os.path.abspath(site_tools_dir)) |