Class: Build::Controller
- Inherits:
-
Object
- Object
- Build::Controller
- Defined in:
- lib/build/controller.rb
Overview
Represents the top-level build controller that manages the walker and process group.
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#walker ⇒ Object
readonly
Returns the value of attribute walker.
Instance Method Summary collapse
-
#add_chain(chain, arguments = [], environment) ⇒ Object
Add a build environment to the controller.
- #failed? ⇒ Boolean
-
#initialize(limit: nil) {|_self| ... } ⇒ Controller
constructor
Initialize the controller, yielding self to allow adding chain nodes.
-
#run ⇒ Object
The entry point for running the walker over the build graph.
-
#step(walker, node, parent_task = nil) ⇒ Object
Execute a single step of the build graph for the given node.
-
#update ⇒ Object
Execute all top-level nodes, waiting for each to complete.
Constructor Details
#initialize(limit: nil) {|_self| ... } ⇒ Controller
Initialize the controller, yielding self to allow adding chain nodes.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/build/controller.rb', line 25 def initialize(limit: nil) @module = Module.new # Top level nodes, for sanity this is a static list. @nodes = [] yield self @nodes.freeze @group = Process::Group.new(limit: limit) # The task class is captured as we traverse all the top level targets: @task_class = nil @walker = Graph::Walker.new(&self.method(:step)) end |
Instance Attribute Details
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
41 42 43 |
# File 'lib/build/controller.rb', line 41 def nodes @nodes end |
#walker ⇒ Object (readonly)
Returns the value of attribute walker.
42 43 44 |
# File 'lib/build/controller.rb', line 42 def walker @walker end |
Instance Method Details
#add_chain(chain, arguments = [], environment) ⇒ Object
Add a build environment to the controller.
63 64 65 |
# File 'lib/build/controller.rb', line 63 def add_chain(chain, arguments = [], environment) @nodes << ChainNode.new(chain, arguments, environment) end |
#failed? ⇒ Boolean
58 59 60 |
# File 'lib/build/controller.rb', line 58 def failed? @walker.failed? end |
#run ⇒ Object
The entry point for running the walker over the build graph.
78 79 80 81 82 83 84 |
# File 'lib/build/controller.rb', line 78 def run @walker.run do self.update yield @walker if block_given? end end |
#step(walker, node, parent_task = nil) ⇒ Object
Execute a single step of the build graph for the given node.
48 49 50 51 52 53 54 55 |
# File 'lib/build/controller.rb', line 48 def step(walker, node, parent_task = nil) task_class = node.task_class(parent_task) || Task task = task_class.new(walker, node, @group) task.visit do task.update end end |
#update ⇒ Object
Execute all top-level nodes, waiting for each to complete.
68 69 70 71 72 73 74 75 |
# File 'lib/build/controller.rb', line 68 def update @nodes.each do |node| # We wait for all processes to complete within each node. The result is that we don't execute top level nodes concurrently, but we do execute within each node concurrently where possible. Ideally, some node could be executed concurrently, but right now expressing non-file dependencies between nodes is not possible. @group.wait do @walker.call(node) end end end |