class Teapot::Command::Build

Public Instance Methods

call() click to toggle source
# File lib/teapot/command/build.rb, line 41
def call
        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
        environment = context.configuration.environment
        
        controller = ::Build::Controller.new(logger: parent.logger, limit: @options[:limit]) do |controller|
                controller.add_chain(chain, self.argv, environment)
        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
end
show_dependencies(walker) click to toggle source
# File lib/teapot/command/build.rb, line 83
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