具有可变任务列表的 Rake 多任务

发布于 2024-11-28 20:52:30 字数 1037 浏览 1 评论 0原文

我读过一些 帖子提示有关使用 rake 参数和 rake 多任务的教程。以下是一些简单的例子。

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

或者

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

我的问题:

在一个任务中构建全局变量然后可以在多任务中使用的最佳方法是什么?以下不执行任务 1、任务 2、任务 3...这意味着全局 $build_list 为空

$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 变量还是首选其他方法?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等往事风中吹 2024-12-05 20:52:30

问题不在于您选择的变量类型,而在于您在任务执行期间填充变量,而依赖关系图是在执行任何任务之前创建的。

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.

情场扛把子 2024-12-05 20:52:30

感谢之前的回复,它让我找到了解决方案:

在运行依赖项列表中的任何任务之前,在任务外部的方法中计算动态变量。

# 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文