2011-03-29 78 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

相關問題