Skip to content

Commit d1de97e

Browse files
committed
* gem_prelude.rb: provide workaround for gem activation. Currently,
gem activation does not work by default. Now it can be worked around by requiring "rubygems" first. [ruby-core:29486] a patch from Evan Phoenix in [ruby-core:31096]. * lib/rubygems.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent ce9c952 commit d1de97e

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

ChangeLog

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
Thu Jul 8 00:15:50 2010 Yusuke Endoh <mame@tsg.ne.jp>
2+
3+
* gem_prelude.rb: provide workaround for gem activation. Currently,
4+
gem activation does not work by default. Now it can be worked
5+
around by requiring "rubygems" first. [ruby-core:29486]
6+
a patch from Evan Phoenix in [ruby-core:31096].
7+
8+
* lib/rubygems.rb: ditto.
9+
110
Wed Jul 7 10:01:34 2010 Adrian Bloomer <adrian.bloomer@gmail.com>
211

312
* numeric.c (fix_rev): Replaced fix_rev with '~num | FIXNUM_FLAG'.

gem_prelude.rb

+14-10
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ module QuickLoader
136136

137137
@loaded_full_rubygems_library = false
138138

139-
def self.load_full_rubygems_library
139+
def self.remove
140140
return if @loaded_full_rubygems_library
141141

142142
@loaded_full_rubygems_library = true
@@ -150,6 +150,12 @@ class << Gem
150150
Kernel.module_eval do
151151
undef_method :gem if method_defined? :gem
152152
end
153+
end
154+
155+
def self.load_full_rubygems_library
156+
return if @loaded_full_rubygems_library
157+
158+
remove
153159

154160
$".delete path_to_full_rubygems_library
155161
if $".any? {|path| path.end_with?('/rubygems.rb')}
@@ -179,6 +185,7 @@ def self.path_to_full_rubygems_library
179185

180186
GemPaths = {}
181187
GemVersions = {}
188+
GemLoadPaths = []
182189

183190
def push_gem_version_on_load_path(gem_name, *version_requirements)
184191
if version_requirements.empty?
@@ -241,29 +248,27 @@ def push_all_highest_version_gems_on_load_path
241248
end
242249
end
243250

244-
require_paths = []
245-
246251
GemPaths.each_value do |path|
247252
if File.exist?(file = File.join(path, ".require_paths")) then
248253
paths = File.read(file).split.map do |require_path|
249254
File.join path, require_path
250255
end
251256

252-
require_paths.concat paths
257+
GemLoadPaths.concat paths
253258
else
254-
require_paths << file if File.exist?(file = File.join(path, "bin"))
255-
require_paths << file if File.exist?(file = File.join(path, "lib"))
259+
GemLoadPaths << file if File.exist?(file = File.join(path, "bin"))
260+
GemLoadPaths << file if File.exist?(file = File.join(path, "lib"))
256261
end
257262
end
258263

259264
# "tag" the first require_path inserted into the $LOAD_PATH to enable
260265
# indexing correctly with rubygems proper when it inserts an explicitly
261266
# gem version
262-
unless require_paths.empty? then
263-
require_paths.first.instance_variable_set(:@gem_prelude_index, true)
267+
unless GemLoadPaths.empty? then
268+
GemLoadPaths.first.instance_variable_set(:@gem_prelude_index, true)
264269
end
265270
# gem directories must come after -I and ENV['RUBYLIB']
266-
$:[$:.index{|e|e.instance_variable_defined?(:@gem_prelude_index)}||-1,0] = require_paths
271+
$:[$:.index{|e|e.instance_variable_defined?(:@gem_prelude_index)}||-1,0] = GemLoadPaths
267272
end
268273

269274
def const_missing(constant)
@@ -289,7 +294,6 @@ def method_missing(method, *args, &block)
289294

290295
begin
291296
Gem.push_all_highest_version_gems_on_load_path
292-
Gem::QuickLoader.fake_rubygems_as_loaded
293297
rescue Exception => e
294298
puts "Error loading gem paths on load path in gem_prelude"
295299
puts e

lib/rubygems.rb

+16-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
gem_disabled = !defined? Gem
99

10+
unless gem_disabled
11+
# Nuke the Quickloader stuff
12+
Gem::QuickLoader.remove
13+
end
14+
1015
require 'rubygems/defaults'
1116
require 'thread'
1217
require 'etc'
@@ -579,6 +584,12 @@ def self.load_path_insert_index
579584
$LOAD_PATH.index { |p| p.instance_variable_defined? :@gem_prelude_index }
580585
end
581586

587+
def self.remove_prelude_paths
588+
Gem::QuickLoader::GemLoadPaths.each do |path|
589+
$LOAD_PATH.delete(path)
590+
end
591+
end
592+
582593
##
583594
# The file name and line number of the caller of the caller of this method.
584595

@@ -1098,13 +1109,14 @@ def RbConfig.datadir(package_name)
10981109

10991110
require 'rubygems/config_file'
11001111

1112+
Gem.remove_prelude_paths
1113+
11011114
##
11021115
# Enables the require hook for RubyGems.
11031116
#
1104-
# Ruby 1.9 allows --disable-gems, so we require it when we didn't detect a Gem
1105-
# constant at rubygems.rb load time.
1106-
1107-
require 'rubygems/custom_require' if gem_disabled or RUBY_VERSION < '1.9'
1117+
# We remove the paths prelude added, so we need custom require to get
1118+
# any gems now.
1119+
require 'rubygems/custom_require'
11081120

11091121
Gem.clear_paths
11101122

test/rubygems/test_gem_activation.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ def test_activation
1717
/can't activate rubygems-bug-child.*already activated rubygems-bug-child-1\.1/, [],
1818
bug3140)
1919
end
20-
end if defined?(::Gem)
20+
end if defined?(::Gem) and RUBY_VERSION < "1.9"

0 commit comments

Comments
 (0)