[前][次][番号順一覧][スレッド一覧]

ruby-changes:12417

From: yugui <ko1@a...>
Date: Wed, 15 Jul 2009 18:05:52 +0900 (JST)
Subject: [ruby-changes:12417] Ruby:r24117 (trunk): * ext/purelib.rb: translates a fake path to rubygems in $" into

yugui	2009-07-15 18:05:32 +0900 (Wed, 15 Jul 2009)

  New Revision: 24117

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24117

  Log:
    * ext/purelib.rb: translates a fake path to rubygems in $" into
      an alternative in $: so that Kernel.#require does not load
      more rubygems.rb.
      Resolves many failures in test/rubygems/*.
    
    * gem_prelude.rb (Gem.load_full_rubygems_library): supports case 
      the rubygems to load is not in $(rubylibprefix).
      (Gem.path_to_full_rubygems_library): new method for the changes in
      purelib.rb and Gem.load_full_rubygems_library.
      (Gem.fake_rubygems_as_loaded): new method.

  Modified files:
    trunk/ChangeLog
    trunk/ext/purelib.rb
    trunk/gem_prelude.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 24116)
+++ ChangeLog	(revision 24117)
@@ -1,3 +1,16 @@
+Wed Jul 15 17:33:52 2009  Yuki Sonoda (Yugui)  <yugui@y...>
+
+	* ext/purelib.rb: translates a fake path to rubygems in $" into
+	  an alternative in $: so that Kernel.#require does not load
+	  more rubygems.rb.
+	  Resolves many failures in test/rubygems/*.
+
+	* gem_prelude.rb (Gem.load_full_rubygems_library): supports case 
+	  the rubygems to load is not in $(rubylibprefix).
+	  (Gem.path_to_full_rubygems_library): new method for the changes in
+	  purelib.rb and Gem.load_full_rubygems_library.
+	  (Gem.fake_rubygems_as_loaded): new method.
+
 Wed Jul 15 16:29:35 2009  NAKAMURA Usaku  <usa@r...>
 
 	* win32/Makefile.sub (LIBPATHFLAG): path is already quoted in mkmf.rb.
Index: gem_prelude.rb
===================================================================
--- gem_prelude.rb	(revision 24116)
+++ gem_prelude.rb	(revision 24117)
@@ -235,18 +235,42 @@
           Gem::GEM_PRELUDE_METHODS.each do |method_name|
             undef_method method_name
           end
+          undef_method :const_missing
+          undef_method :method_missing
         end
 
         Kernel.module_eval do
           undef_method :gem if method_defined? :gem
         end
 
-        $".delete File.join(Gem::ConfigMap[:rubylibprefix],
-                            Gem::ConfigMap[:ruby_version], 'rubygems.rb')
-
+        $".delete path_to_full_rubygems_library
+        $".each do |path|
+          if /#{Regexp.escape File::SEPARATOR}rubygems\.rb\z/ =~ path
+            raise LoadError, "another rubygems is already loaded from #{path}"
+          end
+        end
         require 'rubygems'
       end
 
+      def self.fake_rubygems_as_loaded
+        path = path_to_full_rubygems_library
+        $" << path unless $".include?(path)
+      end
+
+      def self.path_to_full_rubygems_library
+        installed_path = File.join(Gem::ConfigMap[:rubylibprefix], Gem::ConfigMap[:ruby_version])
+        if $:.include?(installed_path)
+          return File.join(installed_path, 'rubygems.rb')
+        else # e.g., on test-all
+          $:.each do |dir|
+            if File.exist?( path = File.join(dir, 'rubygems.rb') )
+              return path
+            end
+          end
+          raise LoadError, 'rubygems.rb'
+        end
+      end
+
       GemPaths = {}
       GemVersions = {}
 
@@ -367,8 +391,7 @@
 
   begin
     Gem.push_all_highest_version_gems_on_load_path
-    $" << File.join(Gem::ConfigMap[:rubylibprefix],
-                    Gem::ConfigMap[:ruby_version], "rubygems.rb")
+    Gem::QuickLoader.fake_rubygems_as_loaded
   rescue Exception => e
     puts "Error loading gem paths on load path in gem_prelude"
     puts e
Index: ext/purelib.rb
===================================================================
--- ext/purelib.rb	(revision 24116)
+++ ext/purelib.rb	(revision 24117)
@@ -6,5 +6,12 @@
   end
 }
 if nul
-  $:[nul..-1] = ["."]
+  removed, $:[nul..-1] = $:[nul..-1], ["."]
+  if defined?(Gem::QuickLoader)
+    removed.each do |path|
+      # replaces a fake rubygems by gem_prelude.rb with an alternative path
+      index = $".index(File.join(path, 'rubygems.rb'))
+      $"[index] = Gem::QuickLoader.path_to_full_rubygems_library if index
+    end
+  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]