具有任务依赖性的Rake规则

时间:2016-12-25 22:24:17

标签: ruby rake

我试图制定依赖于另一项任务的佣金规则。如果我只使用如下所示的任务,它可以工作:

task :foo do
  @iv = 42
end

task :bar => :foo do
  p @iv
end

Rake::Task[:bar].invoke

结果:

42

我希望能够使用规则,因此我可以使用正则表达式。但是我收到了错误:

task :foo do
  @iv = 42
end

rule /bar/ => :foo do
  p @iv
end

Rake::Task["bar"].invoke

结果:

/Users/max/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/task_manager.rb:284:in `block in make_sources': Don't know how to handle rule dependent: :foo (RuntimeError)
  from /Users/max/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/task_manager.rb:267:in `map'
  from /Users/max/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/task_manager.rb:267:in `make_sources'
  from /Users/max/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/task_manager.rb:245:in `attempt_rule'
  from /Users/max/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/task_manager.rb:130:in `block in enhance_with_matching_rule'
  from /Users/max/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/task_manager.rb:128:in `each'
  from /Users/max/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/task_manager.rb:128:in `enhance_with_matching_rule'
  from /Users/max/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/task_manager.rb:56:in `[]'
  from /Users/max/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:361:in `[]'
  from baz.rb:63:in `<main>'

如何使用依赖于其他任务的规则?

编辑:

如下所述,规则将其作为字符串依赖:

task :foo do
  @iv = 42
end

rule /bar/ => "foo" do
  p @iv
end

Rake::Task["bar"].invoke
#=> 42

1 个答案:

答案 0 :(得分:1)

:foo更改为"foo"可以解决问题。

似乎task_manager.rb#make_sources无法处理符号。

https://github.com/ruby/rake/blob/master/lib/rake/task_manager.rb#L266,L288