2011-03-29 42 views
3

我试图建立一个静态库,其名称我只在处理一些文件后才得到。我有这样的事情:如何在我的Rakefile中声明这种依赖关系?

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 

但是,当然,因为我不知道当这项工作变得跑的依赖,应该建立A.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 
    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 

,但我觉得这是太丑陋了。有没有更好的方法来声明这种依赖关系?

回答

1
Rake::Task[libname].invoke 

这看起来稍微漂亮到我的眼睛,我不认为有比调用.execute或.invoke其他耙子任务中excuting rake任务的方式。

+0

我认为他们是等价的。所以,可能这是唯一的方法。 – Geo 2011-04-05 13:57:19

+0

小心点,它们并不完全等效。 #execute将会总是执行任务,即使它已经被调用,而#invoke只会在它尚未被调用时才会执行它。另外,#execute不会执行先决条件,而#invoke会执行。 – 2013-04-01 18:40:15

相关问题