Class: Teapot::Command::Build

Inherits:
Samovar::Command
  • Object
show all
Defined in:
lib/teapot/command/build.rb

Instance Method Summary collapse

Instance Method Details

#invoke(parent) ⇒ Object



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
# File 'lib/teapot/command/build.rb', line 42

def invoke(parent)
  context = parent.context
  
  # The targets to build:
  if @targets.any?
    selection = context.select(@targets)
  else
    selection = context.select(context.configuration.targets[:build])
  end
  
  chain = selection.chain
  
  ordered = chain.ordered
  
  if @options[:only]
    ordered = selection.direct_targets(ordered)
  end
  
  controller = ::Build::Controller.new(logger: parent.logger, limit: @options[:limit]) do |controller|
    ordered.each do |resolution|
      target = resolution.provider
      
      if target.build
        environment = target.environment(selection.configuration, chain)
        
        controller.add_target(target, environment.flatten, self.argv)
      end
    end
  end
  
  walker = nil
  
  # We need to catch interrupt here, and exit with the correct exit code:
  begin
    controller.run do |walker|
      # show_dependencies(walker)
      
      # Only run once is asked:
      unless @options[:continuous]
        if walker.failed?
          raise BuildFailedError.new("Failed to build all nodes successfully!")
        end
      
        break
      end
    end
  rescue Interrupt
    if walker && walker.failed?
      raise BuildFailedError.new("Failed to build all nodes successfully!")
    end
  end
  
  return chain, ordered
end

#show_dependencies(walker) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/teapot/command/build.rb', line 97

def show_dependencies(walker)
  outputs = {}
  
  walker.tasks.each do |node, task|
    # puts "Task #{task} (#{node}) outputs:"
    
    task.outputs.each do |path|
      path = path.to_s
      
      # puts "\t#{path}"
      
      outputs[path] = task
    end
  end
  
  walker.tasks.each do |node, task|
    dependencies = {}
    task.inputs.each do |path|
      path = path.to_s
      
      if generating_task = outputs[path]
        dependencies[path] = generating_task
      end
    end
    
    puts "Task #{task.inspect} has #{dependencies.count} dependencies."
    dependencies.each do |path, task|
      puts "\t#{task.inspect}: #{path}"
    end
  end
end