【问题标题】:How can I declare this dependency in my Rakefile?如何在我的 Rakefile 中声明这种依赖关系?
【发布时间】:2011-07-25 09:21:09
【问题描述】:

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

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

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

【问题讨论】:

    标签: ruby build rake


    【解决方案1】:

    我认为这个帖子已经有了最佳答案:How to run Rake tasks from within Rake tasks?

    【讨论】:

      【解决方案2】:
      Rake::Task[libname].invoke
      

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

      【讨论】:

      • 我认为它们是等价的。所以,这可能是唯一的方法。
      • 小心,它们并不完全等同。 #execute 将始终执行任务,即使它已被调用,而#invoke 将仅在尚未被调用时执行它。此外,#execute 不会执行先决条件,而 #invoke 会。
      猜你喜欢
      • 2018-06-20
      • 2011-03-27
      • 2018-06-08
      • 2013-05-25
      • 2019-03-28
      • 1970-01-01
      • 2015-07-08
      • 2023-03-11
      • 1970-01-01
      相关资源
      最近更新 更多