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

ruby-changes:69590

From: Alyssa <ko1@a...>
Date: Fri, 5 Nov 2021 07:23:50 +0900 (JST)
Subject: [ruby-changes:69590] 1506c8228b (master): [rubygems/rubygems] Don't apply `--destdir` twice when running `setup.rb`

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

From 1506c8228b775776ce846e5cfdb6ce4b81963808 Mon Sep 17 00:00:00 2001
From: Alyssa Ross <hi@a...>
Date: Sat, 18 May 2019 15:10:18 +0000
Subject: [rubygems/rubygems] Don't apply `--destdir` twice when running
 `setup.rb`

Prior to this patch, if I ran:

    ruby setup.rb --destdir /foo

Then Bundler files would be written into /foo/foo, because destdir was
being prepended, even though `bundler_spec.bin_dir` already included
destdir.

https://github.com/rubygems/rubygems/commit/9e857ffb52
---
 lib/rubygems/commands/setup_command.rb           | 13 ++++++++++++-
 test/rubygems/test_gem_commands_setup_command.rb | 22 ++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb
index 90f17b90374..edc4008cb82 100644
--- a/lib/rubygems/commands/setup_command.rb
+++ b/lib/rubygems/commands/setup_command.rb
@@ -385,6 +385,18 @@ By default, this RubyGems will install gem as: https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/setup_command.rb#L385
 
     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(Gem.default_dir, "specifications", "bundler-#{bundler_spec.version}.gemspec")
     if File.file? normal_gemspec
@@ -399,7 +411,6 @@ By default, this RubyGems will install gem as: https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/setup_command.rb#L411
     end
 
     bundler_bin_dir = bundler_spec.bin_dir
-    bundler_bin_dir = File.join(options[:destdir], bundler_bin_dir) unless Gem.win_platform?
     mkdir_p bundler_bin_dir, :mode => 0755
     bundler_spec.executables.each do |e|
       cp File.join("bundler", bundler_spec.bindir, e), File.join(bundler_bin_dir, e)
diff --git a/test/rubygems/test_gem_commands_setup_command.rb b/test/rubygems/test_gem_commands_setup_command.rb
index 3aa6bfa2fe5..b66943610dd 100644
--- a/test/rubygems/test_gem_commands_setup_command.rb
+++ b/test/rubygems/test_gem_commands_setup_command.rb
@@ -246,6 +246,28 @@ class TestGemCommandsSetupCommand < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_setup_command.rb#L246
     end
   end
 
+  def test_install_default_bundler_gem_with_destdir_flag
+    @cmd.extend FileUtils
+
+    bin_dir = File.join(@gemhome, 'bin')
+
+    bindir(bin_dir) do
+      destdir = File.join(@tempdir, 'foo')
+
+      @cmd.options[:destdir] = destdir
+
+      @cmd.install_default_bundler_gem bin_dir
+
+      bundler_spec = Gem::Specification.load("bundler/bundler.gemspec")
+      default_spec_path = File.join(Gem.default_specifications_dir, "#{bundler_spec.full_name}.gemspec")
+      spec = Gem::Specification.load(default_spec_path)
+
+      spec.executables.each do |e|
+        assert_path_exist File.join destdir, spec.bin_dir.gsub(/^[a-zA-Z]:/, ''), e
+      end
+    end
+  end
+
   def test_remove_old_lib_files
     lib                   = File.join @install_dir, 'lib'
     lib_rubygems          = File.join lib, 'rubygems'
-- 
cgit v1.2.1


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

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