8 # Copyright (c) 2001 Steven Knight
10 # Permission is hereby granted, free of charge, to any person obtaining
11 # a copy of this software and associated documentation files (the
12 # "Software"), to deal in the Software without restriction, including
13 # without limitation the rights to use, copy, modify, merge, publish,
14 # distribute, sublicense, and/or sell copies of the Software, and to
15 # permit persons to whom the Software is furnished to do so, subject to
16 # the following conditions:
18 # The above copyright notice and this permission notice shall be included
19 # in all copies or substantial portions of the Software.
21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
22 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
23 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
40 """Default SCons build engine task.
42 This controls the interaction of the actual building of node
43 and the rest of the engine.
45 This is expected to handle all of the normally-customizable
46 aspects of controlling a build, so any given application
47 *should* be able to do what it wants by sub-classing this
48 class and overriding methods as appropriate. If an application
49 needs to customze something by sub-classing Taskmaster (or
50 some other build engine class), we should first try to migrate
51 that functionality into this class.
53 Note that it's generally a good idea for sub-classes to call
54 these methods explicitly to update state, etc., rather than
55 roll their own interaction with Taskmaster from scratch."""
56 def __init__(self, tm, target, top):
62 if not self.target.get_state() == SCons.Node.up_to_date:
66 """Fetch the target being built or updated by this task.
70 def set_bsig(self, bsig):
71 """Set the task's (*not* the target's) build signature.
73 This will be used later to update the target's build
74 signature if the build succeeds."""
77 def set_tstate(self, state):
78 """Set the target node's state."""
79 self.target.set_state(state)
82 """Called when the task has been successfully executed.
84 This may have been a do-nothing operation (to preserve
85 build order), so check the node's state before updating
86 things. Most importantly, this calls back to the
87 Taskmaster to put any node tasks waiting on this one
88 back on the pending list."""
89 if self.target.get_state() == SCons.Node.executing:
90 self.set_tstate(SCons.Node.executed)
91 self.target.set_bsig(self.bsig)
92 self.tm.add_pending(self.target)
95 """Default action when a task fails: stop the build."""
99 """Explicit stop-the-build failure."""
100 self.set_tstate(SCons.Node.failed)
103 def fail_continue(self):
104 """Explicit continue-the-build failure.
106 This sets failure status on the target node and all of
107 its dependent parent nodes.
109 def get_parents(node): return node.get_parents()
110 walker = SCons.Node.Walker(self.target, get_parents)
113 if node == None: break
114 self.tm.remove_pending(node)
115 node.set_state(SCons.Node.failed)
120 def bsig(self, node):
125 def current(self, node, sig):
126 """Default SCons build engine is-it-current function.
128 This returns "always out of date," so every node is always
136 """A generic Taskmaster for handling a bunch of targets.
138 Classes that override methods of this class should call
139 the base class method, so this class can do its thing.
142 def __init__(self, targets=[], tasker=Task, calc=Calc()):
143 self.walkers = map(SCons.Node.Walker, targets)
149 self._find_next_ready_node()
152 """Return the next task to be executed."""
154 task = self.ready.pop()
156 self._find_next_ready_node()
161 def _find_next_ready_node(self):
162 """Find the next node that is ready to be built"""
164 n = self.walkers[0].next()
169 # The state is set, so someone has already been here
170 # (finished or currently executing). Find another one.
173 # It's a source file, we don't need to build it,
174 # but mark it as "up to date" so targets won't
176 n.set_state(SCons.Node.up_to_date)
177 # set the signature for non-derived files
178 # here so they don't get recalculated over
180 n.set_csig(self.calc.csig(n))
182 task = self.tasker(self, n, self.walkers[0].is_done())
183 if not n.children_are_executed():
184 n.set_state(SCons.Node.pending)
186 self.pending = self.pending + 1
188 self.make_ready(task, n)
191 def is_blocked(self):
192 return not self.ready and self.pending
195 """Stop the current build completely."""
200 def add_pending(self, node):
201 """Add all the pending parents that are now executable
202 to the 'ready' queue."""
203 ready = filter(lambda x: (x.get_state() == SCons.Node.pending
204 and x.children_are_executed()),
209 self.make_ready(task, n)
210 self.pending = self.pending - len(ready)
212 def remove_pending(self, node):
213 """Remove a node from the 'ready' queue."""
214 if node.get_state() == SCons.Node.pending:
215 self.pending = self.pending - 1
217 def make_ready(self, task, node):
218 """Common routine that takes a single task+node and makes
219 them available on the 'ready' queue."""
220 bsig = self.calc.bsig(node)
222 if self.calc.current(node, bsig):
223 task.set_tstate(SCons.Node.up_to_date)
225 task.set_tstate(SCons.Node.executing)
226 self.ready.append(task)