使用bundler为不同平台加载不同版本的gems
所以我正在为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以这样做:
可用平台的完整列表:
您可以在
Gemfile(5)
手册页 此处(请参阅“平台”部分)。另一种方法是使用
RUBY_PLATFORM
常量:我还没有看到
RUBY_PLATFORM
可用值的完整列表,但您可以在两个平台上运行并查看差异。
You can do it like that:
Full list of available platforms:
You can find more information in
Gemfile(5)
man page here (see 'Platforms' section).Another approach is to use
RUBY_PLATFORM
constant:I haven't seen full list of available values for
RUBY_PLATFORM
but you can runon both your platforms and see the difference.
您可以使用 --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
您需要一个 gem 的多个版本(全部具有相同的名称)。因此,目前使用 Bundler,您需要多个同时的 Bundler 依赖快照“锁定”文件。如果您的开发人员使用 Bundler 的
gemfile
配置设置,这是可能的。他们可以这样做:BUNDLE_GEMFILE
(在命令行上或在.bash_profile
中);或.bundle/config
中(全局,在其主目录中)。因此,Bundler 可以安全地创建(并且在给定相同的配置设置的情况下,以后可能会自动使用)例如
Gemfile-linux.lock
和Gemfile-windows.lock
。虽然这个基本方法看起来可行,但它并不是很 DRY。但是,如果例如
Gemfile-linux
和Gemfile-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:BUNDLE_GEMFILE
(on the command line or in.bash_profile
); or.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
andGemfile-windows.lock
.Although this basic approach seems workable, it's not very DRY. However, this improves if, e.g., both
Gemfile-linux
andGemfile-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)