ruby-changes:53847
From: hsbt <ko1@a...>
Date: Wed, 28 Nov 2018 12:08:20 +0900 (JST)
Subject: [ruby-changes:53847] hsbt:r66065 (trunk): Merge rubygems upstream from https://github.com/rubygems/rubygems/commit/2c499655f29070c809dfea9f5fda6fac6850e62e
hsbt 2018-11-28 12:08:14 +0900 (Wed, 28 Nov 2018) New Revision: 66065 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66065 Log: Merge rubygems upstream from https://github.com/rubygems/rubygems/commit/2c499655f29070c809dfea9f5fda6fac6850e62e https://github.com/rubygems/rubygems/pull/2493 Modified files: trunk/lib/rubygems/commands/install_command.rb trunk/lib/rubygems/commands/pristine_command.rb trunk/lib/rubygems/commands/uninstall_command.rb trunk/lib/rubygems/installer.rb trunk/lib/rubygems/specification.rb trunk/test/rubygems/test_gem_commands_install_command.rb trunk/test/rubygems/test_gem_commands_pristine_command.rb trunk/test/rubygems/test_gem_commands_uninstall_command.rb trunk/test/rubygems/test_gem_installer.rb trunk/test/rubygems/test_gem_package.rb trunk/test/rubygems/test_gem_specification.rb Index: lib/rubygems/specification.rb =================================================================== --- lib/rubygems/specification.rb (revision 66064) +++ lib/rubygems/specification.rb (revision 66065) @@ -1661,16 +1661,6 @@ class Gem::Specification < Gem::BasicSpe https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L1661 end ## - # Used to detect if the gem is bundled in older version of Ruby, but not - # detectable as default gem (see BasicSpecification#default_gem?). - - def bundled_gem_in_old_ruby? - !default_gem? && - RUBY_VERSION < "2.0.0" && - summary == "This #{name} is bundled with Ruby" - end - - ## # Returns the full path to the cache directory containing this # spec's cached gem. Index: lib/rubygems/commands/pristine_command.rb =================================================================== --- lib/rubygems/commands/pristine_command.rb (revision 66064) +++ lib/rubygems/commands/pristine_command.rb (revision 66065) @@ -129,11 +129,6 @@ extensions will be restored. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/pristine_command.rb#L129 end end - if spec.bundled_gem_in_old_ruby? - say "Skipped #{spec.full_name}, it is bundled with old Ruby" - next - end - unless spec.extensions.empty? or options[:extensions] or options[:only_executables] say "Skipped #{spec.full_name}, it needs to compile an extension" next Index: lib/rubygems/commands/install_command.rb =================================================================== --- lib/rubygems/commands/install_command.rb (revision 66064) +++ lib/rubygems/commands/install_command.rb (revision 66065) @@ -142,7 +142,7 @@ You can use `i` command instead of `inst https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/install_command.rb#L142 if options[:version] != Gem::Requirement.default and get_all_gem_names.size > 1 alert_error "Can't use --version with multiple gems. You can specify multiple gems with" \ - " version requirments using `gem install 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" + " version requirements using `gem install 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" terminate_interaction 1 end end Index: lib/rubygems/commands/uninstall_command.rb =================================================================== --- lib/rubygems/commands/uninstall_command.rb (revision 66064) +++ lib/rubygems/commands/uninstall_command.rb (revision 66065) @@ -114,7 +114,18 @@ that is a dependency of an existing gem. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/uninstall_command.rb#L114 "#{program_name} GEMNAME [GEMNAME ...]" end + def check_version # :nodoc: + if options[:version] != Gem::Requirement.default and + get_all_gem_names.size > 1 + alert_error "Can't use --version with multiple gems. You can specify multiple gems with" \ + " version requirements using `gem uninstall 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" + terminate_interaction 1 + end + end + def execute + check_version + if options[:all] and not options[:args].empty? uninstall_specific elsif options[:all] @@ -138,8 +149,9 @@ that is a dependency of an existing gem. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/uninstall_command.rb#L149 def uninstall_specific deplist = Gem::DependencyList.new - get_all_gem_names.uniq.each do |name| - gem_specs = Gem::Specification.find_all_by_name(name) + get_all_gem_names_and_versions.each do |name, version| + requirement = Array(version || options[:version]) + gem_specs = Gem::Specification.find_all_by_name(name, *requirement) say("Gem '#{name}' is not installed") if gem_specs.empty? gem_specs.each do |spec| deplist.add spec @@ -148,8 +160,9 @@ that is a dependency of an existing gem. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/uninstall_command.rb#L160 deps = deplist.strongly_connected_components.flatten.reverse - deps.map(&:name).uniq.each do |gem_name| - uninstall_gem(gem_name) + deps.each do |dep| + options[:version] = dep.version + uninstall_gem(dep.name) end end Index: lib/rubygems/installer.rb =================================================================== --- lib/rubygems/installer.rb (revision 66064) +++ lib/rubygems/installer.rb (revision 66065) @@ -749,11 +749,11 @@ require 'rubygems' https://github.com/ruby/ruby/blob/trunk/lib/rubygems/installer.rb#L749 version = "#{Gem::Requirement.default}.a" -if ARGV.first - str = ARGV.first - str = str.dup.force_encoding("BINARY") - if str =~ /\\A_(.*)_\\z/ and Gem::Version.correct?($1) - version = $1 +str = ARGV.first +if str + str = str.b[/\\A_(.*)_\\z/, 1] + if str and Gem::Version.correct?(str) + version = str ARGV.shift end end Index: test/rubygems/test_gem_commands_pristine_command.rb =================================================================== --- test/rubygems/test_gem_commands_pristine_command.rb (revision 66064) +++ test/rubygems/test_gem_commands_pristine_command.rb (revision 66065) @@ -505,30 +505,6 @@ class TestGemCommandsPristineCommand < G https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_pristine_command.rb#L505 assert_empty(@ui.error) end - def test_execute_bundled_gem_on_old_rubies - util_set_RUBY_VERSION '1.9.3', 551 - - spec = util_spec 'bigdecimal', '1.1.0' do |s| - s.summary = "This bigdecimal is bundled with Ruby" - end - install_specs spec - - @cmd.options[:args] = %w[bigdecimal] - - use_ui @ui do - @cmd.execute - end - - assert_equal([ - "Restoring gems to pristine condition...", - "Skipped bigdecimal-1.1.0, it is bundled with old Ruby" - ], @ui.output.split("\n")) - - assert_empty @ui.error - ensure - util_restore_RUBY_VERSION - end - def test_handle_options @cmd.handle_options %w[] Index: test/rubygems/test_gem_installer.rb =================================================================== --- test/rubygems/test_gem_installer.rb (revision 66064) +++ test/rubygems/test_gem_installer.rb (revision 66065) @@ -53,11 +53,11 @@ require 'rubygems' https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_installer.rb#L53 version = \">= 0.a\" -if ARGV.first - str = ARGV.first - str = str.dup.force_encoding("BINARY") - if str =~ /\\A_(.*)_\\z/ and Gem::Version.correct?($1) - version = $1 +str = ARGV.first +if str + str = str.b[/\\A_(.*)_\\z/, 1] + if str and Gem::Version.correct?(str) + version = str ARGV.shift end end Index: test/rubygems/test_gem_commands_install_command.rb =================================================================== --- test/rubygems/test_gem_commands_install_command.rb (revision 66064) +++ test/rubygems/test_gem_commands_install_command.rb (revision 66065) @@ -393,6 +393,23 @@ ERROR: Possible alternatives: non_exist https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_install_command.rb#L393 assert_equal %w[a-2.a], @cmd.installed_specs.map { |spec| spec.full_name } end + def test_execute_with_version_specified_by_colon + spec_fetcher do |fetcher| + fetcher.download 'a', 1 + fetcher.download 'a', 2 + end + + @cmd.options[:args] = %w[a:1] + + use_ui @ui do + assert_raises Gem::MockGemUi::SystemExitException, @ui.error do + @cmd.execute + end + end + + assert_equal %w[a-1], @cmd.installed_specs.map { |spec| spec.full_name } + end + def test_execute_prerelease_skipped_when_non_pre_available spec_fetcher do |fetcher| fetcher.gem 'a', '2.pre' @@ -649,12 +666,31 @@ ERROR: Possible alternatives: non_exist https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_install_command.rb#L666 assert_empty @cmd.installed_specs msg = "ERROR: Can't use --version with multiple gems. You can specify multiple gems with" \ - " version requirments using `gem install 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" + " version requirements using `gem install 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" assert_empty @ui.output assert_equal msg, @ui.error.chomp end + def test_execute_two_version_specified_by_colon + spec_fetcher do |fetcher| + fetcher.gem 'a', 1 + fetcher.gem 'a', 2 + fetcher.gem 'b', 1 + fetcher.gem 'b', 2 + end + + @cmd.options[:args] = %w[a:1 b:1] + + use_ui @ui do + assert_raises Gem::MockGemUi::SystemExitException, @ui.error do + @cmd.execute + end + end + + assert_equal %w[a-1 b-1], @cmd.installed_specs.map { |spec| spec.full_name } + end + def test_execute_conservative spec_fetcher do |fetcher| fetcher.download 'b', 2 Index: test/rubygems/test_gem_commands_uninstall_command.rb =================================================================== --- test/rubygems/test_gem_commands_uninstall_command.rb (revision 66064) +++ test/rubygems/test_gem_commands_uninstall_command.rb (revision 66065) @@ -151,12 +151,14 @@ class TestGemCommandsUninstallCommand < https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_uninstall_command.rb#L151 assert_match(/Successfully uninstalled/, output) end - def test_execute_with_force_leaves_executable + def test_execute_with_version_leaves_non_matching_versions ui = Gem::MockGemUi.new util_make_gems util_setup_gem ui + assert_equal 3, Gem::Specification.find_all_by_name('a').length + @cmd.options[:version] = '1' @cmd.options[:force] = true @cmd.options[:args] = ['a'] @@ -165,17 +167,43 @@ class TestGemCommandsUninstallCommand < https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_uninstall_command.rb#L167 @cmd.execute end - assert !Gem::Specification.all_names.include?('a') + assert_equal 2, Gem::Specification.find_all_by_name('a').length + assert File.exist? File.join(@gemhome, 'bin', 'executable') end - def test_execute_with_force_uninstalls_all_versions + def test_execute_with_version_specified_as_colon ui = Gem::MockGemUi.new "y\n" util_make_gems util_setup_gem ui - assert Gem::Specification.find_all_by_name('a').length > 1 + assert_equal 3, Gem::Specification.find_all_by_name('a').length + + @cmd.options[:force] = true + @cmd.options[:args] = ['a:1'] + + use_ui ui do + @cmd.execute + end + + assert_equal 2, Gem::Specification.find_all_by_name('a').length + + assert File.exist? File.join(@gemhome, 'bin', 'executable') + end + + def test_execute_with_force_and_without_version_uninstalls_everything + ui = Gem::MockGemUi.new "y\n" + + a_1, = util_gem 'a', 1 + install_gem a_1 + + a_3a, = util_gem 'a', '3.a' + install_gem a_3a + + util_setup_gem ui + + assert_equal 3, Gem::Specification.find_all_by_name('a').length @cmd.options[:force] = true @cmd.options[:args] = ['a'] @@ -184,7 +212,9 @@ class TestGemCommandsUninstallCommand < https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_uninstall_command.rb#L212 @cmd.execute end - refute_includes Gem::Specification.all_names, 'a' + assert_empty Gem::Specification.find_all_by_name('a') + assert_match "Removing executable", ui.output + refute File.exist? @executable end def test_execute_with_force_ignores_dependencies @@ -261,6 +291,25 @@ WARNING: Use your OS package manager to https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_uninstall_command.rb#L291 assert_match expected, @ui.error end + def test_execute_two_version + @cmd.options[:args] = %w[a b] + @cmd.options[:version] = Gem::Requirement.new("> 1") + + use_ui @ui do + e = assert_raises Gem::MockGemUi::TermError do + @cmd.execute + end + + assert_equal 1, e.exit_code + end + + msg = "ERROR: Can't use --version with multiple gems. You can specify multiple gems with" \ + " version requirements using `gem uninstall 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" + + assert_empty @ui.output + assert_equal msg, @ui.error.lines.last.chomp + end + def test_handle_options_vendor_missing orig_vendordir = RbConfig::CONFIG['vendordir'] RbConfig::CONFIG.delete 'vendordir' Index: test/rubygems/test_gem_specification.rb =================================================================== --- test/rubygems/test_gem_specification.rb (revision 66064) +++ test/rubygems/test_gem_specification.rb (revision 66065) @@ -3724,18 +3724,6 @@ end https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_specification.rb#L3724 assert_equal ["default-2.0.0.0"], Gem::Specification.map(&:full_name) end - def test_detect_bundled_gem_in_old_ruby - util_set_RUBY_VERSION '1.9.3', 551 - - spec = util_spec 'bigdecimal', '1.1.0' do |s| - s.summary = "This bigdecimal is bundled with Ruby" - end - - assert spec.bundled_gem_in_old_ruby? - ensure - util_restore_RUBY_VERSION - end - def util_setup_deps @gem = util_spec "awesome", "1.0" do |awesome| awesome.add_runtime_dependency "bonobo", [] Index: test/rubygems/test_gem_package.rb =================================================================== --- test/rubygems/test_gem_package.rb (revision 66064) +++ test/rubygems/test_gem_package.rb (revision 66065) @@ -150,8 +150,6 @@ class TestGemPackage < Gem::Package::Tar https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_package.rb#L150 end def test_add_files_symlink - skip 'symlink not supported' if Gem.win_platform? && RUBY_VERSION < '2.3' - spec = Gem::Specification.new spec.files = %w[lib/code.rb lib/code_sym.rb] @@ -472,8 +470,6 @@ class TestGemPackage < Gem::Package::Tar https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_package.rb#L470 end def test_extract_tar_gz_symlink_relative_path - skip 'symlink not supported' if Gem.win_platform? && RUBY_VERSION < '2.3' - package = Gem::Package.new @gem tgz_io = util_tar_gz do |tar| @@ -501,8 +497,6 @@ class TestGemPackage < Gem::Package::Tar https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_package.rb#L497 end def test_extract_symlink_parent - skip 'symlink not supported' if Gem.win_platform? && RUBY_VERSION < '2.3' - package = Gem::Package.new @gem tgz_io = util_tar_gz do |tar| -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/