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

ruby-changes:59337

From: Hiroshi <ko1@a...>
Date: Fri, 20 Dec 2019 11:55:54 +0900 (JST)
Subject: [ruby-changes:59337] e672494cd7 (master): Merge RubyGems 3.1.2

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

From e672494cd737b8fea3a186aeb5c2c17d1a18cb96 Mon Sep 17 00:00:00 2001
From: Hiroshi SHIBATA <hsbt@r...>
Date: Fri, 20 Dec 2019 11:50:32 +0900
Subject: Merge RubyGems 3.1.2


diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index 8eedc97..57cb70c 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -9,7 +9,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L9
 require 'rbconfig'
 
 module Gem
-  VERSION = "3.1.1".freeze
+  VERSION = "3.1.2".freeze
 end
 
 # Must be first since it unloads the prelude from 1.9.2
diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb
index 7844e9d..579776d 100644
--- a/lib/rubygems/commands/setup_command.rb
+++ b/lib/rubygems/commands/setup_command.rb
@@ -17,6 +17,7 @@ class Gem::Commands::SetupCommand < Gem::Command https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/setup_command.rb#L17
 
     super 'setup', 'Install RubyGems',
           :format_executable => true, :document => %w[ri],
+          :force => true,
           :site_or_vendor => 'sitelibdir',
           :destdir => '', :prefix => '', :previous_version => '',
           :regenerate_binstubs => true
@@ -88,6 +89,11 @@ class Gem::Commands::SetupCommand < Gem::Command https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/setup_command.rb#L89
       options[:regenerate_binstubs] = value
     end
 
+    add_option '-f', '--[no-]force',
+               'Forcefully overwrite binstubs' do |value, options|
+      options[:force] = value
+    end
+
     add_option('-E', '--[no-]env-shebang',
                'Rewrite executables with a shebang',
                'of /usr/bin/env') do |value, options|
@@ -199,10 +205,10 @@ By default, this RubyGems will install gem as: https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/setup_command.rb#L205
     say
 
     say "RubyGems installed the following executables:"
-    say @bin_file_names.map { |name| "\t#{name}\n" }
+    say bin_file_names.map { |name| "\t#{name}\n" }
     say
 
