From: stevenknight Date: Mon, 20 Sep 2004 18:33:15 +0000 (+0000) Subject: Use callable class strfunction. (Kevin Quick) X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=28a2b810be7c8479e255d73e55dc9bd2e3761b37;p=scons.git Use callable class strfunction. (Kevin Quick) git-svn-id: http://scons.tigris.org/svn/scons/trunk@1087 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/CHANGES.txt b/src/CHANGES.txt index ee2c546a..1d015109 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -116,6 +116,10 @@ RELEASE 0.97 - XXX - Build targets in an associated BuildDir even if there are targets or subdirectories locally in the source directory. + - If a FunctionAction has a callable class as its underlying Python + function, use its strfunction() method (if any) to display the + action. + From Christoph Wiedemann: - Add an Environment.SetDefault() method that only sets values if diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index c1316933..927e3d5f 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -487,6 +487,15 @@ class FunctionAction(ActionBase): def quote(s): return '"' + str(s) + '"' return '[' + string.join(map(quote, a), ", ") + ']' + try: + strfunc = self.execfunction.strfunction + except AttributeError: + pass + else: + if strfunc is None: + return None + if callable(strfunc): + return strfunc(target, source, env) name = self.function_name() tstr = array(target) sstr = array(source) diff --git a/src/engine/SCons/ActionTests.py b/src/engine/SCons/ActionTests.py index a61571eb..bc2387a2 100644 --- a/src/engine/SCons/ActionTests.py +++ b/src/engine/SCons/ActionTests.py @@ -688,6 +688,47 @@ class CommandActionTestCase(unittest.TestCase): s = act.strfunction([], [], env) assert s == "sf was called", s + class actclass1: + def __init__(self, targets, sources, env): + pass + def __call__(self): + return 1 + class actclass2: + def __init__(self, targets, sources, env): + self.strfunction = 5 + def __call__(self): + return 2 + class actclass3: + def __init__(self, targets, sources, env): + pass + def __call__(self): + return 3 + def strfunction(self, targets, sources, env): + return 'actclass3 on %s to get %s'%(str(sources[0]), + str(targets[0])) + class actclass4: + def __init__(self, targets, sources, env): + pass + def __call__(self): + return 4 + strfunction = None + + act1 = SCons.Action.Action(actclass1([t1], [s1], env)) + s = act1.strfunction([t1], [s1], env) + assert s == 'actclass1(["t1"], ["s1"])', s + + act2 = SCons.Action.Action(actclass2([t1], [s1], env)) + s = act2.strfunction([t1], [s1], env) + assert s == 'actclass2(["t1"], ["s1"])', s + + act3 = SCons.Action.Action(actclass3([t1], [s1], env)) + s = act3.strfunction([t1], [s1], env) + assert s == 'actclass3 on s1 to get t1', s + + act4 = SCons.Action.Action(actclass4([t1], [s1], env)) + s = act4.strfunction([t1], [s1], env) + assert s is None, s + def test_execute(self): """Test execution of command Actions