Class: Build::Controller
- Inherits:
-
Object
- Object
- Build::Controller
- Defined in:
- lib/build/controller.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#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(logger: Console.logger, limit: nil) {|_self| ... } ⇒ Controller
constructor
A new instance of Controller.
-
#run ⇒ Object
The entry point for running the walker over the build graph.
- #step(walker, node, parent_task = nil) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(logger: Console.logger, limit: nil) {|_self| ... } ⇒ Controller
Returns a new instance of Controller.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/build/controller.rb', line 37 def initialize(logger: Console.logger, limit: nil) @module = Module.new @logger = logger # 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(logger: @logger, &self.method(:step)) end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
55 56 57 |
# File 'lib/build/controller.rb', line 55 def logger @logger end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
57 58 59 |
# File 'lib/build/controller.rb', line 57 def nodes @nodes end |
#walker ⇒ Object (readonly)
Returns the value of attribute walker.
58 59 60 |
# File 'lib/build/controller.rb', line 58 def walker @walker end |
Instance Method Details
#add_chain(chain, arguments = [], environment) ⇒ Object
Add a build environment to the controller.
74 75 76 |
# File 'lib/build/controller.rb', line 74 def add_chain(chain, arguments = [], environment) @nodes << ChainNode.new(chain, arguments, environment) end |
#failed? ⇒ Boolean
69 70 71 |
# File 'lib/build/controller.rb', line 69 def failed? @walker.failed? end |
#run ⇒ Object
The entry point for running the walker over the build graph.
88 89 90 91 92 93 94 |
# File 'lib/build/controller.rb', line 88 def run @walker.run do self.update yield @walker if block_given? end end |
#step(walker, node, parent_task = nil) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/build/controller.rb', line 60 def step(walker, node, parent_task = nil) task_class = node.task_class(parent_task) || Task task = task_class.new(walker, node, @group, logger: @logger) task.visit do task.update end end |
#update ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/build/controller.rb', line 78 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 |