Skip to content

Commit

Permalink
Merge branch 'all-tasks-are-multitasks' of https://github.com/michael…
Browse files Browse the repository at this point in the history
…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
jimweirich committed Oct 24, 2012
2 parents 93ad875 + c249a0a commit 7c777ff
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 12 deletions.
3 changes: 3 additions & 0 deletions doc/command_line_usage.rdoc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ Options are:
[<tt>--libdir</tt> _directory_ (-I)] [<tt>--libdir</tt> _directory_ (-I)]
Add _directory_ to the list of directories searched for require. 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)] [<tt>--nosearch</tt> (-N)]
Do not search for a Rakefile in parent directories. Do not search for a Rakefile in parent directories.


Expand Down
5 changes: 4 additions & 1 deletion lib/rake/application.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ def standard_rake_options
['--libdir', '-I LIBDIR', "Include LIBDIR in the search path for required modules.", ['--libdir', '-I LIBDIR', "Include LIBDIR in the search path for required modules.",
lambda { |value| $:.push(value) } 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.", ['--no-search', '--nosearch', '-N', "Do not search parent directories for the Rakefile.",
lambda { |value| options.nosearch = true } lambda { |value| options.nosearch = true }
], ],
Expand Down Expand Up @@ -663,6 +666,6 @@ def rakefile_location(backtrace=caller)


private private
FIXNUM_MAX = (2**(0.size * 8 - 2) - 1) # :nodoc: FIXNUM_MAX = (2**(0.size * 8 - 2) - 1) # :nodoc:

end end
end end
9 changes: 2 additions & 7 deletions lib/rake/multi_task.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@ module Rake
# #
class MultiTask < Task class MultiTask < Task
private private
def invoke_prerequisites(args, invocation_chain) def invoke_prerequisites(task_args, invocation_chain) # :nodoc:
futures = @prerequisites.collect do |p| invoke_prerequisites_concurrently(task_args, invocation_chain)
application.thread_pool.future(p) do |r|
application[r, @scope].invoke_with_call_chain(args, invocation_chain)
end
end
futures.each { |f| f.value }
end end
end end


Expand Down
22 changes: 18 additions & 4 deletions lib/rake/task.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -179,10 +179,24 @@ def add_chain_to(exception, new_chain)


# Invoke all the prerequisites of a task. # Invoke all the prerequisites of a task.
def invoke_prerequisites(task_args, invocation_chain) # :nodoc: def invoke_prerequisites(task_args, invocation_chain) # :nodoc:
prerequisite_tasks.each { |prereq| if application.options.always_multitask
prereq_args = task_args.new_scope(prereq.arg_names) invoke_prerequisites_concurrently(task_args, invocation_chain)
prereq.invoke_with_call_chain(prereq_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 end


# Format the trace flags for display. # Format the trace flags for display.
Expand Down
7 changes: 7 additions & 0 deletions test/test_rake_application_options.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test_default_options
assert_nil opts.dryrun assert_nil opts.dryrun
assert_nil opts.ignore_system assert_nil opts.ignore_system
assert_nil opts.load_system assert_nil opts.load_system
assert_nil opts.always_multitask
assert_nil opts.nosearch assert_nil opts.nosearch
assert_equal ['rakelib'], opts.rakelib assert_equal ['rakelib'], opts.rakelib
assert_nil opts.show_prereqs assert_nil opts.show_prereqs
Expand Down Expand Up @@ -132,6 +133,12 @@ def test_libdir
$:.delete('xx') $:.delete('xx')
end end


def test_multitask
flags('--multitask', '-m') do |opts|
assert_equal opts.always_multitask, true
end
end

def test_rakefile def test_rakefile
flags(['--rakefile', 'RF'], ['--rakefile=RF'], ['-f', 'RF'], ['-fRF']) do |opts| flags(['--rakefile', 'RF'], ['--rakefile=RF'], ['-f', 'RF'], ['-fRF']) do |opts|
assert_equal ['RF'], @app.instance_eval { @rakefiles } assert_equal ['RF'], @app.instance_eval { @rakefiles }
Expand Down
32 changes: 32 additions & 0 deletions test/test_rake_task.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -241,6 +241,38 @@ def c.timestamp() Time.now + 5 end
assert_in_delta now + 10, a.timestamp, 0.1, 'computer too slow?' assert_in_delta now + 10, a.timestamp, 0.1, 'computer too slow?'
end 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 def test_investigation_output
t1 = task(:t1 => [:t2, :t3]) { |t| runlist << t.name; 3321 } t1 = task(:t1 => [:t2, :t3]) { |t| runlist << t.name; 3321 }
task(:t2) task(:t2)
Expand Down

0 comments on commit 7c777ff

Please sign in to comment.