ruby-changes:16791
From: mame <ko1@a...>
Date: Fri, 30 Jul 2010 00:15:14 +0900 (JST)
Subject: [ruby-changes:16791] Ruby:r28786 (ruby_1_9_2): merges r28693, r28695 and r28703 from trunk into ruby_1_9_2.
mame 2010-07-30 00:14:57 +0900 (Fri, 30 Jul 2010) New Revision: 28786 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28786 Log: merges r28693, r28695 and r28703 from trunk into ruby_1_9_2. -- * lib/rubygems/custom_require.rb, gem_prelude.rb: Load code from from gems properly. * lib/rubygems.rb: Load the custom require if --disable-rubygems was used. * gem_prelude.rb: Pull in rubygem's custom require [ruby-core:30846] * lib/rubygems.rb: Handle always having custom require available Modified files: branches/ruby_1_9_2/ChangeLog branches/ruby_1_9_2/gem_prelude.rb branches/ruby_1_9_2/lib/rubygems/custom_require.rb branches/ruby_1_9_2/lib/rubygems.rb branches/ruby_1_9_2/test/ruby/test_rubyoptions.rb Index: ruby_1_9_2/ChangeLog =================================================================== --- ruby_1_9_2/ChangeLog (revision 28785) +++ ruby_1_9_2/ChangeLog (revision 28786) @@ -1,3 +1,20 @@ +Wed Jul 21 15:22:17 2010 Evan Phoenix <evan@f...> + + * lib/rubygems/custom_require.rb, gem_prelude.rb: Load code from + from gems properly. + +Tue Jul 20 11:35:11 2010 Evan Phoenix <evan@r...> + + * lib/rubygems.rb: Load the custom require if --disable-rubygems + was used. + +Tue Jul 20 11:27:18 2010 Evan Phoenix <evan@r...> + + * gem_prelude.rb: Pull in rubygem's custom require + [ruby-core:30846] + + * lib/rubygems.rb: Handle always having custom require available + Tue Jul 13 20:58:57 2010 Nobuyoshi Nakada <nobu@r...> * configure.in (RUBY_DEFAULT_ARCH): adjust for target Index: ruby_1_9_2/gem_prelude.rb =================================================================== --- ruby_1_9_2/gem_prelude.rb (revision 28785) +++ ruby_1_9_2/gem_prelude.rb (revision 28786) @@ -13,7 +13,8 @@ module Kernel def gem(gem_name, *version_requirements) - Gem.push_gem_version_on_load_path(gem_name, *version_requirements) + Gem::QuickLoader.load_full_rubygems_library + gem gem_name, *version_requirements end private :gem end @@ -143,17 +144,18 @@ class << Gem undef_method(*Gem::GEM_PRELUDE_METHODS) - undef_method :const_missing - undef_method :method_missing end + remove_method :const_missing + remove_method :method_missing + Kernel.module_eval do undef_method :gem if method_defined? :gem end end def self.load_full_rubygems_library - return if @loaded_full_rubygems_library + return false if @loaded_full_rubygems_library remove @@ -161,12 +163,10 @@ if $".any? {|path| path.end_with?('/rubygems.rb')} raise LoadError, "another rubygems is already loaded from #{path}" end + require 'rubygems' - end - def self.fake_rubygems_as_loaded - path = path_to_full_rubygems_library - $" << path unless $".include?(path) + return true end def self.path_to_full_rubygems_library @@ -183,94 +183,6 @@ end end - GemPaths = {} - GemVersions = {} - GemLoadPaths = [] - - def push_gem_version_on_load_path(gem_name, *version_requirements) - if version_requirements.empty? - unless GemPaths.has_key?(gem_name) then - raise Gem::LoadError, "Could not find RubyGem #{gem_name} (>= 0)\n" - end - - # highest version gems already active - return false - else - if version_requirements.length > 1 then - QuickLoader.load_full_rubygems_library - return gem(gem_name, *version_requirements) - end - - requirement, version = version_requirements[0].split - requirement.strip! - - if loaded_version = GemVersions[gem_name] then - case requirement - when ">", ">=" then - return false if - (loaded_version <=> Gem.integers_for(version)) >= 0 - when "~>" then - required_version = Gem.integers_for version - - return false if loaded_version.first == required_version.first - end - end - - QuickLoader.load_full_rubygems_library - gem gem_name, *version_requirements - end - end - - def integers_for(gem_version) - numbers = gem_version.split(".").collect {|n| n.to_i} - numbers.pop while numbers.last == 0 - numbers << 0 if numbers.empty? - numbers - end - - def push_all_highest_version_gems_on_load_path - Gem.path.each do |path| - gems_directory = File.join(path, "gems") - - if File.exist?(gems_directory) then - Dir.entries(gems_directory).each do |gem_directory_name| - next if gem_directory_name == "." || gem_directory_name == ".." - - next unless gem_name = gem_directory_name[/(.*)-(.*)/, 1] - new_version = integers_for($2) - current_version = GemVersions[gem_name] - - if !current_version or (current_version <=> new_version) < 0 then - GemVersions[gem_name] = new_version - GemPaths[gem_name] = File.join(gems_directory, gem_directory_name) - end - end - end - end - - GemPaths.each_value do |path| - if File.exist?(file = File.join(path, ".require_paths")) then - paths = File.read(file).split.map do |require_path| - File.join path, require_path - end - - GemLoadPaths.concat paths - else - GemLoadPaths << file if File.exist?(file = File.join(path, "bin")) - GemLoadPaths << file if File.exist?(file = File.join(path, "lib")) - end - end - - # "tag" the first require_path inserted into the $LOAD_PATH to enable - # indexing correctly with rubygems proper when it inserts an explicitly - # gem version - unless GemLoadPaths.empty? then - GemLoadPaths.first.instance_variable_set(:@gem_prelude_index, true) - end - # gem directories must come after -I and ENV['RUBYLIB'] - $:[$:.index{|e|e.instance_variable_defined?(:@gem_prelude_index)}||-1,0] = GemLoadPaths - end - def const_missing(constant) QuickLoader.load_full_rubygems_library @@ -290,10 +202,29 @@ extend QuickLoader + def self.try_activate(path) + # This method is only hit when the custom require is hit the first time. + # So we go off and dutifully load all of rubygems and retry the call + # to Gem.try_activate. We retry because full rubygems replaces this + # method with one that actually tries to find a gem for +path+ and load it. + # + # This is conditional because in the course of loading rubygems, the custom + # require will call back into here before all of rubygems is loaded. So + # we must not always retry the call. We only redo the call when + # load_full_rubygems_library returns true, which it only does the first + # time it's called. + # + if QuickLoader.load_full_rubygems_library + return Gem.try_activate(path) + end + + return false + end + end begin - Gem.push_all_highest_version_gems_on_load_path + require 'lib/rubygems/custom_require.rb' rescue Exception => e puts "Error loading gem paths on load path in gem_prelude" puts e Index: ruby_1_9_2/lib/rubygems/custom_require.rb =================================================================== --- ruby_1_9_2/lib/rubygems/custom_require.rb (revision 28785) +++ ruby_1_9_2/lib/rubygems/custom_require.rb (revision 28786) @@ -4,8 +4,6 @@ # See LICENSE.txt for permissions. #++ -require 'rubygems' - module Kernel ## @@ -30,17 +28,17 @@ def require(path) # :doc: gem_original_require path rescue LoadError => load_error - if load_error.message.end_with?(path) and - spec = Gem.searcher.find(path) then - Gem.activate(spec.name, "= #{spec.version}") - gem_original_require path - else - raise load_error + if load_error.message.end_with?(path) + if Gem.try_activate(path) + return gem_original_require(path) + end end + + raise load_error end private :require private :gem_original_require -end +end unless Kernel.private_method_defined?(:gem_original_require) Index: ruby_1_9_2/lib/rubygems.rb =================================================================== --- ruby_1_9_2/lib/rubygems.rb (revision 28785) +++ ruby_1_9_2/lib/rubygems.rb (revision 28786) @@ -1031,7 +1031,7 @@ module Kernel - undef gem if respond_to? :gem # defined in gem_prelude.rb on 1.9 + remove_method :gem if respond_to?(:gem, true) # defined in gem_prelude.rb on 1.9 ## # Use Kernel#gem to activate a specific version of +gem_name+. @@ -1109,15 +1109,28 @@ require 'rubygems/config_file' -Gem.remove_prelude_paths +class << Gem + remove_method :try_activate if Gem.respond_to?(:try_activate, true) + def try_activate(path) + spec = Gem.searcher.find(path) + return false unless spec + + Gem.activate(spec.name, "= #{spec.version}") + return true + end +end + ## # Enables the require hook for RubyGems. # -# We remove the paths prelude added, so we need custom require to get -# any gems now. -require 'rubygems/custom_require' +# if --disable-rubygems was used, then the prelude wasn't loaded, so +# we need to load the custom_require now. +if gem_disabled + require 'rubygems/custom_require' +end + Gem.clear_paths Gem.load_plugins Index: ruby_1_9_2/test/ruby/test_rubyoptions.rb =================================================================== --- ruby_1_9_2/test/ruby/test_rubyoptions.rb (revision 28785) +++ ruby_1_9_2/test/ruby/test_rubyoptions.rb (revision 28786) @@ -322,8 +322,8 @@ pat = Regexp.quote(notexist) bug1573 = '[ruby-core:23717]' assert_equal(false, File.exist?(notexist)) - assert_in_out_err(["-r", notexist, "-ep"], "", [], /\A-e:.* -- #{pat} \(LoadError\)\Z/, bug1573) - assert_in_out_err([notexist], "", [], /\A#{rubybin}:.* -- #{pat} \(LoadError\)\Z/, bug1573) + assert_in_out_err(["-r", notexist, "-ep"], "", [], /.* -- #{pat} \(LoadError\)/, bug1573) + assert_in_out_err([notexist], "", [], /#{rubybin}:.* -- #{pat} \(LoadError\)/, bug1573) end def test_program_name -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/