I’m creating a gem whose dependencies differ by platform – if MRI Ruby,
it
needs to require rjb, and if JRuby, it very much needs not to require
rjb.
In my gemspec file, I have something like this:
if /java/ === RUBY_PLATFORM
spec.platform = Gem::Platform::JAVA
end
However, when I gem build this gemspec in JRuby, I get this error:
Invalid gemspec in [mygem.gemspec]: uninitialized constant
Gem::Platform::JAVA
I also get that error for MSWIN. In pry, I can see that the constants
do
exist:
[8] pry(main)> cd Gem::Platform
[9] pry(Gem::Platform):1> ls
constants: CURRENT JAVA MINGW MSWIN RUBY
Gem::Platform.methods: local match new
Gem::Platform#methods:
== === =~ _deprecated_empty? cpu cpu= empty? eql? hash
inspect
os os= to_a to_s version version=
instance variables: @local
locals: _ __ direxfileinoutpry
Anyone know what’s going on here? My ultimate goal is to have a gem
that’s
dependent on this one install the one appropriate to the platform, and
itself have an MRI and JRuby version.
I don’t see a Gem::Platform::JAVA when running under plain JRuby 1.7.4:
jruby-1.7.4 :001 > RUBY_PLATFORM
=> “java”
jruby-1.7.4 :003 > Gem::VERSION
=> “1.8.24”
jruby-1.7.4 :004 > Gem::Platform::JAVA
NameError: uninitialized constant Gem::Platform::JAVA
from org/jruby/RubyModule.java:2631:in const_missing' from (irb):5:in evaluate’
from org/jruby/RubyKernel.java:1093:in eval' from org/jruby/RubyKernel.java:1489:in loop’
from org/jruby/RubyKernel.java:1254:in catch' from org/jruby/RubyKernel.java:1254:in catch’
from /Users/rsutphin/.rvm/rubies/jruby-1.7.4/bin/irb:13:in `(root)’
I also don’t see it when grepping the source for rubygems.
Perhaps Gem::Platform::JAVA is something introduced by something that’s
loaded in the pry environment but not from a general gem install
environment? Or perhaps there are different versions of rubygems
involved.
That’s the irony. It does have it – it just can’t be specified (see
pry
output below, running MRI 2.0).
I know I can specify “java”, I was doing that before, but I’m skeptical
that something normally requiring a composite object can be assigned
only
one of those elements, and still work properly. I’m having problems
getting platform detection and installation of the proper platform’s gem
working properly, and I thought cleaning up this issue might help.
I think there’s something getting pulled into the environment where you
are running pry for 1.9.3 that’s adding the JAVA constant. It looks like
bundler is one possible culprit:
So you shouldn’t rely on that constant in your gemspec. The only
constant
that rubygems itself defines is Gem::Platform::RUBY, and that’s just the
string “ruby”. I think that using the string “java” is what’s expected
I
can back up kristian in saying that “java” definitely works. If you look
at the source for Gem::Platform, you can see where it maps from the
string
to the composite object.
It seems like something on your system is introducing those constants.
Do
you have any pry plugins or a .pryrc file or anything?
$ rbenv version
2.0.0-rc2
$ pry
[1] pry(main)> cd Gem::Platform
[2] pry(Gem::Platform):1> ls
constants: CURRENT RUBY
Gem::Platform.methods: local match new
Gem::Platform#methods:
== =~ cpu= hash os to_a version
=== cpu eql? inspect os= to_s version=
instance variables: @local
locals: _ __ direxfileinoutpry
[3] pry(Gem::Platform):1>
[4] pry(main)>
$ rbenv version
jruby-1.7.4
$ pry
[1] pry(main)> cd Gem::Platform
[2] pry(Gem::Platform):1> ls
constants: CURRENT RUBY
Gem::Platform.methods: local match new
Gem::Platform#methods:
== =~ cpu empty? hash os to_a version
=== _deprecated_empty? cpu= eql? inspect os= to_s version=
instance variables: @local
locals: _ __ direxfileinoutpry
[3] pry(Gem::Platform):1>
$ rbenv version
1.9.3-p327
$ pry
[1] pry(main)> RUBY_VERSION
=> “1.9.3”
[2] pry(main)> cd Gem::Platform
[3] pry(Gem::Platform):1> ls
constants: CURRENT RUBY
Gem::Platform.methods: local match new
Gem::Platform#methods:
== =~ cpu empty? hash os to_a version
=== _deprecated_empty? cpu= eql? inspect os= to_s version=
instance variables: @local
locals: _ __ direxfileinoutpry
[4] pry(Gem::Platform):1>