3

I've read some posts, tips and tutorials about using rake arguments and rake multitask. The following would be some simple examples.

multitask 'build_parallel' => ['build_a', 'build_z']

or

multitask :mytask => [:task1, :task2, :task3] do
  puts "Completed parallel execution of tasks 1 through 3."
end

My question:

What is the best way to build a global variable in one task that I can then use in my multitask? The following doesn't execute task1, task2, task3...which means the global $build_list is empty

$build_list = []
task :build do
   $build_list << 'task1' 
   $build_list << 'task2' 
   $build_list << 'task3'
   Rake::MultiTask[:build_parallel].invoke # or Rake::Task[:build_parallel].invoke
end

multitask :build_parallel => $build_list

Should I be using an ENV variable here or is some other method preferred?

Community
  • 1
  • 1
josh803316
  • 303
  • 5
  • 10

2 Answers2

1

The problem is not with the type of variable you choose, but with the fact that you're populating the variable during the execution of a task, while the dependency graph is created before any task is executed.

On Freund
  • 4,376
  • 2
  • 23
  • 30
  • Thanks for the response, how would I modify the dependency graph so that I could utilize a variable multitask instead of a pre-configured one. I'm looking for a way to allow for dynamic multitasking. – josh803316 Aug 09 '11 at 16:08
  • If you don't mind your logic being executed before any task, you can simply have inline code in the rake file, outside of any task – On Freund Aug 10 '11 at 04:37
1

Thanks to the previous response it led me to the solution:

Calculate the dynamic variable in a method outside the task before running any of the tasks in the dependency list.

# Generate the list in a method instead of a task
def get_list
  build_list = []
  build_list << 'task1' 
  build_list << 'task2' 
  build_list << 'task3'
end

# Make sure the list has been generated before the multitask call
@build_list  = get_list

# Then define the multitask list dependency
multitask :build_parallel => @build_list
josh803316
  • 303
  • 5
  • 10