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

ruby-changes:69608

From: David <ko1@a...>
Date: Fri, 5 Nov 2021 23:21:11 +0900 (JST)
Subject: [ruby-changes:69608] 907aa47527 (master): [rubygems/rubygems] Fix `ruby setup.rb` command when `--prefix` is passed

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

From 907aa4752752869193f333c4114da85080ec03e3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Thu, 4 Nov 2021 19:27:17 +0100
Subject: [rubygems/rubygems] Fix `ruby setup.rb` command when `--prefix` is
 passed

https://github.com/rubygems/rubygems/commit/8d04092f6e
---
 lib/rubygems/commands/setup_command.rb           | 16 ++++++++++++++--
 test/rubygems/test_gem_commands_setup_command.rb | 18 ++++++++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb
index 2041d67c0d3..ed0a96d19d0 100644
--- a/lib/rubygems/commands/setup_command.rb
+++ b/lib/rubygems/commands/setup_command.rb
@@ -360,7 +360,7 @@ 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 = prepend_destdir_if_present(Gem.default_specifications_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") }
@@ -388,7 +388,7 @@ By default, this RubyGems will install gem as: https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/setup_command.rb#L388
     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")
+    normal_gemspec = File.join(default_dir, "specifications", "bundler-#{bundler_spec.version}.gemspec")
     if File.file? normal_gemspec
       File.delete normal_gemspec
     end
@@ -607,6 +607,18 @@ abort "#{deprecation_message}" https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/setup_command.rb#L607
 
   private
 
+  def default_dir
+    prefix = options[:prefix]
+
+    if prefix.empty?
+      dir = Gem.default_dir
+    else
+      dir = prefix
+    end
+
+    prepend_destdir_if_present(dir)
+  end
+
   def prepend_destdir_if_present(path)
     destdir = options[:destdir]
     return path if destdir.empty?
diff --git a/test/rubygems/test_gem_commands_setup_command.rb b/test/rubygems/test_gem_commands_setup_command.rb
index 59ff45b61e5..50f99bc4198 100644
--- a/test/rubygems/test_gem_commands_setup_command.rb
+++ b/test/rubygems/test_gem_commands_setup_command.rb
@@ -259,6 +259,24 @@ class TestGemCommandsSetupCommand < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_setup_command.rb#L259
     end
   end
 
+  def test_install_default_bundler_gem_with_destdir_and_prefix_flags
+    @cmd.extend FileUtils
+
+    destdir = File.join(@tempdir, 'foo')
+    bin_dir = File.join(destdir, 'bin')
+
+    @cmd.options[:destdir] = destdir
+    @cmd.options[:prefix] = "/"
+
+    @cmd.install_default_bundler_gem bin_dir
+
+    spec = Gem::Specification.load("bundler/bundler.gemspec")
+
+    spec.executables.each do |e|
+      assert_path_exist File.join destdir, 'gems', spec.full_name, spec.bindir, e
+    end
+  end
+
   def test_remove_old_lib_files
     lib                   = RbConfig::CONFIG["sitelibdir"]
     lib_rubygems          = File.join lib, 'rubygems'
-- 
cgit v1.2.1


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

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