From 17f8210401fbaf283fba34e5d87700e4e7431470 Mon Sep 17 00:00:00 2001 From: Steven Knight Date: Tue, 22 Jul 2003 11:38:20 +0000 Subject: Only create a default Environment when asked to. (Chad Austin) --- doc/man/scons.1 | 7 +++++++ src/CHANGES.txt | 3 +++ src/engine/SCons/Defaults.py | 10 ++++++++++ src/engine/SCons/Node/FS.py | 4 ++-- src/engine/SCons/Script/SConscript.py | 2 +- src/engine/SCons/Script/__init__.py | 4 ---- test/BitKeeper.py | 2 +- test/RCS.py | 2 +- 8 files changed, 25 insertions(+), 9 deletions(-) diff --git a/doc/man/scons.1 b/doc/man/scons.1 index b39db93..49fe6fd 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -4076,6 +4076,13 @@ will add to the (now empty) default-target list like normal. .TP +.RI DefaultEnvironment() +Creates and returns a default construction environment object. +This construction environment is used internally by SCons +in order to fetch source files transparently +from source code management systems. + +.TP .RI Dir( name ", [" directory ]) This returns an object that represents a given directory .IR name . diff --git a/src/CHANGES.txt b/src/CHANGES.txt index abbf744..33e481d 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -17,6 +17,9 @@ RELEASE 0.XX - XXX - Give a Value Nodes a timestamp of the system time when they're created, so they'll work when using timestamp-based signatures. + - Add a DefaultEnvironment() function that only creates a default + environment on-demand (for fetching source files, e.g.). + From Steven Knight: - Tighten up the scons -H help output. diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py index e2bb3b4..aa0fbd9 100644 --- a/src/engine/SCons/Defaults.py +++ b/src/engine/SCons/Defaults.py @@ -44,6 +44,7 @@ import string import SCons.Action import SCons.Builder +import SCons.Environment import SCons.Node.Alias import SCons.Node.FS import SCons.Scanner.C @@ -56,6 +57,15 @@ import SCons.Scanner.Prog # interface. _default_env = None +# Lazily instantiate the default environment so the overhead of creating +# it doesn't apply when it's not needed. +def DefaultEnvironment(): + global _default_env + if not _default_env: + _default_env = SCons.Environment.Environment() + return _default_env + + def alias_builder(env, target, source): pass diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index 1f88330..a17cee0 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -168,7 +168,7 @@ def get_DefaultSCCSBuilder(): import SCons.Builder import SCons.Defaults DefaultSCCSBuilder = SCons.Builder.Builder(action = '$SCCSCOM', - env = SCons.Defaults._default_env) + env = SCons.Defaults.DefaultEnvironment()) return DefaultSCCSBuilder def get_DefaultRCSBuilder(): @@ -177,7 +177,7 @@ def get_DefaultRCSBuilder(): import SCons.Builder import SCons.Defaults DefaultRCSBuilder = SCons.Builder.Builder(action = '$RCS_COCOM', - env = SCons.Defaults._default_env) + env = SCons.Defaults.DefaultEnvironment()) return DefaultRCSBuilder # diff --git a/src/engine/SCons/Script/SConscript.py b/src/engine/SCons/Script/SConscript.py index 5f7f4b5..313a3f2 100644 --- a/src/engine/SCons/Script/SConscript.py +++ b/src/engine/SCons/Script/SConscript.py @@ -513,7 +513,6 @@ def BuildDefaultGlobals(): """ globals = {} - globals['_default_env'] = SCons.Defaults._default_env globals['Action'] = SCons.Action.Action globals['AddPostAction'] = AddPostAction globals['AddPreAction'] = AddPreAction @@ -526,6 +525,7 @@ def BuildDefaultGlobals(): globals['Configure'] = SCons.SConf.SConf globals['CScan'] = SCons.Defaults.CScan globals['Default'] = Default + globals['DefaultEnvironment'] = SCons.Defaults.DefaultEnvironment globals['Dir'] = SCons.Node.FS.default_fs.Dir globals['EnsurePythonVersion'] = EnsurePythonVersion globals['EnsureSConsVersion'] = EnsureSConsVersion diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py index fe56568..c171a91 100644 --- a/src/engine/SCons/Script/__init__.py +++ b/src/engine/SCons/Script/__init__.py @@ -750,10 +750,6 @@ def _main(args, parser): SCons.Node.FS.default_fs.set_toplevel_dir(os.getcwd()) - # Now that the top-level directory has been set, - # we can initialize the default Environment. - SCons.Defaults._default_env = SCons.Environment.Environment() - scripts = [] if options.file: scripts.extend(options.file) diff --git a/test/BitKeeper.py b/test/BitKeeper.py index eb5c52c..3374f92 100644 --- a/test/BitKeeper.py +++ b/test/BitKeeper.py @@ -298,7 +298,7 @@ def cat(env, source, target): for src in source: f.write(open(src, "rb").read()) f.close() -_default_env['SCCS'] = r'%s' +DefaultEnvironment()['SCCS'] = r'%s' env = Environment(BUILDERS={'Cat':Builder(action=cat)}) env.Cat('aaa.out', 'aaa.in') env.Cat('bbb.out', 'bbb.in') diff --git a/test/RCS.py b/test/RCS.py index 68bb546..7be0080 100644 --- a/test/RCS.py +++ b/test/RCS.py @@ -181,7 +181,7 @@ def cat(env, source, target): for src in source: f.write(open(src, "rb").read()) f.close() -_default_env['RCS_COFLAGS'] = '-l' +DefaultEnvironment()['RCS_COFLAGS'] = '-l' env = Environment(ENV=ENV, BUILDERS={'Cat':Builder(action=cat)}) env.Cat('aaa.out', 'aaa.in') env.Cat('bbb.out', 'bbb.in') -- cgit v0.12