Skip to content

Commit 0bccf09

Browse files
committed
[GR-21161] Make require 'rubygems/specification' work before require 'rubygems'.
PullRequest: truffleruby/1750
2 parents 1fca74f + 9104335 commit 0bccf09

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Bug fixes:
3030
* Fix missing flushing when printing an exception at top-level with a custom backtrace, which caused no output being shown (#1750, #1895).
3131
* Use the mode of the given `IO` for `IO#reopen(IO)` which is important for the 3 standard IOs (#2034).
3232
* Fix potential deadlock when running finalizers (#2041).
33+
* Let `require 'rubygems/specification'` work before `require 'rubygems'`.
3334

3435
Compatibility:
3536

lib/patches/rubygems/specification.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# rubygems/specification.rb is required by rubygems.rb.
2+
# require "rubygems/specification" only works on MRI if RubyGems is
3+
# already loaded (and is a no-op), and fails with --disable-gems.
4+
# On TruffleRuby with lazy RubyGems, Gem is an autoload.
5+
# So if we are in that case, just require 'rubygems' instead,
6+
# as if RubyGems was loaded eagerly on startup.
7+
8+
if Object.autoload?(:Gem) # lazy-rubygems enabled, rubygems.rb was not yet loaded
9+
require 'rubygems'
10+
raise 'Gem::Specification should have been defined' unless defined?(Gem::Specification)
11+
else
12+
require 'rubygems/specification'
13+
end

spec/tags/truffle/lazy_rubygems_tags.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ slow:RubyGems is loaded when accessing Gem
33
slow:RubyGems is loaded by a failing require
44
slow:Lazy RubyGems defines StringIO like RubyGems which requires it eagerly
55
slow:Lazy RubyGems works for require 'rubygems/package'
6+
slow:Lazy RubyGems works for require 'rubygems/specification'

spec/truffle/lazy_rubygems_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,8 @@
3636
it "works for require 'rubygems/package'" do
3737
ruby_exe("require 'rubygems/package'; p Gem::Package").should == "Gem::Package\n"
3838
end
39+
40+
it "works for require 'rubygems/specification'" do
41+
ruby_exe("require 'rubygems/specification'; p Gem::Specification").should == "Gem::Specification\n"
42+
end
3943
end

0 commit comments

Comments
 (0)