2010-06-10 08:31:08 +04:00
|
|
|
# depends on: array.rb dir.rb env.rb file.rb hash.rb module.rb regexp.rb
|
2008-11-01 01:27:35 +03:00
|
|
|
# vim: filetype=ruby
|
2008-04-01 02:40:06 +04:00
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
# NOTICE: Ruby is during initialization here.
|
|
|
|
# * Encoding.default_external does not reflects -E.
|
|
|
|
# * Should not expect Encoding.default_internal.
|
|
|
|
# * Locale encoding is available.
|
|
|
|
|
2008-05-12 05:52:53 +04:00
|
|
|
if defined?(Gem) then
|
2008-04-01 02:40:06 +04:00
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
# :stopdoc:
|
|
|
|
|
2008-04-01 02:40:06 +04:00
|
|
|
module Kernel
|
|
|
|
|
|
|
|
def gem(gem_name, *version_requirements)
|
2010-07-20 22:30:46 +04:00
|
|
|
Gem::QuickLoader.load_full_rubygems_library
|
|
|
|
gem gem_name, *version_requirements
|
2008-04-01 02:40:06 +04:00
|
|
|
end
|
2009-12-19 11:02:51 +03:00
|
|
|
private :gem
|
2007-11-25 06:26:36 +03:00
|
|
|
end
|
|
|
|
|
2008-04-01 02:40:06 +04:00
|
|
|
module Gem
|
|
|
|
|
|
|
|
ConfigMap = {
|
2009-06-10 01:38:59 +04:00
|
|
|
: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"],
|
2008-04-01 02:40:06 +04:00
|
|
|
}
|
|
|
|
|
2010-08-08 11:08:55 +04:00
|
|
|
def self.suffixes
|
2010-08-17 02:38:46 +04:00
|
|
|
['', '.rb', ".#{RbConfig::CONFIG["DLEXT"]}"]
|
2010-08-08 11:08:55 +04:00
|
|
|
end
|
|
|
|
|
2008-06-18 03:59:31 +04:00
|
|
|
def self.dir
|
|
|
|
@gem_home ||= nil
|
|
|
|
set_home(ENV['GEM_HOME'] || default_dir) unless @gem_home
|
|
|
|
@gem_home
|
|
|
|
end
|
2007-11-25 06:26:36 +03:00
|
|
|
|
2008-06-18 03:59:31 +04:00
|
|
|
def self.path
|
|
|
|
@gem_path ||= nil
|
|
|
|
unless @gem_path
|
2009-07-30 18:12:42 +04:00
|
|
|
paths = [ENV['GEM_PATH'] || default_path]
|
2008-06-18 03:59:31 +04:00
|
|
|
paths << APPLE_GEM_HOME if defined? APPLE_GEM_HOME
|
|
|
|
set_paths(paths.compact.join(File::PATH_SEPARATOR))
|
2008-04-01 02:40:06 +04:00
|
|
|
end
|
2008-06-18 03:59:31 +04:00
|
|
|
@gem_path
|
|
|
|
end
|
2007-11-25 06:26:36 +03:00
|
|
|
|
2008-10-26 02:58:43 +04:00
|
|
|
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
|
|
|
|
|
2008-06-18 03:59:31 +04:00
|
|
|
def self.set_home(home)
|
2009-11-26 14:22:44 +03:00
|
|
|
home = home.dup.force_encoding(Encoding.find('filesystem'))
|
|
|
|
home.gsub!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
|
|
|
|
@gem_home = home
|
2008-06-18 03:59:31 +04:00
|
|
|
end
|
2007-11-25 06:26:36 +03:00
|
|
|
|
2008-06-18 03:59:31 +04:00
|
|
|
def self.set_paths(gpaths)
|
|
|
|
if gpaths
|
|
|
|
@gem_path = gpaths.split(File::PATH_SEPARATOR)
|
2009-06-10 01:38:59 +04:00
|
|
|
|
|
|
|
if File::ALT_SEPARATOR then
|
|
|
|
@gem_path.map! do |path|
|
|
|
|
path.gsub File::ALT_SEPARATOR, File::SEPARATOR
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-06-18 03:59:31 +04:00
|
|
|
@gem_path << Gem.dir
|
|
|
|
else
|
2009-06-10 01:38:59 +04:00
|
|
|
# TODO: should this be Gem.default_path instead?
|
2008-06-18 03:59:31 +04:00
|
|
|
@gem_path = [Gem.dir]
|
2008-04-01 02:40:06 +04:00
|
|
|
end
|
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
@gem_path.uniq!
|
2009-10-28 10:34:24 +03:00
|
|
|
@gem_path.map!{|x|x.force_encoding(Encoding.find('filesystem'))}
|
2008-04-01 02:40:06 +04:00
|
|
|
end
|
2007-11-25 06:26:36 +03:00
|
|
|
|
2009-07-30 18:12:42 +04:00
|
|
|
def self.user_home
|
2009-11-05 06:29:20 +03:00
|
|
|
@user_home ||= File.expand_path("~").force_encoding(Encoding.find('filesystem'))
|
2009-07-30 18:12:42 +04:00
|
|
|
rescue
|
|
|
|
if File::ALT_SEPARATOR then
|
|
|
|
"C:/"
|
|
|
|
else
|
|
|
|
"/"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
# begin rubygems/defaults
|
2009-07-30 18:12:25 +04:00
|
|
|
# NOTE: this require will be replaced with in-place eval before compilation.
|
|
|
|
require 'lib/rubygems/defaults.rb'
|
2009-06-10 01:38:59 +04:00
|
|
|
# end rubygems/defaults
|
2008-11-01 01:27:35 +03:00
|
|
|
|
2009-07-30 18:12:25 +04:00
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
##
|
2008-10-26 02:58:43 +04:00
|
|
|
# Methods before this line will be removed when QuickLoader is replaced
|
|
|
|
# with the real RubyGems
|
|
|
|
|
2008-06-18 03:59:31 +04:00
|
|
|
GEM_PRELUDE_METHODS = Gem.methods(false)
|
|
|
|
|
2008-10-26 02:58:43 +04:00
|
|
|
begin
|
2008-10-26 13:18:39 +03:00
|
|
|
verbose, debug = $VERBOSE, $DEBUG
|
2009-06-10 01:38:59 +04:00
|
|
|
$VERBOSE = $DEBUG = nil
|
2008-10-26 02:58:43 +04:00
|
|
|
|
|
|
|
begin
|
2008-10-26 13:18:39 +03:00
|
|
|
require 'rubygems/defaults/operating_system'
|
2008-12-23 09:47:44 +03:00
|
|
|
rescue ::LoadError
|
2008-10-26 02:58:43 +04:00
|
|
|
end
|
2008-10-26 13:18:39 +03:00
|
|
|
|
|
|
|
if defined?(RUBY_ENGINE) then
|
|
|
|
begin
|
|
|
|
require "rubygems/defaults/#{RUBY_ENGINE}"
|
2008-12-23 09:47:44 +03:00
|
|
|
rescue ::LoadError
|
2008-10-26 13:18:39 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
$VERBOSE, $DEBUG = verbose, debug
|
2008-10-26 02:58:43 +04:00
|
|
|
end
|
|
|
|
|
2008-04-01 02:40:06 +04:00
|
|
|
module QuickLoader
|
2010-06-10 08:31:08 +04:00
|
|
|
|
|
|
|
@loaded_full_rubygems_library = false
|
|
|
|
|
2010-07-07 19:40:52 +04:00
|
|
|
def self.remove
|
2010-06-10 08:31:08 +04:00
|
|
|
return if @loaded_full_rubygems_library
|
2008-12-23 02:06:47 +03:00
|
|
|
|
2010-06-10 08:31:08 +04:00
|
|
|
@loaded_full_rubygems_library = true
|
2008-12-23 02:06:47 +03:00
|
|
|
|
2008-06-18 03:59:31 +04:00
|
|
|
class << Gem
|
2010-04-23 10:31:24 +04:00
|
|
|
undef_method(*Gem::GEM_PRELUDE_METHODS)
|
2010-06-10 08:31:08 +04:00
|
|
|
end
|
|
|
|
|
2010-07-20 22:30:46 +04:00
|
|
|
remove_method :const_missing
|
|
|
|
remove_method :method_missing
|
|
|
|
|
2010-06-10 08:31:08 +04:00
|
|
|
Kernel.module_eval do
|
|
|
|
undef_method :gem if method_defined? :gem
|
2008-06-18 03:59:31 +04:00
|
|
|
end
|
2010-07-07 19:40:52 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.load_full_rubygems_library
|
2010-07-21 10:30:40 +04:00
|
|
|
return false if @loaded_full_rubygems_library
|
2010-07-07 19:40:52 +04:00
|
|
|
|
|
|
|
remove
|
2007-12-24 04:38:43 +03:00
|
|
|
|
2009-07-15 13:05:32 +04:00
|
|
|
$".delete path_to_full_rubygems_library
|
2010-04-23 09:37:26 +04:00
|
|
|
if $".any? {|path| path.end_with?('/rubygems.rb')}
|
|
|
|
raise LoadError, "another rubygems is already loaded from #{path}"
|
2009-07-15 13:05:32 +04:00
|
|
|
end
|
2010-07-21 10:30:40 +04:00
|
|
|
|
2008-06-18 03:59:31 +04:00
|
|
|
require 'rubygems'
|
2010-07-21 10:30:40 +04:00
|
|
|
|
|
|
|
return true
|
2007-11-25 06:26:36 +03:00
|
|
|
end
|
2007-12-23 08:45:11 +03:00
|
|
|
|
2009-07-15 13:05:32 +04:00
|
|
|
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
|
|
|
|
|
2008-04-01 02:40:06 +04:00
|
|
|
def const_missing(constant)
|
|
|
|
QuickLoader.load_full_rubygems_library
|
2009-06-10 01:38:59 +04:00
|
|
|
|
|
|
|
if Gem.const_defined?(constant) then
|
|
|
|
Gem.const_get constant
|
2008-05-12 05:51:47 +04:00
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
2007-11-25 06:26:36 +03:00
|
|
|
end
|
2008-04-01 02:40:06 +04:00
|
|
|
|
|
|
|
def method_missing(method, *args, &block)
|
|
|
|
QuickLoader.load_full_rubygems_library
|
|
|
|
super unless Gem.respond_to?(method)
|
|
|
|
Gem.send(method, *args, &block)
|
2008-02-10 11:00:19 +03:00
|
|
|
end
|
2007-11-25 06:26:36 +03:00
|
|
|
end
|
|
|
|
|
2008-04-01 02:40:06 +04:00
|
|
|
extend QuickLoader
|
2007-11-25 06:26:36 +03:00
|
|
|
|
2010-07-20 22:30:46 +04:00
|
|
|
def self.try_activate(path)
|
2010-07-21 10:30:40 +04:00
|
|
|
# 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
|
2010-07-20 22:30:46 +04:00
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2007-11-25 06:26:36 +03:00
|
|
|
end
|
|
|
|
|
2008-04-01 02:40:06 +04:00
|
|
|
begin
|
2010-07-20 22:30:46 +04:00
|
|
|
require 'lib/rubygems/custom_require.rb'
|
2008-04-01 02:40:06 +04:00
|
|
|
rescue Exception => e
|
|
|
|
puts "Error loading gem paths on load path in gem_prelude"
|
|
|
|
puts e
|
|
|
|
puts e.backtrace.join("\n")
|
|
|
|
end
|
2007-12-23 08:45:11 +03:00
|
|
|
|
2007-12-20 11:39:12 +03:00
|
|
|
end
|
2007-11-25 06:26:36 +03:00
|
|
|
|