Class: Build::Controller

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Controller.

Yields:

  • (_self)

Yield Parameters:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/build/controller.rb', line 37

def initialize(logger: nil, limit: nil)
	@module = Module.new
	
	@logger = logger || Logger.new($stdout).tap do |logger|
		logger.level = Logger::INFO
		logger.formatter = CompactFormatter.new
	end
	
	# 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

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

#nodesObject (readonly)

Returns the value of attribute nodes.



60
61
62
# File 'lib/build/controller.rb', line 60

def nodes
  @nodes
end

#walkerObject (readonly)

Returns the value of attribute walker.



61
62
63
# File 'lib/build/controller.rb', line 61

def walker
  @walker
end

Instance Method Details

#add_target(target, environment) ⇒ Object

Add a build target to the controller.



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/build/controller.rb', line 76

def add_target(target, environment)
	task_class = Rulebook.for(environment).with(Task, environment: environment, target: target)
	
	# Not sure if this is a good idea - makes debugging slightly easier.
	Object.const_set("TaskClassFor#{Name.from_target(target.name).identifier}_#{task_class.object_id}", task_class)
	
	# A target node will invoke the build callback on target.
	@nodes << TargetNode.new(task_class, target)
	
	return @nodes.last
end

#failed?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/build/controller.rb', line 71

def failed?
	@walker.failed?
end

#runObject

The entry point for running the walker over the build graph.



98
99
100
101
102
103
104
# File 'lib/build/controller.rb', line 98

def run
	@walker.run do
		self.update
		
		yield @walker if block_given?
	end
end

#updateObject



88
89
90
91
92
93
94
95
# File 'lib/build/controller.rb', line 88

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, task_class: node.task_class)
		end
	end
end