Class: Build::Graph::Task
- Inherits:
-
Object
- Object
- Build::Graph::Task
- Defined in:
- lib/build/graph/task.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#error ⇒ Object
readonly
The error, if the execution of the node fails.
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#inputs_failed ⇒ Object
readonly
A list of any inputs whose relevant tasks failed:.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#outputs ⇒ Object
readonly
Returns the value of attribute outputs.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#walker ⇒ Object
readonly
Returns the value of attribute walker.
Instance Method Summary collapse
- #changed! ⇒ Object
- #complete? ⇒ Boolean
- #directories ⇒ Object
-
#dirty? ⇒ Boolean
Returns true if the outputs of the task are out of date w.r.t.
- #failed? ⇒ Boolean
-
#initialize(walker, node) ⇒ Task
constructor
A new instance of Task.
- #inspect ⇒ Object
- #invoke(node) ⇒ Object
-
#visit ⇒ Object
Derived task should override this function to provide appropriate behaviour.
Constructor Details
#initialize(walker, node) ⇒ Task
Returns a new instance of Task.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/build/graph/task.rb', line 39 def initialize(walker, node) @walker = walker @walker.tasks[node] = self @node = node @error = nil @children = [] @state = nil @inputs_failed = false end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
58 59 60 |
# File 'lib/build/graph/task.rb', line 58 def children @children end |
#error ⇒ Object (readonly)
The error, if the execution of the node fails.
62 63 64 |
# File 'lib/build/graph/task.rb', line 62 def error @error end |
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
55 56 57 |
# File 'lib/build/graph/task.rb', line 55 def inputs @inputs end |
#inputs_failed ⇒ Object (readonly)
A list of any inputs whose relevant tasks failed:
69 70 71 |
# File 'lib/build/graph/task.rb', line 69 def inputs_failed @inputs_failed end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
66 67 68 |
# File 'lib/build/graph/task.rb', line 66 def node @node end |
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
56 57 58 |
# File 'lib/build/graph/task.rb', line 56 def outputs @outputs end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
59 60 61 |
# File 'lib/build/graph/task.rb', line 59 def state @state end |
#walker ⇒ Object (readonly)
Returns the value of attribute walker.
64 65 66 |
# File 'lib/build/graph/task.rb', line 64 def walker @walker end |
Instance Method Details
#changed! ⇒ Object
130 131 132 |
# File 'lib/build/graph/task.rb', line 130 def changed! @walker.delete(@node) if (@inputs.update! or @outputs.update!) end |
#complete? ⇒ Boolean
120 121 122 |
# File 'lib/build/graph/task.rb', line 120 def complete? @state == :complete end |
#directories ⇒ Object
134 135 136 |
# File 'lib/build/graph/task.rb', line 134 def directories (@inputs.roots + @outputs.roots).collect{|path| path.to_s} end |
#dirty? ⇒ Boolean
Returns true if the outputs of the task are out of date w.r.t. the inputs. Currently, does not take into account if the input is a glob and files have been added.
126 127 128 |
# File 'lib/build/graph/task.rb', line 126 def dirty? @outputs.dirty?(@inputs) end |
#failed? ⇒ Boolean
116 117 118 |
# File 'lib/build/graph/task.rb', line 116 def failed? @state == :failed end |
#inspect ⇒ Object
138 139 140 |
# File 'lib/build/graph/task.rb', line 138 def inspect "#<#{self.class}:#{'0x%X' % self.object_id} #{@node.inspect} #{@state}>" end |
#invoke(node) ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/build/graph/task.rb', line 108 def invoke(node) child_task = @walker.call(node, self) raise ArgumentError.new("Invalid child task") unless child_task @children << child_task end |
#visit ⇒ Object
Derived task should override this function to provide appropriate behaviour.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/build/graph/task.rb', line 72 def visit update_inputs_and_outputs # Inforn the walker a new task is being generated for this node: @walker.enter(self) @fiber = Fiber.new do # If all inputs were good, we can update the node. if wait_for_inputs? begin yield rescue TransientError => error fail!(error) end else fail!(InputsFailed) end unless wait_for_children? fail!(ChildrenFailed) end update_outputs @state ||= :complete @walker.exit(self) end # Schedule the work, hopefully synchronously: @fiber.resume # This allows the child task to be passed back to the parent when it is first invoked. return self end |