使用rake处理多个配置矩阵的最佳方法是什么?

时间:2009-12-28 22:36:33

标签: build-process rake

我有一个应用程序,可以使用2种配置(Company1或Company2)之一以及调试或发布模式构建。

Company1 Release
  All builds done with the Release compiler flag
  Build and output core dll files to build directory
  Build and output Company1Plugin.dll to build directory
  Copy tools\templates\log4net.config to build directory
  Copy tools\templates\Company1.MyApp.exe.config to build directory
Company1 Debug
  All builds done with the Debug compiler flag
  Build and output core dll files to build directory
  Build and output Company1Plugin.dll to build directory
  Build and output MyApp.Debug.dll to build directory
  Copy tools\Growl\log4net.GrowlAppender to build directory
  Copy tools\templates\debug.log4net.config to build directory
  Copy tools\templates\debug.Company1.MyApp.exe.config to build directory
Company2 Release
  All builds done with the Release compiler flag
  Build and output core dll files to build directory
  Build and output Company2Plugin.dll to build directory
  Build and output PrintingUtility.dll to build directory
  Copy tools\templates\log4net.config to build directory
  Copy tools\templates\Company2.MyApp.exe.config to build directory
Company2 Debug
  All builds done with the Debug compiler flag
  Build and output core dll files to build directory
  Build and output Company2Plugin.dll to build directory
  Build and output PrintingUtility.dll to build directory
  Build and output MyApp.Debug.dll to build directory
  Copy tools\Growl\log4net.GrowlAppender to build directory
  Copy tools\templates\debug.log4net.config to build directory
  Copy tools\templates\debug.Company2.MyApp.exe.config to build directory

我在rake文件中如何最好地建模这个依赖关系矩阵,我有点不知所措。 我希望能够做到:

rake company1 #(release is the default)
rake company1 release
rake company2 debug

但是无法弄清楚如何做到这一点。

显然我有一个build_and_output_core任务,一切都取决于,但那么什么?我可以让company1和company2任务简单地设置一些关于应该做什么的变量,然后是什么触发了实际的复制活动?

我刚刚开始使用rake和ruby,所以我们非常感谢任何一般建议。

1 个答案:

答案 0 :(得分:1)

我会使用相同的代码创建两个名称空间,如下面的代码。如果公司数量超过10家公司,我会开始考虑不制作名称空间。

def do_stuff(company, mode)
  # do stuff
end

namespace :company1 do

task :build_debug do
    do_stuff("company1", :debug)
end

task :build_release do
    do_stuff("company1", :release)
end

task :bd => :build_debug
task :br => :build_release

end #namespace company1


namespace :company2 do

task :build_debug do
    do_stuff("company2", :debug)
end

task :build_release do
    do_stuff("company2", :release)
end

task :bd => :build_debug
task :br => :build_release

end #namespace company2