我试图制定依赖于另一项任务的佣金规则。如果我只使用如下所示的任务,它可以工作:
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
答案 0 :(得分:1)
将:foo
更改为"foo"
可以解决问题。
似乎task_manager.rb#make_sources
无法处理符号。
https://github.com/ruby/rake/blob/master/lib/rake/task_manager.rb#L266,L288