From 7fbb9078fe61104606a40e4e450a2cd1a33f8ca1 Mon Sep 17 00:00:00 2001 From: hsbt Date: Mon, 28 Mar 2016 02:26:39 +0000 Subject: * lib/rubygems.rb, lib/rubygems/*, test/rubygems/*: Update rubygems-2.6.2. Please see entries of 2.6.2 on https://github.com/rubygems/rubygems/blob/master/History.txt git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54308 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rubygems.rb | 43 +++++++++++++++++++++++++-------- lib/rubygems/core_ext/kernel_require.rb | 13 ++++++---- lib/rubygems/dependency.rb | 13 +++++----- lib/rubygems/installer.rb | 5 ++-- lib/rubygems/installer_test_case.rb | 2 ++ lib/rubygems/resolver.rb | 4 +-- lib/rubygems/test_case.rb | 11 ++++++++- 7 files changed, 65 insertions(+), 26 deletions(-) (limited to 'lib') diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 9be2398f3d..8783756cd9 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -10,7 +10,7 @@ require 'rbconfig' require 'thread' module Gem - VERSION = '2.6.1' + VERSION = '2.6.2' end # Must be first since it unloads the prelude from 1.9.2 @@ -174,14 +174,6 @@ module Gem @pre_reset_hooks ||= [] @post_reset_hooks ||= [] - 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 - ## # Try to activate a gem containing +path+. Returns true if # activation succeeded or wasn't needed because it was already @@ -243,11 +235,15 @@ module Gem requirements = Gem::Requirement.default if requirements.empty? + find_spec_for_exe(name, exec_name, requirements).bin_file exec_name + end + + def self.find_spec_for_exe name, exec_name, requirements dep = Gem::Dependency.new name, requirements loaded = Gem.loaded_specs[name] - return loaded.bin_file exec_name if loaded && dep.matches_spec?(loaded) + return loaded if loaded && dep.matches_spec?(loaded) specs = dep.matching_specs(true) @@ -263,6 +259,24 @@ module Gem raise Gem::GemNotFoundException, msg end + spec + end + private_class_method :find_spec_for_exe + + ## + # Find the full path to the executable for gem +name+. If the +exec_name+ + # is not given, the gem's default_executable is chosen, otherwise the + # 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. + + def self.activate_bin_path name, exec_name, requirement # :nodoc: + spec = find_spec_for_exe name, exec_name, [requirement] + Gem::LOADED_SPECS_MUTEX.synchronize { spec.activate } spec.bin_file exec_name end @@ -849,6 +863,15 @@ An Array was passed in from #{caller[3]} @ruby_api_version ||= RbConfig::CONFIG['ruby_version'].dup end + 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 = {} } + ## # Returns the latest release-version specification for the gem +name+. diff --git a/lib/rubygems/core_ext/kernel_require.rb b/lib/rubygems/core_ext/kernel_require.rb index 6c00f3fd9b..99093a1338 100755 --- a/lib/rubygems/core_ext/kernel_require.rb +++ b/lib/rubygems/core_ext/kernel_require.rb @@ -121,14 +121,17 @@ module Kernel rescue LoadError => load_error RUBYGEMS_ACTIVATION_MONITOR.enter - if load_error.message.start_with?("Could not find") or - (load_error.message.end_with?(path) and Gem.try_activate(path)) then - RUBYGEMS_ACTIVATION_MONITOR.exit - return gem_original_require(path) - else + begin + if load_error.message.start_with?("Could not find") or + (load_error.message.end_with?(path) and Gem.try_activate(path)) then + require_again = true + end + ensure RUBYGEMS_ACTIVATION_MONITOR.exit end + return gem_original_require(path) if require_again + raise load_error end diff --git a/lib/rubygems/dependency.rb b/lib/rubygems/dependency.rb index bf24b6e724..b7aea4692b 100644 --- a/lib/rubygems/dependency.rb +++ b/lib/rubygems/dependency.rb @@ -286,7 +286,9 @@ class Gem::Dependency } end - matches.sort_by { |s| s.sort_obj } # HACK: shouldn't be needed + # `stubs_for` returns oldest first, but `matching_specs` is supposed to + # return newest first, so just reverse the list + matches.reverse end ## @@ -302,14 +304,13 @@ class Gem::Dependency # TODO: check Gem.activated_spec[self.name] in case matches falls outside if matches.empty? then - specs = Gem::Specification.find_all { |s| - s.name == name - }.map { |x| x.full_name } + specs = Gem::Specification.stubs_for name if specs.empty? - total = Gem::Specification.to_a.size + total = Gem::Specification.stubs.size msg = "Could not find '#{name}' (#{requirement}) among #{total} total gem(s)\n".dup else + specs = specs.map(&:full_name) msg = "Could not find '#{name}' (#{requirement}) - did find: [#{specs.join ','}]\n".dup end msg << "Checked in 'GEM_PATH=#{Gem.path.join(File::PATH_SEPARATOR)}', execute `gem env` for more information" @@ -334,6 +335,6 @@ class Gem::Dependency matches.delete_if { |spec| spec.nil? || spec.version.prerelease? } unless prerelease? - matches.last + matches.first end end diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 85358e0d1a..a88d393336 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -216,7 +216,8 @@ class Gem::Installer existing = io.read.slice(%r{ ^( gem \s | - load \s Gem\.bin_path\( + load \s Gem\.bin_path\( | + load \s Gem\.activate_bin_path\( ) (['"])(.*?)(\2), }x, 3) @@ -719,7 +720,7 @@ if ARGV.first end end -load Gem.bin_path('#{spec.name}', '#{bin_file_name}', version) +load Gem.activate_bin_path('#{spec.name}', '#{bin_file_name}', version) TEXT end diff --git a/lib/rubygems/installer_test_case.rb b/lib/rubygems/installer_test_case.rb index bdefedc9f6..eccd5711c2 100644 --- a/lib/rubygems/installer_test_case.rb +++ b/lib/rubygems/installer_test_case.rb @@ -170,6 +170,8 @@ class Gem::InstallerTestCase < Gem::TestCase EOF end + yield @spec if block_given? + use_ui ui do FileUtils.rm_f @gem diff --git a/lib/rubygems/resolver.rb b/lib/rubygems/resolver.rb index 3a406d0444..50a547e1be 100644 --- a/lib/rubygems/resolver.rb +++ b/lib/rubygems/resolver.rb @@ -193,7 +193,7 @@ class Gem::Resolver conflict = e.conflicts.values.first raise Gem::DependencyResolutionError, Conflict.new(conflict.requirement_trees.first.first, conflict.existing, conflict.requirement) ensure - @output.close if @output and !debug? + @output.close if defined?(@output) and !debug? end ## @@ -233,7 +233,7 @@ class Gem::Resolver exc.errors = @set.errors raise exc end - possibles.sort_by { |s| [s.source, s.version, s.platform.to_s == Gem::Platform.local.to_s ? 1 : 0] }. + possibles.sort_by { |s| [s.source, s.version, Gem::Platform.local =~ s.platform ? 1 : 0] }. map { |s| ActivationRequest.new s, dependency, [] } end diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index bde4ed6713..f7ae97cd8d 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -223,6 +223,10 @@ class Gem::TestCase < MiniTest::Unit::TestCase @orig_gem_spec_cache = ENV['GEM_SPEC_CACHE'] @orig_rubygems_gemdeps = ENV['RUBYGEMS_GEMDEPS'] @orig_rubygems_host = ENV['RUBYGEMS_HOST'] + ENV.keys.find_all { |k| k.start_with?('GEM_REQUIREMENT_') }.each do |k| + ENV.delete k + end + @orig_gem_env_requirements = ENV.to_hash ENV['GEM_VENDOR'] = nil @@ -288,6 +292,7 @@ class Gem::TestCase < MiniTest::Unit::TestCase ENV['HOME'] = @userhome Gem.instance_variable_set :@user_home, nil Gem.instance_variable_set :@gemdeps, nil + Gem.instance_variable_set :@env_requirements_by_name, nil Gem.send :remove_instance_variable, :@ruby_version if Gem.instance_variables.include? :@ruby_version @@ -379,6 +384,11 @@ class Gem::TestCase < MiniTest::Unit::TestCase FileUtils.rm_rf @tempdir unless ENV['KEEP_FILES'] + ENV.clear + @orig_gem_env_requirements.each do |k,v| + ENV[k] = v + end + ENV['GEM_HOME'] = @orig_gem_home ENV['GEM_PATH'] = @orig_gem_path ENV['GEM_VENDOR'] = @orig_gem_vendor @@ -1504,4 +1514,3 @@ tmpdirs << (ENV['GEM_PATH'] = Dir.mktmpdir("path")) pid = $$ END {tmpdirs.each {|dir| Dir.rmdir(dir)} if $$ == pid} Gem.clear_paths - -- cgit v1.2.3