summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2021-01-30 20:43:44 +0900
committernagachika <nagachika@ruby-lang.org>2021-01-30 20:43:44 +0900
commit99b4f20fd65075d2d9ee02f8c7a6b5d6a914ce31 (patch)
tree873aba7eced9f3ec7938c2ef4efe1dff8f171b40 /lib
parentd0693391103672b7fc3976e5ae8ae414059b3e97 (diff)
Merge RubyGems-3.1.6 [Bug #16926]
https://github.com/ruby/ruby/pull/4122
Diffstat (limited to 'lib')
-rw-r--r--lib/rubygems.rb23
-rw-r--r--lib/rubygems/core_ext/kernel_require.rb60
-rw-r--r--lib/rubygems/test_case.rb1
3 files changed, 39 insertions, 45 deletions
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index d8b4dc74f2..f8ca70385e 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -9,7 +9,7 @@
require 'rbconfig'
module Gem
- VERSION = "3.1.5".freeze
+ VERSION = "3.1.6".freeze
end
# Must be first since it unloads the prelude from 1.9.2
@@ -659,22 +659,25 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
index = $LOAD_PATH.index RbConfig::CONFIG['sitelibdir']
- index
+ index || 0
+ end
+
+ ##
+ # 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
##
# 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
+ @activated_gem_paths = activated_gem_paths + paths.size
- 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
+ # gem directories must come after -I and ENV['RUBYLIB']
+ $LOAD_PATH.insert(Gem.load_path_insert_index, *paths)
end
@yaml_loaded = false
diff --git a/lib/rubygems/core_ext/kernel_require.rb b/lib/rubygems/core_ext/kernel_require.rb
index 60f4d18712..115ae0cb50 100644
--- a/lib/rubygems/core_ext/kernel_require.rb
+++ b/lib/rubygems/core_ext/kernel_require.rb
@@ -39,49 +39,40 @@ module Kernel
path = path.to_path if path.respond_to? :to_path
- # Ensure -I beats a default gem
- # https://github.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
-
+ if spec = Gem.find_unresolved_default_spec(path)
+ # Ensure -I beats a default gem
+ resolved_path = begin
+ rp = nil
+ load_path_check_index = Gem.load_path_insert_index - Gem.activated_gem_paths
Gem.suffixes.each do |s|
- full_path = File.expand_path(File.join(safe_lp, "#{path}#{s}"))
- if File.file?(full_path)
- rp = full_path
- break
+ $LOAD_PATH[0...load_path_check_index].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
+
+ full_path = File.expand_path(File.join(safe_lp, "#{path}#{s}"))
+ if File.file?(full_path)
+ rp = full_path
+ break
+ end
end
+ break if rp
end
- break if rp
- end
- rp
- end
-
- if resolved_path
- begin
- RUBYGEMS_ACTIVATION_MONITOR.exit
- return gem_original_require(resolved_path)
- rescue LoadError
- RUBYGEMS_ACTIVATION_MONITOR.enter
+ rp
end
- end
- if spec = Gem.find_unresolved_default_spec(path)
begin
Kernel.send(:gem, spec.name, Gem::Requirement.default_prerelease)
rescue Exception
RUBYGEMS_ACTIVATION_MONITOR.exit
raise
- end
+ end unless resolved_path
end
# If there are no unresolved deps, then we can use just try
@@ -157,8 +148,7 @@ module Kernel
RUBYGEMS_ACTIVATION_MONITOR.enter
begin
- if load_error.message.start_with?("Could not find") or
- (load_error.message.end_with?(path) and Gem.try_activate(path))
+ if load_error.message.end_with?(path) and Gem.try_activate(path)
require_again = true
end
ensure
diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb
index 89403206f9..c6f5f29d4e 100644
--- a/lib/rubygems/test_case.rb
+++ b/lib/rubygems/test_case.rb
@@ -385,6 +385,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni
Gem::Security.reset
Gem.loaded_specs.clear
+ Gem.instance_variable_set(:@activated_gem_paths, 0)
Gem.clear_default_specs
Bundler.reset!