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

ruby-changes:18515

From: ryan <ko1@a...>
Date: Fri, 14 Jan 2011 11:14:34 +0900 (JST)
Subject: [ruby-changes:18515] Ruby:r30538 (trunk): Reduced gem_prelude to just require rubygems. Reviewed by Evan Phoenix

ryan	2011-01-14 11:02:12 +0900 (Fri, 14 Jan 2011)

  New Revision: 30538

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

  Log:
    Reduced gem_prelude to just require rubygems. Reviewed by Evan Phoenix

  Modified files:
    trunk/ChangeLog
    trunk/gem_prelude.rb
    trunk/lib/rubygems.rb
    trunk/ruby.c
    trunk/test/ruby/test_process.rb
    trunk/test/ruby/test_rubyoptions.rb
    trunk/test/ruby/test_thread.rb
    trunk/test/rubygems/gemutilities.rb
    trunk/test/test_tracer.rb
    trunk/test/webrick/test_filehandler.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 30537)
+++ ChangeLog	(revision 30538)
@@ -1,3 +1,15 @@
+Fri Jan 14 10:40:11 2011  Ryan Davis  <ryan@l...>
+
+	* gem_prelude.rb: Just require rubygems. Fixes rubygems 1.4.
+	* lib/rubygems.rb: removed all Gem::Quickloader code.
+	* ruby.c: renamed ruby_init_gems to ruby_init_prelude. Set
+	  $disable_rubygems since there is no fine grained mechanism to
+	  skip parts of the prelude. Open to suggestions on how to do this
+	  better.
+	* test/*.rb: Load path isn't set up correctly, so add
+	  --disable-gems as needed to failing tests that are explicitly
+	  testing stderr w/ ==.
+
 Fri Jan 14 07:30:47 2011  Nobuyoshi Nakada  <nobu@r...>
 
 	* io.c (argf_next_argv): go advance when the next file cannot be
Index: gem_prelude.rb
===================================================================
--- gem_prelude.rb	(revision 30537)
+++ gem_prelude.rb	(revision 30538)
@@ -1,239 +1 @@
-# depends on: array.rb dir.rb env.rb file.rb hash.rb module.rb regexp.rb
-# vim: filetype=ruby
-
-# NOTICE: Ruby is during initialization here.
-# * Encoding.default_external does not reflects -E.
-# * Should not expect Encoding.default_internal.
-# * Locale encoding is available.
-
-if defined?(Gem) then
-
-  # :stopdoc:
-
-  module Kernel
-
-    def gem(gem_name, *version_requirements)
-      Gem::QuickLoader.load_full_rubygems_library
-      gem gem_name, *version_requirements
-    end
-    private :gem
-  end
-
-  module Gem
-
-    ConfigMap = {
-      :EXEEXT            => RbConfig::CONFIG["EXEEXT"],
-      :RUBY_SO_NAME      => RbConfig::CONFIG["RUBY_SO_NAME"],
-      :arch              => RbConfig::CONFIG["arch"],
-      :bindir            => RbConfig::CONFIG["bindir"],
-      :libdir            => RbConfig::CONFIG["libdir"],
-      :ruby_install_name => RbConfig::CONFIG["ruby_install_name"],
-      :ruby_version      => RbConfig::CONFIG["ruby_version"],
-      :rubylibprefix     => RbConfig::CONFIG["rubylibprefix"],
-      :sitedir           => RbConfig::CONFIG["sitedir"],
-      :sitelibdir        => RbConfig::CONFIG["sitelibdir"],
-    }
-
-    def self.suffixes
-      ['', '.rb', ".#{RbConfig::CONFIG["DLEXT"]}"]
-    end
-
-    def self.dir
-      @gem_home ||= nil
-      set_home(ENV['GEM_HOME'] || default_dir) unless @gem_home
-      @gem_home
-    end
-
-    def self.path
-      @gem_path ||= nil
-      unless @gem_path
-        paths = [ENV['GEM_PATH'] || default_path]
-        paths << APPLE_GEM_HOME if defined? APPLE_GEM_HOME
-        set_paths(paths.compact.join(File::PATH_SEPARATOR))
-      end
-      @gem_path
-    end
-
-    def self.post_install(&hook)
-      @post_install_hooks << hook
-    end
-
-    def self.post_uninstall(&hook)
-      @post_uninstall_hooks << hook
-    end
-
-    def self.pre_install(&hook)
-      @pre_install_hooks << hook
-    end
-
-    def self.pre_uninstall(&hook)
-      @pre_uninstall_hooks << hook
-    end
-
-    def self.set_home(home)
-      home = home.dup.force_encoding(Encoding.find('filesystem'))
-      home.gsub!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
-      @gem_home = home
-    end
-
-    def self.set_paths(gpaths)
-      if gpaths
-        @gem_path = gpaths.split(File::PATH_SEPARATOR)
-
-        if File::ALT_SEPARATOR then
-          @gem_path.map! do |path|
-            path.gsub File::ALT_SEPARATOR, File::SEPARATOR
-          end
-        end
-
-        @gem_path << Gem.dir
-      else
-        # TODO: should this be Gem.default_path instead?
-        @gem_path = [Gem.dir]
-      end
-
-      @gem_path.uniq!
-      @gem_path.map!{|x|x.force_encoding(Encoding.find('filesystem'))}
-    end
-
-    def self.user_home
-      @user_home ||= File.expand_path("~").force_encoding(Encoding.find('filesystem'))
-    rescue
-      if File::ALT_SEPARATOR then
-        "C:/"
-      else
-        "/"
-      end
-    end
-
-    # begin rubygems/defaults
-    # NOTE: this require will be replaced with in-place eval before compilation.
-    require 'lib/rubygems/defaults.rb'
-    # end rubygems/defaults
-
-
-    ##
-    # Methods before this line will be removed when QuickLoader is replaced
-    # with the real RubyGems
-
-    GEM_PRELUDE_METHODS = Gem.methods(false)
-
-    begin
-      verbose, debug = $VERBOSE, $DEBUG
-      $VERBOSE = $DEBUG = nil
-
-      begin
-        require 'rubygems/defaults/operating_system'
-      rescue ::LoadError
-      end
-
-      if defined?(RUBY_ENGINE) then
-        begin
-          require "rubygems/defaults/#{RUBY_ENGINE}"
-        rescue ::LoadError
-        end
-      end
-    ensure
-      $VERBOSE, $DEBUG = verbose, debug
-    end
-
-    module QuickLoader
-
-      @loaded_full_rubygems_library = false
-
-      def self.remove
-        return if @loaded_full_rubygems_library
-
-        @loaded_full_rubygems_library = true
-
-        class << Gem
-          undef_method(*Gem::GEM_PRELUDE_METHODS)
-        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 false if @loaded_full_rubygems_library
-
-        remove
-
-        $".delete path_to_full_rubygems_library
-        if $".any? {|path| path.end_with?('/rubygems.rb')}
-          raise LoadError, "another rubygems is already loaded from #{path}"
-        end
-
-        require 'rubygems'
-
-        return true
-      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
-
-      def const_missing(constant)
-        QuickLoader.load_full_rubygems_library
-
-        if Gem.const_defined?(constant) then
-          Gem.const_get constant
-        else
-          super
-        end
-      end
-
-      def method_missing(method, *args, &block)
-        QuickLoader.load_full_rubygems_library
-        super unless Gem.respond_to?(method)
-        Gem.send(method, *args, &block)
-      end
-    end
-
-    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
-    require 'lib/rubygems/custom_require.rb'
-  rescue Exception => e
-    puts "Error loading gem paths on load path in gem_prelude"
-    puts e
-    puts e.backtrace.join("\n")
-  end
-
-end
-
+require 'rubygems' unless $disable_rubygems
Index: lib/rubygems.rb
===================================================================
--- lib/rubygems.rb	(revision 30537)
+++ lib/rubygems.rb	(revision 30538)
@@ -5,13 +5,6 @@
 # See LICENSE.txt for permissions.
 #++
 
-gem_disabled = !defined? Gem
-
-unless gem_disabled
-  # Nuke the Quickloader stuff
-  Gem::QuickLoader.remove
-end
-
 require 'rubygems/defaults'
 require 'thread'
 require 'etc'
@@ -584,9 +577,9 @@
   end
 
   def self.remove_prelude_paths
-    Gem::QuickLoader::GemLoadPaths.each do |path|
-      $LOAD_PATH.delete(path)
-    end
+    # Gem::QuickLoader::GemLoadPaths.each do |path|
+    # $LOAD_PATH.delete(path)
+    # end
   end
 
   ##
@@ -1120,16 +1113,8 @@
   end
 end
 
-##
-# Enables the require hook for RubyGems.
-#
-# if --disable-rubygems was used, then the prelude wasn't loaded, so
-# we need to load the custom_require now.
+require 'rubygems/custom_require'
 
-if gem_disabled
-  require 'rubygems/custom_require'
-end
-
 Gem.clear_paths
 
 Gem.load_plugins
Index: ruby.c
===================================================================
--- ruby.c	(revision 30537)
+++ ruby.c	(revision 30538)
@@ -1103,9 +1103,9 @@
 void Init_prelude(void);
 
 static void
-ruby_init_gems(int enable)
+ruby_init_prelude(int enable_gems)
 {
-    if (enable) rb_define_module("Gem");
+    rb_gv_set("$disable_rubygems", enable_gems ? Qfalse : Qtrue);
     Init_prelude();
     rb_const_remove(rb_cObject, rb_intern_const("TMP_RUBY_PREFIX"));
 }
@@ -1365,7 +1365,7 @@
 	    rb_enc_associate(RARRAY_PTR(load_path)[i], lenc);
 	}
     }
-    ruby_init_gems(!(opt->disable & DISABLE_BIT(gems)));
+    ruby_init_prelude(!(opt->disable & DISABLE_BIT(gems)));
     ruby_set_argv(argc, argv);
     process_sflag(&opt->sflag);
 
Index: test/test_tracer.rb
===================================================================
--- test/test_tracer.rb	(revision 30537)
+++ test/test_tracer.rb	(revision 30538)
@@ -5,16 +5,16 @@
   include EnvUtil
 
   def test_work_with_e
-    assert_in_out_err(%w[-rtracer -e 1]) do |(*lines),|
+    assert_in_out_err(%w[--disable-gems -rtracer -e 1]) do |(*lines),|
       case lines.size
       when 2
         assert_match %r[#0:<internal:lib/rubygems/custom_require>:\d+:Kernel:<: -], lines[0]
       when 1
         # do nothing
       else
-        flunk 'unexpected output from `ruby -rtracer -e 1`'
+        flunk "unexpected output from `ruby -rtracer -e 1`"
       end
-      assert_equal "#0:-e:1::-: 1", lines[1]
+      assert_equal "#0:-e:1::-: 1", lines.last
     end
   end
 end
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 30537)
+++ test/ruby/test_process.rb	(revision 30538)
@@ -1210,8 +1210,8 @@
       Dir.chdir("vd") {
         dir = "#{d}/vd"
         # OpenSolaris cannot remove the current directory.
-        system(RUBY, "-e", "Dir.chdir '..'; Dir.rmdir #{dir.dump}")
-        system({"RUBYLIB"=>nil}, RUBY, "-e", "exit true")
+        system(RUBY, "--disable-gems", "-e", "Dir.chdir '..'; Dir.rmdir #{dir.dump}")
+        system({"RUBYLIB"=>nil}, RUBY, "--disable-gems", "-e", "exit true")
         status = $?
       }
       assert(status.success?, "[ruby-dev:38105]")
Index: test/ruby/test_rubyoptions.rb
===================================================================
--- test/ruby/test_rubyoptions.rb	(revision 30537)
+++ test/ruby/test_rubyoptions.rb	(revision 30538)
@@ -57,13 +57,14 @@
   end
 
   def test_debug
-    assert_in_out_err(%w(-de) + ["p $DEBUG"], "", %w(true), [])
+    assert_in_out_err(["--disable-gems", "-de", "p $DEBUG"], "", %w(true), [])
 
-    assert_in_out_err(%w(--debug -e) + ["p $DEBUG"], "", %w(true), [])
+    assert_in_out_err(["--disable-gems", "--debug", "-e", "p $DEBUG"],
+                      "", %w(true), [])
   end
 
   def test_verbose
-    assert_in_out_err(%w(-vve) + [""]) do |r, e|
+    assert_in_out_err(["-vve", ""]) do |r, e|
       assert_match(/^ruby #{RUBY_VERSION}(?:[p ]|dev).*? \[#{RUBY_PLATFORM}\]$/, r.join)
       assert_equal RUBY_DESCRIPTION, r.join.chomp
       assert_equal([], e)
@@ -209,10 +210,10 @@
     assert_in_out_err([], "", [], /invalid switch in RUBYOPT: -e \(RuntimeError\)/)
 
     ENV['RUBYOPT'] = '-T1'
-    assert_in_out_err([], "", [], /no program input from stdin allowed in tainted mode \(SecurityError\)/)
+    assert_in_out_err(["--disable-gems"], "", [], /no program input from stdin allowed in tainted mode \(SecurityError\)/)
 
     ENV['RUBYOPT'] = '-T4'
-    assert_in_out_err([], "", [], /no program input from stdin allowed in tainted mode \(SecurityError\)/)
+    assert_in_out_err(["--disable-gems"], "", [], /no program input from stdin allowed in tainted mode \(SecurityError\)/)
 
     ENV['RUBYOPT'] = '-Eus-ascii -KN'
     assert_in_out_err(%w(-Eutf-8 -KU), "p '\u3042'") do |r, e|
Index: test/ruby/test_thread.rb
===================================================================
--- test/ruby/test_thread.rb	(revision 30537)
+++ test/ruby/test_thread.rb	(revision 30538)
@@ -271,7 +271,7 @@
       end
     INPUT
 
-    assert_in_out_err(%w(-d), <<-INPUT, %w(false 2), /.+/)
+    assert_in_out_err(%w(--disable-gems -d), <<-INPUT, %w(false 2), /.+/)
       p Thread.abort_on_exception
       begin
         Thread.new { raise }
Index: test/webrick/test_filehandler.rb
===================================================================
--- test/webrick/test_filehandler.rb	(revision 30537)
+++ test/webrick/test_filehandler.rb	(revision 30538)
@@ -241,6 +241,13 @@
       :CGIInterpreter => TestWEBrick::RubyBin,
       :DocumentRoot => File.dirname(__FILE__),
       :CGIPathEnv => ENV['PATH'],
+      :RequestCallback => Proc.new{|req, res|
+        def req.meta_vars
+          meta = super
+          meta["RUBYLIB"] = $:.join(File::PATH_SEPARATOR)
+          return meta
+        end
+      },
     }
     TestWEBrick.start_httpserver(config) do |server, addr, port, log|
       http = Net::HTTP.new(addr, port)
Index: test/rubygems/gemutilities.rb
===================================================================
--- test/rubygems/gemutilities.rb	(revision 30537)
+++ test/rubygems/gemutilities.rb	(revision 30538)
@@ -2,11 +2,7 @@
 
 $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
 
-if RUBY_VERSION > '1.9' then
-  Gem::QuickLoader.load_full_rubygems_library
-else
-  require 'rubygems'
-end
+require 'rubygems'
 require 'fileutils'
 require 'minitest/autorun'
 require 'tmpdir'

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

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