Skip to content

Commit

Permalink
Don't require rubygems/defaults from gem_prelude.rb.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
drbrain committed Oct 31, 2008
1 parent ff5a076 commit af0221e
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 9 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Sat Nov 1 07:09:40 2008 Eric Hodel <drbrain@segment7.net>

* gem_prelude.rb: Don't require rubygems/defaults.rb.

Fri Oct 31 21:58:50 2008 Kouhei Sutou <kou@cozmixng.org>

* lib/rss/converter.rb (RSS::Converter): use String#encode.
Expand Down
111 changes: 104 additions & 7 deletions gem_prelude.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -75,15 +77,105 @@ def self.set_paths(gpaths)
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

GEM_PRELUDE_METHODS = Gem.methods(false)

begin
verbose, debug = $VERBOSE, $DEBUG
$VERBOSE = $DEBUG = nil
require 'rubygems/defaults'
$DEBUG = $VERBOSE = nil

begin
require 'rubygems/defaults/operating_system'
Expand Down Expand Up @@ -113,7 +205,8 @@ class << Gem
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'
Expand All @@ -125,7 +218,7 @@ class << Gem
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
Expand All @@ -141,7 +234,7 @@ def push_gem_version_on_load_path(gem_name, *version_requirements)

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]
Expand Down Expand Up @@ -190,8 +283,12 @@ def push_all_highest_version_gems_on_load_path
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"))
Expand Down
1 change: 1 addition & 0 deletions lib/rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ def self.set_paths(gpaths)
@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
Expand Down
5 changes: 4 additions & 1 deletion lib/rubygems/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ def self.default_dir
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

Expand Down
27 changes: 26 additions & 1 deletion test/rubygems/test_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ def setup
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
Expand Down Expand Up @@ -475,6 +479,27 @@ def test_self_searcher
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
Expand Down

0 comments on commit af0221e

Please sign in to comment.