Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multifile rake build

Tags:

rake

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),

like image 998
paszczi Avatar asked Nov 06 '09 10:11

paszczi


2 Answers

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.

like image 68
paszczi Avatar answered Jan 04 '23 06:01

paszczi


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
like image 21
knoopx Avatar answered Jan 04 '23 07:01

knoopx