How is a recursive rake? - or suitable alternatives

I want my top-level Rakefile projects to build things using rakefiles deeper in the tree; that is, the upper level rakefile says how to build a project (large image), and the lower level - create a specific module (local image).

Of course, there is a common set of settings for the smallest details that each time it can be divided between tasks: this mainly concerns the storage of descriptions of what needs to be built, as close to the sources that are created. For example. /Source/Module/code.foo and cie should be built using the instructions in / Source / Module / Rakefile; and / Rakefile understands dependencies between modules.

I don't care if it uses multiple rake processes (ala recursive make) or just creates separate build environments. In any case, it should be low-key enough to handle the queue: so that independent modules can be created at the same time.

The problem is, how the hell are you actually doing something similar with Rake !? I could not find anything meaningful on the Internet and in the documentation. I tried to create a new Rake :: Application object and configure it, but any methods I try to use only exceptions or "I don’t know how to build the task: errors" default "" get throw ". (Yes, all rakefiles have: default ). Obviously, you can simply rake in the subdirectory for the task: modulename, but this will distinguish the options given at the top level; for example, think about $ (MAKE) and $ (MAKEFLAGS).

Does anyone know how to do something like recursive rake correctly?

+6
ruby build-process rake
source share
4 answers

you can require unzip files from other rake files and run tasks from the desired 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" on the screen. you should be able to organize your rake files and common code, however you want to use this idea

+2
source share

As mentioned in my previous post, here is a snippet of code that supports almost like the recursive behavior of rake, including passing parameters, dry checking, tracing, a top-level task.

rake:

 #!/usr/bin/env ruby begin require 'rubygems' gem 'rake' rescue LoadError end $sub_directories = [] $top_level_task_provided__skip_subdir = 0 module Rake REDUCE_COMPAT = true if ARGV.include?("--reduce-compat") RAKE_OPTS = ARGV.clone.join(" ") module DSL def subdirs dirs puts "DIRS: #{dirs}" $sub_directories = dirs end end end require 'rake' Rake.application.standard_exception_handling do Rake.application.init $top_level_task_provided__skip_subdir = 1 if Rake.application.top_level_tasks.size >= 1 and Rake.application.top_level_tasks[0] != "default" Rake.application.load_rakefile if Rake.application.tasks.size == 0 and $sub_directories.size != 0 then desc "Default task when only subdirs is present in a rakefile" task :default do puts "Default subdir task" end end Rake.application.top_level end if $top_level_task_provided__skip_subdir == 0 then $sub_directories.each do |d| unless rake_system("cd #{d} && pwd && ruby #{File.expand_path $0} #{Rake::RAKE_OPTS}") then exit(1) end end end 
+2
source share

If I understand well, your problem is that you need to call the Rake task in another Rake task from another RakeFile.

You can create the necessary tasks in / Source / Module / Rakefile as you need, and make another Rakefile in / Rakefile and run the tasks this way.

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

-f allows you to determine where the rakefile is

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

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

Hope this helps you.

0
source share

I also have a similar requirement and created the following function

rakeutils.rb:

 def subdirs dirs dirs.each do |d| task d do |t| sh("cd #{t.name} && pwd && rake") end end task :default => dirs end 

and in Rakefiles, wherever I want this feature, I just turned it on ... like

Rakefile:

 require 'rakeutils' task :test1 do puts "Hi" end task :default => :test1 subdirs ["ab", "cd"] 

regarding options, I did not find any automatic way to transfer them ... other than editing the rake and grabbing the options before it is consumed by processing the rake option

0
source share

All Articles