Class: Rake::Task

Inherits:
Object show all
Defined in:
lib/buildr/core/application.rb

Overview

Rake’s circular dependency checks (InvocationChain) only applies to task prerequisites, all other cases result in the non too-descriptive thread sleeping error. This change can deal with circular dependencies that occur from direct task invocation, e.g:

task 'foo'=>'bar'
task 'bar' do
  task('foo').invoke
end

Instance Method Summary collapse

Instance Method Details

#invoke(*args) ⇒ Object

:nodoc:



615
616
617
618
# File 'lib/buildr/core/application.rb', line 615

def invoke(*args)
  task_args = TaskArguments.new(arg_names, args)
  invoke_with_call_chain(task_args, Thread.current[:rake_chain] || InvocationChain::EMPTY)
end

#invoke_with_call_chain(task_args, invocation_chain) ⇒ Object



620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
# File 'lib/buildr/core/application.rb', line 620

def invoke_with_call_chain(task_args, invocation_chain)
  new_chain = InvocationChain.append(self, invocation_chain)
  @lock.synchronize do
    if application.options.trace
      puts "** Invoke #{name} #{format_trace_flags}"
    end
    return if @already_invoked
    @already_invoked = true
    begin
      invoke_prerequisites(task_args, new_chain)
    rescue
      trace "Exception while invoking prerequisites of task #{self.inspect}"
      raise
    end
    begin
      old_chain, Thread.current[:rake_chain] = Thread.current[:rake_chain], new_chain
      execute(task_args) if needed?
    ensure
      Thread.current[:rake_chain] = nil
    end
  end
end