From af0221e728742adb34aa5e2abfcefa899ccd1867 Mon Sep 17 00:00:00 2001 From: drbrain Date: Fri, 31 Oct 2008 22:27:35 +0000 Subject: Don't require rubygems/defaults from gem_prelude.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++ gem_prelude.rb | 111 +++++++++++++++++++++++++++++++++++++++++++--- lib/rubygems.rb | 1 + lib/rubygems/defaults.rb | 5 ++- test/rubygems/test_gem.rb | 27 ++++++++++- 5 files changed, 139 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 96c92e187c..0aa9ceb15c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sat Nov 1 07:09:40 2008 Eric Hodel + + * gem_prelude.rb: Don't require rubygems/defaults.rb. + Fri Oct 31 21:58:50 2008 Kouhei Sutou * lib/rss/converter.rb (RSS::Converter): use String#encode. diff --git a/gem_prelude.rb b/gem_prelude.rb index 7c54bdd9d3..ddc56c87d1 100644 --- a/gem_prelude.rb +++ b/gem_prelude.rb @@ -1,4 +1,6 @@ # depends on: array.rb dir.rb env.rb file.rb hash.rb module.rb regexp.rb +# vim: filetype=ruby +# THIS FILE WAS AUTOGENERATED, DO NOT EDIT if defined?(Gem) then @@ -75,6 +77,97 @@ if defined?(Gem) then def self.ensure_gem_subdirectories(path) end + + @post_install_hooks ||= [] + @post_uninstall_hooks ||= [] + @pre_uninstall_hooks ||= [] + @pre_install_hooks ||= [] + + ## + # An Array of the default sources that come with RubyGems + + def self.default_sources + %w[http://gems.rubyforge.org/] + end + + ## + # Default home directory path to be used if an alternate value is not + # specified in the environment + + def self.default_dir + if defined? RUBY_FRAMEWORK_VERSION then + File.join File.dirname(ConfigMap[:sitedir]), 'Gems', + ConfigMap[:ruby_version] + elsif RUBY_VERSION > '1.9' then + File.join(ConfigMap[:libdir], ConfigMap[:ruby_install_name], 'gems', + ConfigMap[:ruby_version]) + else + File.join(ConfigMap[:libdir], ruby_engine, 'gems', + ConfigMap[:ruby_version]) + end + end + + ## + # Path for gems in the user's home directory + + def self.user_dir + File.join(Gem.user_home, '.gem', ruby_engine, + ConfigMap[:ruby_version]) + end + + ## + # Default gem load path + + def self.default_path + [user_dir, default_dir] + end + + ## + # Deduce Ruby's --program-prefix and --program-suffix from its install name + + def self.default_exec_format + baseruby = ConfigMap[:BASERUBY] || 'ruby' + ConfigMap[:RUBY_INSTALL_NAME].sub(baseruby, '%s') rescue '%s' + end + + ## + # The default directory for binaries + + def self.default_bindir + if defined? RUBY_FRAMEWORK_VERSION then # mac framework support + '/usr/bin' + else # generic install + ConfigMap[:bindir] + end + end + + ## + # The default system-wide source info cache directory + + def self.default_system_source_cache_dir + File.join Gem.dir, 'source_cache' + end + + ## + # The default user-specific source info cache directory + + def self.default_user_source_cache_dir + File.join Gem.user_home, '.gem', 'source_cache' + end + + ## + # A wrapper around RUBY_ENGINE const that may not be defined + + def self.ruby_engine + if defined? RUBY_ENGINE then + RUBY_ENGINE + else + 'ruby' + end + end + + + # Methods before this line will be removed when QuickLoader is replaced # with the real RubyGems @@ -82,8 +175,7 @@ if defined?(Gem) then begin verbose, debug = $VERBOSE, $DEBUG - $VERBOSE = $DEBUG = nil - require 'rubygems/defaults' + $DEBUG = $VERBOSE = nil begin require 'rubygems/defaults/operating_system' @@ -113,7 +205,8 @@ if defined?(Gem) then undef_method :gem if method_defined? :gem end - $".delete File.join(Gem::ConfigMap[:libdir], Gem::ConfigMap[:ruby_install_name], + $".delete File.join(Gem::ConfigMap[:libdir], + Gem::ConfigMap[:ruby_install_name], Gem::ConfigMap[:ruby_version], 'rubygems.rb') require 'rubygems' @@ -125,7 +218,7 @@ if defined?(Gem) then def push_gem_version_on_load_path(gem_name, *version_requirements) if version_requirements.empty? unless GemPaths.has_key?(gem_name) - raise LoadError.new("Could not find RubyGem #{gem_name} (>= 0)\n") + raise LoadError.new("Could not find RubyGem #{gem_name} (>= 0)\n") end # highest version gems already active @@ -141,7 +234,7 @@ if defined?(Gem) then if requirement == ">" || requirement == ">=" if (GemVersions[gem_name] <=> Gem.calculate_integers_for_gem_version(version)) >= 0 - return false + return false end elsif requirement == "~>" loaded_version = GemVersions[gem_name] @@ -190,8 +283,12 @@ if defined?(Gem) then require_paths = [] GemPaths.each_value do |path| - if File.exist?(file = File.join(path, ".require_paths")) - require_paths.concat(File.read(file).split.map {|require_path| File.join(path, require_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 + + require_paths.concat paths else require_paths << file if File.exist?(file = File.join(path, "bin")) require_paths << file if File.exist?(file = File.join(path, "lib")) diff --git a/lib/rubygems.rb b/lib/rubygems.rb index e85d97c003..9913b59ce1 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -718,6 +718,7 @@ module Gem @gem_path.uniq! @gem_path.each do |path| if 0 == File.expand_path(path).index(Gem.user_home) + next unless File.directory? Gem.user_home unless win_platform? then # only create by matching user next if Etc.getpwuid.uid != File::Stat.new(Gem.user_home).uid diff --git a/lib/rubygems/defaults.rb b/lib/rubygems/defaults.rb index 315d12a484..7884fad83d 100644 --- a/lib/rubygems/defaults.rb +++ b/lib/rubygems/defaults.rb @@ -20,9 +20,12 @@ module Gem if defined? RUBY_FRAMEWORK_VERSION then File.join File.dirname(ConfigMap[:sitedir]), 'Gems', ConfigMap[:ruby_version] - else + elsif RUBY_VERSION > '1.9' then File.join(ConfigMap[:libdir], ConfigMap[:ruby_install_name], 'gems', ConfigMap[:ruby_version]) + else + File.join(ConfigMap[:libdir], ruby_engine, 'gems', + ConfigMap[:ruby_version]) end end diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index 242d0cee60..f5bfa28e54 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -11,7 +11,11 @@ class TestGem < RubyGemTestCase super @additional = %w[a b].map { |d| File.join @tempdir, d } - @default_dir_re = %r|/\.*?[Rr]uby.*?/[Gg]ems/[0-9.]+| + @default_dir_re = if RUBY_VERSION > '1.9' then + %r|/.*?[Rr]uby.*?/[Gg]ems/[0-9.]+| + else + %r|/[Rr]uby/[Gg]ems/[0-9.]+| + end end def test_self_all_load_paths @@ -475,6 +479,27 @@ class TestGem < RubyGemTestCase assert_kind_of Gem::GemPathSearcher, Gem.searcher end + def test_self_set_paths + other = File.join @tempdir, 'other' + path = [@userhome, other].join File::PATH_SEPARATOR + Gem.send :set_paths, path + + assert File.exist?(File.join(@userhome, 'gems')) + assert File.exist?(File.join(other, 'gems')) + end + + def test_self_set_paths_nonexistent_home + Gem.clear_paths + + other = File.join @tempdir, 'other' + + ENV['HOME'] = other + + Gem.send :set_paths, other + + refute File.exist?(File.join(other, 'gems')) + end + def test_self_source_index assert_kind_of Gem::SourceIndex, Gem.source_index end -- cgit v1.2.3