Reputation: 303
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?
Upvotes: 3
Views: 3724
Reputation: 303
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
Upvotes: 1
Reputation: 4436
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.
Upvotes: 1