-    unless @bin_file_names.grep(/#{File::SEPARATOR}gem$/)
+    unless bin_file_names.grep(/#{File::SEPARATOR}gem$/)
       say "If `gem` was installed by a previous RubyGems installation, you may need"
       say "to remove it by hand."
       say
@@ -235,8 +241,6 @@ By default, this RubyGems will install gem as: https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/setup_command.rb#L241
   end
 
   def install_executables(bin_dir)
-    @bin_file_names = []
-
     prog_mode = options[:prog_mode] || 0755
 
     executables = { 'gem' => 'bin' }
@@ -249,13 +253,7 @@ By default, this RubyGems will install gem as: https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/setup_command.rb#L253
         bin_files -= %w[update_rubygems]
 
         bin_files.each do |bin_file|
-          bin_file_formatted = if options[:format_executable]
-                                 Gem.default_exec_format % bin_file
-                               else
-                                 bin_file
-                               end
-
-          dest_file = File.join bin_dir, bin_file_formatted
+          dest_file = target_bin_path(bin_dir, bin_file)
           bin_tmp_file = File.join Dir.tmpdir, "#{bin_file}.#{$$}"
 
           begin
@@ -267,7 +265,7 @@ By default, this RubyGems will install gem as: https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/setup_command.rb#L265
             end
 
             install bin_tmp_file, dest_file, :mode => prog_mode
-            @bin_file_names << dest_file
+            bin_file_names << dest_file
           ensure
             rm bin_tmp_file
           end
@@ -429,13 +427,15 @@ By default, this RubyGems will install gem as: https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/setup_command.rb#L427
     Dir.chdir("bundler") do
       built_gem = Gem::Package.build(bundler_spec)
       begin
-        installer = Gem::Installer.at(built_gem, env_shebang: options[:env_shebang], format_executable: options[:format_executable], install_as_default: true, bin_dir: bin_dir, wrappers: true)
+        installer = Gem::Installer.at(built_gem, env_shebang: options[:env_shebang], format_executable: options[:format_executable], force: options[:force], install_as_default: true, bin_dir: bin_dir, wrappers: true)
         installer.install
       ensure
         FileUtils.rm_f built_gem
       end
     end
 
+    bundler_spec.executables.each {|executable| bin_file_names << target_bin_path(bin_dir, executable) }
+
     say "Bundler #{bundler_spec.version} installed"
   end
 
@@ -592,7 +592,7 @@ abort "#{deprecation_message}" https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/setup_command.rb#L592
         history_string = ""
 
         until versions.length == 0 or
-              versions.shift < options[:previous_version] do
+              versions.shift <= options[:previous_version] do
           history_string += version_lines.shift + text.shift
         end
 
@@ -626,4 +626,19 @@ abort "#{deprecation_message}" https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/setup_command.rb#L626
     command.invoke(*args)
   end
 
+  private
+
+  def target_bin_path(bin_dir, bin_file)
+    bin_file_formatted = if options[:format_executable]
+                           Gem.default_exec_format % bin_file
+                         else
+                           bin_file
+                         end
+    File.join bin_dir, bin_file_formatted
+  end
+
+  def bin_file_names
+    @bin_file_names ||= []
+  end
+
 end
diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb
index 5ecf2ab..206497c 100644
--- a/lib/rubygems/test_case.rb
+++ b/lib/rubygems/test_case.rb
@@ -164,6 +164,50 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni https://github.com/ruby/ruby/blob/trunk/lib/rubygems/test_case.rb#L164
     end
   end
 
+  ##
+  # Sets the bindir entry in RbConfig::CONFIG to +value+ and restores the
+  # original value when the block ends
+  #
+  def bindir(value)
+    bindir = RbConfig::CONFIG['bindir']
+
+    if value
+      RbConfig::CONFIG['bindir'] = value
+    else
+      RbConfig::CONFIG.delete 'bindir'
+    end
+
+    yield
+  ensure
+    if bindir
+      RbConfig::CONFIG['bindir'] = bindir
+    else
+      RbConfig::CONFIG.delete 'bindir'
+    end
+  end
+
+  ##
+  # Sets the EXEEXT entry in RbConfig::CONFIG to +value+ and restores the
+  # original value when the block ends
+  #
+  def exeext(value)
+    exeext = RbConfig::CONFIG['EXEEXT']
+
+    if value
+      RbConfig::CONFIG['EXEEXT'] = value
+    else
+      RbConfig::CONFIG.delete 'EXEEXT'
+    end
+
+    yield
+  ensure
+    if exeext
+      RbConfig::CONFIG['EXEEXT'] = exeext
+    else
+      RbConfig::CONFIG.delete 'EXEEXT'
+    end
+  end
+
   # TODO: move to minitest
   def refute_path_exists(path, msg = nil)
     msg = message(msg) { "Expected path '#{path}' to not exist" }
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index a0debb4..6d223b7 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -1917,16 +1917,11 @@ You may need to `gem install -g` to install missing gems https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1917
   end
 
   def with_bindir_and_exeext(bindir, exeext)
-    orig_bindir = RbConfig::CONFIG['bindir']
-    orig_exe_ext = RbConfig::CONFIG['EXEEXT']
-
-    RbConfig::CONFIG['bindir'] = bindir
-    RbConfig::CONFIG['EXEEXT'] = exeext
-
-    yield
-  ensure
-    RbConfig::CONFIG['bindir'] = orig_bindir
-    RbConfig::CONFIG['EXEEXT'] = orig_exe_ext
+    bindir(bindir) do
+      exeext(exeext) do
+        yield
+      end
+    end
   end
 
   def with_clean_path_to_ruby
diff --git a/test/rubygems/test_gem_commands_setup_command.rb b/test/rubygems/test_gem_commands_setup_command.rb
index 02171ec..c63f717 100644
--- a/test/rubygems/test_gem_commands_setup_command.rb
+++ b/test/rubygems/test_gem_commands_setup_command.rb
@@ -123,6 +123,18 @@ class TestGemCommandsSetupCommand < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_setup_command.rb#L123
     assert_equal "I changed it!\n", File.read(gem_bin_path)
   end
 
+  def test_execute_informs_about_installed_executables
+    use_ui @ui do
+      @cmd.execute
+    end
+
+    out = @ui.output.split "\n"
+
+    exec_line = out.shift until exec_line == "RubyGems installed the following executables:"
+    assert_equal "\t#{default_gem_bin_path}", out.shift
+    assert_equal "\t#{default_bundle_bin_path}", out.shift
+  end
+
   def test_env_shebang_flag
     gem_bin_path = gem_install 'a'
     write_file gem_bin_path do |io|
@@ -133,10 +145,6 @@ class TestGemCommandsSetupCommand < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_setup_command.rb#L145
     @cmd.options[:env_shebang] = true
     @cmd.execute
 
-    gem_exec = sprintf Gem.default_exec_format, 'gem'
-    default_gem_bin_path = File.join @install_dir, 'bin', gem_exec
-    bundle_exec = sprintf Gem.default_exec_format, 'bundle'
-    default_bundle_bin_path = File.join @install_dir, 'bin', bundle_exec
     ruby_exec = sprintf Gem.default_exec_format, 'ruby'
 
     if Gem.win_platform?
@@ -212,10 +220,41 @@ class TestGemCommandsSetupCommand < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_setup_command.rb#L220
 
     # TODO: We need to assert to remove same version of bundler on gem_dir directory(It's not site_ruby dir)
 
-    # expect to not remove bundler-* direcotyr.
+    # expect to not remove bundler-* directory.
     assert_path_exists 'default/gems/bundler-audit-1.0.0'
   end
 
+  def test_install_default_bundler_gem_with_force_flag
+    @cmd.extend FileUtils
+
+    bin_dir = File.join(@gemhome, 'bin')
+    bundle_bin = File.join(bin_dir, 'bundle')
+
+    write_file bundle_bin do |f|
+      f.puts '#!/usr/bin/ruby'
+      f.puts ''
+      f.puts 'echo "hello"'
+    end
+
+    bin (... truncated)

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

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