Class: Build::ChainNode

Inherits:
Graph::Node
  • Object
show all
Defined in:
lib/build/chain_node.rb

Instance Method Summary collapse

Constructor Details

#initialize(chain, arguments, environment) ⇒ ChainNode

Returns a new instance of ChainNode.



28
29
30
31
32
33
34
35
# File 'lib/build/chain_node.rb', line 28

def initialize(chain, arguments, environment)
  @chain = chain
  @arguments = arguments
  @environment = environment
  
  # Wait here, for all dependent targets, to be done:
  super(Files::List::NONE, :inherit, chain)
end

Instance Method Details

#apply!(scope) ⇒ Object



98
99
100
101
102
# File 'lib/build/chain_node.rb', line 98

def apply!(scope)
  @chain.dependencies.each do |dependency|
    apply_dependency(scope, dependency)
  end
end

#apply_dependency(scope, dependency) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/build/chain_node.rb', line 41

def apply_dependency(scope, dependency)
  logger = scope.logger
  
  # logger.debug {"Traversing: #{dependency}..."}
  
  environments = [@environment]
  public_environments = []
  provisions = @chain.resolved[dependency]
  public_alias = dependency.alias?
  
  provisions.each do |provision|
    provision.each_dependency do |nested_dependency|
      if environment = apply_dependency(scope, nested_dependency)
        # logger.debug("Evaluating #{nested_dependency} -> #{provision} generated: #{environment}")
        
        environments << environment
        
        if public_alias || nested_dependency.public?
          public_environments << environment
        # else
        #   logger.debug("Skipping #{nested_dependency} in public environment.")
        end
      end
    end
  end
  
  unless dependency.alias?
    logger.debug {"Building: #{dependency}"}
    
    # environments.each do |environment|
    #   logger.debug {"Using #{environment}"}
    # end
    
    local_environment = Build::Environment.combine(*environments)&.evaluate || Build::Environment.new
    
    # logger.debug("Local Environment: #{local_environment}")
    
    task_class = Rulebook.for(local_environment).with(Task, environment: local_environment)
    task = task_class.new(scope.walker, self, scope.group, logger: scope.logger)
    
    output_environment = nil
    
    task.visit do
      output_environment = Build::Environment.new(local_environment, name: dependency.name)
      
      provisions.each do |provision|
        # When executing the environment build steps, we create new build nodes. But those build nodes are not capturing the right task class.
        output_environment.construct!(task, *@arguments, &provision.value)
      end
      
      public_environments << output_environment.dup(parent: nil, name: dependency.name)
    end
  end
  
  return Build::Environment.combine(*public_environments)
end

#task_classObject



37
38
39
# File 'lib/build/chain_node.rb', line 37

def task_class
  Task
end

#to_sObject



104
105
106
# File 'lib/build/chain_node.rb', line 104

def to_s
  "#<#{self.class}>"
end