[Rake-devel] Rules with Multiple Prerequisites

Allan Knight aknight at cs.ucsb.edu
Mon Mar 26 14:10:26 EDT 2007


I recently came across what I believe is a bug in rake, however, I  
could be wrong. Here is the behavior in question. When I right a rule  
with two prerequisites everything works fine if both prerequisites  
exists. The problem occurs when the second or both prerequisites do  
not exist. In this case the first prerequisite task is invoked twice  
and the second task not at all. For example, the following Rakefile  
demonstrates the described behavior

============================ Rakefile ============================

rule '.avi' => ['.wmv'] do |t|
   sh %{touch #{t.name}}

rule '.aac' => ['.avi'] do |t|
   sh %{touch #{t.name}}

rule '.h264' => ['.avi'] do |t|
   sh %{touch #{t.name}}

rule '.mp4' => ['.aac', '.h264'] do |t|
   sh %{touch #{t.name}}

=========================== End Rakefile ==========================

The output for the command 'test.mp4' given that test.wmv exits is:

============================= Output =============================

(in /Users/aknight/rake)
touch test.avi
touch test.aac
touch test.aac
touch test.mp4

============================ End Output ==========================

The output illustrates the improper behavior. Rather than touching  
'test.h264', Rake  touches test.aac twice. First, the test.aac task  
should not be invoked twice, and second, the test.h264 task is never  

Is this the desired behavior for Rake? I've tried a similar setup in  
Make and it seems to work as I would expect and invokes tasks for  
both the .aac and .h264 file. My argument is not that Rake should  
work like Make, but I just wanted to see if my thinking was  
completely stupid or not.

I've found where the bug is (if it acutally is a bug), created a  
patch and tested it. The patch seems to make Rake work in the desired  
way. If you also agree that Rake should be have in this way, let me  
know and I'll submit the patch. It's a quick fix. I've tested the  
patch with different combinations of files existing and it seems to  
work. Also, I've tested it with more than two prerequisites and the  
unpatched behavior is similar, and the patch also creates the desired  
behavior in this case.


Allan Knight

More information about the Rake-devel mailing list