lib/build/dependency_node.rb in build-2.5.2 vs lib/build/dependency_node.rb in build-2.6.0

- old
+ new

@@ -18,11 +18,11 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. require 'build/graph' -require_relative 'build_node' +require_relative 'provision_node' module Build class DependencyNode < Graph::Node def initialize(chain, dependency, environment, arguments) @chain = chain @@ -46,11 +46,11 @@ @environment == other.environment and @arguments == other.arguments end def hash - super ^ @chain.hash ^ @environment.hash ^ @arguments.hash + super ^ @chain.hash ^ @dependency.hash ^ @environment.hash ^ @arguments.hash end def task_class(parent_task) DependencyTask end @@ -61,117 +61,67 @@ def provisions @chain.resolved[@dependency] end - def alias? - @dependency.alias? - end - def public? @dependency.public? end - # This is the main entry point when invoking the node from `Build::Task`. - def apply!(task) - # Go through all the dependencies in order and apply them to the build graph: - @chain.dependencies.each do |dependency| - node = DependencyNode.new(@chain, dependency, @environment, @arguments) - - task.invoke(node) - end + def provision_node_for(provision) + ProvisionNode.new(@chain, provision, @environment, @arguments) end - - def dependency_node_for(dependency) - DependencyNode.new(@chain, dependency, @environment, @arguments) + end + + module ProvisionsFailed + def self.to_s + "Failed to build all provisions!" end - - def print_dependencies(buffer = $stderr, level = 0) - self.provisions.each do |provision| - buffer.puts "#{" " * indentation}building #{provision.provider.name} which #{provision} which depends on:" - - provision.each_dependency do |nested_dependency| - child = self.dependency_node_for(nested_dependency) - - child.print_dependencies(buffer, level + 1) - end - end - - return nil - end end class DependencyTask < Task def initialize(*arguments, **options) super + @provisions = [] + + @environments = nil @environment = nil - @tasks = [] end - attr :group - attr :logger - attr :environment + def dependency + @node.dependency + end + def update logger.debug(self) do |buffer| buffer.puts "building #{@node} which #{@node.dependency}" @node.provisions.each do |provision| buffer.puts "\tbuilding #{provision.provider.name} which #{provision}" end end # Lookup what things this dependency provides: @node.provisions.each do |provision| - provision.each_dependency do |nested_dependency| - @tasks << invoke(@node.dependency_node_for(nested_dependency)) - end + @provisions << invoke( + @node.provision_node_for(provision) + ) end + + if wait_for_children? + update_environments! + else + fail!(ProvisionsFailed) + end end - def update_outputs - dependency = @node.dependency - environments = [@node.environment] + private + + def update_environments! + @environments = @provisions.flat_map(&:output_environments) - public_environments = [] - public_alias = @node.alias? - - @tasks.each do |task| - if environment = task.environment - environments << environment - - if public_alias || task.node.public? - public_environments << environment - # else - # logger.debug("Skipping #{nested_dependency} in public environment.") - end - end - end - - unless public_alias - logger.debug(self) {"Building: #{dependency} <- #{@tasks.join}"} - - # environments.each do |environment| - # logger.debug {"Using #{environment}"} - # end - - local_environment = Build::Environment.combine(*environments)&.evaluate(name: dependency.name) || Build::Environment.new(name: dependency.name) - - # logger.debug("Local Environment: #{local_environment}") - - build_task = invoke( - BuildNode.new(local_environment, @node.provisions, @node.arguments) - ) - - if wait_for_children? - output_environment = build_task.output_environment - public_environments << output_environment.dup(parent: nil, name: dependency.name) - end - end - - @environment = Build::Environment.combine(*public_environments) - - super + @environment = Build::Environment.combine(*@environments) end end end