本文介绍了带有可变任务列表的多任务耙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了一些帖子提示教程有关使用rake参数和rake多任务的信息.以下是一些简单的示例.

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']

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

我的问题:

在一个可以在多任务中使用的任务中构建全局变量的最佳方法是什么?以下代码不会执行task1,task2,task3 ...,这意味着全局$ build_list为空

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

我应该在这里使用ENV变量还是其他方法?

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

推荐答案

由于先前的回答,我将其引向了解决方案:

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

这篇关于带有可变任务列表的多任务耙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-30 02:31