Use callable class strfunction. (Kevin Quick)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 20 Sep 2004 18:33:15 +0000 (18:33 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 20 Sep 2004 18:33:15 +0000 (18:33 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@1087 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Action.py
src/engine/SCons/ActionTests.py

index ee2c546a1db50e33db30dd2b95c58f64416264cc..1d015109432eb20d52b75ff74e41449be12ccb6f 100644 (file)
@@ -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
index c131693354b3592570039d4aa2d3ac4c99d5d217..927e3d5f7cfbfcd504c84983ca0ea3792b15e103 100644 (file)
@@ -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)
index a61571eb065924b799ecb02b2674b8b11a564548..bc2387a27f42ff3aafadc7431b62b2381fbf8ec7 100644 (file)
@@ -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