rake icon indicating copy to clipboard operation
rake copied to clipboard

Rake executes file task when prerequisites have older timestamp

Open satosho opened this issue 7 years ago • 5 comments

When a file task depends on some non-file task indirectly, Rake executes the file task even if its immediate prerequisite files have older timestamp.

It looks like the behavior changed at 12.1.0.

Example

require "rake/clean"

CLEAN.include("config.yml", "component")

task "setup" do
  puts Rake::VERSION
  touch "config.yml" unless File.exist?("config.yml")
end

file "config.yml" => "setup"

file "component" => "config.yml" do |t|
  puts "[config.yml] #{File.mtime(t.prerequisites[0])}"
  puts "[component]  #{File.exist?(t.name) && File.mtime(t.name)}"
  sleep 1
  touch t.name
end

Based on the above Rakefile, clean up and create the "component" first.

$ rake clean && rake component

The next rake component results in different behavior as follows. On 12.0.0:

$ rake component --trace
(in /path/to/Rakefile-directory)
** Invoke component (first_time, not_needed)
** Invoke config.yml (first_time)
** Invoke setup (first_time)
** Execute setup
12.0.0
** Execute config.yml

On 12.1.0:

$ rake component --trace
(in /path/to/Rakefile-directory)
** Invoke component (first_time)
** Invoke config.yml (first_time)
** Invoke setup (first_time)
** Execute setup
12.1.0
** Execute config.yml
** Execute component
[config.yml] 2018-01-01 15:13:19 +0900
[component]  2018-01-01 15:13:20 +0900
touch component

satosho avatar Jan 01 '18 06:01 satosho

I can reproduce the same issue.

Working on a fix for this.

grzuy avatar Feb 07 '18 14:02 grzuy

There's an opened PR attempting to fix this https://github.com/ruby/rake/pull/251

grzuy avatar Feb 21 '18 13:02 grzuy

Second attempt at fixing this one here https://github.com/ruby/rake/pull/257

grzuy avatar Feb 22 '18 16:02 grzuy

Was a fix for this bug ever merged? I've run into it today and it would be great if it could be fixed.

chrislo avatar Jul 13 '20 14:07 chrislo

Maybe this is precisely the use case of Phony tasks: https://ruby.github.io/rake/doc/rakefile_rdoc.html#label-Phony+Task

jgomo3 avatar Jun 22 '22 18:06 jgomo3