2008-03-31 18:40:06 -04:00
|
|
|
# depends on: array.rb dir.rb env.rb file.rb hash.rb module.rb regexp.rb
|
2008-10-31 18:27:35 -04:00
|
|
|
# vim: filetype=ruby
|
|
|
|
# THIS FILE WAS AUTOGENERATED, DO NOT EDIT
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2009-06-09 17: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-11 21:52:53 -04:00
|
|
|
if defined?(Gem) then
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
# :stopdoc:
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
module Kernel
|
|
|
|
|
|
|
|
def gem(gem_name, *version_requirements)
|
|
|
|
Gem.push_gem_version_on_load_path(gem_name, *version_requirements)
|
|
|
|
end
|
2007-11-24 22:26:36 -05:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
module Gem
|
|
|
|
|
|
|
|
ConfigMap = {
|
2009-06-09 17: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-03-31 18:40:06 -04:00
|
|
|
}
|
|
|
|
|
2008-06-17 19: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-24 22:26:36 -05:00
|
|
|
|
2008-06-17 19:59:31 -04:00
|
|
|
def self.path
|
|
|
|
@gem_path ||= nil
|
|
|
|
unless @gem_path
|
|
|
|
paths = [ENV['GEM_PATH']]
|
|
|
|
paths << APPLE_GEM_HOME if defined? APPLE_GEM_HOME
|
|
|
|
set_paths(paths.compact.join(File::PATH_SEPARATOR))
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2008-06-17 19:59:31 -04:00
|
|
|
@gem_path
|
|
|
|
end
|
2007-11-24 22:26:36 -05:00
|
|
|
|
2008-10-25 18: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-17 19:59:31 -04:00
|
|
|
def self.set_home(home)
|
2009-06-09 17:38:59 -04:00
|
|
|
home = home.gsub File::ALT_SEPARATOR, File::SEPARATOR if File::ALT_SEPARATOR
|
2008-06-17 19:59:31 -04:00
|
|
|
@gem_home = home
|
|
|
|
end
|
2007-11-24 22:26:36 -05:00
|
|
|
|
2008-06-17 19:59:31 -04:00
|
|
|
def self.set_paths(gpaths)
|
|
|
|
if gpaths
|
|
|
|
@gem_path = gpaths.split(File::PATH_SEPARATOR)
|
2009-06-09 17: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-17 19:59:31 -04:00
|
|
|
@gem_path << Gem.dir
|
|
|
|
else
|
2009-06-09 17:38:59 -04:00
|
|
|
# TODO: should this be Gem.default_path instead?
|
2008-06-17 19:59:31 -04:00
|
|
|
@gem_path = [Gem.dir]
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
@gem_path.uniq!
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-11-24 22:26:36 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
# begin rubygems/defaults
|
2008-10-31 18:27:35 -04:00
|
|
|
|
|
|
|
@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]
|
2009-06-09 17:38:59 -04:00
|
|
|
# 1.9.2dev reverted to 1.8 style path
|
|
|
|
elsif RUBY_VERSION > '1.9' and RUBY_VERSION < '1.9.2' then
|
|
|
|
File.join(ConfigMap[:libdir], ConfigMap[:ruby_install_name], 'gems',
|
|
|
|
ConfigMap[:ruby_version])
|
2008-10-31 18:27:35 -04:00
|
|
|
else
|
2009-06-09 17:38:59 -04:00
|
|
|
File.join(ConfigMap[:libdir], ruby_engine, 'gems',
|
|
|
|
ConfigMap[:ruby_version])
|
2008-10-31 18:27:35 -04:00
|
|
|
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
|
2009-06-09 17:38:59 -04:00
|
|
|
if File.exist?(Gem.user_home)
|
|
|
|
[user_dir, default_dir]
|
|
|
|
else
|
|
|
|
[default_dir]
|
|
|
|
end
|
2008-10-31 18:27:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Deduce Ruby's --program-prefix and --program-suffix from its install name
|
|
|
|
|
|
|
|
def self.default_exec_format
|
2009-06-09 17:38:59 -04:00
|
|
|
exec_format = ConfigMap[:ruby_install_name].sub('ruby', '%s') rescue '%s'
|
|
|
|
|
|
|
|
unless exec_format =~ /%s/ then
|
|
|
|
raise Gem::Exception,
|
|
|
|
"[BUG] invalid exec_format #{exec_format.inspect}, no %s"
|
|
|
|
end
|
|
|
|
|
|
|
|
exec_format
|
2008-10-31 18:27:35 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
# end rubygems/defaults
|
2008-10-31 18:27:35 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
2008-10-25 18:58:43 -04:00
|
|
|
# Methods before this line will be removed when QuickLoader is replaced
|
|
|
|
# with the real RubyGems
|
|
|
|
|
2008-06-17 19:59:31 -04:00
|
|
|
GEM_PRELUDE_METHODS = Gem.methods(false)
|
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
begin
|
2008-10-26 06:18:39 -04:00
|
|
|
verbose, debug = $VERBOSE, $DEBUG
|
2009-06-09 17:38:59 -04:00
|
|
|
$VERBOSE = $DEBUG = nil
|
2008-10-25 18:58:43 -04:00
|
|
|
|
|
|
|
begin
|
2008-10-26 06:18:39 -04:00
|
|
|
require 'rubygems/defaults/operating_system'
|
2008-12-23 01:47:44 -05:00
|
|
|
rescue ::LoadError
|
2008-10-25 18:58:43 -04:00
|
|
|
end
|
2008-10-26 06:18:39 -04:00
|
|
|
|
|
|
|
if defined?(RUBY_ENGINE) then
|
|
|
|
begin
|
|
|
|
require "rubygems/defaults/#{RUBY_ENGINE}"
|
2008-12-23 01:47:44 -05:00
|
|
|
rescue ::LoadError
|
2008-10-26 06:18:39 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
$VERBOSE, $DEBUG = verbose, debug
|
2008-10-25 18:58:43 -04:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
module QuickLoader
|
2007-12-23 00:45:11 -05:00
|
|
|
|
2008-12-22 18:06:47 -05:00
|
|
|
@loaded_full_rubygems_library = false
|
|
|
|
|
2008-06-17 19:59:31 -04:00
|
|
|
def self.load_full_rubygems_library
|
2008-12-22 18:06:47 -05:00
|
|
|
return if @loaded_full_rubygems_library
|
|
|
|
|
|
|
|
@loaded_full_rubygems_library = true
|
|
|
|
|
2008-06-17 19:59:31 -04:00
|
|
|
class << Gem
|
|
|
|
Gem::GEM_PRELUDE_METHODS.each do |method_name|
|
|
|
|
undef_method method_name
|
2007-12-23 20:38:43 -05:00
|
|
|
end
|
2008-06-17 19:59:31 -04:00
|
|
|
end
|
2007-12-23 00:45:11 -05:00
|
|
|
|
2008-06-17 19:59:31 -04:00
|
|
|
Kernel.module_eval do
|
|
|
|
undef_method :gem if method_defined? :gem
|
|
|
|
end
|
2007-12-23 20:38:43 -05:00
|
|
|
|
2009-05-21 06:00:48 -04:00
|
|
|
$".delete File.join(Gem::ConfigMap[:rubylibprefix],
|
2008-06-17 19:59:31 -04:00
|
|
|
Gem::ConfigMap[:ruby_version], 'rubygems.rb')
|
2007-12-23 00:45:11 -05:00
|
|
|
|
2008-06-17 19:59:31 -04:00
|
|
|
require 'rubygems'
|
2007-11-24 22:26:36 -05:00
|
|
|
end
|
2007-12-23 00:45:11 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
GemPaths = {}
|
|
|
|
GemVersions = {}
|
|
|
|
|
|
|
|
def push_gem_version_on_load_path(gem_name, *version_requirements)
|
|
|
|
if version_requirements.empty?
|
2009-06-09 17:38:59 -04:00
|
|
|
unless GemPaths.has_key?(gem_name) then
|
|
|
|
raise Gem::LoadError, "Could not find RubyGem #{gem_name} (>= 0)\n"
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# highest version gems already active
|
|
|
|
return false
|
|
|
|
else
|
2009-06-09 17:38:59 -04:00
|
|
|
if version_requirements.length > 1 then
|
2008-03-31 18:40:06 -04:00
|
|
|
QuickLoader.load_full_rubygems_library
|
|
|
|
return gem(gem_name, *version_requirements)
|
2007-11-24 22:26:36 -05:00
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
|
|
|
|
requirement, version = version_requirements[0].split
|
|
|
|
requirement.strip!
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
if loaded_version = GemVersions[gem_name] then
|
2009-04-19 00:17:26 -04:00
|
|
|
case requirement
|
2009-06-09 17:38:59 -04:00
|
|
|
when ">", ">=" then
|
|
|
|
return false if
|
|
|
|
(loaded_version <=> Gem.integers_for(version)) >= 0
|
|
|
|
when "~>" then
|
|
|
|
required_version = Gem.integers_for version
|
|
|
|
|
|
|
|
return false if loaded_version.first == required_version.first
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-11-24 22:26:36 -05:00
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
|
|
|
|
QuickLoader.load_full_rubygems_library
|
2009-06-09 17:38:59 -04:00
|
|
|
gem gem_name, *version_requirements
|
2007-11-24 22:26:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def integers_for(gem_version)
|
2008-03-31 18:40:06 -04:00
|
|
|
numbers = gem_version.split(".").collect {|n| n.to_i}
|
|
|
|
numbers.pop while numbers.last == 0
|
|
|
|
numbers << 0 if numbers.empty?
|
|
|
|
numbers
|
|
|
|
end
|
|
|
|
|
|
|
|
def push_all_highest_version_gems_on_load_path
|
|
|
|
Gem.path.each do |path|
|
|
|
|
gems_directory = File.join(path, "gems")
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
if File.exist?(gems_directory) then
|
2008-03-31 18:40:06 -04:00
|
|
|
Dir.entries(gems_directory).each do |gem_directory_name|
|
|
|
|
next if gem_directory_name == "." || gem_directory_name == ".."
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
dash = gem_directory_name.rindex("-")
|
|
|
|
next if dash.nil?
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
gem_name = gem_directory_name[0...dash]
|
|
|
|
current_version = GemVersions[gem_name]
|
2009-06-09 17:38:59 -04:00
|
|
|
new_version = integers_for(gem_directory_name[dash+1..-1])
|
|
|
|
|
|
|
|
if current_version then
|
|
|
|
if (current_version <=> new_version) == -1 then
|
2008-03-31 18:40:06 -04:00
|
|
|
GemVersions[gem_name] = new_version
|
|
|
|
GemPaths[gem_name] = File.join(gems_directory, gem_directory_name)
|
|
|
|
end
|
|
|
|
else
|
2007-11-24 22:26:36 -05:00
|
|
|
GemVersions[gem_name] = new_version
|
|
|
|
GemPaths[gem_name] = File.join(gems_directory, gem_directory_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
|
|
|
|
require_paths = []
|
|
|
|
|
2008-10-26 06:18:39 -04:00
|
|
|
GemPaths.each_value do |path|
|
2008-10-31 18:27:35 -04:00
|
|
|
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
|
2008-03-31 18:40:06 -04:00
|
|
|
else
|
2008-10-26 06:18:39 -04:00
|
|
|
require_paths << file if File.exist?(file = File.join(path, "bin"))
|
|
|
|
require_paths << file if File.exist?(file = File.join(path, "lib"))
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# "tag" the first require_path inserted into the $LOAD_PATH to enable
|
|
|
|
# indexing correctly with rubygems proper when it inserts an explicitly
|
|
|
|
# gem version
|
2009-06-09 17:38:59 -04:00
|
|
|
unless require_paths.empty? then
|
2008-03-31 18:40:06 -04:00
|
|
|
require_paths.first.instance_variable_set(:@gem_prelude_index, true)
|
2007-11-24 22:26:36 -05:00
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
# gem directories must come after -I and ENV['RUBYLIB']
|
|
|
|
$:[$:.index(ConfigMap[:sitelibdir]),0] = require_paths
|
|
|
|
end
|
|
|
|
|
|
|
|
def const_missing(constant)
|
|
|
|
QuickLoader.load_full_rubygems_library
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
if Gem.const_defined?(constant) then
|
|
|
|
Gem.const_get constant
|
2008-05-11 21:51:47 -04:00
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
2007-11-24 22:26:36 -05:00
|
|
|
end
|
2008-03-31 18: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 03:00:19 -05:00
|
|
|
end
|
2007-11-24 22:26:36 -05:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
extend QuickLoader
|
2007-11-24 22:26:36 -05:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
begin
|
|
|
|
Gem.push_all_highest_version_gems_on_load_path
|
2009-06-09 17:38:59 -04:00
|
|
|
$" << File.join(Gem::ConfigMap[:rubylibprefix],
|
2008-03-31 18:40:06 -04:00
|
|
|
Gem::ConfigMap[:ruby_version], "rubygems.rb")
|
|
|
|
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 00:45:11 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
2007-11-24 22:26:36 -05:00
|
|
|
|