使用bundler为不同平台加载不同版本的gems

发布于 2024-12-24 17:46:57 字数 484 浏览 3 评论 0原文

所以我正在为 Windows 和 Linux 开发 Sinatra。问题是我使用 Thin 而不是 Webrick,并且 Windows 的 eventmachine 仅适用于预发行版本,而 Linux 使用最新的稳定版。在gemfile中,您当然不能包含具有不同版本的相同gem,如下所示:

gem "eventmachine", "~> 1.0.0.beta.4.1", :group => :development_win
gem "eventmachine", group => :development_linux
gem "thin

我想知道是否有一种方法可以解决这个问题,也许对Windows使用一个gemfile,对linux使用一个gemfile,加载一个gemfile的命令是什么或其他。

或者,有没有一种方法可以在 git 中只管理两个不同平台的 gemfile,也许通过文件的分支(不知道从我读到的 git 分支中这是否可能)。

So I am developing a Sinatra for both windows and linux. The problem is I'm using Thin instead of Webrick and eventmachine for windows only works with a pre-release version while linux uses the latest stable. in the gemfile you of course cannot include the same gem with different versions like so:

gem "eventmachine", "~> 1.0.0.beta.4.1", :group => :development_win
gem "eventmachine", group => :development_linux
gem "thin

I was wondering if there was a way to work around this, maybe using one gemfile for windows and one gemfile for linux, what would the command be to load one or the other.

Alternatively is there a way to perhaps in git manage just the gemfile for two different platforms, perhaps through a branch for just the file (don't know if that's possible from what I've read of git branches).

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

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

发布评论

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

评论(3

触ぅ动初心 2024-12-31 17:46:57

您可以这样做:

# Windows
gem "eventmachine", "~> 1.0.0.beta.4.1", :platform => [:mswin, :mingw]

# C Ruby (MRI) or Rubinius, but NOT Windows
gem "eventmachine", :platform => :ruby

可用平台的完整列表:

ruby      C Ruby (MRI) or Rubinius, but NOT Windows
ruby_18   ruby AND version 1.8
ruby_19   ruby AND version 1.9
ruby_20   ruby AND version 2.0
mri       Same as ruby, but not Rubinius
mri_18    mri AND version 1.8
mri_19    mri AND version 1.9
mri_20    mri AND version 2.0
rbx       Same as ruby, but only Rubinius (not MRI)
jruby     JRuby
mswin     Windows
mingw     Windows 'mingw32' platform (aka RubyInstaller)
mingw_18  mingw AND version 1.8
mingw_19  mingw AND version 1.9
mingw_20  mingw AND version 2.0 

您可以在 Gemfile(5) 手册页 此处(请参阅“平台”部分)。

另一种方法是使用 RUBY_PLATFORM 常量:

if RUBY_PLATFORM =~ /win32/
  gem "eventmachine", "~> 1.0.0.beta.4.1"
else
  gem "eventmachine"
end

我还没有看到 RUBY_PLATFORM 可用值的完整列表,但您可以

ruby -e 'puts RUBY_PLATFORM'

在两个平台上运行并查看差异。

You can do it like that:

# Windows
gem "eventmachine", "~> 1.0.0.beta.4.1", :platform => [:mswin, :mingw]

# C Ruby (MRI) or Rubinius, but NOT Windows
gem "eventmachine", :platform => :ruby

Full list of available platforms:

ruby      C Ruby (MRI) or Rubinius, but NOT Windows
ruby_18   ruby AND version 1.8
ruby_19   ruby AND version 1.9
ruby_20   ruby AND version 2.0
mri       Same as ruby, but not Rubinius
mri_18    mri AND version 1.8
mri_19    mri AND version 1.9
mri_20    mri AND version 2.0
rbx       Same as ruby, but only Rubinius (not MRI)
jruby     JRuby
mswin     Windows
mingw     Windows 'mingw32' platform (aka RubyInstaller)
mingw_18  mingw AND version 1.8
mingw_19  mingw AND version 1.9
mingw_20  mingw AND version 2.0 

You can find more information in Gemfile(5) man page here (see 'Platforms' section).

Another approach is to use RUBY_PLATFORM constant:

if RUBY_PLATFORM =~ /win32/
  gem "eventmachine", "~> 1.0.0.beta.4.1"
else
  gem "eventmachine"
end

I haven't seen full list of available values for RUBY_PLATFORM but you can run

ruby -e 'puts RUBY_PLATFORM'

on both your platforms and see the difference.

童话 2024-12-31 17:46:57

您可以使用 --gemfile 选项为不同平台使用不同的 gemfile。请参阅此处的文档
http://gembundler.com/man/bundle-config.1.html

You can use the --gemfile option to use different gemfiles for different platforms. See the documentation here
http://gembundler.com/man/bundle-config.1.html

你好,陌生人 2024-12-31 17:46:57

您需要一个 gem 的多个版本(全部具有相同的名称)。因此,目前使用 Bundler,您需要多个同时的 Bundler 依赖快照“锁定”文件。如果您的开发人员使用 Bundler 的 gemfile 配置设置,这是可能的。他们可以这样做:

  1. 通过使用环境变量 BUNDLE_GEMFILE (在命令行上或在 .bash_profile 中);或
  2. (可能不太理想)在 .bundle/config 中(全局,在其主目录中)。

因此,Bundler 可以安全地创建(并且在给定相同的配置设置的情况下,以后可能会自动使用)例如 Gemfile-linux.lockGemfile-windows.lock

虽然这个基本方法看起来可行,但它并不是很 DRY。但是,如果例如 Gemfile-linuxGemfile-windows 自动合并它们共同共享的任何 Gemfile 语句:即,如果它们包含

以下 语句: >::Kernel.eval(File.open('Gemfile-common','r'){|f| f.read},::Kernel.binding)

You need multiple versions (all with the same name) of a gem. Therefore, currently with Bundler, you need multiple, simultaneous Bundler dependency snapshot 'lock' files. This is possible, if your developers make use of Bundler's gemfile configuration setting. They might do this either:

  1. By making use of environment variable BUNDLE_GEMFILE (on the command line or in .bash_profile); or
  2. (Probably less desirably) in .bundle/config (globally, in their home directories).

Thus, safely, Bundler can create (and presumably automatically later use, given the same configuration settings) e.g. Gemfile-linux.lock and Gemfile-windows.lock.

Although this basic approach seems workable, it's not very DRY. However, this improves if, e.g., both Gemfile-linux and Gemfile-windows automatically incorporate whatever Gemfile statements they share in common: i.e., if they include the statement:

::Kernel.eval(File.open('Gemfile-common','r'){|f| f.read},::Kernel.binding)

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