diff --git a/lib/rake.rb b/lib/rake.rb index 498b8d644..2495fbd35 100755 --- a/lib/rake.rb +++ b/lib/rake.rb @@ -590,12 +590,12 @@ def invoke(*args) if application.num_threads == 1 base_invoke(*args) else - if application.parallel_lock.locked? + if application.parallel.lock.locked? raise "Calling Task#invoke within a task is not allowed." end - application.parallel_lock.synchronize { - application.parallel_tasks.clear - application.parallel_parent_flags.clear + application.parallel.lock.synchronize { + application.parallel.tasks.clear + application.parallel.needed.clear base_invoke(*args) application.invoke_parallel(self.name) } @@ -622,23 +622,20 @@ def invoke_with_call_chain(task_args, invocation_chain) # :nodoc: execute(task_args) if needed? else # - # parallel mode + # Parallel mode -- gather tasks for batch execution. # # Either the task knows it's needed or we've marked it as - # such. See next comments. + # needed. + # + # Why do we manually mark tasks as needed? Since this is a + # dry run, files are not created or modified. Therefore the + # 'needed?' result does not propagate through the recursion. # prereqs = invoke_prerequisites_parallel(task_args, new_chain) - if application.parallel_parent_flags[self] or needed? - # gather tasks for batch execution - application.parallel_tasks[name] = [task_args, prereqs] - - # - # Since this is a dry run, parents must be manually marked - # as needed. Files are not created or modified, so the - # the 'needed?' flag does not propagate. - # + if needed? or application.parallel.needed[self] + application.parallel.tasks[name] = [task_args, prereqs] unless invocation_chain == InvocationChain::EMPTY - application.parallel_parent_flags[invocation_chain.value] = true + application.parallel.needed[invocation_chain.value] = true end end end @@ -1758,9 +1755,7 @@ module TaskManager alias :last_comment :last_description # Backwards compatibility attr_accessor :num_threads - attr_reader :parallel_tasks #:nodoc: - attr_reader :parallel_lock #:nodoc: - attr_reader :parallel_parent_flags #:nodoc: + attr_reader :parallel def initialize super @@ -1770,9 +1765,11 @@ def initialize @last_description = nil @num_threads = 1 - @parallel_tasks = Hash.new - @parallel_lock = Mutex.new - @parallel_parent_flags = Hash.new + + @parallel = Struct.new(:tasks, :needed, :lock).new + @parallel.tasks = Hash.new + @parallel.needed = Hash.new + @parallel.lock = Mutex.new end def create_rule(*args, &block) diff --git a/lib/rake/parallel.rb b/lib/rake/parallel.rb index 2c83bdf32..f38e932d4 100644 --- a/lib/rake/parallel.rb +++ b/lib/rake/parallel.rb @@ -1,6 +1,4 @@ -module Rake ; end - require 'rake/comp_tree/comp_tree' module Rake @@ -10,19 +8,17 @@ def invoke_parallel(root_task_name) # :nodoc: # # Build the computation tree from task prereqs. # - parallel_tasks.each_pair { |task_name, cache| + self.parallel.tasks.each_pair { |task_name, cache| task = self[task_name] task_args, prereqs = cache - children_names = prereqs.map { |child| - child.name.to_sym - } - driver.define(task_name.to_sym, *children_names) { + children_names = prereqs.map { |child| child.name } + driver.define(task_name, *children_names) { task.execute(task_args) true } } - root_node = driver.nodes[root_task_name.to_sym] + root_node = driver.nodes[root_task_name] # # If there were nothing to do, there would be no root node. @@ -40,7 +36,7 @@ def invoke_parallel(root_task_name) # :nodoc: # # Launch the computation. # - driver.compute(root_node.name, num_threads) + driver.compute(root_node.name, self.num_threads) end end end