Skip to content
Open
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
11 changes: 11 additions & 0 deletions lib/rake/file_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ def timestamp

private

def invoke_prerequisites(task_args, invocation_chain)
return super unless actions.empty?

# An explicit prerequisite can create the source that makes a rule match.
explicit = prerequisite_tasks
super(task_args, invocation_chain, explicit)
if actions.empty? && application.enhance_with_matching_rule(name)
super(task_args, invocation_chain, prerequisite_tasks - explicit)
end
end

# Are there any prerequisites with a later time than the given time stamp?
def out_of_date?(stamp)
all_prerequisite_tasks.any? { |prereq|
Expand Down
10 changes: 5 additions & 5 deletions lib/rake/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,20 @@ def add_chain_to(exception, new_chain) # :nodoc:
private :add_chain_to

# Invoke all the prerequisites of a task.
def invoke_prerequisites(task_args, invocation_chain) # :nodoc:
def invoke_prerequisites(task_args, invocation_chain, tasks=prerequisite_tasks) # :nodoc:
if application.options.always_multitask
invoke_prerequisites_concurrently(task_args, invocation_chain)
invoke_prerequisites_concurrently(task_args, invocation_chain, tasks)
else
prerequisite_tasks.each { |p|
tasks.each { |p|
prereq_args = task_args.new_scope(p.arg_names)
p.invoke_with_call_chain(prereq_args, invocation_chain)
}
end
end

# Invoke all the prerequisites of a task in parallel.
def invoke_prerequisites_concurrently(task_args, invocation_chain)# :nodoc:
futures = prerequisite_tasks.map do |p|
def invoke_prerequisites_concurrently(task_args, invocation_chain, tasks=prerequisite_tasks)# :nodoc:
futures = tasks.map do |p|
prereq_args = task_args.new_scope(p.arg_names)
application.thread_pool.future(p) do |r|
r.invoke_with_call_chain(prereq_args, invocation_chain)
Expand Down
48 changes: 48 additions & 0 deletions test/test_rake_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,54 @@ def test_rule_runs_when_explicit_task_has_no_actions
assert_equal [SRCFILE], @runs
end

def test_explicit_file_task_builds_rule_source_before_running_the_rule
file OBJFILE => [SRCFILE2]
file SRCFILE2 do |t|
@runs << t.name
create_file(t.name)
end
rule ".c" do |t|
@runs << t.name
create_file(t.name)
end
rule ".o" => ".c" do |t|
@runs << t.name
assert File.exist?(t.source)
end

Task[OBJFILE].invoke
assert_equal [SRCFILE2, SRCFILE, OBJFILE], @runs
end

def test_explicit_file_task_rebuilds_when_only_the_rule_source_is_newer
create_timed_files(OBJFILE, SRCFILE)
create_file(SRCFILE2, File.mtime(OBJFILE))
file OBJFILE => [SRCFILE2]
rule ".o" => ".c" do |t|
@runs << t.source
end

Task[OBJFILE].invoke
assert_equal [SRCFILE], @runs
end

def test_rule_selection_can_use_a_file_created_by_an_explicit_prerequisite
create_file(FTNFILE)
file OBJFILE => ["generate"]
task "generate" do
create_file(SRCFILE)
end
rule ".o" => ".c" do |t|
@runs << t.source
end
rule ".o" => ".f" do |t|
@runs << t.source
end

Task[OBJFILE].invoke
assert_equal [SRCFILE], @runs
end

def test_close_matches_on_name_do_not_trigger_rule
create_file("x.c")
rule ".o" => [".c"] do |t|
Expand Down