[Rake-devel] Task#prerequisites and Task#needed?

James M. Lawrence quixoticsycophant at gmail.com
Thu Oct 30 01:23:04 EDT 2008

On Thu, Oct 30, 2008 at 12:42 AM, Jim Weirich <jim.weirich at gmail.com> wrote:
> On Oct 28, 2008, at 9:17 PM, James M. Lawrence wrote:
>> When I saw commit 995b742d "fixed namespace task list bug" I was
>> reminded of the problem I had in Drake where Task#prerequisites gave
>> namespace-unqualified task names
>> (http://rubyforge.org/pipermail/rake-devel/2008-September/000574.html).
>> namespace :a do
>>  task :x
>>  task :y => :x
>> end
>> task :default do
>>  p Rake::Task["a:y"].prerequisites   #=> ["x"]
>>                                     #   should be ["a:x"] ?
>> end
>> Does this work as designed?  I had initially conjectured that you
>> wanted a task manager to have context-dependent behavior (where the
>> "x" prereq can mean something different depending on the current
>> namespace), but it doesn't look like Rake is designed this way.
> Yes, this works as designed.  The prerequisites are deliberately stored as
> name references that are looked up in the tasks scope.  It is the lookup
> process that applies the namespace resolution, not the definition process.
> Although your suggestions makes a lot of sense.  I should reevaluate that
> decision.

But the @scope is an attr_reader of Task, which why I said, on the
other hand, that it looks like Rake is not designed this way.  The
lookup always finds the same thing.

>> The other issue was that File#needed? does not look past its immediate
>> prereqs.
> Hmmm, interesting.  I will confess that I'm not entirely sure why it works
> that way, and yet it will correctly rebuild out of date files.  I'll take
> another look at this code when I'm not so tired and maybe enlightenment will
> occur.  (FYI, the needed? method was originally within the first 1 hour of
> the creation of Rake)

In the link I gave, I mentioned that the "needed?" flag is correctly
propagated by the recursive invoke.  The problem only occurs when
someone asks for it explicitly, outside of invoke().

This posed a problem for Drake because Drake gathers tasks with a dry
run, resulting in grandparent tasks of a dirty file being left out of
the dependency graph.  I solved it by manually marking parents of a
File task (see invoke_prerequisites in Drake).

James M. Lawrence

More information about the Rake-devel mailing list