[前][次][番号順一覧][スレッド一覧]

ruby-changes:72587

From: David <ko1@a...>
Date: Mon, 18 Jul 2022 19:08:06 +0900 (JST)
Subject: [ruby-changes:72587] a74634de10 (master): [rubygems/rubygems] Fix upgrading RubyGems with a customized `Gem.default_dir`

https://git.ruby-lang.org/ruby.git/commit/?id=a74634de10

From a74634de106df63fb39a7077561657bb61a0bc97 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Sat, 16 Jul 2022 12:09:54 +0200
Subject: [rubygems/rubygems] Fix upgrading RubyGems with a customized
 `Gem.default_dir`

https://github.com/rubygems/rubygems/commit/16d01f9486
---
 lib/rubygems/commands/setup_command.rb           | 28 ++++++++----------------
 test/rubygems/test_gem_commands_setup_command.rb | 18 +++++++++++++++
 2 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb
index 35b500936d..f85d435f58 100644
--- a/lib/rubygems/commands/setup_command.rb
+++ b/lib/rubygems/commands/setup_command.rb
@@ -360,34 +360,24 @@ By default, this RubyGems will install gem as: https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/setup_command.rb#L360
   end
 
   def install_default_bundler_gem(bin_dir)
-    specs_dir = File.join(default_dir, "specifications", "default")
-    mkdir_p specs_dir, :mode => 0755
-
-    bundler_spec = Dir.chdir("bundler") { Gem::Specification.load("bundler.gemspec") }
-
     current_default_spec = Gem::Specification.default_stubs.find {|s| s.name == "bundler" }
-    if current_default_spec
-      File.delete(current_default_spec.loaded_from)
+    specs_dir = if current_default_spec
       Gem::Specification.remove_spec current_default_spec
+      loaded_from = current_default_spec.loaded_from
+      File.delete(loaded_from)
+      File.dirname(loaded_from)
+    else
+      File.join(default_dir, "specifications", "default")
     end
 
+    mkdir_p specs_dir, :mode => 0755
+
+    bundler_spec = Dir.chdir("bundler") { Gem::Specification.load("bundler.gemspec") }
     default_spec_path = File.join(specs_dir, "#{bundler_spec.full_name}.gemspec")
     Gem.write_binary(default_spec_path, bundler_spec.to_ruby)
 
     bundler_spec = Gem::Specification.load(default_spec_path)
 
-    # The base_dir value for a specification is inferred by walking up from the
-    # folder where the spec was `loaded_from`. In the case of default gems, we
-    # walk up two levels, because they live at `specifications/default/`, whereas
-    # in the case of regular gems we walk up just one level because they live at
-    # `specifications/`. However, in this case, the gem we are installing is
-    # misdetected as a regular gem, when it's a default gem in reality. This is
-    # because when there's a `:destdir`, the `loaded_from` path has changed and
-    # doesn't match `Gem.default_specifications_dir` which is the criteria to
-    # tag a gem as a default gem. So, in that case, write the correct
-    # `@base_dir` directly.
-    bundler_spec.instance_variable_set(:@base_dir, File.dirname(File.dirname(specs_dir)))
-
     # Remove gemspec that was same version of vendored bundler.
     normal_gemspec = File.join(default_dir, "specifications", "bundler-#{bundler_spec.version}.gemspec")
     if File.file? normal_gemspec
diff --git a/test/rubygems/test_gem_commands_setup_command.rb b/test/rubygems/test_gem_commands_setup_command.rb
index ab563b28ee..69db09f747 100644
--- a/test/rubygems/test_gem_commands_setup_command.rb
+++ b/test/rubygems/test_gem_commands_setup_command.rb
@@ -228,6 +228,24 @@ class TestGemCommandsSetupCommand < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_setup_command.rb#L228
     assert_path_exist "#{Gem.dir}/gems/bundler-audit-1.0.0"
   end
 
+  def test_install_default_bundler_gem_with_default_gems_not_installed_at_default_dir
+    @cmd.extend FileUtils
+
+    gemhome2 = File.join(@tempdir, 'gemhome2')
+    Gem.instance_variable_set(:@default_dir, gemhome2)
+
+    FileUtils.mkdir_p gemhome2
+    bin_dir = File.join(gemhome2, 'bin')
+
+    @cmd.install_default_bundler_gem bin_dir
+
+    default_dir = Gem.default_specifications_dir
+
+    # expect to remove other versions of bundler gemspecs on default specification directory.
+    assert_path_not_exist File.join(default_dir, "bundler-1.15.4.gemspec")
+    assert_path_exist File.join(default_dir, "bundler-#{BUNDLER_VERS}.gemspec")
+  end
+
   def test_install_default_bundler_gem_with_force_flag
     @cmd.extend FileUtils
 
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]