From f28be7e02d113bd26c33cb94e65004055576c065 Mon Sep 17 00:00:00 2001 From: hsbt Date: Tue, 2 Apr 2019 11:48:18 +0000 Subject: Merge rubygems/rubygems from upstream. The current master branch is https://github.com/rubygems/rubygems/commit/97b264f0fa248c864b6ee9a23d3ff1cdd217dddb git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67415 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rubygems.rb | 1 - lib/rubygems/basic_specification.rb | 2 +- lib/rubygems/command.rb | 1 - lib/rubygems/commands/cert_command.rb | 1 - lib/rubygems/commands/pristine_command.rb | 2 +- lib/rubygems/commands/setup_command.rb | 19 +++---- lib/rubygems/commands/uninstall_command.rb | 22 +++++--- lib/rubygems/dependency_installer.rb | 25 +++++++-- lib/rubygems/gemcutter_utilities.rb | 4 -- lib/rubygems/installer.rb | 5 +- lib/rubygems/package.rb | 1 - lib/rubygems/spec_fetcher.rb | 2 - lib/rubygems/specification.rb | 84 +++++------------------------- lib/rubygems/test_case.rb | 8 --- 14 files changed, 63 insertions(+), 114 deletions(-) (limited to 'lib') diff --git a/lib/rubygems.rb b/lib/rubygems.rb index d0933e1b6c..54bd995b83 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -112,7 +112,6 @@ require 'rubygems/errors' # # -The RubyGems Team - module Gem RUBYGEMS_DIR = File.dirname File.expand_path(__FILE__) diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb index 45a6fc08a0..bafada01a3 100644 --- a/lib/rubygems/basic_specification.rb +++ b/lib/rubygems/basic_specification.rb @@ -71,7 +71,7 @@ class Gem::BasicSpecification elsif missing_extensions? @ignored = true - if platform == RUBY_ENGINE + if RUBY_ENGINE == platform || Gem::Platform.local === platform warn "Ignoring #{full_name} because its extensions are not built. " + "Try: gem pristine #{name} --version #{version}" end diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb index a509b783dd..4b32376954 100644 --- a/lib/rubygems/command.rb +++ b/lib/rubygems/command.rb @@ -593,7 +593,6 @@ class Gem::Command 'Avoid loading any .gemrc file') do end - # :stopdoc: HELP = <<-HELP.freeze diff --git a/lib/rubygems/commands/cert_command.rb b/lib/rubygems/commands/cert_command.rb index 5695460d94..72400f3edd 100644 --- a/lib/rubygems/commands/cert_command.rb +++ b/lib/rubygems/commands/cert_command.rb @@ -319,5 +319,4 @@ For further reading on signing gems see `ri Gem::Security`. email =~ /\A.+@.+\z/ end - end if defined?(OpenSSL::SSL) diff --git a/lib/rubygems/commands/pristine_command.rb b/lib/rubygems/commands/pristine_command.rb index 95e9ed0a15..a25b690afc 100644 --- a/lib/rubygems/commands/pristine_command.rb +++ b/lib/rubygems/commands/pristine_command.rb @@ -104,7 +104,7 @@ extensions will be restored. end.flatten end - specs = specs.select{|spec| spec.platform == RUBY_ENGINE } + specs = specs.select{|spec| RUBY_ENGINE == spec.platform || Gem::Platform.local === spec.platform } if specs.to_a.empty? raise Gem::Exception, diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index 975eca593d..e3afc8cff8 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -165,7 +165,7 @@ By default, this RubyGems will install gem as: remove_old_lib_files lib_dir - install_default_bundler_gem + install_default_bundler_gem bin_dir if mode = options[:dir_mode] @mkdirs.uniq! @@ -234,21 +234,19 @@ By default, this RubyGems will install gem as: end end - def install_executables(bin_dir) @bin_file_names = [] prog_mode = options[:prog_mode] || 0755 executables = { 'gem' => 'bin' } - executables['bundler'] = 'bundler/exe' if Gem::USE_BUNDLER_FOR_GEMDEPS executables.each do |tool, path| say "Installing #{tool} executable" if @verbose Dir.chdir path do bin_files = Dir['*'] - bin_files -= %w[update_rubygems bundler bundle_ruby] + bin_files -= %w[update_rubygems] bin_files.each do |bin_file| bin_file_formatted = if options[:format_executable] @@ -383,7 +381,7 @@ By default, this RubyGems will install gem as: return false end - def install_default_bundler_gem + def install_default_bundler_gem(bin_dir) return unless Gem::USE_BUNDLER_FOR_GEMDEPS specs_dir = Gem::Specification.default_specifications_dir @@ -428,13 +426,12 @@ By default, this RubyGems will install gem as: cp File.join("bundler", bundler_spec.bindir, e), File.join(bundler_bin_dir, e) end - if Gem.win_platform? - require 'rubygems/installer' + require 'rubygems/installer' - installer = Gem::Installer.for_spec bundler_spec - bundler_spec.executables.each do |e| - installer.generate_windows_script e, bundler_spec.bin_dir - end + Dir.chdir("bundler") do + built_gem = Gem::Package.build(bundler_spec) + installer = Gem::Installer.at(built_gem, env_shebang: options[:env_shebang], install_as_default: true, bin_dir: bin_dir, wrappers: true) + installer.install end say "Bundler #{bundler_spec.version} installed" diff --git a/lib/rubygems/commands/uninstall_command.rb b/lib/rubygems/commands/uninstall_command.rb index 698ff4b555..68e048c010 100644 --- a/lib/rubygems/commands/uninstall_command.rb +++ b/lib/rubygems/commands/uninstall_command.rb @@ -148,10 +148,13 @@ that is a dependency of an existing gem. You can use the def uninstall_specific deplist = Gem::DependencyList.new + original_gem_version = {} 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) + original_gem_version[name] = version || options[:version] + + gem_specs = Gem::Specification.find_all_by_name(name, original_gem_version[name]) + say("Gem '#{name}' is not installed") if gem_specs.empty? gem_specs.each do |spec| deplist.add spec @@ -160,16 +163,23 @@ that is a dependency of an existing gem. You can use the deps = deplist.strongly_connected_components.flatten.reverse + gems_to_uninstall = {} + deps.each do |dep| - options[:version] = dep.version - uninstall_gem(dep.name) + unless gems_to_uninstall[dep.name] + gems_to_uninstall[dep.name] = true + + unless original_gem_version[dep.name] == Gem::Requirement.default + options[:version] = dep.version + end + + uninstall_gem(dep.name) + end end end def uninstall_gem(gem_name) uninstall(gem_name) - rescue Gem::InstallError - nil rescue Gem::GemNotInHomeException => e spec = e.spec alert("In order to remove #{spec.name}, please execute:\n" + diff --git a/lib/rubygems/dependency_installer.rb b/lib/rubygems/dependency_installer.rb index 7f4f914591..b1f1946d79 100644 --- a/lib/rubygems/dependency_installer.rb +++ b/lib/rubygems/dependency_installer.rb @@ -143,7 +143,9 @@ class Gem::DependencyInstaller end end - results = find_gems_with_sources(dep) + results = Gem::Deprecate.skip_during do + find_gems_with_sources(dep) + end results.sorted.each do |t| to_do.push t.spec @@ -166,15 +168,20 @@ class Gem::DependencyInstaller def available_set_for(dep_or_name, version) # :nodoc: if String === dep_or_name - find_spec_by_name_and_version dep_or_name, version, @prerelease + Gem::Deprecate.skip_during do + find_spec_by_name_and_version dep_or_name, version, @prerelease + end else dep = dep_or_name.dup dep.prerelease = @prerelease - @available = find_gems_with_sources dep + @available = Gem::Deprecate.skip_during do + find_gems_with_sources dep + end end @available.pick_best! end + deprecate :available_set_for, :none, 2019, 12 ## # Indicated, based on the requested domain, if local @@ -266,6 +273,7 @@ class Gem::DependencyInstaller set end + deprecate :find_gems_with_sources, :none, 2019, 12 ## # Finds a spec and the source_uri it came from for gem +gem_name+ and @@ -302,7 +310,10 @@ class Gem::DependencyInstaller dep = Gem::Dependency.new gem_name, version dep.prerelease = true if prerelease - set = find_gems_with_sources(dep, true) + set = Gem::Deprecate.skip_during do + find_gems_with_sources(dep, true) + end + set.match_platform! end @@ -312,6 +323,7 @@ class Gem::DependencyInstaller @available = set end + deprecate :find_spec_by_name_and_version, :none, 2019, 12 ## # Gathers all dependencies necessary for the installation from local and @@ -332,7 +344,10 @@ class Gem::DependencyInstaller dependency_list = Gem::DependencyList.new @development dependency_list.add(*specs) to_do = specs.dup - add_found_dependencies to_do, dependency_list unless @ignore_dependencies + + Gem::Deprecate.skip_during do + add_found_dependencies to_do, dependency_list unless @ignore_dependencies + end # REFACTOR maybe abstract away using Gem::Specification.include? so # that this isn't dependent only on the currently installed gems diff --git a/lib/rubygems/gemcutter_utilities.rb b/lib/rubygems/gemcutter_utilities.rb index a125664ce5..e68784bb67 100644 --- a/lib/rubygems/gemcutter_utilities.rb +++ b/lib/rubygems/gemcutter_utilities.rb @@ -190,10 +190,6 @@ module Gem::GemcutterUtilities # Returns true when the user has enabled multifactor authentication from # +response+ text and no otp provided by options. - - - - def set_api_key(host, key) if host == Gem::DEFAULT_HOST Gem.configuration.rubygems_api_key = key diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 1415a14f22..8b80125922 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -324,8 +324,11 @@ class Gem::Installer build_extensions write_build_info_file run_post_build_hooks + end + + generate_bin - generate_bin + unless @options[:install_as_default] write_spec write_cache_file end diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index 16cf0c173a..4ad4f8c3a9 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -86,7 +86,6 @@ class Gem::Package class TarInvalidError < Error; end - attr_accessor :build_time # :nodoc: ## diff --git a/lib/rubygems/spec_fetcher.rb b/lib/rubygems/spec_fetcher.rb index 4e62d7dd81..adb2505f95 100644 --- a/lib/rubygems/spec_fetcher.rb +++ b/lib/rubygems/spec_fetcher.rb @@ -138,7 +138,6 @@ class Gem::SpecFetcher return [tuples, errors] end - ## # Return all gem name tuples who's names match +obj+ @@ -157,7 +156,6 @@ class Gem::SpecFetcher tuples end - ## # Find and fetch specs that match +dependency+. # diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 6e1246c920..ca590ea579 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -6,7 +6,6 @@ # See LICENSE.txt for permissions. #++ - require 'rubygems/version' require 'rubygems/requirement' require 'rubygems/platform' @@ -18,7 +17,7 @@ require 'rubygems/util/list' require 'stringio' ## -# The Specification class contains the information for a Gem. Typically +# The Specification class contains the information for a gem. Typically # defined in a .gemspec file or a Rakefile, and looks like this: # # Gem::Specification.new do |s| @@ -364,8 +363,7 @@ class Gem::Specification < Gem::BasicSpecification ## # The metadata holds extra data for this gem that may be useful to other - # consumers and is settable by gem authors without requiring an update to - # the rubygems software. + # consumers and is settable by gem authors. # # Metadata items have the following restrictions: # @@ -775,15 +773,6 @@ class Gem::Specification < Gem::BasicSpecification end private_class_method :gemspec_stubs_in - def self.default_stubs(pattern) - base_dir = Gem.default_dir - gems_dir = File.join base_dir, "gems" - gemspec_stubs_in(default_specifications_dir, pattern) do |path| - Gem::StubSpecification.default_gemspec_stub(path, base_dir, gems_dir) - end - end - private_class_method :default_stubs - def self.installed_stubs(dirs, pattern) map_stubs(dirs, pattern) do |path, base_dir, gems_dir| Gem::StubSpecification.gemspec_stub(path, base_dir, gems_dir) @@ -832,6 +821,17 @@ class Gem::Specification < Gem::BasicSpecification end end + ## + # Returns a Gem::StubSpecification for default gems + + def self.default_stubs(pattern = "*.gemspec") + base_dir = Gem.default_dir + gems_dir = File.join base_dir, "gems" + gemspec_stubs_in(default_specifications_dir, pattern) do |path| + Gem::StubSpecification.default_gemspec_stub(path, base_dir, gems_dir) + end + end + EMPTY = [].freeze # :nodoc: ## @@ -872,51 +872,6 @@ class Gem::Specification < Gem::BasicSpecification end end - ## - # Adds +spec+ to the known specifications, keeping the collection - # properly sorted. - - def self.add_spec(spec) - warn "Gem::Specification.add_spec is deprecated and will be removed in RubyGems 3.0" unless Gem::Deprecate.skip - # TODO: find all extraneous adds - # puts - # p :add_spec => [spec.full_name, caller.reject { |s| s =~ /minitest/ }] - - # TODO: flush the rest of the crap from the tests - # raise "no dupes #{spec.full_name} in #{all_names.inspect}" if - # _all.include? spec - - raise "nil spec!" unless spec # TODO: remove once we're happy with tests - - return if _all.include? spec - - _all << spec - stubs << spec - (@@stubs_by_name[spec.name] ||= []) << spec - sort_by!(@@stubs_by_name[spec.name]) { |s| s.version } - _resort!(_all) - _resort!(stubs) - end - - ## - # Adds multiple specs to the known specifications. - - def self.add_specs(*specs) - warn "Gem::Specification.add_specs is deprecated and will be removed in RubyGems 3.0" unless Gem::Deprecate.skip - - raise "nil spec!" if specs.any?(&:nil?) # TODO: remove once we're happy - - # TODO: this is much more efficient, but we need the extra checks for now - # _all.concat specs - # _resort! - - Gem::Deprecate.skip_during do - specs.each do |spec| # TODO: slow - add_spec spec - end - end - end - ## # Returns all specifications. This method is discouraged from use. # You probably want to use one of the Enumerable methods instead. @@ -1244,17 +1199,6 @@ class Gem::Specification < Gem::BasicSpecification nil end - ## - # Removes +spec+ from the known specs. - - def self.remove_spec(spec) - warn "Gem::Specification.remove_spec is deprecated and will be removed in RubyGems 3.0" unless Gem::Deprecate.skip - _all.delete spec - stubs.delete_if { |s| s.full_name == spec.full_name } - (@@stubs_by_name[spec.name] || []).delete_if { |s| s.full_name == spec.full_name } - reset - end - ## # Is +name+ a required attribute? @@ -2029,8 +1973,6 @@ class Gem::Specification < Gem::BasicSpecification yaml_initialize coder.tag, coder.map end - - eval <<-RB, binding, __FILE__, __LINE__ + 1 def set_nil_attributes_to_nil #{@@nil_attributes.map {|key| "@#{key} = nil" }.join "; "} diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index 958d157465..6061be1a84 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -383,8 +383,6 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni Gem.searcher = nil Gem::SpecFetcher.fetcher = nil - @orig_BASERUBY = RbConfig::CONFIG['BASERUBY'] - RbConfig::CONFIG['BASERUBY'] = RbConfig::CONFIG['ruby_install_name'] @orig_arch = RbConfig::CONFIG['arch'] @@ -422,11 +420,6 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni end end - if @orig_BASERUBY - RbConfig::CONFIG['BASERUBY'] = @orig_BASERUBY - else - RbConfig::CONFIG.delete('BASERUBY') - end RbConfig::CONFIG['arch'] = @orig_arch if defined? Gem::RemoteFetcher @@ -716,7 +709,6 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni end deprecate :quick_spec, :util_spec, 2018, 12 - ## # Builds a gem from +spec+ and places it in File.join @gemhome, # 'cache'. Automatically creates files based on +spec.files+ -- cgit v1.2.3