gpt4 book ai didi

ruby-on-rails - 如何添加特定于 Mac 的 gem 以在 Mac 上 bundle 而不在 Linux 上 bundle ?

转载 作者:数据小太阳 更新时间:2023-10-29 06:27:10 26 4
gpt4 key购买 nike

我正在 Mac 上开发 Rails 应用程序,我是测试新手,所以我刚刚将这些 gem 添加到我的 Gemfile:

group :test, :development do
gem 'rspec-rails'
gem 'rb-fsevent'
gem 'growl'
end

但我的生产服务器运行 Linux,所以即使它们没有分组在 :production 中, bundle 程序 (v1.0.21) 仍会尝试安装它们。 ...显然失败了!
extconf.rb:19:in '<main>': Only Darwin (Mac OS X) systems are supported (RuntimeError)

设置RAILS_ENV运行前到生产环境 bundle install 不起作用

它通过运行 bundle install --without development test 来工作,但是 bundler 如何仅根据您的操作系统考虑这些 gem?


编辑: bundler wiki 提供了有关如何 use platform as a parameter 的详细信息.
bundler issue #663 中给出了相同的解决方案,所以我尝试了:

group :test, :development do
gem 'rspec-rails'
platforms :darwin do
gem 'rb-fsevent'
gem 'growl'
end
end

bundle install行不通,但即使我们回到第一步并做
bundle install --without darwin , 结果是 'darwin' is not a valid platform.<br/>
The available options are: [:ruby, :ruby_18, :ruby_19, :mri, :mri_18, :mri_19, :rbx, :jruby, :mswin, :mingw, :mingw_18, :mingw_19]


还有其他(优雅的)方法吗?

最佳答案

Bundler wiki有一种方法可以将所有 gem 添加到 Gemfile.lock,而不管平台如何。它根据系统设置 require => false,因此您不需要能够实际运行 gems:

gem 'rb-inotify', :require => RUBY_PLATFORM.include?('linux') && 'rb-inotify'

并且他们提供了一些辅助方法来清理:

def os_is(re)
RbConfig::CONFIG['host_os'] =~ re
end

gem 'rb-fsevent', "~> 0.9.3", platforms: :ruby, install_if: os_is(/darwin/)
gem 'rb-inotify', "~> 0.8.8", platforms: :ruby, install_if: os_is(/linux/)
gem 'wdm', "~> 0.1.0", platforms: [:mswin, :mingw. :x64_mingw], install_if: os_is(/mingw|mswin/i)

在我的 Windows 7 x64 系统上,在 Vagrant VM 中运行 Ubuntu 12.04,这工作正常,但需要 :platforms 设置 - Linux bundler 在 'win32console' gem 上阻塞:

Console.c:1:21: fatal error: windows.h: No such file or directory

关于ruby-on-rails - 如何添加特定于 Mac 的 gem 以在 Mac 上 bundle 而不在 Linux 上 bundle ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8420414/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com