Permalink
Browse files

Merge branch 'all-tasks-are-multitasks' of https://github.com/michael…

…jbishop/rake into dashm

* 'all-tasks-are-multitasks' of https://github.com/michaeljbishop/rake:
  Added -m option which changes all tasks into multitasks

Conflicts:
	lib/rake/application.rb
	lib/rake/multi_task.rb
  • Loading branch information...
2 parents 93ad875 + c249a0a commit 7c777ff6d8315cf216aeecdd2ce1683fb59eb6ee @jimweirich committed Oct 24, 2012
@@ -49,6 +49,9 @@ Options are:
[<tt>--libdir</tt> _directory_ (-I)]
Add _directory_ to the list of directories searched for require.
+[<tt>--multitask</tt> (-m)]
+ Treat all tasks as multitasks. ('make/drake' semantics)
+
[<tt>--nosearch</tt> (-N)]
Do not search for a Rakefile in parent directories.
View
@@ -370,6 +370,9 @@ def standard_rake_options
['--libdir', '-I LIBDIR', "Include LIBDIR in the search path for required modules.",
lambda { |value| $:.push(value) }
],
+ ['--multitask', '-m', "Treat all tasks as multitasks.",
+ lambda { |value| options.always_multitask = true }
+ ],
['--no-search', '--nosearch', '-N', "Do not search parent directories for the Rakefile.",
lambda { |value| options.nosearch = true }
],
@@ -663,6 +666,6 @@ def rakefile_location(backtrace=caller)
private
FIXNUM_MAX = (2**(0.size * 8 - 2) - 1) # :nodoc:
-
+
end
end
View
@@ -5,13 +5,8 @@ module Rake
#
class MultiTask < Task
private
- def invoke_prerequisites(args, invocation_chain)
- futures = @prerequisites.collect do |p|
- application.thread_pool.future(p) do |r|
- application[r, @scope].invoke_with_call_chain(args, invocation_chain)
- end
- end
- futures.each { |f| f.value }
+ def invoke_prerequisites(task_args, invocation_chain) # :nodoc:
+ invoke_prerequisites_concurrently(task_args, invocation_chain)
end
end
View
@@ -179,10 +179,24 @@ def add_chain_to(exception, new_chain)
# Invoke all the prerequisites of a task.
def invoke_prerequisites(task_args, invocation_chain) # :nodoc:
- prerequisite_tasks.each { |prereq|
- prereq_args = task_args.new_scope(prereq.arg_names)
- prereq.invoke_with_call_chain(prereq_args, invocation_chain)
- }
+ if application.options.always_multitask
+ invoke_prerequisites_concurrently(task_args, invocation_chain)
+ else
+ prerequisite_tasks.each { |prereq|
+ prereq_args = task_args.new_scope(prereq.arg_names)
+ prereq.invoke_with_call_chain(prereq_args, invocation_chain)
+ }
+ end
+ end
+
+ # Invoke all the prerequisites of a task in parallel.
+ def invoke_prerequisites_concurrently(args, invocation_chain) # :nodoc:
+ futures = @prerequisites.collect do |p|
+ application.thread_pool.future(p) do |r|
+ application[r, @scope].invoke_with_call_chain(args, invocation_chain)
+ end
+ end
+ futures.each { |f| f.call }
end
# Format the trace flags for display.
@@ -34,6 +34,7 @@ def test_default_options
assert_nil opts.dryrun
assert_nil opts.ignore_system
assert_nil opts.load_system
+ assert_nil opts.always_multitask
assert_nil opts.nosearch
assert_equal ['rakelib'], opts.rakelib
assert_nil opts.show_prereqs
@@ -132,6 +133,12 @@ def test_libdir
$:.delete('xx')
end
+ def test_multitask
+ flags('--multitask', '-m') do |opts|
+ assert_equal opts.always_multitask, true
+ end
+ end
+
def test_rakefile
flags(['--rakefile', 'RF'], ['--rakefile=RF'], ['-f', 'RF'], ['-fRF']) do |opts|
assert_equal ['RF'], @app.instance_eval { @rakefiles }
View
@@ -241,6 +241,38 @@ def c.timestamp() Time.now + 5 end
assert_in_delta now + 10, a.timestamp, 0.1, 'computer too slow?'
end
+ def test_always_multitask
+ mx = Mutex.new
+ result = ""
+
+ t_a = task(:a) do |t|
+ sleep 0.02
+ mx.synchronize{ result << t.name }
+ end
+
+ t_b = task(:b) do |t|
+ mx.synchronize{ result << t.name }
+ end
+
+ t_c = task(:c => [:a,:b]) do |t|
+ mx.synchronize{ result << t.name }
+ end
+
+ t_c.invoke
+
+ # task should always run in order
+ assert_equal 'abc', result
+
+ [t_a, t_b, t_c].each { |t| t.reenable }
+ result.clear
+
+ Rake.application.options.always_multitask = true
+ t_c.invoke
+
+ # with multitask, task 'b' should grab the mutex first
+ assert_equal 'bac', result
+ end
+
def test_investigation_output
t1 = task(:t1 => [:t2, :t3]) { |t| runlist << t.name; 3321 }
task(:t2)

0 comments on commit 7c777ff

Please sign in to comment.