views:

53

answers:

2

I want my projects top level Rakefile to build things using rakefiles deeper in the tree; i.e. the top level rakefile says how to build the project (big picture) and the lower level ones build a specific module (local picture).

There is of course a shared set of configuration for the minute details of doing that whenever it can be shared between tasks: so it is mostly about keeping the descriptions of what needs building, as close to the sources being built. E.g. /Source/Module/code.foo and cie should be built using the instructions in /Source/Module/Rakefile; and /Rakefile understands the dependencies between modules.

I don't care if it uses multiple rake processes (ala recursive make), or just creates separate build environments. Either way it should be self-containable enough to be processed by a queue: so that non-dependent modules could be built simultaneously.

The problem is, how the heck do you actually do something like that with Rake!? I haven't been able to find anything meaningful on the Internet, nor in the documentation. I tried creating a new Rake::Application object and setting it up, but whatever methods I try invoking, only exceptions or "Don't know how to build task ':default'" errors get thrown. (Yes, all rakefiles have a :default). Obviously one could just execute 'rake' in a sub directory for a :modulename task, but that would ditch the options given to the top level; e.g. think of $(MAKE) and $(MAKEFLAGS).

Anyone have a clue on how to properly do something like a recursive rake?

A: 

you can require rake files from other rake files and run the tasks from the required file.

put this in rakefile.rb:

require 'foo/rakefile.rb'

task :default => [:bar]

put this in foo/rakefile.rb:

task :bar do
  puts "baz"
end

run the root level rakefile and it will print "baz" to the screen. you should be able to organize your rake files and common code however you want using this idea

Derick Bailey
A: 

If I understood well your problem is that you need to call a Rake task within another Rake task from a different RakeFile.

You can built your needed tasks in /Source/Module/Rakefile the way you need it and make another Rakefile in /Rakefile and run tasks that way.

desc 'Description'
task :foo do
    %x[rake -f /Source/Module/RakeFile foo:bar]
end

-f let you define where the Rakefile is located

You could also specify where your rakelib folder is located with -R.

rake -f /path/to/Rakefile -R /path/to/rakelib foo:bar

I hope this would help you.

garno