2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2007-12-20 03:39:12 -05:00
|
|
|
module Gem
|
2018-10-21 20:27:02 -04:00
|
|
|
DEFAULT_HOST = "https://rubygems.org".freeze
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2019-02-14 07:59:03 -05:00
|
|
|
@post_install_hooks ||= []
|
|
|
|
@done_installing_hooks ||= []
|
2008-10-25 18:58:43 -04:00
|
|
|
@post_uninstall_hooks ||= []
|
|
|
|
@pre_uninstall_hooks ||= []
|
|
|
|
@pre_install_hooks ||= []
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
|
|
|
# An Array of the default sources that come with RubyGems
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
def self.default_sources
|
2013-02-28 17:25:55 -05:00
|
|
|
%w[https://rubygems.org/]
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
##
|
|
|
|
# Default spec directory path to be used if an alternate value is not
|
|
|
|
# specified in the environment
|
|
|
|
|
|
|
|
def self.default_spec_cache_dir
|
2020-04-23 06:16:06 -04:00
|
|
|
default_spec_cache_dir = File.join Gem.user_home, '.gem', 'specs'
|
|
|
|
|
|
|
|
unless File.exist?(default_spec_cache_dir)
|
|
|
|
default_spec_cache_dir = File.join Gem.data_home, 'gem', 'specs'
|
|
|
|
end
|
|
|
|
|
|
|
|
default_spec_cache_dir
|
2013-09-14 04:59:02 -04:00
|
|
|
end
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
2007-12-20 03:39:12 -05:00
|
|
|
# Default home directory path to be used if an alternate value is not
|
2008-09-25 06:13:50 -04:00
|
|
|
# specified in the environment
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
def self.default_dir
|
2018-11-21 05:20:47 -05:00
|
|
|
path = if defined? RUBY_FRAMEWORK_VERSION
|
2011-05-31 23:45:05 -04:00
|
|
|
[
|
2014-01-06 20:19:28 -05:00
|
|
|
File.dirname(RbConfig::CONFIG['sitedir']),
|
2011-05-31 23:45:05 -04:00
|
|
|
'Gems',
|
2014-01-06 20:19:28 -05:00
|
|
|
RbConfig::CONFIG['ruby_version']
|
2011-05-31 23:45:05 -04:00
|
|
|
]
|
|
|
|
else
|
|
|
|
[
|
2019-08-20 00:56:04 -04:00
|
|
|
RbConfig::CONFIG['rubylibprefix'],
|
2011-05-31 23:45:05 -04:00
|
|
|
'gems',
|
2014-01-06 20:19:28 -05:00
|
|
|
RbConfig::CONFIG['ruby_version']
|
2011-05-31 23:45:05 -04:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
@default_dir ||= File.join(*path)
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
|
|
|
|
2013-12-12 19:51:04 -05:00
|
|
|
##
|
|
|
|
# Returns binary extensions dir for specified RubyGems base dir or nil
|
|
|
|
# if such directory cannot be determined.
|
|
|
|
#
|
|
|
|
# By default, the binary extensions are located side by side with their
|
|
|
|
# Ruby counterparts, therefore nil is returned
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.default_ext_dir_for(base_dir)
|
2013-12-12 19:51:04 -05:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2012-04-17 20:04:12 -04:00
|
|
|
##
|
|
|
|
# Paths where RubyGems' .rb files and bin files are installed
|
|
|
|
|
|
|
|
def self.default_rubygems_dirs
|
|
|
|
nil # default to standard layout
|
|
|
|
end
|
|
|
|
|
2019-07-22 08:31:10 -04:00
|
|
|
##
|
|
|
|
# Path to specification files of default gems.
|
|
|
|
|
|
|
|
def self.default_specifications_dir
|
|
|
|
File.join(Gem.default_dir, "specifications", "default")
|
|
|
|
end
|
|
|
|
|
2020-04-23 06:16:06 -04:00
|
|
|
##
|
|
|
|
# Finds the user's home directory.
|
|
|
|
#--
|
|
|
|
# Some comments from the ruby-talk list regarding finding the home
|
|
|
|
# directory:
|
|
|
|
#
|
|
|
|
# I have HOME, USERPROFILE and HOMEDRIVE + HOMEPATH. Ruby seems
|
|
|
|
# to be depending on HOME in those code samples. I propose that
|
|
|
|
# it should fallback to USERPROFILE and HOMEDRIVE + HOMEPATH (at
|
|
|
|
# least on Win32).
|
|
|
|
#++
|
|
|
|
#--
|
|
|
|
#
|
|
|
|
#++
|
|
|
|
|
|
|
|
def self.find_home
|
|
|
|
Dir.home.dup
|
|
|
|
rescue
|
|
|
|
if Gem.win_platform?
|
|
|
|
File.expand_path File.join(ENV['HOMEDRIVE'] || ENV['SystemDrive'], '/')
|
|
|
|
else
|
|
|
|
File.expand_path "/"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private_class_method :find_home
|
|
|
|
|
|
|
|
##
|
|
|
|
# The home directory for the user.
|
|
|
|
|
|
|
|
def self.user_home
|
|
|
|
@user_home ||= find_home.tap(&Gem::UNTAINT)
|
|
|
|
end
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
|
|
|
# Path for gems in the user's home directory
|
|
|
|
|
|
|
|
def self.user_dir
|
2020-04-23 06:16:06 -04:00
|
|
|
gem_dir = File.join(Gem.user_home, ".gem")
|
|
|
|
gem_dir = File.join(Gem.data_home, "gem") unless File.exist?(gem_dir)
|
|
|
|
parts = [gem_dir, ruby_engine]
|
2014-01-06 20:19:28 -05:00
|
|
|
parts << RbConfig::CONFIG['ruby_version'] unless RbConfig::CONFIG['ruby_version'].empty?
|
2013-07-08 18:41:03 -04:00
|
|
|
File.join parts
|
2008-09-25 06:13:50 -04:00
|
|
|
end
|
|
|
|
|
2020-04-23 06:16:06 -04:00
|
|
|
##
|
|
|
|
# The path to standard location of the user's configuration directory.
|
|
|
|
|
|
|
|
def self.config_home
|
|
|
|
@config_home ||= (ENV["XDG_CONFIG_HOME"] || File.join(Gem.user_home, '.config'))
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Finds the user's config file
|
|
|
|
|
|
|
|
def self.find_config_file
|
|
|
|
gemrc = File.join Gem.user_home, '.gemrc'
|
|
|
|
if File.exist? gemrc
|
|
|
|
gemrc
|
|
|
|
else
|
|
|
|
File.join Gem.config_home, "gem", "gemrc"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# The path to standard location of the user's .gemrc file.
|
|
|
|
|
|
|
|
def self.config_file
|
|
|
|
@config_file ||= find_config_file.tap(&Gem::UNTAINT)
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# The path to standard location of the user's cache directory.
|
|
|
|
|
|
|
|
def self.cache_home
|
|
|
|
@cache_home ||= (ENV["XDG_CACHE_HOME"] || File.join(Gem.user_home, '.cache'))
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# The path to standard location of the user's data directory.
|
|
|
|
|
|
|
|
def self.data_home
|
|
|
|
@data_home ||= (ENV["XDG_DATA_HOME"] || File.join(Gem.user_home, '.local', 'share'))
|
|
|
|
end
|
|
|
|
|
2012-11-29 19:23:15 -05:00
|
|
|
##
|
|
|
|
# How String Gem paths should be split. Overridable for esoteric platforms.
|
|
|
|
|
|
|
|
def self.path_separator
|
|
|
|
File::PATH_SEPARATOR
|
|
|
|
end
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
|
|
|
# Default gem load path
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
def self.default_path
|
2014-09-13 23:30:02 -04:00
|
|
|
path = []
|
|
|
|
path << user_dir if user_home && File.exist?(user_home)
|
|
|
|
path << default_dir
|
|
|
|
path << vendor_dir if vendor_dir and File.directory? vendor_dir
|
|
|
|
path
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
|
|
|
# Deduce Ruby's --program-prefix and --program-suffix from its install name
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
def self.default_exec_format
|
2014-01-06 20:19:28 -05:00
|
|
|
exec_format = RbConfig::CONFIG['ruby_install_name'].sub('ruby', '%s') rescue '%s'
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
unless exec_format =~ /%s/
|
2009-06-09 17:38:59 -04:00
|
|
|
raise Gem::Exception,
|
|
|
|
"[BUG] invalid exec_format #{exec_format.inspect}, no %s"
|
|
|
|
end
|
|
|
|
|
|
|
|
exec_format
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
2007-12-20 03:39:12 -05:00
|
|
|
# The default directory for binaries
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
def self.default_bindir
|
2019-05-03 13:56:58 -04:00
|
|
|
if defined? RUBY_FRAMEWORK_VERSION # mac framework support
|
2008-03-31 18:40:06 -04:00
|
|
|
'/usr/bin'
|
|
|
|
else # generic install
|
2014-01-06 20:19:28 -05:00
|
|
|
RbConfig::CONFIG['bindir']
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
def self.ruby_engine
|
2019-08-04 08:39:55 -04:00
|
|
|
RUBY_ENGINE
|
2008-09-25 06:13:50 -04:00
|
|
|
end
|
2013-06-04 17:54:58 -04:00
|
|
|
|
|
|
|
##
|
|
|
|
# The default signing key path
|
|
|
|
|
|
|
|
def self.default_key_path
|
2020-04-23 06:16:06 -04:00
|
|
|
default_key_path = File.join Gem.user_home, ".gem", "gem-private_key.pem"
|
|
|
|
|
|
|
|
unless File.exist?(default_key_path)
|
|
|
|
default_key_path = File.join Gem.data_home, "gem", "gem-private_key.pem"
|
|
|
|
end
|
|
|
|
|
|
|
|
default_key_path
|
2013-06-04 17:54:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# The default signing certificate chain path
|
|
|
|
|
|
|
|
def self.default_cert_path
|
2020-04-23 06:16:06 -04:00
|
|
|
default_cert_path = File.join Gem.user_home, ".gem", "gem-public_cert.pem"
|
|
|
|
|
|
|
|
unless File.exist?(default_cert_path)
|
|
|
|
default_cert_path = File.join Gem.data_home, "gem", "gem-public_cert.pem"
|
|
|
|
end
|
|
|
|
|
|
|
|
default_cert_path
|
2013-06-04 17:54:58 -04:00
|
|
|
end
|
2013-09-14 04:59:02 -04:00
|
|
|
|
2013-12-16 15:18:29 -05:00
|
|
|
##
|
|
|
|
# Install extensions into lib as well as into the extension directory.
|
|
|
|
|
|
|
|
def self.install_extension_in_lib # :nodoc:
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
##
|
|
|
|
# Directory where vendor gems are installed.
|
|
|
|
|
|
|
|
def self.vendor_dir # :nodoc:
|
2018-11-21 05:20:47 -05:00
|
|
|
if vendor_dir = ENV['GEM_VENDOR']
|
2014-09-13 23:30:02 -04:00
|
|
|
return vendor_dir.dup
|
|
|
|
end
|
|
|
|
|
|
|
|
return nil unless RbConfig::CONFIG.key? 'vendordir'
|
|
|
|
|
|
|
|
File.join RbConfig::CONFIG['vendordir'], 'gems',
|
|
|
|
RbConfig::CONFIG['ruby_version']
|
|
|
|
end
|
|
|
|
|
2016-06-24 00:13:11 -04:00
|
|
|
##
|
2018-05-30 09:01:35 -04:00
|
|
|
# Default options for gem commands for Ruby packagers.
|
|
|
|
#
|
|
|
|
# The options here should be structured as an array of string "gem"
|
|
|
|
# command names as keys and a string of the default options as values.
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
#
|
|
|
|
# def self.operating_system_defaults
|
|
|
|
# {
|
|
|
|
# 'install' => '--no-rdoc --no-ri --env-shebang',
|
|
|
|
# 'update' => '--no-rdoc --no-ri --env-shebang'
|
|
|
|
# }
|
|
|
|
# end
|
|
|
|
|
|
|
|
def self.operating_system_defaults
|
|
|
|
{}
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Default options for gem commands for Ruby implementers.
|
2016-06-24 00:13:11 -04:00
|
|
|
#
|
|
|
|
# The options here should be structured as an array of string "gem"
|
|
|
|
# command names as keys and a string of the default options as values.
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
#
|
|
|
|
# def self.platform_defaults
|
|
|
|
# {
|
|
|
|
# 'install' => '--no-rdoc --no-ri --env-shebang',
|
|
|
|
# 'update' => '--no-rdoc --no-ri --env-shebang'
|
|
|
|
# }
|
|
|
|
# end
|
|
|
|
|
|
|
|
def self.platform_defaults
|
|
|
|
{}
|
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|