2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2007-11-10 02:48:56 -05:00
|
|
|
# -*- ruby -*-
|
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
|
2019-01-22 01:28:04 -05:00
|
|
|
VERSION = "3.1.0.pre1".freeze
|
2013-02-05 15:52:28 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# Must be first since it unloads the prelude from 1.9.2
|
|
|
|
require 'rubygems/compatibility'
|
|
|
|
|
|
|
|
require 'rubygems/defaults'
|
|
|
|
require 'rubygems/deprecate'
|
|
|
|
require 'rubygems/errors'
|
2019-04-27 18:47:33 -04:00
|
|
|
require 'rubygems/path_support'
|
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>
|
2015-07-01 17:50:14 -04:00
|
|
|
# * {RubyGems User Guide}[http://guides.rubygems.org/]
|
|
|
|
# * {Frequently Asked Questions}[http://guides.rubygems.org/faqs]
|
2009-06-09 17:38:59 -04:00
|
|
|
#
|
|
|
|
# For gem developer documentation see:
|
|
|
|
#
|
2015-07-01 17:50:14 -04:00
|
|
|
# * {Creating Gems}[http://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:
|
|
|
|
#
|
2013-08-26 16:24:51 -04:00
|
|
|
# * {RubyGems Guides}[http://guides.rubygems.org]
|
2017-10-07 21:32:18 -04:00
|
|
|
# * {RubyGems API}[http://www.rubydoc.info/github/rubygems/rubygems] (also available from
|
2009-06-09 17:38:59 -04:00
|
|
|
# <tt>gem server</tt>)
|
|
|
|
#
|
|
|
|
# == RubyGems Plugins
|
|
|
|
#
|
|
|
|
# As of RubyGems 1.3.2, RubyGems will load plugins installed in gems or
|
2010-02-21 21:52:35 -05:00
|
|
|
# $LOAD_PATH. Plugins must be named 'rubygems_plugin' (.rb, .so, etc) and
|
|
|
|
# placed at the root of your gem's #require_path. Plugins are discovered via
|
2017-11-28 17:30:28 -05:00
|
|
|
# Gem::find_files and then loaded.
|
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__)
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2016-06-18 01:11:55 -04:00
|
|
|
##
|
|
|
|
# Exception classes used in a Gem.read_binary +rescue+ statement. Not all of
|
|
|
|
# these are defined in Ruby 1.8.7, hence the need for this convoluted setup.
|
|
|
|
|
|
|
|
READ_BINARY_ERRORS = begin
|
2018-02-05 21:58:35 -05:00
|
|
|
read_binary_errors = [Errno::EACCES, Errno::EROFS, Errno::ENOSYS]
|
2016-06-18 01:11:55 -04:00
|
|
|
read_binary_errors << Errno::ENOTSUP if Errno.const_defined?(:ENOTSUP)
|
|
|
|
read_binary_errors
|
|
|
|
end.freeze
|
|
|
|
|
|
|
|
##
|
|
|
|
# Exception classes used in Gem.write_binary +rescue+ statement. Not all of
|
|
|
|
# these are defined in Ruby 1.8.7.
|
|
|
|
|
|
|
|
WRITE_BINARY_ERRORS = begin
|
2018-02-05 21:58:35 -05:00
|
|
|
write_binary_errors = [Errno::ENOSYS]
|
2016-06-18 01:11:55 -04:00
|
|
|
write_binary_errors << Errno::ENOTSUP if Errno.const_defined?(:ENOTSUP)
|
|
|
|
write_binary_errors
|
|
|
|
end.freeze
|
|
|
|
|
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 = {}
|
2014-09-13 23:30:02 -04:00
|
|
|
LOADED_SPECS_MUTEX = 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
|
|
|
|
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)
|
2011-05-31 23:45:05 -04:00
|
|
|
# TODO: fails test_self_bin_path_bin_file_gone_in_latest
|
|
|
|
# Gem::Specification.find_by_name(name, *requirements).bin_file exec_name
|
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
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}"
|
|
|
|
if name == "bundler" && bundler_message = Gem::BundlerVersionFinder.missing_version_message
|
|
|
|
msg = bundler_message
|
|
|
|
end
|
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
|
|
|
|
|
|
|
|
##
|
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 path to standard location of the user's .gemrc file.
|
|
|
|
|
|
|
|
def self.config_file
|
2011-05-31 23:45:05 -04:00
|
|
|
@config_file ||= File.join Gem.user_home, '.gemrc'
|
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
|
|
|
|
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]}
|
2016-03-03 19:29:40 -05:00
|
|
|
eowarn
|
|
|
|
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.
|
2011-05-31 23:45:05 -04:00
|
|
|
#--
|
|
|
|
# FIXME deprecate these once everything else has been done -ebh
|
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
|
2013-03-05 18:02:00 -05:00
|
|
|
FileUtils.mkdir_p subdir, options rescue nil
|
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
|
|
|
|
|
|
|
|
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)
|
2019-02-14 07:59:03 -05:00
|
|
|
end.flatten.select { |file| File.file? file.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
|
|
|
|
|
|
|
|
files.concat Gem::Specification.latest_specs(true).map { |spec|
|
|
|
|
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
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
|
|
|
# Finds the user's home directory.
|
2011-01-18 19:08:49 -05:00
|
|
|
#--
|
|
|
|
# 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).
|
2011-03-01 04:41:32 -05:00
|
|
|
#++
|
2011-05-31 23:45:05 -04:00
|
|
|
#--
|
|
|
|
#
|
|
|
|
# FIXME move to pathsupport
|
|
|
|
#
|
|
|
|
#++
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def self.find_home
|
2018-12-22 19:20:49 -05:00
|
|
|
Dir.home.dup
|
2009-01-04 03:07:22 -05:00
|
|
|
rescue
|
2018-11-21 05:20:47 -05:00
|
|
|
if Gem.win_platform?
|
2011-05-31 23:45:05 -04:00
|
|
|
File.expand_path File.join(ENV['HOMEDRIVE'] || ENV['SystemDrive'], '/')
|
2009-01-04 03:07:22 -05:00
|
|
|
else
|
2011-05-31 23:45:05 -04:00
|
|
|
File.expand_path "/"
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
private_class_method :find_home
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2018-05-17 21:39:13 -04:00
|
|
|
# TODO: remove in RubyGems 4.0
|
2013-11-18 19:34:13 -05:00
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
##
|
|
|
|
# Zlib::GzipReader wrapper that unzips +data+.
|
|
|
|
|
|
|
|
def self.gunzip(data)
|
2013-11-18 19:34:13 -05:00
|
|
|
Gem::Util.gunzip data
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
2018-05-17 21:39:13 -04:00
|
|
|
class << self
|
2019-02-14 07:59:03 -05:00
|
|
|
|
2018-05-17 21:39:13 -04:00
|
|
|
extend Gem::Deprecate
|
|
|
|
deprecate :gunzip, "Gem::Util.gunzip", 2018, 12
|
2019-02-14 07:59:03 -05:00
|
|
|
|
2018-05-17 21:39:13 -04:00
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
##
|
|
|
|
# Zlib::GzipWriter wrapper that zips +data+.
|
|
|
|
|
|
|
|
def self.gzip(data)
|
2013-11-18 19:34:13 -05:00
|
|
|
Gem::Util.gzip data
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
2018-05-17 21:39:13 -04:00
|
|
|
class << self
|
2019-02-14 07:59:03 -05:00
|
|
|
|
2018-05-17 21:39:13 -04:00
|
|
|
extend Gem::Deprecate
|
|
|
|
deprecate :gzip, "Gem::Util.gzip", 2018, 12
|
2019-02-14 07:59:03 -05:00
|
|
|
|
2018-05-17 21:39:13 -04:00
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
##
|
|
|
|
# A Zlib::Inflate#inflate wrapper
|
|
|
|
|
|
|
|
def self.inflate(data)
|
2013-11-18 19:34:13 -05:00
|
|
|
Gem::Util.inflate data
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
2018-05-17 21:39:13 -04:00
|
|
|
class << self
|
2019-02-14 07:59:03 -05:00
|
|
|
|
2018-05-17 21:39:13 -04:00
|
|
|
extend Gem::Deprecate
|
|
|
|
deprecate :inflate, "Gem::Util.inflate", 2018, 12
|
2019-02-14 07:59:03 -05:00
|
|
|
|
2018-05-17 21:39:13 -04:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
##
|
|
|
|
# Top level install helper method. Allows you to install gems interactively:
|
|
|
|
#
|
|
|
|
# % irb
|
|
|
|
# >> Gem.install "minitest"
|
|
|
|
# Fetching: minitest-3.0.1.gem (100%)
|
|
|
|
# => [#<Gem::Specification:0x1013b4528 @name="minitest", ...>]
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.install(name, version = Gem::Requirement.default, *options)
|
2012-11-29 01:52:18 -05:00
|
|
|
require "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
|
2011-05-31 23:45:05 -04:00
|
|
|
# TODO: move to utils
|
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-05-31 23:45:05 -04:00
|
|
|
# TODO: move to utils
|
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
|
|
|
|
|
|
|
index
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
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)
|
|
|
|
insert_index = load_path_insert_index
|
|
|
|
|
|
|
|
if insert_index
|
|
|
|
# gem directories must come after -I and ENV['RUBYLIB']
|
|
|
|
$LOAD_PATH.insert(insert_index, *paths)
|
|
|
|
else
|
|
|
|
# we are probably testing in core, -I and RUBYLIB don't apply
|
|
|
|
$LOAD_PATH.unshift(*paths)
|
|
|
|
end
|
|
|
|
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-11-29 03:34:52 -05:00
|
|
|
return unless defined?(gem)
|
2012-04-17 16:50:00 -04:00
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
begin
|
|
|
|
gem 'psych', '>= 2.0.0'
|
|
|
|
rescue Gem::LoadError
|
|
|
|
# It's OK if the user does not have the psych gem installed. We will
|
|
|
|
# attempt to require the stdlib version
|
|
|
|
end
|
2015-10-29 20:54:12 -04:00
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
begin
|
|
|
|
# Try requiring the gem version *or* stdlib version of psych.
|
|
|
|
require 'psych'
|
|
|
|
rescue ::LoadError
|
|
|
|
# If we can't load psych, thats fine, go on.
|
|
|
|
else
|
|
|
|
# If 'yaml' has already been required, then we have to
|
|
|
|
# be sure to switch it over to the newly loaded psych.
|
|
|
|
if defined?(YAML::ENGINE) && YAML::ENGINE.yamler != "psych"
|
|
|
|
YAML::ENGINE.yamler = "psych"
|
2012-04-17 20:04:12 -04:00
|
|
|
end
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
require 'rubygems/psych_additions'
|
|
|
|
require 'rubygems/psych_tree'
|
2012-04-17 17:17:56 -04:00
|
|
|
end
|
2012-04-17 20:04:12 -04:00
|
|
|
|
|
|
|
require 'yaml'
|
2017-10-10 04:58:22 -04:00
|
|
|
require 'rubygems/safe_yaml'
|
2012-04-17 20:04:12 -04:00
|
|
|
|
|
|
|
# Now that we're sure some kind of yaml library is loaded, pull
|
|
|
|
# in our hack to deal with Syck's DefaultKey ugliness.
|
|
|
|
require 'rubygems/syck_hack'
|
|
|
|
|
|
|
|
@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)
|
2018-02-05 21:58:35 -05:00
|
|
|
File.open path, 'rb+' do |f|
|
2013-12-12 19:51:04 -05:00
|
|
|
f.flock(File::LOCK_EX)
|
2013-12-12 19:56:06 -05:00
|
|
|
f.read
|
2013-12-12 19:51:04 -05:00
|
|
|
end
|
2016-06-18 01:11:55 -04:00
|
|
|
rescue *READ_BINARY_ERRORS
|
2018-02-05 21:58:35 -05:00
|
|
|
File.open path, 'rb' do |f|
|
2014-01-06 20:19:28 -05:00
|
|
|
f.read
|
|
|
|
end
|
2015-10-29 20:54:12 -04:00
|
|
|
rescue Errno::ENOLCK # NFS
|
|
|
|
if Thread.main != Thread.current
|
|
|
|
raise
|
|
|
|
else
|
2018-02-05 21:58:35 -05:00
|
|
|
File.open path, 'rb' do |f|
|
2015-10-29 20:54:12 -04:00
|
|
|
f.read
|
|
|
|
end
|
|
|
|
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)
|
|
|
|
open(path, 'wb') do |io|
|
|
|
|
begin
|
|
|
|
io.flock(File::LOCK_EX)
|
|
|
|
rescue *WRITE_BINARY_ERRORS
|
|
|
|
end
|
|
|
|
io.write data
|
|
|
|
end
|
|
|
|
rescue Errno::ENOLCK # NFS
|
|
|
|
if Thread.main != Thread.current
|
|
|
|
raise
|
|
|
|
else
|
|
|
|
open(path, 'wb') do |io|
|
|
|
|
io.write data
|
|
|
|
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?
|
2014-01-06 20:19:28 -05:00
|
|
|
@ruby = File.join(RbConfig::CONFIG['bindir'],
|
|
|
|
"#{RbConfig::CONFIG['ruby_install_name']}#{RbConfig::CONFIG['EXEEXT']}")
|
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
|
|
|
|
2012-12-22 19:35:09 -05:00
|
|
|
spec, = spec_tuples.first
|
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
|
|
|
|
|
|
|
|
##
|
|
|
|
# Suffixes for require-able paths.
|
|
|
|
|
|
|
|
def self.suffixes
|
2011-01-18 19:08:49 -05:00
|
|
|
@suffixes ||= ['',
|
|
|
|
'.rb',
|
2019-02-14 07:59:03 -05: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}"
|
2019-02-14 07:59:03 -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
|
|
|
|
require 'rubygems/user_interaction'
|
|
|
|
|
|
|
|
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) }
|
|
|
|
hash.delete_if { |_, v| v.nil? }
|
|
|
|
self.paths = hash
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# The home directory for the user.
|
|
|
|
|
|
|
|
def self.user_home
|
2012-11-29 01:52:18 -05:00
|
|
|
@user_home ||= find_home.untaint
|
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']
|
|
|
|
@@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
|
|
|
|
|
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
|
|
|
##
|
2013-09-14 04:59:02 -04:00
|
|
|
# Find the 'rubygems_plugin' files in the latest installed gems and load
|
|
|
|
# them
|
2011-01-18 19:08:49 -05:00
|
|
|
|
|
|
|
def self.load_plugins
|
2013-09-14 04:59:02 -04:00
|
|
|
# Remove this env var by at least 3.0
|
|
|
|
if ENV['RUBYGEMS_LOAD_ALL_PLUGINS']
|
|
|
|
load_plugin_files find_files('rubygems_plugin', false)
|
|
|
|
else
|
|
|
|
load_plugin_files find_latest_files('rubygems_plugin', false)
|
|
|
|
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
|
|
|
|
path = "rubygems_plugin"
|
|
|
|
|
|
|
|
files = []
|
2018-08-27 06:05:04 -04:00
|
|
|
glob = "#{path}#{Gem.suffix_pattern}"
|
2011-01-18 19:08:49 -05:00
|
|
|
$LOAD_PATH.each do |load_path|
|
2018-08-27 06:05:04 -04:00
|
|
|
globbed = Gem::Util.glob_files_in_dir(glob, load_path)
|
2011-01-18 19:08:49 -05:00
|
|
|
|
|
|
|
globbed.each do |load_path_file|
|
|
|
|
files << load_path_file if File.file?(load_path_file.untaint)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
load_plugin_files files
|
|
|
|
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|
|
|
|
|
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
|
|
|
|
|
|
|
|
path.untaint
|
|
|
|
|
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)
|
|
|
|
require 'rubygems/user_interaction'
|
|
|
|
Gem::DefaultUserInteraction.use_ui(ui) do
|
2019-06-06 03:49:40 -04:00
|
|
|
require "bundler"
|
2019-06-06 02:25:18 -04:00
|
|
|
begin
|
|
|
|
@gemdeps = Bundler.setup
|
|
|
|
ensure
|
|
|
|
if Gem::DefaultUserInteraction.ui.is_a?(Gem::SilentUI)
|
|
|
|
Gem::DefaultUserInteraction.ui.close
|
|
|
|
end
|
|
|
|
end
|
2019-04-26 07:26:21 -04:00
|
|
|
Bundler.ui = nil
|
|
|
|
@gemdeps.requested_specs.map(&:to_spec).sort_by(&:name)
|
2013-11-21 18:27:30 -05:00
|
|
|
end
|
2019-04-26 07:26:21 -04:00
|
|
|
|
2017-10-07 21:32:18 -04:00
|
|
|
rescue => e
|
|
|
|
case e
|
|
|
|
when Gem::LoadError, Gem::UnsatisfiableDependencyError, (defined?(Bundler::GemNotFound) ? Bundler::GemNotFound : Gem::LoadError)
|
|
|
|
warn e.message
|
|
|
|
warn "You may need to `gem install -g` to install missing gems"
|
|
|
|
warn ""
|
|
|
|
else
|
|
|
|
raise
|
|
|
|
end
|
2013-11-21 18:27:30 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class << self
|
2019-02-14 07:59:03 -05:00
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
2018-05-17 21:39:13 -04:00
|
|
|
# TODO remove with RubyGems 4.0
|
2013-11-25 14:14:49 -05:00
|
|
|
|
2013-11-21 18:27:30 -05:00
|
|
|
alias detect_gemdeps use_gemdeps # :nodoc:
|
2018-05-17 21:39:13 -04:00
|
|
|
|
|
|
|
extend Gem::Deprecate
|
|
|
|
deprecate :detect_gemdeps, "Gem.use_gemdeps", 2018, 12
|
2019-02-14 07:59:03 -05:00
|
|
|
|
2013-11-21 18:27:30 -05: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
|
|
|
|
|
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)
|
2019-06-01 05:45:11 -04:00
|
|
|
new_format = spec.require_paths.any? {|path| spec.files.any? {|f| f.start_with? path } }
|
2013-09-14 04:59:02 -04:00
|
|
|
|
|
|
|
if new_format
|
|
|
|
prefix_group = spec.require_paths.map {|f| f + "/"}.join("|")
|
|
|
|
prefix_pattern = /^(#{prefix_group})/
|
|
|
|
end
|
|
|
|
|
2017-10-07 21:32:18 -04:00
|
|
|
suffix_pattern = /#{Regexp.union(Gem.suffixes)}\z/
|
|
|
|
|
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
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
@path_to_default_spec_map[file] = spec
|
2017-10-07 21:32:18 -04:00
|
|
|
@path_to_default_spec_map[file.sub(suffix_pattern, "")] = 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)
|
2017-10-07 21:32:18 -04:00
|
|
|
@path_to_default_spec_map[path]
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Remove needless Gem::Specification of default gem from
|
|
|
|
# unresolved default gem list
|
|
|
|
|
|
|
|
def remove_unresolved_default_spec(spec)
|
|
|
|
spec.files.each do |file|
|
|
|
|
@path_to_default_spec_map.delete(file)
|
|
|
|
end
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2017-10-07 21:32:18 -04:00
|
|
|
autoload :BundlerVersionFinder, 'rubygems/bundler_version_finder'
|
2012-12-01 04:52:39 -05:00
|
|
|
autoload :ConfigFile, 'rubygems/config_file'
|
|
|
|
autoload :Dependency, 'rubygems/dependency'
|
|
|
|
autoload :DependencyList, 'rubygems/dependency_list'
|
2013-12-12 19:51:04 -05:00
|
|
|
autoload :Installer, 'rubygems/installer'
|
2015-09-08 18:46:43 -04:00
|
|
|
autoload :Licenses, 'rubygems/util/licenses'
|
2012-12-01 04:52:39 -05:00
|
|
|
autoload :PathSupport, 'rubygems/path_support'
|
|
|
|
autoload :Platform, 'rubygems/platform'
|
|
|
|
autoload :RequestSet, 'rubygems/request_set'
|
|
|
|
autoload :Requirement, 'rubygems/requirement'
|
2013-12-12 19:51:04 -05:00
|
|
|
autoload :Resolver, 'rubygems/resolver'
|
|
|
|
autoload :Source, 'rubygems/source'
|
2012-12-01 04:52:39 -05:00
|
|
|
autoload :SourceList, 'rubygems/source_list'
|
|
|
|
autoload :SpecFetcher, 'rubygems/spec_fetcher'
|
|
|
|
autoload :Specification, 'rubygems/specification'
|
2017-10-07 21:32:18 -04:00
|
|
|
autoload :Util, 'rubygems/util'
|
2012-12-01 04:52:39 -05:00
|
|
|
autoload :Version, 'rubygems/version'
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
require "rubygems/specification"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
require 'rubygems/exceptions'
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
# REFACTOR: This should be pulled out into some kind of hacks file.
|
2018-05-30 09:01:35 -04:00
|
|
|
begin
|
|
|
|
##
|
|
|
|
# Defaults the operating system (or packager) wants to provide for RubyGems.
|
|
|
|
|
|
|
|
require 'rubygems/defaults/operating_system'
|
|
|
|
rescue LoadError
|
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
if defined?(RUBY_ENGINE)
|
2008-06-17 18:04:18 -04:00
|
|
|
begin
|
2010-04-22 04:24:42 -04:00
|
|
|
##
|
2018-05-30 09:01:35 -04:00
|
|
|
# Defaults the Ruby implementation wants to provide for RubyGems
|
2010-04-22 04:24:42 -04:00
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
require "rubygems/defaults/#{RUBY_ENGINE}"
|
2008-06-17 18:04:18 -04:00
|
|
|
rescue LoadError
|
|
|
|
end
|
2010-07-20 14:30:46 -04:00
|
|
|
end
|
2010-07-07 11:40:52 -04:00
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
##
|
2012-11-29 01:52:18 -05:00
|
|
|
# Loads the default specs.
|
|
|
|
Gem::Specification.load_defaults
|
2010-02-21 21:52:35 -05:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
require 'rubygems/core_ext/kernel_gem'
|
|
|
|
require 'rubygems/core_ext/kernel_require'
|
2018-09-24 10:26:00 -04:00
|
|
|
require 'rubygems/core_ext/kernel_warn'
|
2010-02-21 21:52:35 -05:00
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
Gem.use_gemdeps
|