New issue

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

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

Already on GitHub? Sign in to your account

Rake does not rebuild files that depend on deleted files #286

Closed
DavidEGrayson opened this Issue Jul 28, 2014 · 3 comments

Comments

Projects
None yet
3 participants
@DavidEGrayson
Contributor

DavidEGrayson commented Jul 28, 2014

The following Rakefile behaves in an undesirable way which is inconsistent with GNU Make:

file 'foo' => 'bar' do
  sh 'echo hi > foo'
end
file 'bar' do
  sh 'running bar task'
end

Suppose the file foo exists but bar has been deleted. I would expect that since bar has been deleted, then foo would be considered out of date, and the Rake would run the bar task to attempt to rebuild bar, and then run the foo task to attempt to rebuild foo. Instead, it only runs the bar task and then stops.

The expected output of the "rake" command is:

running bar task
echo hi > foo

The actual output of the "rake" command is:

running bar task

GNU Make behaves in the expected way. If I use the following Makefile and run "make foo" while foo exists and bar does not exist, then I get the expected output from above.

foo: bar
    echo hi > foo
bar:
    @echo running bar task

So clearly GNU Make and Rake are behaving differently, and I would argue that the GNU Make behavior is better. If you are building a C or C++ program, then the GNU Make behavior in this situation is necessary to properly support the case where a header file has been deleted, and therefore all C files that previously depended on it need to be rebuilt.

It should be easy to fix this issue: we can just change https://github.com/jimweirich/rake/blob/master/lib/rake/file_task.rb#L24 to use Rake::LATE instead of Rake::EARLY (and we would need to add a definiton of Rake::LATE of course). Does that sound good? I would be happy to make a pull request if so.

I tried to look around to see if this issue has been reported before; I found issue #104 and this forum post from 2006 but neither of them seem to directly address the issue of deleted files.

In case it matters, I am using Rake 10.1.0, JRuby 1.7.13, and Windows 8 64-bit.

@drbrain

This comment has been minimized.

Collaborator

drbrain commented Jul 28, 2014

Rake is intended to mimic the behavior of make, so this change sounds good. A pull request would be excellent!

@damphyr

This comment has been minimized.

damphyr commented Jul 31, 2014

My initial reaction was that the header example was not a good reproduction of this behaviour and then I realized that I never explicitly define headers as dependencies, these are always generated fresh so the deleted files just vanish.

Having said that I would go as far as to say the original behaviour is a bug and should be fixed on the following reasoning:
The dependency chain indicates a relationship to the action of all previous tasks. From rake's point of view if a file is missing then we cannot know what the file task for it does (recreates the file, tranforms it etc.) The only way to ensure consistency is to rerun the task and any tasks that depend on it. Every other state would be inconsistent.

So 👍

@DavidEGrayson

This comment has been minimized.

Contributor

DavidEGrayson commented Jul 31, 2014

Yeah, in my example Rakefile above, bar is analogous to a header file and the dependencies on bar were automatically generated as the result of previous builds. When Rake runs, it should run the dummy bar task, then rebuild foo, at which point the record of foo's dependency on bar will be deleted from the dependency file, and the next time Rake runs it will know nothing about bar.

@drbrain drbrain closed this in 019b10d Nov 24, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment