Cleaner Task interface when using the -c option.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 8 May 2004 22:56:08 +0000 (22:56 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 8 May 2004 22:56:08 +0000 (22:56 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@972 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Script/__init__.py
src/engine/SCons/Taskmaster.py
src/engine/SCons/TaskmasterTests.py

index 3a7d4c1cbe7263be6372cebc7e527fdd07449289..79786291f708fa2ee3f055e7dba4bcd9790efae0 100644 (file)
@@ -267,6 +267,11 @@ class CleanTask(SCons.Taskmaster.Task):
 
     execute = remove
 
+    # Have the taskmaster arrange to "execute" all of the targets, because
+    # we'll figure out ourselves (in remove() or show() above) whether
+    # anything really needs to be done.
+    make_ready = SCons.Taskmaster.Task.make_ready_all
+
     def prepare(self):
         pass
 
@@ -1051,7 +1056,6 @@ def _main(args, parser):
 
     nodes = filter(lambda x: x is not None, map(Entry, targets))
 
-    calc = None
     task_class = BuildTask     # default action is to build targets
     opening_message = "Building targets ..."
     closing_message = "done building targets."
@@ -1061,16 +1065,6 @@ def _main(args, parser):
     try:
         if ssoptions.get('clean'):
             task_class = CleanTask
-            class CleanCalculator:
-                def bsig(self, node):
-                    return None
-                def csig(self, node):
-                    return None
-                def current(self, node, sig):
-                    return 0
-                def write(self):
-                    pass
-            calc = CleanCalculator()
             opening_message = "Cleaning targets ..."
             closing_message = "done cleaning targets."
             failure_message = "cleaning terminated because of errors."
@@ -1095,7 +1089,7 @@ def _main(args, parser):
             return dependencies
 
     progress_display("scons: " + opening_message)
-    taskmaster = SCons.Taskmaster.Taskmaster(nodes, task_class, calc, order)
+    taskmaster = SCons.Taskmaster.Taskmaster(nodes, task_class, None, order)
 
     nj = ssoptions.get('num_jobs')
     jobs = SCons.Job.Jobs(nj, taskmaster)
index ffdc065a8bfcae10cb1355a96b650e724e25effb..e5b35483b6460735420de084722957da9ed5aa17 100644 (file)
@@ -167,8 +167,25 @@ class Task:
 
         self.tm.executed(self.node)
 
-    def make_ready(self):
-        """Make a task ready for execution."""
+    def make_ready_all(self):
+        """Mark all targets in a task ready for execution.
+
+        This is used when the interface needs every target Node to be
+        visited--the canonical example being the "scons -c" option.
+        """
+        self.out_of_date = self.targets[:]
+        state = SCons.Node.executing
+        for t in self.targets:
+            for side_effect in t.side_effects:
+                side_effect.set_state(state)
+            t.set_state(state)
+
+    def make_ready_current(self):
+        """Mark all targets in a task ready for execution if any target
+        is not current.
+
+        This is the default behavior for building only what's necessary.
+        """
         self.out_of_date = []
         calc = self.tm.calc
         if calc:
@@ -190,6 +207,8 @@ class Task:
             for t in self.targets:
                 t.set_state(state)
 
+    make_ready = make_ready_current
+
     def postprocess(self):
         """Post process a task after it's been executed."""
         for t in self.targets:
index 1f66e06bb9d82bec121a2763094cbde3c30de808..8ca7e86f035b093204b127b1804daf21413e45dd 100644 (file)
@@ -470,6 +470,71 @@ class TaskmasterTestCase(unittest.TestCase):
         assert str(e.value) == "from make_ready()", str(e.value)
 
 
+    def test_make_ready_all(self):
+        class MyCalc(SCons.Taskmaster.Calc):
+            def current(self, node, sig):
+                n = str(node)
+                return n[0] == 'c'
+
+        class MyTask(SCons.Taskmaster.Task):
+            make_ready = SCons.Taskmaster.Task.make_ready_all
+
+        n1 = Node("n1")
+        c2 = Node("c2")
+        n3 = Node("n3")
+        c4 = Node("c4")
+
+        tm = SCons.Taskmaster.Taskmaster(targets = [n1, c2, n3, c4],
+                                         calc = MyCalc())
+
+        t = tm.next_task()
+        target = t.get_target()
+        assert target is n1, target
+        assert target.state == SCons.Node.executing, target.state
+        t = tm.next_task()
+        target = t.get_target()
+        assert target is c2, target
+        assert target.state == SCons.Node.up_to_date, target.state
+        t = tm.next_task()
+        target = t.get_target()
+        assert target is n3, target
+        assert target.state == SCons.Node.executing, target.state
+        t = tm.next_task()
+        target = t.get_target()
+        assert target is c4, target
+        assert target.state == SCons.Node.up_to_date, target.state
+        t = tm.next_task()
+        assert t is None
+
+        n1 = Node("n1")
+        c2 = Node("c2")
+        n3 = Node("n3")
+        c4 = Node("c4")
+
+        tm = SCons.Taskmaster.Taskmaster(targets = [n1, c2, n3, c4],
+                                         tasker = MyTask,
+                                         calc = MyCalc())
+
+        t = tm.next_task()
+        target = t.get_target()
+        assert target is n1, target
+        assert target.state == SCons.Node.executing, target.state
+        t = tm.next_task()
+        target = t.get_target()
+        assert target is c2, target
+        assert target.state == SCons.Node.executing, target.state
+        t = tm.next_task()
+        target = t.get_target()
+        assert target is n3, target
+        assert target.state == SCons.Node.executing, target.state
+        t = tm.next_task()
+        target = t.get_target()
+        assert target is c4, target
+        assert target.state == SCons.Node.executing, target.state
+        t = tm.next_task()
+        assert t is None
+
+
     def test_children_errors(self):
         """Test errors when fetching the children of a node.
         """