如何在所有其他任务之后运行 Rake 任务?(即 Rake AfterBuild 任务) [英] How do I make a Rake Task run after all other tasks? (i.e. a Rake AfterBuild task)

查看:42
本文介绍了如何在所有其他任务之后运行 Rake 任务?(即 Rake AfterBuild 任务)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Rake 的新手,我用它来构建 .net 项目.我感兴趣的是有一个总结任务,它打印出已经完成的事情的总结.我希望这个任务总是被调用,无论 rake 是用什么任务调用的.

I'm new to Rake and using it to build .net projects. What I'm interested in is having a Summary task that prints out a summary of what has been done. I want this task to always be called, no matter what tasks rake was invoked with.

有没有一种简单的方法可以做到这一点?

Is there an easy way to accomplish this?

谢谢

更新问题,回复Patrick 的回答 我想要的是在所有其他任务之后运行一次的后任务,所以我想要的输出是:

Update on the question, responding to Patrick's answer what I want is the after task to run once after all other tasks, so the output I want is:

task :test1 do 
  puts 'test1'
end

task :test2 do 
  puts 'test2'
end

Rake::Task.tasks.each do |t|
    <Insert rake magic here>
#  t.enhance do 
#    puts 'after'
#  end
end

$ rake test1
test1
after

$rake test2
test2
after

$rake test1 test2  
test1
test2
after

如果

task :test3 =>[:test1, :test2]
   puts 'test3'
end

    $rake test3
test1
test2
test3
after

即使赏金消失了,也非常感谢任何进一步的帮助.(遗憾的是,我不认为我可以提供另一个赏金.)

Even though the bounty is gone, any further help much appreciated. (Sadily I don't think that I can offer another bounty.)

推荐答案

将此作为新答案发布以保持另一个可用.这不太优雅,因为我必须深入了解 Rake 并手动更新任务列表,但它确实有效.

Posting this as a new answer to keep the other one available. This is much less elegant as I have to get into the guts of Rake and manually update the task list, but it works.

task :test1 do
  puts 'test1'
end

task :test2 do 
  puts 'test2'
end

task :after do
  puts 'after'
end

# top_level_tasks is't writable so we need to do this ugly
# instance_variable_set hack...
current_tasks =  Rake.application.top_level_tasks
current_tasks << :after
Rake.application.instance_variable_set(:@top_level_tasks, current_tasks)

输出:

$ rake test1
test1
after

$ rake test1 test2
test1
test2
after

这篇关于如何在所有其他任务之后运行 Rake 任务?(即 Rake AfterBuild 任务)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