From b27d86f92a7164c9d922b3a942d6a7fc74f8b5bf Mon Sep 17 00:00:00 2001 From: Gonzalo Date: Thu, 22 Feb 2018 13:35:47 -0300 Subject: [PATCH] Don't run file tasks needlessly. Fixes #246 --- lib/rake/file_task.rb | 9 +-------- lib/rake/task.rb | 7 ++++++- test/test_rake_functional.rb | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/lib/rake/file_task.rb b/lib/rake/file_task.rb index 364d8e395..f8cd57a25 100644 --- a/lib/rake/file_task.rb +++ b/lib/rake/file_task.rb @@ -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 # ---------------------------------------------------------------- diff --git a/lib/rake/task.rb b/lib/rake/task.rb index 256571112..bcd8763bd 100644 --- a/lib/rake/task.rb +++ b/lib/rake/task.rb @@ -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) diff --git a/test/test_rake_functional.rb b/test/test_rake_functional.rb index daf832254..f8e3b8ca6 100644 --- a/test/test_rake_functional.rb +++ b/test/test_rake_functional.rb @@ -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