diff options
author | Steven Knight <knight@baldmt.com> | 2002-04-05 17:19:03 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2002-04-05 17:19:03 (GMT) |
commit | 3ccdd2cb4b633d5d3603d1af53c2e578f1af8f1d (patch) | |
tree | c71dae402386e33a4267679c4c0a292b0ba1971a /src/engine/SCons/Action.py | |
parent | 703eac076d304885578e80ea100453e768abb52b (diff) | |
download | SCons-3ccdd2cb4b633d5d3603d1af53c2e578f1af8f1d.zip SCons-3ccdd2cb4b633d5d3603d1af53c2e578f1af8f1d.tar.gz SCons-3ccdd2cb4b633d5d3603d1af53c2e578f1af8f1d.tar.bz2 |
Clean up how the Environment dictionary is passed to function Actions. (Charles Crain)
Diffstat (limited to 'src/engine/SCons/Action.py')
-rw-r--r-- | src/engine/SCons/Action.py | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index 9b65e38..3ed3d73 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -29,11 +29,13 @@ XXX __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import copy import os import os.path import re import string import sys +import UserDict import SCons.Util @@ -259,6 +261,27 @@ class ActionBase: _rm = re.compile(r'\$[()]') _remove = re.compile(r'\$\(([^\$]|\$[^\(])*?\$\)') +class EnvDictProxy(UserDict.UserDict): + """This is a dictionary-like class that contains the + Environment dictionary we pass to FunctionActions + and CommandGeneratorActions. + + In addition to providing + normal dictionary-like access to the variables in the + Environment, it also exposes the functions subst() + and subst_list(), allowing users to easily do variable + interpolation when writing their FunctionActions + and CommandGeneratorActions.""" + + def __init__(self, env): + UserDict.UserDict.__init__(self, env) + + def subst(self, string): + return SCons.Util.scons_subst(string, self.data, {}, _rm) + + def subst_list(self, string): + return SCons.Util.scons_subst_list(string, self.data, {}, _rm) + class CommandAction(ActionBase): """Class for command-execution actions.""" def __init__(self, string): @@ -325,7 +348,14 @@ class CommandGeneratorAction(ActionBase): if kw.has_key("target") and not SCons.Util.is_List(kw["target"]): kw["target"] = [kw["target"]] - gen_list = apply(self.generator, (), kw) + # Wrap the environment dictionary in an EnvDictProxy + # object to make variable interpolation easier for the + # client. + args = copy.copy(kw) + if args.has_key("env") and not isinstance(args["env"], EnvDictProxy): + args["env"] = EnvDictProxy(args["env"]) + + gen_list = apply(self.generator, (), args) gen_list = map(lambda x: map(str, x), gen_list) # Do environment variable substitution on returned command list @@ -386,6 +416,8 @@ class FunctionAction(ActionBase): if kw.has_key('source') and not \ SCons.Util.is_List(kw['source']): kw['source'] = [ kw['source'] ] + if kw.has_key("env") and not isinstance(kw["env"], EnvDictProxy): + kw["env"] = EnvDictProxy(kw["env"]) return apply(self.function, (), kw) def get_contents(self, **kw): |