[Rake-devel] Feature request: expand all matching rules instead of first match only

Robin Luckey robin at ohloh.net
Thu Oct 4 17:04:13 EDT 2007

One of the nice things about rake is the ability to add additional  
actions or prerequisites to a task via multiple calls to "task".  
However, this cannot be done for rule-generated tasks, because the  
rule matching algorithm stops after the first match. It would be very  
nice if instead all matching rules were expanded into tasks.

This would be helpful to our project because we would like to create  
a plug-in architecture that allows core rake tasks to be extended by  
a plug-in, even if those core tasks are created via rules.

For example, we'd like this to be possible:

namespace :example do
   task :foo
   rule(/\ba$/ => 'example:foo')

   task :bar
   rule(/\ba$/ => 'example:bar')

Executing 'a' should then execute 'foo' and 'bar'.

It's a simple code change, but I'm not sure how this change might  
impact other users:

Index: lib/rake.rb
--- lib/rake.rb (revision 609)
+++ lib/rake.rb (working copy)
@@ -1626,13 +1626,13 @@
      def enhance_with_matching_rule(task_name, level=0)
        fail Rake::RuleRecursionOverflowError,
          "Rule Recursion Too Deep" if level >= 16
+      task = nil
        @rules.each do |pattern, extensions, block|
          if md = pattern.match(task_name)
            task = attempt_rule(task_name, extensions, block, level)
-          return task if task
-      nil
+      task
      rescue Rake::RuleRecursionOverflowError => ex
        fail ex

More information about the Rake-devel mailing list