Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not run tasks when their prerequisites fail #142

Merged
merged 1 commit into from
Jun 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions lib/rake/multi_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,42 @@ module Rake
# parallel using Ruby threads.
#
class MultiTask < Task

# Same as invoke, but explicitly pass a call chain to detect
# circular dependencies. This is largely copied from Rake::Task
# but has been updated such that if multiple tasks depend on this
# one in parallel, they will all fail if the first execution of
# this task fails.
def invoke_with_call_chain(task_args, invocation_chain)
new_chain = Rake::InvocationChain.append(self, invocation_chain)
@lock.synchronize do
begin
if @already_invoked
if @invocation_exception
if application.options.trace
application.trace "** Previous invocation of #{name} failed #{format_trace_flags}"
end
raise @invocation_exception
else
return
end
end

if application.options.trace
application.trace "** Invoke #{name} #{format_trace_flags}"
end
@already_invoked = true

invoke_prerequisites(task_args, new_chain)
execute(task_args) if needed?
rescue Exception => ex
add_chain_to(ex, new_chain)
@invocation_exception = ex
raise
end
end
end

private
def invoke_prerequisites(task_args, invocation_chain) # :nodoc:
invoke_prerequisites_concurrently(task_args, invocation_chain)
Expand Down
21 changes: 21 additions & 0 deletions test/test_rake_multi_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,25 @@ def test_multitasks_with_parameters
assert @runs[0] == "b"
assert @runs[1] == "bmt"
end

def test_cross_thread_prerequisite_failures
failed = false

multitask :fail_once do
fail_now = !failed
failed = true
raise 'failing once' if fail_now
end

task a: :fail_once
task b: :fail_once

assert_raises RuntimeError do
Rake::Task[:a].invoke
end

assert_raises RuntimeError do
Rake::Task[:b].invoke
end
end
end