diff options
| author | Steven Knight <knight@baldmt.com> | 2004-12-07 23:21:53 (GMT) |
|---|---|---|
| committer | Steven Knight <knight@baldmt.com> | 2004-12-07 23:21:53 (GMT) |
| commit | 3953f0e69aae524012d80ea6b1c86bf4393d8cf9 (patch) | |
| tree | fd243ce2671b1b67746fe425135f3cf77fe6a707 /src/engine | |
| parent | 3df74590f61e6de1271fc57df1a478f99ab28819 (diff) | |
| download | SCons-3953f0e69aae524012d80ea6b1c86bf4393d8cf9.zip SCons-3953f0e69aae524012d80ea6b1c86bf4393d8cf9.tar.gz SCons-3953f0e69aae524012d80ea6b1c86bf4393d8cf9.tar.bz2 | |
ActionFactory action functions should take an env argument, too.
Diffstat (limited to 'src/engine')
| -rw-r--r-- | src/engine/SCons/Action.py | 14 | ||||
| -rw-r--r-- | src/engine/SCons/ActionTests.py | 19 |
2 files changed, 24 insertions, 9 deletions
diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index 545bd61..6db1e6a 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -665,14 +665,22 @@ class ActionCaller: # or something like that. Do the best we can. contents = str(actfunc) return contents + def subst(self, s, target, source, env): + # Special-case hack: Let a custom function wrapped in an + # ActionCaller get at the environment through which the action + # was called by using this hard-coded value as a special return. + if s == '$__env__': + return env + else: + return env.subst(s, 0, target, source) def subst_args(self, target, source, env): - return map(lambda x, e=env, t=target, s=source: - e.subst(x, 0, t, s), + return map(lambda x, self=self, t=target, s=source, e=env: + self.subst(x, t, s, e), self.args) def subst_kw(self, target, source, env): kw = {} for key in self.kw.keys(): - kw[key] = env.subst(self.kw[key], 0, target, source) + kw[key] = self.subst(self.kw[key], target, source, env) return kw def __call__(self, target, source, env): args = self.subst_args(target, source, env) diff --git a/src/engine/SCons/ActionTests.py b/src/engine/SCons/ActionTests.py index 315b1ac..705daff 100644 --- a/src/engine/SCons/ActionTests.py +++ b/src/engine/SCons/ActionTests.py @@ -1588,15 +1588,22 @@ class ActionCallerTestCase(unittest.TestCase): def strfunc(a1, a2, a3): pass + e = Environment(FOO = 2, BAR = 5) + af = SCons.Action.ActionFactory(actfunc, strfunc) - ac = SCons.Action.ActionCaller(af, [1, '$FOO', 3], {}) - ac([], [], Environment(FOO = 2)) - assert actfunc_args == [1, '2', 3], actfunc_args + ac = SCons.Action.ActionCaller(af, ['$__env__', '$FOO', 3], {}) + ac([], [], e) + assert actfunc_args[0] is e, actfunc_args + assert actfunc_args[1] == '2', actfunc_args + assert actfunc_args[2] == 3, actfunc_args + del actfunc_args[:] + ac = SCons.Action.ActionCaller(af, [], {'a3' : '$__env__', 'a2' : '$BAR', 'a1' : 4}) + ac([], [], e) + assert actfunc_args[0] == 4, actfunc_args + assert actfunc_args[1] == '5', actfunc_args + assert actfunc_args[2] is e, actfunc_args del actfunc_args[:] - ac = SCons.Action.ActionCaller(af, [], {'a3' : 6, 'a2' : '$BAR', 'a1' : 4}) - ac([], [], Environment(BAR = 5)) - assert actfunc_args == [4, '5', 6], actfunc_args def test_strfunction(self): """Test calling the ActionCaller strfunction() method""" |
