Skip to content
New issue

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

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

Already on GitHub? # to your account

Rake executes file task when prerequisites have older timestamp #246

Open
satosho opened this issue Jan 1, 2018 · 5 comments
Open

Rake executes file task when prerequisites have older timestamp #246

satosho opened this issue Jan 1, 2018 · 5 comments

Comments

@satosho
Copy link

satosho commented Jan 1, 2018

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
@grzuy
Copy link
Contributor

grzuy commented Feb 7, 2018

I can reproduce the same issue.

Working on a fix for this.

grzuy added a commit to grzuy/rake that referenced this issue Feb 7, 2018
This reverts commit 5ba97af, reversing
changes made to bc5765f.

Fixes ruby#246
@grzuy
Copy link
Contributor

grzuy commented Feb 21, 2018

There's an opened PR attempting to fix this #251

@grzuy
Copy link
Contributor

grzuy commented Feb 22, 2018

Second attempt at fixing this one here #257

@chrislo
Copy link

chrislo commented Jul 13, 2020

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

@jgomo3
Copy link

jgomo3 commented Jun 22, 2022

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

No branches or pull requests

4 participants