通过系统执行其他 rake 任务的 Rake 任务失败 - 没有这样的文件来加载“rake”;

发布于 2024-10-02 04:17:41 字数 914 浏览 0 评论 0原文

我编写了一个 rake 任务来通过系统运行其他一些 rake 任务(以便将 ActiveRecord 绑定到不同的数据库等)。它在我的 OS X 机器上运行良好,但在我们的生产 Linux 机器上失败并出现加载错误。这些任务简单地归结为:

namespace :jobs do

  task :foo => :environment do
    system "rake jobs:bar"
  end

  task :bar => :environment do
    puts "foobar"
  end

跟踪的输出是:

-bash-3.2$ rake jobs:foo --trace
(in /the/path)
** Invoke jobs:foo (first_time)
** Invoke environment (first_time)
** Execute environment
** Erubis 2.6.6
** Execute jobs:foo
/usr/bin/rake:19:in `load': no such file to load -- rake (LoadError)
    from /usr/bin/rake:19

我将 put $: 转储到 /usr/bin/rake 中,并发现了一些有趣的东西。主作业的加载路径包含这两个路径:

/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib

而辅助作业的加载路径仅包含:

/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib

这可能解释了加载错误,但不是其原因。有什么想法吗?

I've written a rake task to run a few other rake tasks via system (so as to bind ActiveRecord to different databases, among other things). It works fine on my OS X box, but fails on our production Linux boxes with a load error. The tasks trivially boil down to:

namespace :jobs do

  task :foo => :environment do
    system "rake jobs:bar"
  end

  task :bar => :environment do
    puts "foobar"
  end

and the traced output is:

-bash-3.2$ rake jobs:foo --trace
(in /the/path)
** Invoke jobs:foo (first_time)
** Invoke environment (first_time)
** Execute environment
** Erubis 2.6.6
** Execute jobs:foo
/usr/bin/rake:19:in `load': no such file to load -- rake (LoadError)
    from /usr/bin/rake:19

I dumped a puts $: into /usr/bin/rake and have discovered something interesting. The primary job has a load path containing both of these paths:

/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib

while the secondary job has a load path containing only:

/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib

which probably explains the load error, but not the reason for it. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

-柠檬树下少年和吉他 2024-10-09 04:17:41

检查以确保您的安装已正确设置所需的环境变量。
http://docs.rubygems.org/read/chapter/3
当使用“export RUBYOPT=RUBYGEM”而不是“export RUBYOPT=RUBYGEMS”时,我也出现了同样的问题。啊,一个角色就能带来如此大的改变。

Check to make sure your install has set up the required environment variables correctly.
http://docs.rubygems.org/read/chapter/3
The same problem occurred for me when using "export RUBYOPT=RUBYGEM" instead of "export RUBYOPT=RUBYGEMS". Ahh the difference a single character can make.

倦话 2024-10-09 04:17:41

如果您确实想从另一个 rake 任务调用一个 rake 任务。为什么不这样做呢? “Rake::Task['jobs:bar'].invoke”。您甚至可以在循环中执行此操作,例如更改 ENV 变量的 Array#each 等。我之前在任务中完成过此操作。

不过,如果您的示例是人为的,并且您并没有真正调用一项任务,而只是询问为什么子 shell 有不同的 PATH 设置,那么我不知道。也许如果这很难,那就暗示应该用另一种方式来做。

If you are really trying to invoke a rake task from another rake task. Why not do this? "Rake::Task['jobs:bar'].invoke". You can even do it in a loop, for instance an Array#each that changes ENV vars, etc. I've done this in tasks before.

Though, if your example was contrived and your not really calling one task but just asking why the sub shell has different PATH setting, that I do not know. Perhaps if it's hard, then it's a hint that it should be done another way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文