From: stevenknight Date: Tue, 7 Dec 2004 23:21:53 +0000 (+0000) Subject: ActionFactory action functions should take an env argument, too. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2b336c691210597d94f05f566312d0248cb1b8e3;p=scons.git ActionFactory action functions should take an env argument, too. git-svn-id: http://scons.tigris.org/svn/scons/trunk@1184 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index 545bd618..6db1e6af 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 315b1ac0..705daff2 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"""