# 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)
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"""