Skip to content

Commit

Permalink
Don't run file tasks needlessly. Fixes ruby#246
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Feb 22, 2018
1 parent 5fca980 commit b27d86f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
9 changes: 1 addition & 8 deletions lib/rake/file_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ def timestamp

# Are there any prerequisites with a later time than the given time stamp?
def out_of_date?(stamp)
all_prerequisite_tasks.any? { |prereq|
prereq_task = application[prereq, @scope]
if prereq_task.instance_of?(Rake::FileTask)
prereq_task.timestamp > stamp || @application.options.build_all
else
prereq_task.timestamp > stamp
end
}
prerequisite_tasks.any? { |task| task.timestamp > stamp }
end

# ----------------------------------------------------------------
Expand Down
7 changes: 6 additions & 1 deletion lib/rake/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ def invoke_with_call_chain(task_args, invocation_chain) # :nodoc:
return if @already_invoked
@already_invoked = true
invoke_prerequisites(task_args, new_chain)
execute(task_args) if needed?

if needed?
execute(task_args)
elsif application.options.dryrun && prerequisite_tasks.any? { |p| p.is_a?(Rake::FileTask) }
application.trace "** Execute (dry run) #{name}"
end
end
rescue Exception => ex
add_chain_to(ex, new_chain)
Expand Down
19 changes: 19 additions & 0 deletions test/test_rake_functional.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,25 @@ def dryrun_tasks
}
end

def test_file_timestamps_respected_despite_task_prerequisite
rakefile <<-RAKEFILE
task "some_task" do
end
file "A" => "some_task"
file "B" => "A" do |t|
touch t.name
end
RAKEFILE

FileUtils.touch("A")
FileUtils.touch("B")

rake "B"

assert(@err !~ /touch B/)
end

def test_update_midway_through_chaining_to_file_task
rakefile_file_chains

Expand Down

0 comments on commit b27d86f

Please sign in to comment.