ruby-changes:61545
From: David <ko1@a...>
Date: Fri, 5 Jun 2020 07:34:25 +0900 (JST)
Subject: [ruby-changes:61545] f8f5e7fadf (master): [rubygems/rubygems] Respect files loaded from default gems before rubygems
https://git.ruby-lang.org/ruby.git/commit/?id=f8f5e7fadf From f8f5e7fadf689a11a8ee28b7af4e7777e2dec1ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...> Date: Wed, 25 Mar 2020 15:55:16 +0100 Subject: [rubygems/rubygems] Respect files loaded from default gems before rubygems https://github.com/rubygems/rubygems/commit/f3da3c1190 diff --git a/lib/rubygems.rb b/lib/rubygems.rb index b03d747..ca80326 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -1226,6 +1226,8 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L1226 next unless $~ end + spec.activate if already_loaded?(file) + @path_to_default_spec_map[file] = spec @path_to_default_spec_map[file.sub(suffix_regexp, "")] = spec end @@ -1291,6 +1293,18 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L1293 attr_reader :pre_uninstall_hooks + private + + def already_loaded?(file) + default_gem_load_paths.find do |load_path_entry| + $LOADED_FEATURES.include?("#{load_path_entry}/#{file}") + end + end + + def default_gem_load_paths + @default_gem_load_paths ||= $LOAD_PATH[load_path_insert_index..-1] + end + end ## diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index 9b83f03..fef9540 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -803,6 +803,7 @@ class Gem::TestCase < Minitest::Test https://github.com/ruby/ruby/blob/trunk/lib/rubygems/test_case.rb#L803 lib_dir = File.join(@tempdir, "default_gems", "lib") lib_dir.instance_variable_set(:@gem_prelude_index, lib_dir) + Gem.instance_variable_set(:@default_gem_load_paths, [*Gem.instance_variable_get(:@default_gem_load_paths), lib_dir]) $LOAD_PATH.unshift(lib_dir) files.each do |file| rb_path = File.join(lib_dir, file) diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb index 56aa37f..2b11e26 100644 --- a/test/rubygems/test_require.rb +++ b/test/rubygems/test_require.rb @@ -300,6 +300,24 @@ class TestGemRequire < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_require.rb#L300 $LOAD_PATH.replace lp if load_path_changed end + def test_activate_via_require_respects_loaded_default_from_default_gems + a1 = new_default_spec "a", "1", nil, "a.rb" + + # simulate requiring a default gem before rubygems is loaded + Kernel.send(:gem_original_require, "a") + + # simulate registering default specs on loading rubygems + install_default_gems a1 + + a2 = util_spec "a", "2", nil, "lib/a.rb" + + install_specs a2 + + refute_require 'a' + + assert_equal %w[a-1], loaded_spec_names + end + def test_already_activated_direct_conflict a1 = util_spec "a", "1", { "b" => "> 0" } b1 = util_spec "b", "1", { "c" => ">= 1" }, "lib/ib.rb" -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/