Inconsistent behaviors with the "task" task #82

Closed
zimbatm opened this Issue Oct 26, 2011 · 4 comments

Projects

None yet

3 participants

@zimbatm
task :default => "file1"
file "file1" => "foo" do
  puts "file1"
  touch "file1"
end

task "foo" => "file2" do
  puts "foo"
end

file "file2" do
  puts "file2"
  touch "file2"
end

On the second run, "foo" gets executed, but not "file1" ? I can't see why you would want to have a task execute only in the middle of a dependency tree.

If "foo" where to become a dependency of "file2" instead, the whole tree would get executed the whole time. Why ?

I propose to change the "Rake::Task#timestamp" method to:

def timestamp
  return Time.now if needed?
  prerequisite_tasks.collect { |pre| pre.timestamp }.max || Rake::EARLY
end

and introduce a new "alias" task type that has "#needed?" set to false for the cases where you don't want to always type long file dependencies.

@jimweirich
Owner

Wow, that's weird.

Its because the basic task will (a) return the latest time of its prerequisites, or (b) return the current time if it has no prerequisites.

From my current state of mind, I can't imagine why it was done this way, but it is in the very earliest versions of Rake going back to 2003. Probably no one noticed it because few people make file tasks dependent on basic tasks (at least I don't).

If I were to do it today, I think I would have it return the current time unconditionally. However, I'm reluctant to make such a semantic change in a minor revision. But this will definitely go on the block for consideration in the next major release.

@jimweirich
Owner

Thanks for catching that, and sorry for the slow response time. I'm slogging through all the old issues in Rake at the moment.

@jimweirich
Owner

I've marked this for fixing post 0.9.x.

@jimweirich
Owner

Fixed in version 10.

@jimweirich jimweirich closed this Oct 27, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment