具有可变任务列表的 Rake 多任务
我读过一些 帖子、提示 和 有关使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题不在于您选择的变量类型,而在于您在任务执行期间填充变量,而依赖关系图是在执行任何任务之前创建的。
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.
感谢之前的回复,它让我找到了解决方案:
在运行依赖项列表中的任何任务之前,在任务外部的方法中计算动态变量。
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.