Class: Build::Controller

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

Overview

Represents the top-level build controller that manages the walker and process group.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(limit: nil) {|_self| ... } ⇒ Controller

Initialize the controller, yielding self to allow adding chain nodes.

Yields:

  • (_self)

Yield Parameters:



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

#nodesObject (readonly)

Returns the value of attribute nodes.



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

def nodes
  @nodes
end

#walkerObject (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

Returns:

  • (Boolean)


58
59
60
# File 'lib/build/controller.rb', line 58

def failed?
	@walker.failed?
end

#runObject

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

#updateObject

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