[Rake-devel] FileTask#needed? and FileTask#timestamp "bug"

Patrick Bennett patrick.bennett at inin.com
Mon Sep 5 01:00:40 EDT 2005

I simply patched my local rake's timestamp method to return Time.at(0) 
for files that didn't exist as it fit the existing model better as far 
as I was concerned.
Since I created a dependency generator for C++ source, it was possible 
to generate dependencies for files (based on #include's) that might not 
exist on a particular platform, so prerequisites that didn't exist had 
to effectively be ignored.
Once you change the timestamp method to check for the existance of its 
file and return a timestamp as appropriate, a rescue class in needed? is 
no longer necessary.

However, IMO, in your example 'bar' should *not* be invoked.  A missing 
prerequisite should not be counted as a newer prerequisite.
Should a rule that specifies main.obj with a prereq of main.cpp cause an 
attempted invokation of the main.obj rule when main.cpp is missing?  
That's what you're stating here.

Patrick Bennett

philipp.neubeck at gmx.de wrote:

>Hi there,
>think of the following situation:
>file "foo"
>file "bar" => [ "foo" ]
>file "foo" does NOT exist, while "bar" does, then the timestamp method of bar's FileTask raises an unhandeled (not handeled by Rake) exception ('file not found...'), because it is called by "foo"'s FileTask#needed?.
>i think there shouldn't be any exception thrown in this situation, but "bar" rebuild. if "bar" did not exist then "bar" would also be rebuild, so why not in this case. so my patch would be:
>class FileTask
>  def needed?
>    return true unless File.exist?(name)
>    @prerequisites.each{|n| return true if Task[n].timestamp >= timestamp }
>    return false
>  rescue Errno::ENOENT => ex # one of the prereqs does not exist
>    raise unless $dryrun or $trace
>    true
>  end
>  def timestamp
>    return Time.now unless File.exist?( name )
>    File.mtime(name.to_s)
>  end
>i also removed the collect{}.max. if one want's to check if the prerequisites exist, then do that but don't calculate a maximum, which is unneeded.
>if it is supposed that 'needed?' is mainly called by Task#invoke then the checking should be there (see Task#invoke, it iterates the @prerequ..s already) and not here
>hope it helps,
> phil
>Rake-devel mailing list
>Rake-devel at rubyforge.org

More information about the Rake-devel mailing list