tags:

views:

232

answers:

2

Hi!

I have a build system that consists of several subdirectories with projects, where in each of them there's a separate rakiefile (or couple of rakefiles). No the top-level directory has a rakefile that goes through all subdirectories and calls rake via: system("rake "), gets resulting packages and sends them to appropriate machine. Is there more elegant way of doing this? I've tried Rake.application.load() but this doesn't seem to accept any argument as to which file must be loaded (as I've mentioned sometimes there are 2 rakefiles in each subdirectory),

+1  A: 

Just create a new Rakefile at the root of your big project and dynamically load your sub-project Rakefiles

Dir.glob(File.join(File.dirname(__FILE__), '**', 'Rakefile')).each do |tasks|
  load tasks
end
knoopx
This partially resolves problem. I'm able to call tasks from other files but it seems that dependencies are not processed. So having main file, with your code that calls sub rakefile withtask :default => :footask :foo do puts "foo"endtask "foo" isn't called
A: 

Ok, I have solution that is based on what knoopx said. Here is my master file:

task :default do
    FileList["*/**/rakefile*.rb"].each do |project|
        # clear current tasks
        Rake::Task.clear
        #load tasks from this project
        load project
        if !Rake::Task.task_defined?(:default)
            puts "No default task defined in #{project}, aborting!"
            exit -1
        else
            dir = project.pathmap("%d")
            Dir.chdir(dir) do
                default_task = Rake::Task[:default]
                default_task.invoke()
            end
        end
    end
    puts "Done building projects"
end

Each rakefile in subdirectory must contain definition of default task.