Class: Build::Graph::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/build/graph/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(walker, node) ⇒ Task

Returns a new instance of Task.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/build/graph/task.rb', line 24

def initialize(walker, node)
  @walker = walker
  
  @walker.tasks[node] = self
  
  @node = node
  
  @error = nil
  
  @children = []
  
  @state = nil
  
  @inputs_failed = false
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



43
44
45
# File 'lib/build/graph/task.rb', line 43

def children
  @children
end

#errorObject (readonly)

The error, if the execution of the node fails.



47
48
49
# File 'lib/build/graph/task.rb', line 47

def error
  @error
end

#inputsObject (readonly)

Returns the value of attribute inputs.



40
41
42
# File 'lib/build/graph/task.rb', line 40

def inputs
  @inputs
end

#inputs_failedObject (readonly)

A list of any inputs whose relevant tasks failed:



54
55
56
# File 'lib/build/graph/task.rb', line 54

def inputs_failed
  @inputs_failed
end

#nodeObject (readonly)

Returns the value of attribute node.



51
52
53
# File 'lib/build/graph/task.rb', line 51

def node
  @node
end

#outputsObject (readonly)

Returns the value of attribute outputs.



41
42
43
# File 'lib/build/graph/task.rb', line 41

def outputs
  @outputs
end

#stateObject (readonly)

Returns the value of attribute state.



44
45
46
# File 'lib/build/graph/task.rb', line 44

def state
  @state
end

#walkerObject (readonly)

Returns the value of attribute walker.



49
50
51
# File 'lib/build/graph/task.rb', line 49

def walker
  @walker
end

Instance Method Details

#changed!Object



115
116
117
# File 'lib/build/graph/task.rb', line 115

def changed!
  @walker.delete(@node) if (@inputs.update! or @outputs.update!)
end

#complete?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/build/graph/task.rb', line 105

def complete?
  @state == :complete
end

#directoriesObject



119
120
121
# File 'lib/build/graph/task.rb', line 119

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.

Returns:

  • (Boolean)


111
112
113
# File 'lib/build/graph/task.rb', line 111

def dirty?
  @outputs.dirty?(@inputs)
end

#failed?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/build/graph/task.rb', line 101

def failed?
  @state == :failed
end

#inspectObject



123
124
125
# File 'lib/build/graph/task.rb', line 123

def inspect
  "#<#{self.class}:#{'0x%X' % self.object_id} #{@node.inspect} #{@state}>"
end

#invoke(node) ⇒ Object

Raises:

  • (ArgumentError)


93
94
95
96
97
98
99
# File 'lib/build/graph/task.rb', line 93

def invoke(node)
  child_task = @walker.call(node)
  
  raise ArgumentError.new("Invalid child task") unless child_task
  
  @children << child_task
end

#visitObject

Derived task should override this function to provide appropriate behaviour.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/build/graph/task.rb', line 57

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!(:inputs)
    end
    
    unless wait_for_children?
      fail!(:children)
    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