summaryrefslogtreecommitdiff
path: root/lib/rubygems
diff options
context:
space:
mode:
authorDavid Rodríguez <[email protected]>2020-03-24 07:39:24 +0100
committer<[email protected]>2020-03-24 15:39:24 +0900
commit96064e6f1ce100a37680dc8f9509f06b3350e9c8 ()
tree798b59f015cb82ee3cd0427f80584032175829ba /lib/rubygems
parent930b012ad96bfb0bd12446b89407120744ef92eb (diff)
Sync rubygems with current master (#2889)
Notes: Merged-By: hsbt <[email protected]>
-rw-r--r--lib/rubygems/bundler_version_finder.rb17
-rw-r--r--lib/rubygems/command.rb8
-rw-r--r--lib/rubygems/commands/contents_command.rb2
-rw-r--r--lib/rubygems/commands/update_command.rb4
-rw-r--r--lib/rubygems/core_ext/kernel_require.rb31
-rw-r--r--lib/rubygems/dependency_installer.rb148
-rw-r--r--lib/rubygems/ext/builder.rb4
-rw-r--r--lib/rubygems/install_update_options.rb4
-rw-r--r--lib/rubygems/installer.rb37
-rw-r--r--lib/rubygems/installer_uninstaller_utils.rb8
-rw-r--r--lib/rubygems/source_specific_file.rb6
-rw-r--r--lib/rubygems/spec_fetcher.rb23
-rw-r--r--lib/rubygems/specification.rb14
-rw-r--r--lib/rubygems/test_case.rb19
-rw-r--r--lib/rubygems/uninstaller.rb5
15 files changed, 98 insertions, 232 deletions
@@ -82,12 +82,19 @@ To install the missing version, run `gem install bundler:#{vr.first}`
def self.lockfile_contents
gemfile = ENV["BUNDLE_GEMFILE"]
gemfile = nil if gemfile && gemfile.empty?
- Gem::Util.traverse_parents Dir.pwd do |directory|
- next unless gemfile = Gem::GEM_DEP_FILES.find { |f| File.file?(f.tap(&Gem::UNTAINT)) }
- gemfile = File.join directory, gemfile
- break
- end unless gemfile
return unless gemfile
@@ -77,7 +77,7 @@ class Gem::Command
when Array
@extra_args = value
when String
- @extra_args = value.split(' ')
end
end
@@ -174,8 +174,7 @@ class Gem::Command
alert_error msg
unless suppress_suggestions
- suggestions = Gem::SpecFetcher.fetcher.suggest_gems_from_name gem_name
-
unless suggestions.empty?
alert_error "Possible alternatives: #{suggestions.join(", ")}"
end
@@ -625,8 +624,7 @@ class Gem::Command
# :stopdoc:
HELP = <<-HELP.freeze
-RubyGems is a sophisticated package manager for Ruby. This is a
-basic help message containing pointers to more information.
Usage:
gem -h/--help
@@ -167,7 +167,7 @@ prefix or only the files that are requireable.
end
def spec_for(name)
- spec = Gem::Specification.find_all_by_name(name, @version).last
return spec if spec
@@ -184,14 +184,14 @@ command to remove old versions.
else
require "tmpdir"
tmpdir = Dir.mktmpdir
- FileUtils.mv Gem.plugins_dir, tmpdir
status = yield
if status
FileUtils.rm_rf tmpdir
else
- FileUtils.mv File.join(tmpdir, "plugins"), Gem.plugins_dir
end
status
@@ -43,18 +43,21 @@ module Kernel
# https://.com/rubygems/rubygems/pull/1868
resolved_path = begin
rp = nil
- $LOAD_PATH[0...Gem.load_path_insert_index || -1].each do |lp|
- safe_lp = lp.dup.tap(&Gem::UNTAINT)
- begin
- if File.symlink? safe_lp # for backward compatibility
- next
end
- rescue SecurityError
- RUBYGEMS_ACTIVATION_MONITOR.exit
- raise
- end
- Gem.suffixes.each do |s|
full_path = File.expand_path(File.join(safe_lp, "#{path}#{s}"))
if File.file?(full_path)
rp = full_path
@@ -67,12 +70,8 @@ module Kernel
end
if resolved_path
- begin
- RUBYGEMS_ACTIVATION_MONITOR.exit
- return gem_original_require(resolved_path)
- rescue LoadError
- RUBYGEMS_ACTIVATION_MONITOR.enter
- end
end
if spec = Gem.find_unresolved_default_spec(path)
@@ -7,7 +7,6 @@ require 'rubygems/spec_fetcher'
require 'rubygems/user_interaction'
require 'rubygems/source'
require 'rubygems/available_set'
-require 'rubygems/deprecate'
##
# Installs a gem along with all its dependencies from local and remote gems.
@@ -15,7 +14,6 @@ require 'rubygems/deprecate'
class Gem::DependencyInstaller
include Gem::UserInteraction
- extend Gem::Deprecate
DEFAULT_OPTIONS = { # :nodoc:
:env_shebang => false,
@@ -107,27 +105,6 @@ class Gem::DependencyInstaller
end
##
- # Creates an AvailableSet to install from based on +dep_or_name+ and
- # +version+
-
- def available_set_for(dep_or_name, version) # :nodoc:
- if String === dep_or_name
- Gem::Deprecate.skip_during do
- find_spec_by_name_and_version dep_or_name, version, @prerelease
- end
- else
- dep = dep_or_name.dup
- dep.prerelease = @prerelease
- @available = Gem::Deprecate.skip_during do
- find_gems_with_sources dep
- end
- end
-
- @available.pick_best!
- end
- deprecate :available_set_for, :none, 2019, 12
-
- ##
# Indicated, based on the requested domain, if local
# gems should be considered.
@@ -143,131 +120,6 @@ class Gem::DependencyInstaller
@domain == :both or @domain == :remote
end
- ##
- # Returns a list of pairs of gemspecs and source_uris that match
- # Gem::Dependency +dep+ from both local (Dir.pwd) and remote (Gem.sources)
- # sources. Gems are sorted with newer gems preferred over older gems, and
- # local gems preferred over remote gems.
-
- def find_gems_with_sources(dep, best_only=false) # :nodoc:
- set = Gem::AvailableSet.new
-
- if consider_local?
- sl = Gem::Source::Local.new
-
- if spec = sl.find_gem(dep.name)
- if dep.matches_spec? spec
- set.add spec, sl
- end
- end
- end
-
- if consider_remote?
- begin
- # This is pulled from #spec_for_dependency to allow
- # us to filter tuples before fetching specs.
- tuples, errors = Gem::SpecFetcher.fetcher.search_for_dependency dep
-
- if best_only && !tuples.empty?
- tuples.sort! do |a,b|
- if b[0].version == a[0].version
- if b[0].platform != Gem::Platform::RUBY
- 1
- else
- -1
- end
- else
- b[0].version <=> a[0].version
- end
- end
- tuples = [tuples.first]
- end
-
- specs = []
- tuples.each do |tup, source|
- begin
- spec = source.fetch_spec(tup)
- rescue Gem::RemoteFetcher::FetchError => e
- errors << Gem::SourceFetchProblem.new(source, e)
- else
- specs << [spec, source]
- end
- end
-
- if @errors
- @errors += errors
- else
- @errors = errors
- end
-
- set << specs
-
- rescue Gem::RemoteFetcher::FetchError => e
- # FIX if there is a problem talking to the network, we either need to always tell
- # the user (no really_verbose) or fail hard, not silently tell them that we just
- # couldn't find their requested gem.
- verbose do
- "Error fetching remote data:\t\t#{e.message}\n" \
- "Falling back to local-only install"
- end
- @domain = :local
- end
- end
-
- set
- end
- deprecate :find_gems_with_sources, :none, 2019, 12
-
- ##
- # Finds a spec and the source_uri it came from for gem +gem_name+ and
- # +version+. Returns an Array of specs and sources required for
- # installation of the gem.
-
- def find_spec_by_name_and_version(gem_name,
- version = Gem::Requirement.default,
- prerelease = false)
- set = Gem::AvailableSet.new
-
- if consider_local?
- if gem_name =~ /\.gem$/ and File.file? gem_name
- src = Gem::Source::SpecificFile.new(gem_name)
- set.add src.spec, src
- elsif gem_name =~ /\.gem$/
- Dir[gem_name].each do |name|
- begin
- src = Gem::Source::SpecificFile.new name
- set.add src.spec, src
- rescue Gem::Package::FormatError
- end
- end
- else
- local = Gem::Source::Local.new
-
- if s = local.find_gem(gem_name, version)
- set.add s, local
- end
- end
- end
-
- if set.empty?
- dep = Gem::Dependency.new gem_name, version
- dep.prerelease = true if prerelease
-
- set = Gem::Deprecate.skip_during do
- find_gems_with_sources(dep, true)
- end
-
- set.match_platform!
- end
-
- if set.empty?
- raise Gem::SpecificGemNotFoundException.new(gem_name, version, @errors)
- end
-
- @available = set
- end
- deprecate :find_spec_by_name_and_version, :none, 2019, 12
-
def in_background(what) # :nodoc:
fork_happened = false
if @build_docs_in_background and Process.respond_to?(:fork)
@@ -68,7 +68,9 @@ class Gem::Ext::Builder
results << (command.respond_to?(:shelljoin) ? command.shelljoin : command)
require "open3"
- output, status = Open3.capture2e(*command)
if verbose
puts output
else
@@ -25,8 +25,8 @@ module Gem::InstallUpdateOptions
end
add_option(:"Install/Update", '-n', '--bindir DIR',
- 'Directory where executables are',
- 'located') do |value, options|
options[:bin_dir] = File.expand_path(value)
end
@@ -47,11 +47,6 @@ class Gem::Installer
include Gem::InstallerUninstallerUtils
##
- # Filename of the gem being installed.
-
- attr_reader :gem
-
- ##
# The directory a gem's executables will be installed into
attr_reader :bin_dir
@@ -487,13 +482,7 @@ class Gem::Installer
def generate_bin # :nodoc:
return if spec.executables.nil? or spec.executables.empty?
- begin
- Dir.mkdir @bin_dir, *[options[:dir_mode] && 0755].compact
- rescue SystemCallError
- raise unless File.directory? @bin_dir
- end
-
- raise Gem::FilePermissionError.new(@bin_dir) unless File.writable? @bin_dir
spec.executables.each do |filename|
filename.tap(&Gem::UNTAINT)
@@ -523,10 +512,12 @@ class Gem::Installer
latest = Gem::Specification.latest_spec_for(spec.name)
return if latest && latest.version > spec.version
if spec.plugins.empty?
- remove_plugins_for(spec)
else
- regenerate_plugins_for(spec)
end
end
@@ -690,6 +681,7 @@ class Gem::Installer
@force = options[:force]
@install_dir = options[:install_dir]
@gem_home = options[:install_dir] || Gem.dir
@ignore_dependencies = options[:ignore_dependencies]
@format_executable = options[:format_executable]
@wrappers = options[:wrappers]
@@ -890,6 +882,13 @@ TEXT
end
##
# Performs various checks before installing the gem such as the install
# repository is writable and its directories exist, required Ruby and
# rubygems versions are met and that dependencies are installed.
@@ -953,4 +952,14 @@ TEXT
@package.copy_to cache_file
end
end
@@ -5,9 +5,9 @@
module Gem::InstallerUninstallerUtils
- def regenerate_plugins_for(spec)
spec.plugins.each do |plugin|
- plugin_script_path = File.join Gem.plugins_dir, "#{spec.name}_plugin#{File.extname(plugin)}"
File.open plugin_script_path, 'wb' do |file|
file.puts "require '#{plugin}'"
@@ -17,8 +17,8 @@ module Gem::InstallerUninstallerUtils
end
end
- def remove_plugins_for(spec)
- FileUtils.rm_f Gem::Util.glob_files_in_dir("#{spec.name}#{Gem.plugin_suffix_pattern}", Gem.plugins_dir)
end
end
@@ -1,6 +0,0 @@
-# frozen_string_literal: true
-require 'rubygems/source/specific_file'
-
-unless Gem::Deprecate.skip
- Kernel.warn "#{Gem.location_of_caller(3).join(':')}: Warning: Requiring rubygems/source_specific_file is deprecated; please use rubygems/source/specific_file instead."
-end
@@ -171,30 +171,33 @@ class Gem::SpecFetcher
# Suggests gems based on the supplied +gem_name+. Returns an array of
# alternative gem names.
- def suggest_gems_from_name(gem_name, type = :latest)
gem_name = gem_name.downcase.tr('_-', '')
max = gem_name.size / 2
names = available_specs(type).first.values.flatten(1)
matches = names.map do |n|
next unless n.match_platform?
-
- distance = levenshtein_distance gem_name, n.name.downcase.tr('_-', '')
-
- next if distance >= max
-
- return [n.name] if distance == 0
-
- [n.name, distance]
end.compact
matches = if matches.empty? && type != :prerelease
suggest_gems_from_name gem_name, :prerelease
else
matches.uniq.sort_by { |name, dist| dist }
end
- matches.first(5).map { |name, dist| name }
end
##
@@ -790,16 +790,6 @@ class Gem::Specification < Gem::BasicSpecification
end
private_class_method :map_stubs
- def self.uniq_by(list, &block) # :nodoc:
- list.uniq(&block)
- end
- private_class_method :uniq_by
-
- def self.sort_by!(list, &block)
- list.sort_by!(&block)
- end
- private_class_method :sort_by!
-
def self.each_spec(dirs) # :nodoc:
each_gemspec(dirs) do |path|
spec = self.load path
@@ -814,7 +804,7 @@ class Gem::Specification < Gem::BasicSpecification
@@stubs ||= begin
pattern = "*.gemspec"
stubs = Gem.loaded_specs.values + installed_stubs(dirs, pattern) + default_stubs(pattern)
- stubs = uniq_by(stubs) { |stub| stub.full_name }
_resort!(stubs)
@@stubs_by_name = stubs.select { |s| Gem::Platform.match s.platform }.group_by(&:name)
@@ -847,7 +837,7 @@ class Gem::Specification < Gem::BasicSpecification
stubs = Gem.loaded_specs.values +
installed_stubs(dirs, pattern).select { |s| Gem::Platform.match s.platform } +
default_stubs(pattern)
- stubs = uniq_by(stubs) { |stub| stub.full_name }.group_by(&:name)
stubs.each_value { |v| _resort!(v) }
@@stubs_by_name.merge! stubs
@@ -78,6 +78,20 @@ module Gem
end
end
##
# RubyGemTestCase provides a variety of methods for testing rubygems and
# gem-related behavior in a sandbox. Through RubyGemTestCase you can install
@@ -1246,10 +1260,7 @@ Also, a list:
end
begin
- require "rbconfig"
- File.join(RbConfig::CONFIG["bindir"],
- RbConfig::CONFIG["ruby_install_name"] +
- RbConfig::CONFIG["EXEEXT"])
rescue LoadError
"ruby"
end
@@ -50,6 +50,7 @@ class Gem::Uninstaller
@gem = gem
@version = options[:version] || Gem::Requirement.default
@gem_home = File.realpath(options[:install_dir] || Gem.dir)
@force_executables = options[:executables]
@force_all = options[:all]
@force_ignore = options[:ignore]
@@ -281,7 +282,7 @@ class Gem::Uninstaller
def remove_plugins(spec) # :nodoc:
return if spec.plugins.empty?
- remove_plugins_for(spec)
end
##
@@ -291,7 +292,7 @@ class Gem::Uninstaller
latest = Gem::Specification.latest_spec_for(@spec.name)
return if latest.nil?
- regenerate_plugins_for(latest)
end
##