Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
657 views
in Technique[技术] by (71.8m points)

ruby - does using ":platforms =>" in your gemfile work?

I have a Rails app that I'm developing on Windows and deploying to Linux. I suspect I'll just switch entirely over to Linux in the future. Anyway, on Linux I need 'execjs' and 'therubyracer' but I don't need those in Win7. So I put these lines in my gemfile:

gem 'therubyracer', :platforms => :ruby
gem 'execjs', :platforms => :ruby

Ran a bundle install on the Linux VM and the app started up fine. But on Windows I get:

Uncaught exception: Could not find execjs-1.2.11 in any of the sources

Now, from what I read (here under PLATFORMS) it tells me that "If a gem should only be used in a particular platform or set of platforms, you can specify them" and the sample is this:

gem "weakling",   :platforms => :jruby 

And it says "ruby C Ruby (MRI) or Rubinius, but NOT Windows". So to me that says that bundler should be ignoring the execjs line on Windows. However on Windows when I ran bundle install I saw this:

Installing execjs (1.2.11)

So that says to me I'm missing something about the docs or bundler is ignoring the platforms command. Am I doing something wrong?

PS>bundle -v
Bundler version 1.0.21
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

:platforms => :ruby does indeed exclude gems from being installed on Windows.

However, it does not work in a cygwin environment. In cygwin, it considers the platform to be :mri.

You'll also notice that ruby -e 'puts RUBY_PLATFORM' outputs i386-cygwin, not i386-mingw32 or i386-mswin like it would on Windows ruby.

Were you working in a cygwin environment?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...