Ruby 如何在Rakefile中声明此依赖关系?

Ruby 如何在Rakefile中声明此依赖关系?,ruby,build,rake,Ruby,Build,Rake,我正在尝试构建一个静态库,只有在处理了一些文件后才能得到它的名称。我有这样的想法: task :lib,:config do |t,args| # ... do some processing here, get a string representing the # fullpath of the lib. Imaging libname contains a.lib file libname => object_files end task :lib,:config d

我正在尝试构建一个静态库,只有在处理了一些文件后才能得到它的名称。我有这样的想法:

task :lib,:config do |t,args|
  # ... do some processing here, get a string representing the 
  # fullpath of the lib. Imaging libname contains a.lib
  file libname => object_files
end
task :lib,:config do |t,args|
  # ... do some processing here, get a string representing the 
  # fullpath of the lib. Imaging libname contains a.lib
  file libname => object_files
  task :lib => [libname]
end
但是,当然,由于在运行任务时我不知道依赖项的名称,因此不执行应该构建.lib的代码。我试着这样做:

task :lib,:config do |t,args|
  # ... do some processing here, get a string representing the 
  # fullpath of the lib. Imaging libname contains a.lib
  file libname => object_files
end
task :lib,:config do |t,args|
  # ... do some processing here, get a string representing the 
  # fullpath of the lib. Imaging libname contains a.lib
  file libname => object_files
  task :lib => [libname]
end
将其添加为依赖项,但它不起作用。我现在就有了这样的系统,它可以工作:

task :lib,:config do |t,args|
  # ... do some processing here, get a string representing the 
  # fullpath of the lib. Imaging libname contains a.lib
  file libname => object_files
  Rake.application[libname].invoke
end
但我觉得太难看了。有没有更好的方法来声明此依赖关系

Rake::Task[libname].invoke

在我看来,这稍微好一点,我认为除了调用.execute或.invoke之外,没有其他方法可以在rake任务中执行rake任务。

我认为这个线程已经有了最好的答案:

我认为它们是等价的。所以,这可能是唯一的办法。小心,它们并不完全相同#execute将始终执行任务,即使任务已经被调用,而#invoke仅在任务尚未被调用时执行。此外,#execute将不执行先决条件,而#invoke将执行先决条件。