2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2013-02-07 00:56:53 -05:00
|
|
|
#--
|
2007-11-10 02:48:56 -05:00
|
|
|
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
|
|
|
|
# All rights reserved.
|
|
|
|
# See LICENSE.txt for permissions.
|
2013-02-07 00:56:53 -05:00
|
|
|
#++
|
2013-02-05 15:52:28 -05:00
|
|
|
|
|
|
|
require 'rbconfig'
|
|
|
|
|
|
|
|
module Gem
|
2021-12-26 19:41:55 -05:00
|
|
|
VERSION = "3.4.0.dev".freeze
|
2013-02-05 15:52:28 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# Must be first since it unloads the prelude from 1.9.2
|
2019-04-22 07:56:16 -04:00
|
|
|
require_relative 'rubygems/compatibility'
|
2013-02-05 15:52:28 -05:00
|
|
|
|
2019-04-22 07:56:16 -04:00
|
|
|
require_relative 'rubygems/defaults'
|
|
|
|
require_relative 'rubygems/deprecate'
|
|
|
|
require_relative 'rubygems/errors'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
2009-06-09 17:38:59 -04:00
|
|
|
# RubyGems is the Ruby standard for publishing and managing third party
|
|
|
|
# libraries.
|
|
|
|
#
|
|
|
|
# For user documentation, see:
|
|
|
|
#
|
|
|
|
# * <tt>gem help</tt> and <tt>gem help [command]</tt>
|
2020-01-31 21:14:04 -05:00
|
|
|
# * {RubyGems User Guide}[https://guides.rubygems.org/]
|
|
|
|
# * {Frequently Asked Questions}[https://guides.rubygems.org/faqs]
|
2009-06-09 17:38:59 -04:00
|
|
|
#
|
|
|
|
# For gem developer documentation see:
|
|
|
|
#
|
2020-01-31 21:14:04 -05:00
|
|
|
# * {Creating Gems}[https://guides.rubygems.org/make-your-own-gem]
|
2009-06-09 17:38:59 -04:00
|
|
|
# * Gem::Specification
|
2010-02-21 21:52:35 -05:00
|
|
|
# * Gem::Version for version dependency notes
|
2009-06-09 17:38:59 -04:00
|
|
|
#
|
|
|
|
# Further RubyGems documentation can be found at:
|
|
|
|
#
|
2020-01-31 21:14:04 -05:00
|
|
|
# * {RubyGems Guides}[https://guides.rubygems.org]
|
|
|
|
# * {RubyGems API}[https://www.rubydoc.info/github/rubygems/rubygems] (also available from
|
2009-06-09 17:38:59 -04:00
|
|
|
# <tt>gem server</tt>)
|
|
|
|
#
|
|
|
|
# == RubyGems Plugins
|
|
|
|
#
|
2020-01-31 21:14:04 -05:00
|
|
|
# RubyGems will load plugins in the latest version of each installed gem or
|
2010-02-21 21:52:35 -05:00
|
|
|
# $LOAD_PATH. Plugins must be named 'rubygems_plugin' (.rb, .so, etc) and
|
2020-01-31 21:14:04 -05:00
|
|
|
# placed at the root of your gem's #require_path. Plugins are installed at a
|
|
|
|
# special location and loaded on boot.
|
2009-06-09 17:38:59 -04:00
|
|
|
#
|
2017-10-07 21:32:18 -04:00
|
|
|
# For an example plugin, see the {Graph gem}[https://github.com/seattlerb/graph]
|
|
|
|
# which adds a `gem graph` command.
|
2009-06-09 17:38:59 -04:00
|
|
|
#
|
|
|
|
# == RubyGems Defaults, Packaging
|
|
|
|
#
|
2017-10-07 21:32:18 -04:00
|
|
|
# RubyGems defaults are stored in lib/rubygems/defaults.rb. If you're packaging
|
2009-06-09 17:38:59 -04:00
|
|
|
# RubyGems or implementing Ruby you can change RubyGems' defaults.
|
|
|
|
#
|
2014-09-13 23:30:02 -04:00
|
|
|
# For RubyGems packagers, provide lib/rubygems/defaults/operating_system.rb
|
|
|
|
# and override any defaults from lib/rubygems/defaults.rb.
|
2009-06-09 17:38:59 -04:00
|
|
|
#
|
2012-11-29 01:52:18 -05:00
|
|
|
# For Ruby implementers, provide lib/rubygems/defaults/#{RUBY_ENGINE}.rb and
|
|
|
|
# override any defaults from lib/rubygems/defaults.rb.
|
2009-06-09 17:38:59 -04:00
|
|
|
#
|
|
|
|
# If you need RubyGems to perform extra work on install or uninstall, your
|
2017-10-07 21:32:18 -04:00
|
|
|
# defaults override file can set pre/post install and uninstall hooks.
|
2009-06-09 17:38:59 -04:00
|
|
|
# See Gem::pre_install, Gem::pre_uninstall, Gem::post_install,
|
|
|
|
# Gem::post_uninstall.
|
|
|
|
#
|
|
|
|
# == Bugs
|
|
|
|
#
|
|
|
|
# You can submit bugs to the
|
2012-11-29 01:52:18 -05:00
|
|
|
# {RubyGems bug tracker}[https://github.com/rubygems/rubygems/issues]
|
|
|
|
# on GitHub
|
2009-06-09 17:38:59 -04:00
|
|
|
#
|
|
|
|
# == Credits
|
|
|
|
#
|
|
|
|
# RubyGems is currently maintained by Eric Hodel.
|
|
|
|
#
|
|
|
|
# RubyGems was originally developed at RubyConf 2003 by:
|
|
|
|
#
|
2010-02-21 21:52:35 -05:00
|
|
|
# * Rich Kilmer -- rich(at)infoether.com
|
|
|
|
# * Chad Fowler -- chad(at)chadfowler.com
|
|
|
|
# * David Black -- dblack(at)wobblini.net
|
2009-06-09 17:38:59 -04:00
|
|
|
# * Paul Brannan -- paul(at)atdesk.com
|
2014-09-13 23:30:02 -04:00
|
|
|
# * Jim Weirich -- jim(at)weirichhouse.org
|
2009-06-09 17:38:59 -04:00
|
|
|
#
|
|
|
|
# Contributors:
|
|
|
|
#
|
2010-02-21 21:52:35 -05:00
|
|
|
# * Gavin Sinclair -- gsinclair(at)soyabean.com.au
|
|
|
|
# * George Marrows -- george.marrows(at)ntlworld.com
|
|
|
|
# * Dick Davies -- rasputnik(at)hellooperator.net
|
2009-06-09 17:38:59 -04:00
|
|
|
# * Mauricio Fernandez -- batsman.geo(at)yahoo.com
|
2010-02-21 21:52:35 -05:00
|
|
|
# * Simon Strandgaard -- neoneye(at)adslhome.dk
|
|
|
|
# * Dave Glasser -- glasser(at)mit.edu
|
|
|
|
# * Paul Duncan -- pabs(at)pablotron.org
|
|
|
|
# * Ville Aine -- vaine(at)cs.helsinki.fi
|
|
|
|
# * Eric Hodel -- drbrain(at)segment7.net
|
|
|
|
# * Daniel Berger -- djberg96(at)gmail.com
|
|
|
|
# * Phil Hagelberg -- technomancy(at)gmail.com
|
|
|
|
# * Ryan Davis -- ryand-ruby(at)zenspider.com
|
2012-11-29 01:52:18 -05:00
|
|
|
# * Evan Phoenix -- evan(at)fallingsnow.net
|
|
|
|
# * Steve Klabnik -- steve(at)steveklabnik.com
|
2009-06-09 17:38:59 -04:00
|
|
|
#
|
|
|
|
# (If your name is missing, PLEASE let us know!)
|
|
|
|
#
|
2017-10-07 21:32:18 -04:00
|
|
|
# == License
|
|
|
|
#
|
2013-02-05 15:52:28 -05:00
|
|
|
# See {LICENSE.txt}[rdoc-ref:lib/rubygems/LICENSE.txt] for permissions.
|
|
|
|
#
|
2009-06-09 17:38:59 -04:00
|
|
|
# Thanks!
|
|
|
|
#
|
|
|
|
# -The RubyGems Team
|
2013-02-07 00:56:53 -05:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
module Gem
|
2011-03-01 04:41:32 -05:00
|
|
|
RUBYGEMS_DIR = File.dirname File.expand_path(__FILE__)
|
|
|
|
|
2019-11-11 01:03:57 -05:00
|
|
|
# Taint support is deprecated in Ruby 2.7.
|
|
|
|
# This allows switching ".untaint" to ".tap(&Gem::UNTAINT)",
|
|
|
|
# to avoid deprecation warnings in Ruby 2.7.
|
|
|
|
UNTAINT = RUBY_VERSION < '2.7' ? :untaint.to_sym : proc{}
|
|
|
|
|
2020-12-08 02:33:39 -05:00
|
|
|
# When https://bugs.ruby-lang.org/issues/17259 is available, there is no need to override Kernel#warn
|
|
|
|
KERNEL_WARN_IGNORES_INTERNAL_ENTRIES = RUBY_ENGINE == "truffleruby" ||
|
|
|
|
(RUBY_ENGINE == "ruby" && RUBY_VERSION >= '3.0')
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
2013-09-14 04:59:02 -04:00
|
|
|
# An Array of Regexps that match windows Ruby platforms.
|
2008-03-31 18:40:06 -04:00
|
|
|
|
|
|
|
WIN_PATTERNS = [
|
|
|
|
/bccwin/i,
|
|
|
|
/cygwin/i,
|
|
|
|
/djgpp/i,
|
|
|
|
/mingw/i,
|
|
|
|
/mswin/i,
|
|
|
|
/wince/i,
|
2018-10-21 20:27:02 -04:00
|
|
|
].freeze
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2012-12-22 19:35:09 -05:00
|
|
|
GEM_DEP_FILES = %w[
|
|
|
|
gem.deps.rb
|
2017-10-07 21:32:18 -04:00
|
|
|
gems.rb
|
2012-12-22 19:35:09 -05:00
|
|
|
Gemfile
|
|
|
|
Isolate
|
2018-10-21 20:27:02 -04:00
|
|
|
].freeze
|
2012-12-22 19:35:09 -05:00
|
|
|
|
|
|
|
##
|
|
|
|
# Subdirectories in a gem repository
|
|
|
|
|
|
|
|
REPOSITORY_SUBDIRECTORIES = %w[
|
|
|
|
build_info
|
|
|
|
cache
|
|
|
|
doc
|
2013-10-15 20:14:16 -04:00
|
|
|
extensions
|
2012-12-22 19:35:09 -05:00
|
|
|
gems
|
2020-01-31 21:14:04 -05:00
|
|
|
plugins
|
2012-12-22 19:35:09 -05:00
|
|
|
specifications
|
2018-10-21 20:27:02 -04:00
|
|
|
].freeze
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
##
|
|
|
|
# Subdirectories in a gem repository for default gems
|
|
|
|
|
|
|
|
REPOSITORY_DEFAULT_GEM_SUBDIRECTORIES = %w[
|
|
|
|
gems
|
|
|
|
specifications/default
|
2018-10-21 20:27:02 -04:00
|
|
|
].freeze
|
2013-09-14 04:59:02 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
@@win_platform = nil
|
|
|
|
|
|
|
|
@configuration = nil
|
2015-07-01 17:50:14 -04:00
|
|
|
@gemdeps = nil
|
2007-11-10 02:48:56 -05:00
|
|
|
@loaded_specs = {}
|
2021-07-07 01:07:29 -04:00
|
|
|
LOADED_SPECS_MUTEX = Thread::Mutex.new
|
2012-11-29 01:52:18 -05:00
|
|
|
@path_to_default_spec_map = {}
|
2008-04-11 16:57:02 -04:00
|
|
|
@platforms = []
|
2007-11-10 02:48:56 -05:00
|
|
|
@ruby = nil
|
2013-10-15 20:14:16 -04:00
|
|
|
@ruby_api_version = nil
|
2011-05-31 23:45:05 -04:00
|
|
|
@sources = nil
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2011-01-19 16:23:04 -05:00
|
|
|
@post_build_hooks ||= []
|
2008-10-25 18:58:43 -04:00
|
|
|
@post_install_hooks ||= []
|
|
|
|
@post_uninstall_hooks ||= []
|
|
|
|
@pre_uninstall_hooks ||= []
|
|
|
|
@pre_install_hooks ||= []
|
2011-05-31 23:45:05 -04:00
|
|
|
@pre_reset_hooks ||= []
|
|
|
|
@post_reset_hooks ||= []
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2020-03-24 02:39:24 -04:00
|
|
|
@default_source_date_epoch = nil
|
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
##
|
|
|
|
# Try to activate a gem containing +path+. Returns true if
|
|
|
|
# activation succeeded or wasn't needed because it was already
|
|
|
|
# activated. Returns false if it can't find the path in a gem.
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.try_activate(path)
|
2011-03-01 04:41:32 -05:00
|
|
|
# finds the _latest_ version... regardless of loaded specs and their deps
|
2012-11-29 01:52:18 -05:00
|
|
|
# if another gem had a requirement that would mean we shouldn't
|
2013-11-30 18:27:52 -05:00
|
|
|
# activate the latest version, then either it would already be activated
|
|
|
|
# or if it was ambiguous (and thus unresolved) the code in our custom
|
2012-11-29 01:52:18 -05:00
|
|
|
# require will try to activate the more specific version.
|
2011-03-01 04:41:32 -05:00
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
spec = Gem::Specification.find_by_path path
|
|
|
|
return false unless spec
|
|
|
|
return true if spec.activated?
|
2011-01-18 19:08:49 -05:00
|
|
|
|
2011-03-01 04:41:32 -05:00
|
|
|
begin
|
2011-05-31 23:45:05 -04:00
|
|
|
spec.activate
|
2016-03-03 19:29:40 -05:00
|
|
|
rescue Gem::LoadError => e # this could fail due to gem dep collisions, go lax
|
|
|
|
spec_by_name = Gem::Specification.find_by_name(spec.name)
|
|
|
|
if spec_by_name.nil?
|
|
|
|
raise e
|
|
|
|
else
|
|
|
|
spec_by_name.activate
|
|
|
|
end
|
2011-03-01 04:41:32 -05:00
|
|
|
end
|
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def self.needs
|
|
|
|
rs = Gem::RequestSet.new
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
yield rs
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
finish_resolve rs
|
2011-03-01 04:41:32 -05:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def self.finish_resolve(request_set=Gem::RequestSet.new)
|
|
|
|
request_set.import Gem::Specification.unresolved_deps.values
|
2017-05-01 07:40:46 -04:00
|
|
|
request_set.import Gem.loaded_specs.values.map {|s| Gem::Dependency.new(s.name, s.version) }
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
request_set.resolve_current.each do |s|
|
|
|
|
s.full_spec.activate
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Find the full path to the executable for gem +name+. If the +exec_name+
|
2018-05-30 09:01:35 -04:00
|
|
|
# is not given, an exception will be raised, otherwise the
|
2011-01-18 19:08:49 -05:00
|
|
|
# specified executable's path is returned. +requirements+ allows
|
2010-04-22 04:24:42 -04:00
|
|
|
# you to specify specific gem versions.
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
def self.bin_path(name, exec_name = nil, *requirements)
|
|
|
|
requirements = Gem::Requirement.default if
|
|
|
|
requirements.empty?
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2016-03-27 22:26:39 -04:00
|
|
|
find_spec_for_exe(name, exec_name, requirements).bin_file exec_name
|
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.find_spec_for_exe(name, exec_name, requirements)
|
2019-04-26 07:26:21 -04:00
|
|
|
raise ArgumentError, "you must supply exec_name" unless exec_name
|
|
|
|
|
2014-12-06 19:53:01 -05:00
|
|
|
dep = Gem::Dependency.new name, requirements
|
|
|
|
|
|
|
|
loaded = Gem.loaded_specs[name]
|
|
|
|
|
2016-03-27 22:26:39 -04:00
|
|
|
return loaded if loaded && dep.matches_spec?(loaded)
|
2014-12-06 19:53:01 -05:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
specs = dep.matching_specs(true)
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2019-02-14 07:59:03 -05:00
|
|
|
specs = specs.find_all do |spec|
|
2011-05-31 23:45:05 -04:00
|
|
|
spec.executables.include? exec_name
|
2019-02-14 07:59:03 -05:00
|
|
|
end if exec_name
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2016-03-27 22:30:28 -04:00
|
|
|
unless spec = specs.first
|
2017-10-07 21:32:18 -04:00
|
|
|
msg = "can't find gem #{dep} with executable #{exec_name}"
|
2011-01-18 19:08:49 -05:00
|
|
|
raise Gem::GemNotFoundException, msg
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
|
2016-03-27 22:26:39 -04:00
|
|
|
spec
|
|
|
|
end
|
|
|
|
private_class_method :find_spec_for_exe
|
|
|
|
|
|
|
|
##
|
|
|
|
# Find the full path to the executable for gem +name+. If the +exec_name+
|
2018-05-30 09:01:35 -04:00
|
|
|
# is not given, an exception will be raised, otherwise the
|
2016-03-27 22:26:39 -04:00
|
|
|
# specified executable's path is returned. +requirements+ allows
|
|
|
|
# you to specify specific gem versions.
|
|
|
|
#
|
|
|
|
# A side effect of this method is that it will activate the gem that
|
|
|
|
# contains the executable.
|
|
|
|
#
|
|
|
|
# This method should *only* be used in bin stub files.
|
|
|
|
|
2019-04-26 07:26:21 -04:00
|
|
|
def self.activate_bin_path(name, exec_name = nil, *requirements) # :nodoc:
|
|
|
|
spec = find_spec_for_exe name, exec_name, requirements
|
2017-10-07 21:32:18 -04:00
|
|
|
Gem::LOADED_SPECS_MUTEX.synchronize do
|
|
|
|
spec.activate
|
|
|
|
finish_resolve
|
|
|
|
end
|
2011-05-31 23:45:05 -04:00
|
|
|
spec.bin_file exec_name
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
|
|
|
# The mode needed to read a file as straight binary.
|
|
|
|
|
|
|
|
def self.binary_mode
|
2009-10-04 01:01:12 -04:00
|
|
|
'rb'
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# The path where gem executables are to be installed.
|
|
|
|
|
|
|
|
def self.bindir(install_dir=Gem.dir)
|
2011-05-31 23:45:05 -04:00
|
|
|
return File.join install_dir, 'bin' unless
|
|
|
|
install_dir.to_s == Gem.default_dir.to_s
|
2008-03-31 18:40:06 -04:00
|
|
|
Gem.default_bindir
|
|
|
|
end
|
|
|
|
|
2020-03-24 02:39:24 -04:00
|
|
|
##
|
|
|
|
# The path were rubygems plugins are to be installed.
|
|
|
|
|
|
|
|
def self.plugindir(install_dir=Gem.dir)
|
|
|
|
File.join install_dir, 'plugins'
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
2007-11-10 02:48:56 -05:00
|
|
|
# Reset the +dir+ and +path+ values. The next time +dir+ or +path+
|
|
|
|
# is requested, the values will be calculated from scratch. This is
|
|
|
|
# mainly used by the unit tests to provide test isolation.
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def self.clear_paths
|
2011-05-31 23:45:05 -04:00
|
|
|
@paths = nil
|
|
|
|
@user_home = nil
|
|
|
|
Gem::Specification.reset
|
2013-09-09 20:52:14 -04:00
|
|
|
Gem::Security.reset if defined?(Gem::Security)
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2008-03-31 18:40:06 -04:00
|
|
|
# The standard configuration object for gems.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def self.configuration
|
2008-09-25 06:13:50 -04:00
|
|
|
@configuration ||= Gem::ConfigFile.new []
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
|
|
|
# Use the given configuration object (which implements the ConfigFile
|
|
|
|
# protocol) as the standard configuration object.
|
|
|
|
|
|
|
|
def self.configuration=(config)
|
|
|
|
@configuration = config
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2014-09-13 23:30:02 -04:00
|
|
|
# The path to the data directory specified by the gem name. If the
|
2008-03-31 18:40:06 -04:00
|
|
|
# package is not available as a gem, return nil.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def self.datadir(gem_name)
|
|
|
|
spec = @loaded_specs[gem_name]
|
|
|
|
return nil if spec.nil?
|
2015-11-11 23:50:06 -05:00
|
|
|
spec.datadir
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
##
|
|
|
|
# A Zlib::Deflate.deflate wrapper
|
|
|
|
|
|
|
|
def self.deflate(data)
|
2008-10-25 18:58:43 -04:00
|
|
|
require 'zlib'
|
2008-06-17 18:04:18 -04:00
|
|
|
Zlib::Deflate.deflate data
|
|
|
|
end
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
# Retrieve the PathSupport object that RubyGems uses to
|
|
|
|
# lookup files.
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
def self.paths
|
2016-03-03 19:29:40 -05:00
|
|
|
@paths ||= Gem::PathSupport.new(ENV)
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
# Initialize the filesystem paths to use from +env+.
|
|
|
|
# +env+ is a hash-like object (typically ENV) that
|
|
|
|
# is queried for 'GEM_HOME', 'GEM_PATH', and 'GEM_SPEC_CACHE'
|
2016-03-03 19:29:40 -05:00
|
|
|
# Keys for the +env+ hash should be Strings, and values of the hash should
|
|
|
|
# be Strings or +nil+.
|
2013-11-18 19:34:13 -05:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
def self.paths=(env)
|
|
|
|
clear_paths
|
2016-03-03 19:29:40 -05:00
|
|
|
target = {}
|
|
|
|
env.each_pair do |k,v|
|
|
|
|
case k
|
|
|
|
when 'GEM_HOME', 'GEM_PATH', 'GEM_SPEC_CACHE'
|
|
|
|
case v
|
|
|
|
when nil, String
|
|
|
|
target[k] = v
|
|
|
|
when Array
|
|
|
|
unless Gem::Deprecate.skip
|
2020-04-20 12:32:51 -04:00
|
|
|
warn <<-EOWARN
|
2016-04-06 02:01:14 -04:00
|
|
|
Array values in the parameter to `Gem.paths=` are deprecated.
|
|
|
|
Please use a String or nil.
|
|
|
|
An Array (#{env.inspect}) was passed in from #{caller[3]}
|
2020-04-20 12:32:51 -04:00
|
|
|
EOWARN
|
2016-03-03 19:29:40 -05:00
|
|
|
end
|
|
|
|
target[k] = v.join File::PATH_SEPARATOR
|
|
|
|
end
|
|
|
|
else
|
|
|
|
target[k] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@paths = Gem::PathSupport.new ENV.to_hash.merge(target)
|
2013-11-18 19:34:13 -05:00
|
|
|
Gem::Specification.dirs = @paths.path
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
##
|
2008-03-31 18:40:06 -04:00
|
|
|
# The path where gems are to be installed.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def self.dir
|
2011-05-31 23:45:05 -04:00
|
|
|
paths.home
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.path
|
|
|
|
paths.path
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
def self.spec_cache_dir
|
|
|
|
paths.spec_cache_dir
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
2013-03-05 18:02:00 -05:00
|
|
|
# Quietly ensure the Gem directory +dir+ contains all the proper
|
2008-03-31 18:40:06 -04:00
|
|
|
# subdirectories. If we can't create a directory due to a permission
|
|
|
|
# problem, then we will silently continue.
|
2013-03-05 18:02:00 -05:00
|
|
|
#
|
|
|
|
# If +mode+ is given, missing directories are created with this mode.
|
|
|
|
#
|
|
|
|
# World-writable directories will never be created.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.ensure_gem_subdirectories(dir = Gem.dir, mode = nil)
|
2013-09-14 04:59:02 -04:00
|
|
|
ensure_subdirectories(dir, mode, REPOSITORY_SUBDIRECTORIES)
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Quietly ensure the Gem directory +dir+ contains all the proper
|
|
|
|
# subdirectories for handling default gems. If we can't create a
|
|
|
|
# directory due to a permission problem, then we will silently continue.
|
|
|
|
#
|
|
|
|
# If +mode+ is given, missing directories are created with this mode.
|
|
|
|
#
|
|
|
|
# World-writable directories will never be created.
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.ensure_default_gem_subdirectories(dir = Gem.dir, mode = nil)
|
2013-09-14 04:59:02 -04:00
|
|
|
ensure_subdirectories(dir, mode, REPOSITORY_DEFAULT_GEM_SUBDIRECTORIES)
|
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.ensure_subdirectories(dir, mode, subdirs) # :nodoc:
|
2012-04-17 17:17:56 -04:00
|
|
|
old_umask = File.umask
|
2012-04-17 20:04:12 -04:00
|
|
|
File.umask old_umask | 002
|
|
|
|
|
|
|
|
require 'fileutils'
|
2012-04-17 17:17:56 -04:00
|
|
|
|
2013-03-05 18:02:00 -05:00
|
|
|
options = {}
|
|
|
|
|
|
|
|
options[:mode] = mode if mode
|
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
subdirs.each do |name|
|
2011-05-31 23:45:05 -04:00
|
|
|
subdir = File.join dir, name
|
|
|
|
next if File.exist? subdir
|
2020-03-24 02:39:24 -04:00
|
|
|
begin
|
|
|
|
FileUtils.mkdir_p subdir, **options
|
2021-02-01 10:17:16 -05:00
|
|
|
rescue SystemCallError
|
2020-03-24 02:39:24 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2011-08-04 21:00:01 -04:00
|
|
|
ensure
|
|
|
|
File.umask old_umask
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2013-10-17 17:03:49 -04:00
|
|
|
##
|
|
|
|
# The extension API version of ruby. This includes the static vs non-static
|
|
|
|
# distinction as extensions cannot be shared between the two.
|
|
|
|
|
|
|
|
def self.extension_api_version # :nodoc:
|
2018-11-21 05:20:47 -05:00
|
|
|
if 'no' == RbConfig::CONFIG['ENABLE_SHARED']
|
2013-10-17 17:03:49 -04:00
|
|
|
"#{ruby_api_version}-static"
|
|
|
|
else
|
|
|
|
ruby_api_version
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
2011-01-18 19:08:49 -05:00
|
|
|
# Returns a list of paths matching +glob+ that can be used by a gem to pick
|
2008-09-25 06:13:50 -04:00
|
|
|
# up features from other gems. For example:
|
|
|
|
#
|
|
|
|
# Gem.find_files('rdoc/discover').each do |path| load path end
|
|
|
|
#
|
2011-01-18 19:08:49 -05:00
|
|
|
# if +check_load_path+ is true (the default), then find_files also searches
|
|
|
|
# $LOAD_PATH for files as well as gems.
|
2009-06-09 17:38:59 -04:00
|
|
|
#
|
|
|
|
# Note that find_files will return all files even if they are from different
|
2013-09-14 04:59:02 -04:00
|
|
|
# versions of the same gem. See also find_latest_files
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
def self.find_files(glob, check_load_path=true)
|
|
|
|
files = []
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
files = find_files_from_load_path glob if check_load_path
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2016-03-03 19:29:40 -05:00
|
|
|
gem_specifications = @gemdeps ? Gem.loaded_specs.values : Gem::Specification.stubs
|
|
|
|
|
2020-06-10 13:46:05 -04:00
|
|
|
files.concat gem_specifications.map {|spec|
|
2011-05-31 23:45:05 -04:00
|
|
|
spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}")
|
|
|
|
}.flatten
|
2011-01-18 19:08:49 -05:00
|
|
|
|
|
|
|
# $LOAD_PATH might contain duplicate entries or reference
|
|
|
|
# the spec dirs directly, so we prune.
|
|
|
|
files.uniq! if check_load_path
|
|
|
|
|
|
|
|
return files
|
2008-09-25 06:13:50 -04:00
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.find_files_from_load_path(glob) # :nodoc:
|
2018-08-27 06:05:04 -04:00
|
|
|
glob_with_suffixes = "#{glob}#{Gem.suffix_pattern}"
|
2019-02-14 07:59:03 -05:00
|
|
|
$LOAD_PATH.map do |load_path|
|
2018-08-27 06:05:04 -04:00
|
|
|
Gem::Util.glob_files_in_dir(glob_with_suffixes, load_path)
|
2020-06-10 13:46:05 -04:00
|
|
|
end.flatten.select {|file| File.file? file.tap(&Gem::UNTAINT) }
|
2013-09-14 04:59:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Returns a list of paths matching +glob+ from the latest gems that can be
|
|
|
|
# used by a gem to pick up features from other gems. For example:
|
|
|
|
#
|
|
|
|
# Gem.find_latest_files('rdoc/discover').each do |path| load path end
|
|
|
|
#
|
|
|
|
# if +check_load_path+ is true (the default), then find_latest_files also
|
|
|
|
# searches $LOAD_PATH for files as well as gems.
|
|
|
|
#
|
|
|
|
# Unlike find_files, find_latest_files will return only files from the
|
|
|
|
# latest version of a gem.
|
|
|
|
|
|
|
|
def self.find_latest_files(glob, check_load_path=true)
|
|
|
|
files = []
|
|
|
|
|
|
|
|
files = find_files_from_load_path glob if check_load_path
|
|
|
|
|
2020-06-10 13:46:05 -04:00
|
|
|
files.concat Gem::Specification.latest_specs(true).map {|spec|
|
2013-09-14 04:59:02 -04:00
|
|
|
spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}")
|
|
|
|
}.flatten
|
|
|
|
|
|
|
|
# $LOAD_PATH might contain duplicate entries or reference
|
|
|
|
# the spec dirs directly, so we prune.
|
|
|
|
files.uniq! if check_load_path
|
|
|
|
|
|
|
|
return files
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
##
|
|
|
|
# Top level install helper method. Allows you to install gems interactively:
|
|
|
|
#
|
|
|
|
# % irb
|
|
|
|
# >> Gem.install "minitest"
|
2020-03-27 05:26:27 -04:00
|
|
|
# Fetching: minitest-5.14.0.gem (100%)
|
2012-11-29 01:52:18 -05:00
|
|
|
# => [#<Gem::Specification:0x1013b4528 @name="minitest", ...>]
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.install(name, version = Gem::Requirement.default, *options)
|
2019-04-22 07:56:16 -04:00
|
|
|
require_relative "rubygems/dependency_installer"
|
2014-09-13 23:30:02 -04:00
|
|
|
inst = Gem::DependencyInstaller.new(*options)
|
2012-11-29 01:52:18 -05:00
|
|
|
inst.install name, version
|
|
|
|
inst.installed_gems
|
|
|
|
end
|
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
##
|
|
|
|
# Get the default RubyGems API host. This is normally
|
|
|
|
# <tt>https://rubygems.org</tt>.
|
|
|
|
|
|
|
|
def self.host
|
2012-11-29 01:52:18 -05:00
|
|
|
@host ||= Gem::DEFAULT_HOST
|
2011-01-18 19:08:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
## Set the default RubyGems API host.
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.host=(host)
|
2011-01-18 19:08:49 -05:00
|
|
|
@host = host
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
2013-12-21 20:16:22 -05:00
|
|
|
# The index to insert activated gem paths into the $LOAD_PATH. The activated
|
|
|
|
# gem's paths are inserted before site lib directory by default.
|
2008-03-31 18:40:06 -04:00
|
|
|
|
|
|
|
def self.load_path_insert_index
|
2015-07-02 01:15:53 -04:00
|
|
|
$LOAD_PATH.each_with_index do |path, i|
|
|
|
|
return i if path.instance_variable_defined?(:@gem_prelude_index)
|
|
|
|
end
|
|
|
|
|
2014-01-06 20:19:28 -05:00
|
|
|
index = $LOAD_PATH.index RbConfig::CONFIG['sitelibdir']
|
2011-01-18 19:08:49 -05:00
|
|
|
|
2020-05-19 08:08:19 -04:00
|
|
|
index || 0
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2020-05-19 08:00:00 -04:00
|
|
|
##
|
|
|
|
# The number of paths in the `$LOAD_PATH` from activated gems. Used to
|
|
|
|
# prioritize `-I` and `ENV['RUBYLIB`]` entries during `require`.
|
|
|
|
|
|
|
|
def self.activated_gem_paths
|
|
|
|
@activated_gem_paths ||= 0
|
|
|
|
end
|
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
##
|
|
|
|
# Add a list of paths to the $LOAD_PATH at the proper place.
|
|
|
|
|
|
|
|
def self.add_to_load_path(*paths)
|
2020-05-19 08:00:00 -04:00
|
|
|
@activated_gem_paths = activated_gem_paths + paths.size
|
|
|
|
|
2020-05-19 08:08:19 -04:00
|
|
|
# gem directories must come after -I and ENV['RUBYLIB']
|
|
|
|
$LOAD_PATH.insert(Gem.load_path_insert_index, *paths)
|
2019-06-01 05:45:11 -04:00
|
|
|
end
|
|
|
|
|
2012-04-17 20:04:12 -04:00
|
|
|
@yaml_loaded = false
|
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
##
|
|
|
|
# Loads YAML, preferring Psych
|
|
|
|
|
|
|
|
def self.load_yaml
|
2012-04-17 20:04:12 -04:00
|
|
|
return if @yaml_loaded
|
2012-04-17 16:50:00 -04:00
|
|
|
|
2022-01-18 23:28:23 -05:00
|
|
|
require 'psych'
|
|
|
|
require_relative 'rubygems/psych_additions'
|
|
|
|
require_relative 'rubygems/psych_tree'
|
2012-04-17 20:04:12 -04:00
|
|
|
|
2019-04-22 07:56:16 -04:00
|
|
|
require_relative 'rubygems/safe_yaml'
|
2012-04-17 20:04:12 -04:00
|
|
|
|
|
|
|
@yaml_loaded = true
|
2010-07-07 11:40:52 -04:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
|
|
|
# The file name and line number of the caller of the caller of this method.
|
2017-10-07 21:32:18 -04:00
|
|
|
#
|
|
|
|
# +depth+ is how many layers up the call stack it should go.
|
|
|
|
#
|
|
|
|
# e.g.,
|
|
|
|
#
|
|
|
|
# def a; Gem.location_of_caller; end
|
|
|
|
# a #=> ["x.rb", 2] # (it'll vary depending on file name and line number)
|
|
|
|
#
|
|
|
|
# def b; c; end
|
|
|
|
# def c; Gem.location_of_caller(2); end
|
|
|
|
# b #=> ["x.rb", 6] # (it'll vary depending on file name and line number)
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2017-10-07 21:32:18 -04:00
|
|
|
def self.location_of_caller(depth = 1)
|
|
|
|
caller[depth] =~ /(.*?):(\d+).*?$/i
|
2008-10-25 18:58:43 -04:00
|
|
|
file = $1
|
|
|
|
lineno = $2.to_i
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
[file, lineno]
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
|
|
|
# The version of the Marshal format for your Ruby.
|
2008-02-10 03:00:19 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def self.marshal_version
|
|
|
|
"#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}"
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
2008-04-11 16:57:02 -04:00
|
|
|
# Set array of platforms this RubyGems supports (primarily for testing).
|
|
|
|
|
|
|
|
def self.platforms=(platforms)
|
|
|
|
@platforms = platforms
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-04-11 16:57:02 -04:00
|
|
|
##
|
|
|
|
# Array of platforms this RubyGems supports.
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def self.platforms
|
2008-04-11 16:57:02 -04:00
|
|
|
@platforms ||= []
|
|
|
|
if @platforms.empty?
|
|
|
|
@platforms = [Gem::Platform::RUBY, Gem::Platform.local]
|
|
|
|
end
|
|
|
|
@platforms
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2011-01-19 16:23:04 -05:00
|
|
|
##
|
|
|
|
# Adds a post-build hook that will be passed an Gem::Installer instance
|
|
|
|
# when Gem::Installer#install is called. The hook is called after the gem
|
|
|
|
# has been extracted and extensions have been built but before the
|
|
|
|
# executables or gemspec has been written. If the hook returns +false+ then
|
|
|
|
# the gem's files will be removed and the install will be aborted.
|
|
|
|
|
|
|
|
def self.post_build(&hook)
|
|
|
|
@post_build_hooks << hook
|
|
|
|
end
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
|
|
|
# Adds a post-install hook that will be passed an Gem::Installer instance
|
|
|
|
# when Gem::Installer#install is called
|
|
|
|
|
|
|
|
def self.post_install(&hook)
|
|
|
|
@post_install_hooks << hook
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
##
|
|
|
|
# Adds a post-installs hook that will be passed a Gem::DependencyInstaller
|
|
|
|
# and a list of installed specifications when
|
|
|
|
# Gem::DependencyInstaller#install is complete
|
|
|
|
|
|
|
|
def self.done_installing(&hook)
|
|
|
|
@done_installing_hooks << hook
|
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
##
|
|
|
|
# Adds a hook that will get run after Gem::Specification.reset is
|
|
|
|
# run.
|
|
|
|
|
|
|
|
def self.post_reset(&hook)
|
|
|
|
@post_reset_hooks << hook
|
|
|
|
end
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
|
|
|
# Adds a post-uninstall hook that will be passed a Gem::Uninstaller instance
|
|
|
|
# and the spec that was uninstalled when Gem::Uninstaller#uninstall is
|
|
|
|
# called
|
|
|
|
|
|
|
|
def self.post_uninstall(&hook)
|
|
|
|
@post_uninstall_hooks << hook
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Adds a pre-install hook that will be passed an Gem::Installer instance
|
2011-01-19 16:23:04 -05:00
|
|
|
# when Gem::Installer#install is called. If the hook returns +false+ then
|
|
|
|
# the install will be aborted.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
|
|
|
def self.pre_install(&hook)
|
|
|
|
@pre_install_hooks << hook
|
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
##
|
|
|
|
# Adds a hook that will get run before Gem::Specification.reset is
|
|
|
|
# run.
|
|
|
|
|
|
|
|
def self.pre_reset(&hook)
|
|
|
|
@pre_reset_hooks << hook
|
|
|
|
end
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
|
|
|
# Adds a pre-uninstall hook that will be passed an Gem::Uninstaller instance
|
|
|
|
# and the spec that will be uninstalled when Gem::Uninstaller#uninstall is
|
|
|
|
# called
|
|
|
|
|
|
|
|
def self.pre_uninstall(&hook)
|
|
|
|
@pre_uninstall_hooks << hook
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
2011-03-01 04:41:32 -05:00
|
|
|
# The directory prefix this RubyGems was installed at. If your
|
|
|
|
# prefix is in a standard location (ie, rubygems is installed where
|
|
|
|
# you'd expect it to be), then prefix returns nil.
|
2007-12-24 18:28:35 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def self.prefix
|
2011-03-01 04:41:32 -05:00
|
|
|
prefix = File.dirname RUBYGEMS_DIR
|
2008-02-10 03:00:19 -05:00
|
|
|
|
2014-01-06 20:19:28 -05:00
|
|
|
if prefix != File.expand_path(RbConfig::CONFIG['sitelibdir']) and
|
|
|
|
prefix != File.expand_path(RbConfig::CONFIG['libdir']) and
|
2018-11-21 05:20:47 -05:00
|
|
|
'lib' == File.basename(RUBYGEMS_DIR)
|
2010-02-21 21:52:35 -05:00
|
|
|
prefix
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
2012-11-29 01:52:18 -05:00
|
|
|
# Refresh available gems from disk.
|
2008-04-11 16:57:02 -04:00
|
|
|
|
|
|
|
def self.refresh
|
2011-05-31 23:45:05 -04:00
|
|
|
Gem::Specification.reset
|
2008-04-11 16:57:02 -04:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
|
|
|
# Safely read a file in binary mode on all platforms.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def self.read_binary(path)
|
2022-01-11 14:11:20 -05:00
|
|
|
open_file(path, 'rb+') do |io|
|
2021-12-23 19:32:59 -05:00
|
|
|
io.read
|
2013-12-12 19:51:04 -05:00
|
|
|
end
|
2021-12-23 19:32:59 -05:00
|
|
|
rescue Errno::EACCES, Errno::EROFS
|
2022-01-11 14:11:20 -05:00
|
|
|
open_file(path, 'rb') do |io|
|
2021-12-23 19:32:59 -05:00
|
|
|
io.read
|
2015-10-29 20:54:12 -04:00
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
2016-06-18 01:11:55 -04:00
|
|
|
##
|
|
|
|
# Safely write a file in binary mode on all platforms.
|
|
|
|
def self.write_binary(path, data)
|
2022-01-11 14:11:20 -05:00
|
|
|
open_file(path, 'wb') do |io|
|
2021-02-25 12:43:51 -05:00
|
|
|
io.write data
|
|
|
|
end
|
2021-12-23 19:32:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2022-01-11 14:11:20 -05:00
|
|
|
# Open a file with given flags, and on Windows protect access with flock
|
2021-12-23 19:32:59 -05:00
|
|
|
|
2022-01-11 14:11:20 -05:00
|
|
|
def self.open_file(path, flags, &block)
|
2021-12-23 19:32:59 -05:00
|
|
|
File.open(path, flags) do |io|
|
2022-01-11 13:53:41 -05:00
|
|
|
if !java_platform? && win_platform?
|
2021-12-23 19:32:59 -05:00
|
|
|
begin
|
|
|
|
io.flock(File::LOCK_EX)
|
|
|
|
rescue Errno::ENOSYS, Errno::ENOTSUP
|
|
|
|
end
|
|
|
|
end
|
|
|
|
yield io
|
2016-06-18 01:11:55 -04:00
|
|
|
end
|
|
|
|
rescue Errno::ENOLCK # NFS
|
|
|
|
if Thread.main != Thread.current
|
|
|
|
raise
|
|
|
|
else
|
2021-12-23 19:32:59 -05:00
|
|
|
File.open(path, flags) do |io|
|
|
|
|
yield io
|
2016-06-18 01:11:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
|
|
|
# The path to the running Ruby interpreter.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def self.ruby
|
2018-11-21 05:20:47 -05:00
|
|
|
if @ruby.nil?
|
2020-03-24 02:39:24 -04:00
|
|
|
@ruby = RbConfig.ruby
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
@ruby = "\"#{@ruby}\"" if @ruby =~ /\s/
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
@ruby
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2013-10-15 20:14:16 -04:00
|
|
|
##
|
|
|
|
# Returns a String containing the API compatibility version of Ruby
|
|
|
|
|
|
|
|
def self.ruby_api_version
|
2014-01-06 20:19:28 -05:00
|
|
|
@ruby_api_version ||= RbConfig::CONFIG['ruby_version'].dup
|
2013-10-15 20:14:16 -04:00
|
|
|
end
|
|
|
|
|
2016-03-27 22:26:39 -04:00
|
|
|
def self.env_requirement(gem_name)
|
|
|
|
@env_requirements_by_name ||= {}
|
|
|
|
@env_requirements_by_name[gem_name] ||= begin
|
|
|
|
req = ENV["GEM_REQUIREMENT_#{gem_name.upcase}"] || '>= 0'.freeze
|
|
|
|
Gem::Requirement.create(req)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
post_reset { @env_requirements_by_name = {} }
|
|
|
|
|
2012-12-22 19:35:09 -05:00
|
|
|
##
|
|
|
|
# Returns the latest release-version specification for the gem +name+.
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.latest_spec_for(name)
|
2012-12-22 19:35:09 -05:00
|
|
|
dependency = Gem::Dependency.new name
|
|
|
|
fetcher = Gem::SpecFetcher.fetcher
|
|
|
|
spec_tuples, = fetcher.spec_for_dependency dependency
|
2011-03-01 04:41:32 -05:00
|
|
|
|
2019-05-14 01:02:48 -04:00
|
|
|
spec, = spec_tuples.last
|
2011-03-01 04:41:32 -05:00
|
|
|
|
2012-12-22 19:35:09 -05:00
|
|
|
spec
|
2011-03-01 04:41:32 -05:00
|
|
|
end
|
|
|
|
|
2012-12-22 19:35:09 -05:00
|
|
|
##
|
|
|
|
# Returns the latest release version of RubyGems.
|
2011-03-01 04:41:32 -05:00
|
|
|
|
|
|
|
def self.latest_rubygems_version
|
2012-12-22 19:35:09 -05:00
|
|
|
latest_version_for('rubygems-update') or
|
2012-11-29 01:52:18 -05:00
|
|
|
raise "Can't find 'rubygems-update' in any repo. Check `gem source list`."
|
2011-03-01 04:41:32 -05:00
|
|
|
end
|
|
|
|
|
2012-12-22 19:35:09 -05:00
|
|
|
##
|
|
|
|
# Returns the version of the latest release-version of gem +name+
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.latest_version_for(name)
|
2012-12-22 19:35:09 -05:00
|
|
|
spec = latest_spec_for name
|
|
|
|
spec and spec.version
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
2013-09-14 04:59:02 -04:00
|
|
|
# A Gem::Version for the currently running Ruby.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def self.ruby_version
|
|
|
|
return @ruby_version if defined? @ruby_version
|
|
|
|
version = RUBY_VERSION.dup
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
if defined?(RUBY_PATCHLEVEL) && RUBY_PATCHLEVEL != -1
|
2009-06-09 17:38:59 -04:00
|
|
|
version << ".#{RUBY_PATCHLEVEL}"
|
2018-11-21 05:20:47 -05:00
|
|
|
elsif defined?(RUBY_DESCRIPTION)
|
|
|
|
if RUBY_ENGINE == "ruby"
|
|
|
|
desc = RUBY_DESCRIPTION[/\Aruby #{Regexp.quote(RUBY_VERSION)}([^ ]+) /, 1]
|
|
|
|
else
|
|
|
|
desc = RUBY_DESCRIPTION[/\A#{RUBY_ENGINE} #{Regexp.quote(RUBY_ENGINE_VERSION)} \(#{RUBY_VERSION}([^ ]+)\) /, 1]
|
|
|
|
end
|
|
|
|
version << ".#{desc}" if desc
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
@ruby_version = Gem::Version.new version
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
2012-11-29 01:52:18 -05:00
|
|
|
# A Gem::Version for the currently running RubyGems
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def self.rubygems_version
|
|
|
|
return @rubygems_version if defined? @rubygems_version
|
|
|
|
@rubygems_version = Gem::Version.new Gem::VERSION
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2012-11-29 01:52:18 -05:00
|
|
|
# Returns an Array of sources to fetch remote gems from. Uses
|
|
|
|
# default_sources if the sources list is empty.
|
2008-03-31 18:40:06 -04:00
|
|
|
|
|
|
|
def self.sources
|
2016-09-27 20:57:53 -04:00
|
|
|
source_list = configuration.sources || default_sources
|
|
|
|
@sources ||= Gem::SourceList.from(source_list)
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
|
|
|
# Need to be able to set the sources without calling
|
|
|
|
# Gem.sources.replace since that would cause an infinite loop.
|
2012-11-29 01:52:18 -05:00
|
|
|
#
|
|
|
|
# DOC: This comment is not documentation about the method itself, it's
|
|
|
|
# more of a code comment about the implementation.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.sources=(new_sources)
|
2012-11-29 01:52:18 -05:00
|
|
|
if !new_sources
|
|
|
|
@sources = nil
|
|
|
|
else
|
|
|
|
@sources = Gem::SourceList.from(new_sources)
|
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
|
|
|
# Glob pattern for require-able path suffixes.
|
|
|
|
|
|
|
|
def self.suffix_pattern
|
|
|
|
@suffix_pattern ||= "{#{suffixes.join(',')}}"
|
|
|
|
end
|
|
|
|
|
2020-01-31 21:14:04 -05:00
|
|
|
##
|
|
|
|
# Regexp for require-able path suffixes.
|
|
|
|
|
2019-04-25 09:57:41 -04:00
|
|
|
def self.suffix_regexp
|
|
|
|
@suffix_regexp ||= /#{Regexp.union(suffixes)}\z/
|
|
|
|
end
|
|
|
|
|
2020-01-31 21:14:04 -05:00
|
|
|
##
|
|
|
|
# Glob pattern for require-able plugin suffixes.
|
|
|
|
|
|
|
|
def self.plugin_suffix_pattern
|
|
|
|
@plugin_suffix_pattern ||= "_plugin#{suffix_pattern}"
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Regexp for require-able plugin suffixes.
|
|
|
|
|
|
|
|
def self.plugin_suffix_regexp
|
|
|
|
@plugin_suffix_regexp ||= /_plugin#{suffix_regexp}\z/
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
|
|
|
# Suffixes for require-able paths.
|
|
|
|
|
|
|
|
def self.suffixes
|
2011-01-18 19:08:49 -05:00
|
|
|
@suffixes ||= ['',
|
|
|
|
'.rb',
|
2020-03-24 14:51:43 -04:00
|
|
|
*%w[DLEXT DLEXT2].map do |key|
|
2011-01-18 19:08:49 -05:00
|
|
|
val = RbConfig::CONFIG[key]
|
2011-01-19 16:23:04 -05:00
|
|
|
next unless val and not val.empty?
|
|
|
|
".#{val}"
|
2020-12-08 02:33:39 -05:00
|
|
|
end,
|
2011-01-18 19:08:49 -05:00
|
|
|
].compact.uniq
|
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Prints the amount of time the supplied block takes to run using the debug
|
|
|
|
# UI output.
|
|
|
|
|
|
|
|
def self.time(msg, width = 0, display = Gem.configuration.verbose)
|
|
|
|
now = Time.now
|
|
|
|
|
|
|
|
value = yield
|
|
|
|
|
|
|
|
elapsed = Time.now - now
|
|
|
|
|
|
|
|
ui.say "%2$*1$s: %3$3.3fs" % [-width, msg, elapsed] if display
|
|
|
|
|
|
|
|
value
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Lazily loads DefaultUserInteraction and returns the default UI.
|
|
|
|
|
|
|
|
def self.ui
|
2019-04-22 07:56:16 -04:00
|
|
|
require_relative 'rubygems/user_interaction'
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
Gem::DefaultUserInteraction.ui
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
|
|
|
# Use the +home+ and +paths+ values for Gem.dir and Gem.path. Used mainly
|
|
|
|
# by the unit tests to provide environment isolation.
|
|
|
|
|
2011-08-23 18:58:06 -04:00
|
|
|
def self.use_paths(home, *paths)
|
2016-03-03 19:29:40 -05:00
|
|
|
paths.flatten!
|
|
|
|
paths.compact!
|
|
|
|
hash = { "GEM_HOME" => home, "GEM_PATH" => paths.empty? ? home : paths.join(File::PATH_SEPARATOR) }
|
2020-06-10 13:46:05 -04:00
|
|
|
hash.delete_if {|_, v| v.nil? }
|
2016-03-03 19:29:40 -05:00
|
|
|
self.paths = hash
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Is this a windows platform?
|
|
|
|
|
|
|
|
def self.win_platform?
|
2018-11-21 05:20:47 -05:00
|
|
|
if @@win_platform.nil?
|
2013-03-05 17:40:53 -05:00
|
|
|
ruby_platform = RbConfig::CONFIG['host_os']
|
2020-06-10 13:46:05 -04:00
|
|
|
@@win_platform = !!WIN_PATTERNS.find {|r| ruby_platform =~ r }
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
@@win_platform
|
|
|
|
end
|
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
##
|
|
|
|
# Is this a java platform?
|
|
|
|
|
|
|
|
def self.java_platform?
|
|
|
|
RUBY_PLATFORM == "java"
|
|
|
|
end
|
|
|
|
|
2021-12-24 00:24:09 -05:00
|
|
|
##
|
|
|
|
# Is this platform Solaris?
|
|
|
|
|
|
|
|
def self.solaris_platform?
|
|
|
|
RUBY_PLATFORM =~ /solaris/
|
|
|
|
end
|
|
|
|
|
2010-04-22 04:24:42 -04:00
|
|
|
##
|
2013-09-14 04:59:02 -04:00
|
|
|
# Load +plugins+ as Ruby files
|
2010-04-22 04:24:42 -04:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.load_plugin_files(plugins) # :nodoc:
|
2010-04-22 04:24:42 -04:00
|
|
|
plugins.each do |plugin|
|
|
|
|
|
|
|
|
# Skip older versions of the GemCutter plugin: Its commands are in
|
|
|
|
# RubyGems proper now.
|
|
|
|
|
|
|
|
next if plugin =~ /gemcutter-0\.[0-3]/
|
|
|
|
|
|
|
|
begin
|
|
|
|
load plugin
|
|
|
|
rescue ::Exception => e
|
|
|
|
details = "#{plugin.inspect}: #{e.message} (#{e.class})"
|
|
|
|
warn "Error loading RubyGems plugin #{details}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
##
|
2020-01-31 21:14:04 -05:00
|
|
|
# Find rubygems plugin files in the standard location and load them
|
2011-01-18 19:08:49 -05:00
|
|
|
|
|
|
|
def self.load_plugins
|
2021-08-06 06:21:23 -04:00
|
|
|
Gem.path.each do |gem_path|
|
|
|
|
load_plugin_files Gem::Util.glob_files_in_dir("*#{Gem.plugin_suffix_pattern}", plugindir(gem_path))
|
|
|
|
end
|
2011-01-18 19:08:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Find all 'rubygems_plugin' files in $LOAD_PATH and load them
|
|
|
|
|
|
|
|
def self.load_env_plugins
|
2020-01-31 21:14:04 -05:00
|
|
|
load_plugin_files find_files_from_load_path("rubygems_plugin")
|
2011-01-18 19:08:49 -05:00
|
|
|
end
|
|
|
|
|
2013-11-21 18:27:30 -05:00
|
|
|
##
|
2014-09-13 23:30:02 -04:00
|
|
|
# Looks for a gem dependency file at +path+ and activates the gems in the
|
|
|
|
# file if found. If the file is not found an ArgumentError is raised.
|
|
|
|
#
|
|
|
|
# If +path+ is not given the RUBYGEMS_GEMDEPS environment variable is used,
|
|
|
|
# but if no file is found no exception is raised.
|
|
|
|
#
|
|
|
|
# If '-' is given for +path+ RubyGems searches up from the current working
|
|
|
|
# directory for gem dependency files (gem.deps.rb, Gemfile, Isolate) and
|
|
|
|
# activates the gems in the first one found.
|
2013-11-21 18:27:30 -05:00
|
|
|
#
|
2013-11-22 13:53:21 -05:00
|
|
|
# You can run this automatically when rubygems starts. To enable, set
|
|
|
|
# the <code>RUBYGEMS_GEMDEPS</code> environment variable to either the path
|
2014-09-13 23:30:02 -04:00
|
|
|
# of your gem dependencies file or "-" to auto-discover in parent
|
|
|
|
# directories.
|
2013-11-22 13:53:21 -05:00
|
|
|
#
|
|
|
|
# NOTE: Enabling automatic discovery on multiuser systems can lead to
|
|
|
|
# execution of arbitrary code when used from directories outside your
|
|
|
|
# control.
|
2013-11-21 18:27:30 -05:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.use_gemdeps(path = nil)
|
2014-09-13 23:30:02 -04:00
|
|
|
raise_exception = path
|
|
|
|
|
|
|
|
path ||= ENV['RUBYGEMS_GEMDEPS']
|
|
|
|
return unless path
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
path = path.dup
|
2013-11-21 18:27:30 -05:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
if path == "-"
|
2013-11-25 14:14:49 -05:00
|
|
|
Gem::Util.traverse_parents Dir.pwd do |directory|
|
2020-06-10 13:46:05 -04:00
|
|
|
dep_file = GEM_DEP_FILES.find {|f| File.file?(f) }
|
2013-11-21 18:27:30 -05:00
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
next unless dep_file
|
2013-11-21 18:27:30 -05:00
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
path = File.join directory, dep_file
|
|
|
|
break
|
2013-11-21 18:27:30 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-11 01:03:57 -05:00
|
|
|
path.tap(&Gem::UNTAINT)
|
2013-11-21 18:27:30 -05:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
unless File.file? path
|
2014-09-13 23:30:02 -04:00
|
|
|
return unless raise_exception
|
|
|
|
|
|
|
|
raise ArgumentError, "Unable to find gem dependencies file at #{path}"
|
|
|
|
end
|
2013-11-21 18:27:30 -05:00
|
|
|
|
2019-04-26 07:26:21 -04:00
|
|
|
ENV["BUNDLE_GEMFILE"] ||= File.expand_path(path)
|
2019-04-22 07:56:16 -04:00
|
|
|
require_relative 'rubygems/user_interaction'
|
2021-04-13 06:13:59 -04:00
|
|
|
require "bundler"
|
|
|
|
begin
|
|
|
|
Gem::DefaultUserInteraction.use_ui(ui) do
|
|
|
|
begin
|
|
|
|
Bundler.ui.silence do
|
|
|
|
@gemdeps = Bundler.setup
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
Gem::DefaultUserInteraction.ui.close
|
2019-06-06 02:25:18 -04:00
|
|
|
end
|
|
|
|
end
|
2021-04-13 06:13:59 -04:00
|
|
|
rescue Bundler::BundlerError => e
|
|
|
|
warn e.message
|
2021-04-13 07:03:59 -04:00
|
|
|
warn "You may need to `bundle install` to install missing gems"
|
2021-04-13 06:13:59 -04:00
|
|
|
warn ""
|
2013-11-21 18:27:30 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-17 00:45:09 -04:00
|
|
|
##
|
2020-03-24 02:39:24 -04:00
|
|
|
# If the SOURCE_DATE_EPOCH environment variable is set, returns it's value.
|
|
|
|
# Otherwise, returns the time that `Gem.source_date_epoch_string` was
|
|
|
|
# first called in the same format as SOURCE_DATE_EPOCH.
|
|
|
|
#
|
|
|
|
# NOTE(@duckinator): The implementation is a tad weird because we want to:
|
|
|
|
# 1. Make builds reproducible by default, by having this function always
|
|
|
|
# return the same result during a given run.
|
|
|
|
# 2. Allow changing ENV['SOURCE_DATE_EPOCH'] at runtime, since multiple
|
|
|
|
# tests that set this variable will be run in a single process.
|
2019-08-17 00:45:09 -04:00
|
|
|
#
|
2020-03-24 02:39:24 -04:00
|
|
|
# If you simplify this function and a lot of tests fail, that is likely
|
|
|
|
# due to #2 above.
|
2019-08-17 00:45:09 -04:00
|
|
|
#
|
|
|
|
# Details on SOURCE_DATE_EPOCH:
|
|
|
|
# https://reproducible-builds.org/specs/source-date-epoch/
|
|
|
|
|
2020-03-24 02:39:24 -04:00
|
|
|
def self.source_date_epoch_string
|
|
|
|
# The value used if $SOURCE_DATE_EPOCH is not set.
|
|
|
|
@default_source_date_epoch ||= Time.now.to_i.to_s
|
|
|
|
|
|
|
|
specified_epoch = ENV["SOURCE_DATE_EPOCH"]
|
|
|
|
|
|
|
|
# If it's empty or just whitespace, treat it like it wasn't set at all.
|
|
|
|
specified_epoch = nil if !specified_epoch.nil? && specified_epoch.strip.empty?
|
|
|
|
|
|
|
|
epoch = specified_epoch || @default_source_date_epoch
|
|
|
|
|
|
|
|
epoch.strip
|
|
|
|
end
|
2019-08-17 00:45:09 -04:00
|
|
|
|
2020-03-24 02:39:24 -04:00
|
|
|
##
|
|
|
|
# Returns the value of Gem.source_date_epoch_string, as a Time object.
|
|
|
|
#
|
|
|
|
# This is used throughout RubyGems for enabling reproducible builds.
|
|
|
|
|
|
|
|
def self.source_date_epoch
|
|
|
|
Time.at(self.source_date_epoch_string.to_i).utc.freeze
|
2019-08-17 00:45:09 -04:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
# FIX: Almost everywhere else we use the `def self.` way of defining class
|
|
|
|
# methods, and then we switch over to `class << self` here. Pick one or the
|
|
|
|
# other.
|
2008-03-31 18:40:06 -04:00
|
|
|
class << self
|
2020-06-13 18:26:23 -04:00
|
|
|
##
|
|
|
|
# RubyGems distributors (like operating system package managers) can
|
|
|
|
# disable RubyGems update by setting this to error message printed to
|
|
|
|
# end-users on gem update --system instead of actual update.
|
|
|
|
attr_accessor :disable_system_update_message
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Hash of loaded Gem::Specification keyed by name
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
attr_reader :loaded_specs
|
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
##
|
|
|
|
# GemDependencyAPI object, which is set when .use_gemdeps is called.
|
|
|
|
# This contains all the information from the Gemfile.
|
|
|
|
|
|
|
|
attr_reader :gemdeps
|
|
|
|
|
2011-01-19 16:23:04 -05:00
|
|
|
##
|
2013-09-14 04:59:02 -04:00
|
|
|
# Register a Gem::Specification for default gem.
|
|
|
|
#
|
|
|
|
# Two formats for the specification are supported:
|
|
|
|
#
|
|
|
|
# * MRI 2.0 style, where spec.files contains unprefixed require names.
|
|
|
|
# The spec's filenames will be registered as-is.
|
|
|
|
# * New style, where spec.files contains files prefixed with paths
|
|
|
|
# from spec.require_paths. The prefixes are stripped before
|
|
|
|
# registering the spec's filenames. Unprefixed files are omitted.
|
|
|
|
#
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
def register_default_spec(spec)
|
2020-06-10 13:46:05 -04:00
|
|
|
extended_require_paths = spec.require_paths.map {|f| f + "/" }
|
[rubygems/rubygems] Fix incorrect bundler version being required
In ruby 2.7.0, there's a slight change in bundler's default gemspec file
where the executable folder of the bundler gem is `libexec` instead of
`exe`. I made that change in https://github.com/ruby/ruby/pull/2380 to
try to simplify the integration of the `bundler` gem with upstream,
minimizing the number of changes that need to be made to the gemspec to
adapt to the structure of ruby-core.
That worked ok, expected for this issue. The new name of the folder
including the executable files uncovered a bug in rubygems, which is the
following:
* In order to be able to use newer versions of default gems, `rubygems`
ships with a customized `require` that has knowledge about which files
belong to which default gem. If one of these files is required,
`rubygems` will detect that and activate its gem mechanism to choose the
newest version of the corresponding default gem present in the system
(unless a different version has already been activated). It's this part
of the custom require:
https://github.com/rubygems/rubygems/blob/ea3e6f194df500b028b52b3b64decbd3df1d5ab0/lib/rubygems/core_ext/kernel_require.rb#L77-L85
* In order to do that, `rubygems` registers a map of default gems and
their files when it is first required:
https://github.com/rubygems/rubygems/blob/ea3e6f194df500b028b52b3b64decbd3df1d5ab0/lib/rubygems.rb#L1247-L1276
As explained in the method's header, two types of default gem
specifications are supported. One of the formats is the style used by
some ruby-core gemspec files, where paths inside the `spec.files` array
don't include the `spec.require_paths` part. So in this "old style", if
a gem ships with a `lib/bundler.rb` file, it will be registered in this
array as `spec.files = ["bundler.rb"]`, not as `spec.files =
["lib/bundler.rb"]`. The `Gem.register_default_spec` method "detects"
this style by making sure that none of the files in the `spec.files`
array start with any of the `spec.require_paths`.
* Since in ruby 2.7 the default specification file of the `bundler` gem
includes a `libexec/bundle` file, this check would no longer work
correctly, because even though the specification file is still "old
style", it has one registered file which starts with "lib", one of the
"require paths" of the gem.
* This means that the gem is incorrectly detected as "new style", but
since none of the paths start with "lib/", no files are actually
registered, so the gem is not being considered a default gem, and thus
the default version is always used with no possibility of being
"upgraded".
The fix of the problem is simple: check that no files start with `lib/`
(or any other require paths), instead of with "lib" which doesn't
exclude other potential "non requirable folder" starting with lib, like
in the `bundler` case.
https://github.com/rubygems/rubygems/commit/94df740c2b
2020-03-29 15:45:39 -04:00
|
|
|
new_format = extended_require_paths.any? {|path| spec.files.any? {|f| f.start_with? path } }
|
2013-09-14 04:59:02 -04:00
|
|
|
|
|
|
|
if new_format
|
2020-03-29 15:22:34 -04:00
|
|
|
prefix_group = extended_require_paths.join("|")
|
2013-09-14 04:59:02 -04:00
|
|
|
prefix_pattern = /^(#{prefix_group})/
|
|
|
|
end
|
|
|
|
|
2013-08-26 16:24:51 -04:00
|
|
|
spec.files.each do |file|
|
2013-09-14 04:59:02 -04:00
|
|
|
if new_format
|
|
|
|
file = file.sub(prefix_pattern, "")
|
|
|
|
next unless $~
|
|
|
|
end
|
|
|
|
|
2020-03-25 10:55:16 -04:00
|
|
|
spec.activate if already_loaded?(file)
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
@path_to_default_spec_map[file] = spec
|
2019-04-25 09:57:41 -04:00
|
|
|
@path_to_default_spec_map[file.sub(suffix_regexp, "")] = spec
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Find a Gem::Specification of default gem from +path+
|
|
|
|
|
|
|
|
def find_unresolved_default_spec(path)
|
2019-04-25 05:48:40 -04:00
|
|
|
default_spec = @path_to_default_spec_map[path]
|
|
|
|
return default_spec if default_spec && loaded_specs[default_spec.name] != default_spec
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2013-12-08 14:32:07 -05:00
|
|
|
# Clear default gem related variables. It is for test
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
def clear_default_specs
|
|
|
|
@path_to_default_spec_map.clear
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# The list of hooks to be run after Gem::Installer#install extracts files
|
|
|
|
# and builds extensions
|
2011-01-19 16:23:04 -05:00
|
|
|
|
|
|
|
attr_reader :post_build_hooks
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
2012-11-29 01:52:18 -05:00
|
|
|
# The list of hooks to be run after Gem::Installer#install completes
|
|
|
|
# installation
|
2008-09-25 06:13:50 -04:00
|
|
|
|
|
|
|
attr_reader :post_install_hooks
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
##
|
|
|
|
# The list of hooks to be run after Gem::DependencyInstaller installs a
|
|
|
|
# set of gems
|
|
|
|
|
|
|
|
attr_reader :done_installing_hooks
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
##
|
|
|
|
# The list of hooks to be run after Gem::Specification.reset is run.
|
|
|
|
|
|
|
|
attr_reader :post_reset_hooks
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
2012-11-29 01:52:18 -05:00
|
|
|
# The list of hooks to be run after Gem::Uninstaller#uninstall completes
|
|
|
|
# installation
|
2008-09-25 06:13:50 -04:00
|
|
|
|
|
|
|
attr_reader :post_uninstall_hooks
|
|
|
|
|
|
|
|
##
|
2012-11-29 01:52:18 -05:00
|
|
|
# The list of hooks to be run before Gem::Installer#install does any work
|
2008-09-25 06:13:50 -04:00
|
|
|
|
|
|
|
attr_reader :pre_install_hooks
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
##
|
|
|
|
# The list of hooks to be run before Gem::Specification.reset is run.
|
|
|
|
|
|
|
|
attr_reader :pre_reset_hooks
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
2012-11-29 01:52:18 -05:00
|
|
|
# The list of hooks to be run before Gem::Uninstaller#uninstall does any
|
|
|
|
# work
|
2008-09-25 06:13:50 -04:00
|
|
|
|
|
|
|
attr_reader :pre_uninstall_hooks
|
2019-02-14 07:59:03 -05:00
|
|
|
|
2020-03-25 10:55:16 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def already_loaded?(file)
|
2020-07-06 09:18:05 -04:00
|
|
|
$LOADED_FEATURES.any? do |feature_path|
|
|
|
|
feature_path.end_with?(file) && default_gem_load_paths.any? {|load_path_entry| feature_path == "#{load_path_entry}/#{file}" }
|
2020-03-25 10:55:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_gem_load_paths
|
2021-12-14 07:14:58 -05:00
|
|
|
@default_gem_load_paths ||= $LOAD_PATH[load_path_insert_index..-1].map do |lp|
|
|
|
|
expanded = File.expand_path(lp)
|
|
|
|
next expanded unless File.exist?(expanded)
|
|
|
|
|
|
|
|
File.realpath(expanded)
|
|
|
|
end
|
2020-03-25 10:55:16 -04:00
|
|
|
end
|
2011-03-01 04:41:32 -05:00
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Location of Marshal quick gemspecs on remote repositories
|
|
|
|
|
2018-10-21 20:27:02 -04:00
|
|
|
MARSHAL_SPEC_DIR = "quick/Marshal.#{Gem.marshal_version}/".freeze
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2020-01-31 21:14:04 -05:00
|
|
|
autoload :BundlerVersionFinder, File.expand_path('rubygems/bundler_version_finder', __dir__)
|
|
|
|
autoload :ConfigFile, File.expand_path('rubygems/config_file', __dir__)
|
|
|
|
autoload :Dependency, File.expand_path('rubygems/dependency', __dir__)
|
|
|
|
autoload :DependencyList, File.expand_path('rubygems/dependency_list', __dir__)
|
|
|
|
autoload :Installer, File.expand_path('rubygems/installer', __dir__)
|
|
|
|
autoload :Licenses, File.expand_path('rubygems/util/licenses', __dir__)
|
2020-03-16 02:36:41 -04:00
|
|
|
autoload :NameTuple, File.expand_path('rubygems/name_tuple', __dir__)
|
2020-01-31 21:14:04 -05:00
|
|
|
autoload :PathSupport, File.expand_path('rubygems/path_support', __dir__)
|
|
|
|
autoload :RequestSet, File.expand_path('rubygems/request_set', __dir__)
|
|
|
|
autoload :Resolver, File.expand_path('rubygems/resolver', __dir__)
|
|
|
|
autoload :Source, File.expand_path('rubygems/source', __dir__)
|
|
|
|
autoload :SourceList, File.expand_path('rubygems/source_list', __dir__)
|
|
|
|
autoload :SpecFetcher, File.expand_path('rubygems/spec_fetcher', __dir__)
|
2021-12-25 22:28:57 -05:00
|
|
|
autoload :SpecificationPolicy, File.expand_path('rubygems/specification_policy', __dir__)
|
2020-01-31 21:14:04 -05:00
|
|
|
autoload :Util, File.expand_path('rubygems/util', __dir__)
|
|
|
|
autoload :Version, File.expand_path('rubygems/version', __dir__)
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2019-04-22 07:56:16 -04:00
|
|
|
require_relative 'rubygems/exceptions'
|
2021-12-14 07:14:58 -05:00
|
|
|
require_relative 'rubygems/specification'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
# REFACTOR: This should be pulled out into some kind of hacks file.
|
2021-11-30 21:00:10 -05:00
|
|
|
begin
|
|
|
|
##
|
|
|
|
# Defaults the operating system (or packager) wants to provide for RubyGems.
|
|
|
|
|
|
|
|
require 'rubygems/defaults/operating_system'
|
|
|
|
rescue LoadError
|
|
|
|
# Ignored
|
|
|
|
rescue StandardError => e
|
|
|
|
msg = "#{e.message}\n" \
|
|
|
|
"Loading the rubygems/defaults/operating_system.rb file caused an error. " \
|
|
|
|
"This file is owned by your OS, not by rubygems upstream. " \
|
|
|
|
"Please find out which OS package this file belongs to and follow the guidelines from your OS to report " \
|
|
|
|
"the problem and ask for help."
|
|
|
|
raise e.class, msg
|
|
|
|
end
|
2021-12-14 07:14:58 -05:00
|
|
|
|
|
|
|
begin
|
|
|
|
##
|
|
|
|
# Defaults the Ruby implementation wants to provide for RubyGems
|
|
|
|
|
|
|
|
require "rubygems/defaults/#{RUBY_ENGINE}"
|
|
|
|
rescue LoadError
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Loads the default specs.
|
|
|
|
Gem::Specification.load_defaults
|
|
|
|
|
|
|
|
require_relative 'rubygems/core_ext/kernel_gem'
|
|
|
|
require_relative 'rubygems/core_ext/kernel_require'
|
|
|
|
require_relative 'rubygems/core_ext/kernel_warn'
|