From e373d99f356779c1823c81603eaee6ed71cf68f5 Mon Sep 17 00:00:00 2001 From: hsbt Date: Fri, 4 Mar 2016 00:29:40 +0000 Subject: * lib/rubygems.rb, lib/rubygems/*, test/rubygems/*: Update rubygems-2.6.1. Please see entries of 2.6.0 and 2.6.1 on https://github.com/rubygems/rubygems/blob/master/History.txt [fix GH-1270] Patch by @segiddins git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53992 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rubygems/basic_specification.rb | 3 +- lib/rubygems/command.rb | 9 +++- lib/rubygems/commands/cleanup_command.rb | 11 +++-- lib/rubygems/commands/install_command.rb | 1 + lib/rubygems/commands/open_command.rb | 4 ++ lib/rubygems/commands/push_command.rb | 10 +++-- lib/rubygems/commands/update_command.rb | 1 + lib/rubygems/config_file.rb | 13 +++++- lib/rubygems/dependency.rb | 3 +- lib/rubygems/gemcutter_utilities.rb | 10 ++++- lib/rubygems/install_update_options.rb | 1 + lib/rubygems/path_support.rb | 36 ++++++--------- lib/rubygems/resolver/installer_set.rb | 12 +++-- .../molinillo/lib/molinillo/dependency_graph.rb | 4 ++ .../molinillo/lib/molinillo/gem_metadata.rb | 2 +- .../resolver/molinillo/lib/molinillo/modules/ui.rb | 3 +- .../resolver/molinillo/lib/molinillo/resolution.rb | 51 ++++++++++++++++------ lib/rubygems/source_list.rb | 2 +- lib/rubygems/specification.rb | 3 ++ lib/rubygems/test_case.rb | 2 +- lib/rubygems/version.rb | 28 +++++++----- 21 files changed, 139 insertions(+), 70 deletions(-) (limited to 'lib/rubygems') diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb index 5c57076f91..86f2248b52 100644 --- a/lib/rubygems/basic_specification.rb +++ b/lib/rubygems/basic_specification.rb @@ -95,7 +95,7 @@ class Gem::BasicSpecification # Returns path to the extensions directory. def extensions_dir - @extensions_dir ||= Gem.default_ext_dir_for(base_dir) || + Gem.default_ext_dir_for(base_dir) || File.join(base_dir, 'extensions', Gem::Platform.local.to_s, Gem.extension_api_version) end @@ -196,7 +196,6 @@ class Gem::BasicSpecification def internal_init # :nodoc: @extension_dir = nil - @extensions_dir = nil @full_gem_path = nil @gem_dir = nil @ignored = nil diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb index 5b41fc288e..14b70b75ec 100644 --- a/lib/rubygems/command.rb +++ b/lib/rubygems/command.rb @@ -300,6 +300,8 @@ class Gem::Command options[:build_args] = build_args + self.ui = Gem::SilentUI.new if options[:silent] + if options[:help] then show_help elsif @when_invoked then @@ -520,10 +522,15 @@ class Gem::Command end end - add_common_option('-q', '--quiet', 'Silence commands') do |value, options| + add_common_option('-q', '--quiet', 'Silence command progress meter') do |value, options| Gem.configuration.verbose = false end + add_common_option("--silent", + "Silence rubygems output") do |value, options| + options[:silent] = true + end + # Backtrace and config-file are added so they show up in the help # commands. Both options are actually handled before the other # options get parsed. diff --git a/lib/rubygems/commands/cleanup_command.rb b/lib/rubygems/commands/cleanup_command.rb index 46f89f1bb8..83ee6b5c7c 100644 --- a/lib/rubygems/commands/cleanup_command.rb +++ b/lib/rubygems/commands/cleanup_command.rb @@ -76,6 +76,9 @@ If no gems are named all gems in GEM_HOME are cleaned. end def clean_gems + @original_home = Gem.dir + @original_path = Gem.path + get_primary_gems get_candidate_gems get_gems_to_cleanup @@ -87,9 +90,6 @@ If no gems are named all gems in GEM_HOME are cleaned. deps = deplist.strongly_connected_components.flatten - @original_home = Gem.dir - @original_path = Gem.path - deps.reverse_each do |spec| uninstall_dep spec end @@ -108,6 +108,7 @@ If no gems are named all gems in GEM_HOME are cleaned. end def get_gems_to_cleanup + gems_to_cleanup = @candidate_gems.select { |spec| @primary_gems[spec.name].version != spec.version } @@ -116,6 +117,10 @@ If no gems are named all gems in GEM_HOME are cleaned. spec.default_gem? } + gems_to_cleanup = gems_to_cleanup.select { |spec| + spec.base_dir == @original_home + } + @default_gems += default_gems @default_gems.uniq! @gems_to_cleanup = gems_to_cleanup.uniq diff --git a/lib/rubygems/commands/install_command.rb b/lib/rubygems/commands/install_command.rb index 5f0934aa17..4dd2f943c1 100644 --- a/lib/rubygems/commands/install_command.rb +++ b/lib/rubygems/commands/install_command.rb @@ -186,6 +186,7 @@ to write the specification by hand. For example: end def execute + if options.include? :gemdeps then install_from_gemdeps return # not reached diff --git a/lib/rubygems/commands/open_command.rb b/lib/rubygems/commands/open_command.rb index 957d369b26..a89b7421e3 100644 --- a/lib/rubygems/commands/open_command.rb +++ b/lib/rubygems/commands/open_command.rb @@ -15,6 +15,10 @@ class Gem::Commands::OpenCommand < Gem::Command "Opens gem sources in EDITOR") do |editor, options| options[:editor] = editor || get_env_editor end + add_option('-v', '--version VERSION', String, + "Opens specific gem version") do |version| + options[:version] = version + end end def arguments # :nodoc: diff --git a/lib/rubygems/commands/push_command.rb b/lib/rubygems/commands/push_command.rb index 035a03e5e7..6adeff6b30 100644 --- a/lib/rubygems/commands/push_command.rb +++ b/lib/rubygems/commands/push_command.rb @@ -76,13 +76,17 @@ You can upgrade or downgrade to the latest release version with: @host = gem_data.spec.metadata['default_gem_server'] end - # Always include this, even if it's nil - args << @host + push_host = nil if gem_data.spec.metadata.has_key?('allowed_push_host') - args << gem_data.spec.metadata['allowed_push_host'] + push_host = gem_data.spec.metadata['allowed_push_host'] end + @host ||= push_host + + # Always include @host, even if it's nil + args += [ @host, push_host ] + say "Pushing gem to #{@host || Gem.host}..." response = rubygems_api_request(*args) do |request| diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb index d654a5fa4e..688e9b0e6c 100644 --- a/lib/rubygems/commands/update_command.rb +++ b/lib/rubygems/commands/update_command.rb @@ -85,6 +85,7 @@ command to remove old versions. end def execute + if options[:system] then update_rubygems return diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index de90cbfd65..c8014814b4 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -306,9 +306,18 @@ if you believe they were disclosed to a third party. # Sets the RubyGems.org API key to +api_key+ def rubygems_api_key= api_key + set_api_key :rubygems_api_key, api_key + + @rubygems_api_key = api_key + end + + ## + # Set a specific host's API key to +api_key+ + + def set_api_key host, api_key check_credentials_permissions - config = load_file(credentials_path).merge(:rubygems_api_key => api_key) + config = load_file(credentials_path).merge(host => api_key) dirname = File.dirname credentials_path Dir.mkdir(dirname) unless File.exist? dirname @@ -320,7 +329,7 @@ if you believe they were disclosed to a third party. f.write config.to_yaml end - @rubygems_api_key = api_key + load_api_keys # reload end def load_file(filename) diff --git a/lib/rubygems/dependency.rb b/lib/rubygems/dependency.rb index c7b2451c6a..bf24b6e724 100644 --- a/lib/rubygems/dependency.rb +++ b/lib/rubygems/dependency.rb @@ -275,8 +275,9 @@ class Gem::Dependency end def matching_specs platform_only = false + env_req = Gem.env_requirement(name) matches = Gem::Specification.stubs_for(name).find_all { |spec| - requirement.satisfied_by? spec.version + requirement.satisfied_by?(spec.version) && env_req.satisfied_by?(spec.version) }.map(&:to_spec) if platform_only diff --git a/lib/rubygems/gemcutter_utilities.rb b/lib/rubygems/gemcutter_utilities.rb index 464993b11f..7c6d6bb364 100644 --- a/lib/rubygems/gemcutter_utilities.rb +++ b/lib/rubygems/gemcutter_utilities.rb @@ -115,7 +115,7 @@ module Gem::GemcutterUtilities with_response response do |resp| say "Signed in." - Gem.configuration.rubygems_api_key = resp.body + set_api_key host, resp.body end end @@ -156,5 +156,13 @@ module Gem::GemcutterUtilities end end + def set_api_key host, key + if host == Gem::DEFAULT_HOST + Gem.configuration.rubygems_api_key = key + else + Gem.configuration.set_api_key host, key + end + end + end diff --git a/lib/rubygems/install_update_options.rb b/lib/rubygems/install_update_options.rb index 26c5e84d1f..b2ab419800 100644 --- a/lib/rubygems/install_update_options.rb +++ b/lib/rubygems/install_update_options.rb @@ -179,6 +179,7 @@ module Gem::InstallUpdateOptions "Print post install message") do |value, options| options[:post_install_message] = value end + end ## diff --git a/lib/rubygems/path_support.rb b/lib/rubygems/path_support.rb index afb559d472..618bc793c4 100644 --- a/lib/rubygems/path_support.rb +++ b/lib/rubygems/path_support.rb @@ -22,21 +22,16 @@ class Gem::PathSupport # Constructor. Takes a single argument which is to be treated like a # hashtable, or defaults to ENV, the system environment. # - def initialize(env=ENV) - @env = env - - # note 'env' vs 'ENV'... - @home = env["GEM_HOME"] || ENV["GEM_HOME"] || Gem.default_dir + def initialize(env) + @home = env["GEM_HOME"] || Gem.default_dir if File::ALT_SEPARATOR then @home = @home.gsub(File::ALT_SEPARATOR, File::SEPARATOR) end - self.path = env["GEM_PATH"] || ENV["GEM_PATH"] + @path = split_gem_path env["GEM_PATH"], @home - @spec_cache_dir = - env["GEM_SPEC_CACHE"] || ENV["GEM_SPEC_CACHE"] || - Gem.default_spec_cache_dir + @spec_cache_dir = env["GEM_SPEC_CACHE"] || Gem.default_spec_cache_dir @spec_cache_dir = @spec_cache_dir.dup.untaint end @@ -44,24 +39,19 @@ class Gem::PathSupport private ## - # Set the Gem search path (as reported by Gem.path). + # Split the Gem search path (as reported by Gem.path). - def path=(gpaths) + def split_gem_path gpaths, home # FIX: it should be [home, *path], not [*path, home] gem_path = [] - # FIX: I can't tell wtf this is doing. - gpaths ||= (ENV['GEM_PATH'] || "").empty? ? nil : ENV["GEM_PATH"] - if gpaths - if gpaths.kind_of?(Array) - gem_path = gpaths.dup - else - gem_path = gpaths.split(Gem.path_separator) - if gpaths.end_with?(Gem.path_separator) - gem_path += default_path - end + gem_path = gpaths.split(Gem.path_separator) + # Handle the path_separator being set to a regexp, which will cause + # end_with? to error + if gpaths =~ /#{Gem.path_separator}\z/ + gem_path += default_path end if File::ALT_SEPARATOR then @@ -70,12 +60,12 @@ class Gem::PathSupport end end - gem_path << @home + gem_path << home else gem_path = default_path end - @path = gem_path.uniq + gem_path.uniq end # Return the default Gem path diff --git a/lib/rubygems/resolver/installer_set.rb b/lib/rubygems/resolver/installer_set.rb index 1ed02e6f9f..07fffeb150 100644 --- a/lib/rubygems/resolver/installer_set.rb +++ b/lib/rubygems/resolver/installer_set.rb @@ -138,10 +138,14 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set local_source = Gem::Source::Local.new - if local_spec = local_source.find_gem(name, dep.requirement) then - res << Gem::Resolver::IndexSpecification.new( - self, local_spec.name, local_spec.version, - local_source, local_spec.platform) + begin + if local_spec = local_source.find_gem(name, dep.requirement) then + res << Gem::Resolver::IndexSpecification.new( + self, local_spec.name, local_spec.version, + local_source, local_spec.platform) + end + rescue Gem::Package::FormatError + # ignore end end diff --git a/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb b/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb index deb4659448..42563664d6 100644 --- a/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb +++ b/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb @@ -127,6 +127,10 @@ module Gem::Resolver::Molinillo v.incoming_edges.delete(e) detach_vertex_named(v.name) unless v.root? || v.predecessors.any? end + vertex.incoming_edges.each do |e| + v = e.origin + v.outgoing_edges.delete(e) + end end # @param [String] name diff --git a/lib/rubygems/resolver/molinillo/lib/molinillo/gem_metadata.rb b/lib/rubygems/resolver/molinillo/lib/molinillo/gem_metadata.rb index 79cae2c697..1b66500f0f 100644 --- a/lib/rubygems/resolver/molinillo/lib/molinillo/gem_metadata.rb +++ b/lib/rubygems/resolver/molinillo/lib/molinillo/gem_metadata.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Gem::Resolver::Molinillo # The version of Gem::Resolver::Molinillo. - VERSION = '0.4.1'.freeze + VERSION = '0.4.3'.freeze end diff --git a/lib/rubygems/resolver/molinillo/lib/molinillo/modules/ui.rb b/lib/rubygems/resolver/molinillo/lib/molinillo/modules/ui.rb index 348ace286a..540b5b809c 100644 --- a/lib/rubygems/resolver/molinillo/lib/molinillo/modules/ui.rb +++ b/lib/rubygems/resolver/molinillo/lib/molinillo/modules/ui.rb @@ -58,7 +58,8 @@ module Gem::Resolver::Molinillo # # @return [Boolean] def debug? - @debug_mode ||= ENV['MOLINILLO_DEBUG'] + return @debug_mode if defined?(@debug_mode) + @debug_mode = ENV['MOLINILLO_DEBUG'] end end end diff --git a/lib/rubygems/resolver/molinillo/lib/molinillo/resolution.rb b/lib/rubygems/resolver/molinillo/lib/molinillo/resolution.rb index 0f822f0b82..2fc18843fe 100644 --- a/lib/rubygems/resolver/molinillo/lib/molinillo/resolution.rb +++ b/lib/rubygems/resolver/molinillo/lib/molinillo/resolution.rb @@ -342,26 +342,37 @@ module Gem::Resolver::Molinillo # @return [Boolean] Whether the possibility was swapped into {#activated} def attempt_to_swap_possibility swapped = activated.dup - swapped.vertex_named(name).payload = possibility - return unless swapped.vertex_named(name).requirements. + vertex = swapped.vertex_named(name) + vertex.payload = possibility + return unless vertex.requirements. all? { |r| requirement_satisfied_by?(r, swapped, possibility) } - attempt_to_activate_new_spec + return unless new_spec_satisfied? + actual_vertex = activated.vertex_named(name) + actual_vertex.payload = possibility + fixup_swapped_children(actual_vertex) + activate_spec + end + + # Ensures there are no orphaned successors to the given {vertex}. + # @param [DependencyGraph::Vertex] vertex the vertex to fix up. + # @return [void] + def fixup_swapped_children(vertex) + payload = vertex.payload + dep_names = dependencies_for(payload).map(&method(:name_for)) + vertex.successors.each do |succ| + if !dep_names.include?(succ.name) && !succ.root? && succ.predecessors.to_a == [vertex] + debug(depth) { "Removing orphaned spec #{succ.name} after swapping #{name}" } + activated.detach_vertex_named(succ.name) + requirements.delete_if { |r| name_for(r) == succ.name } + end + end end # Attempts to activate the current {#possibility} (given that it hasn't # already been activated) # @return [void] def attempt_to_activate_new_spec - satisfied = begin - locked_requirement = locked_requirement_named(name) - requested_spec_satisfied = requirement_satisfied_by?(requirement, activated, possibility) - locked_spec_satisfied = !locked_requirement || - requirement_satisfied_by?(locked_requirement, activated, possibility) - debug(depth) { 'Unsatisfied by requested spec' } unless requested_spec_satisfied - debug(depth) { 'Unsatisfied by locked spec' } unless locked_spec_satisfied - requested_spec_satisfied && locked_spec_satisfied - end - if satisfied + if new_spec_satisfied? activate_spec else create_conflict @@ -369,6 +380,18 @@ module Gem::Resolver::Molinillo end end + # @return [Boolean] whether the current spec is satisfied as a new + # possibility. + def new_spec_satisfied? + locked_requirement = locked_requirement_named(name) + requested_spec_satisfied = requirement_satisfied_by?(requirement, activated, possibility) + locked_spec_satisfied = !locked_requirement || + requirement_satisfied_by?(locked_requirement, activated, possibility) + debug(depth) { 'Unsatisfied by requested spec' } unless requested_spec_satisfied + debug(depth) { 'Unsatisfied by locked spec' } unless locked_spec_satisfied + requested_spec_satisfied && locked_spec_satisfied + end + # @param [String] requirement_name the spec name to search for # @return [Object] the locked spec named `requirement_name`, if one # is found on {#base} @@ -394,7 +417,7 @@ module Gem::Resolver::Molinillo # @return [void] def require_nested_dependencies_for(activated_spec) nested_dependencies = dependencies_for(activated_spec) - debug(depth) { "Requiring nested dependencies (#{nested_dependencies.map(&:to_s).join(', ')})" } + debug(depth) { "Requiring nested dependencies (#{nested_dependencies.join(', ')})" } nested_dependencies.each { |d| activated.add_child_vertex(name_for(d), nil, [name_for(activated_spec)], d) } push_state_for_requirements(requirements + nested_dependencies, nested_dependencies.size > 0) diff --git a/lib/rubygems/source_list.rb b/lib/rubygems/source_list.rb index 942d657963..66ce4d57ed 100644 --- a/lib/rubygems/source_list.rb +++ b/lib/rubygems/source_list.rb @@ -59,7 +59,7 @@ class Gem::SourceList Gem::Source.new(URI.parse(obj)) end - @sources << src + @sources << src unless @sources.include?(src) src end diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 8e2557cdb2..8ff6299a41 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -1684,6 +1684,8 @@ class Gem::Specification < Gem::BasicSpecification (conflicts[spec] ||= []) << dep end } + env_req = Gem.env_requirement(name) + (conflicts[self] ||= []) << env_req unless env_req.satisfied_by? version conflicts end @@ -1701,6 +1703,7 @@ class Gem::Specification < Gem::BasicSpecification # Return true if there are possible conflicts against the currently loaded specs. def has_conflicts? + return true unless Gem.env_requirement(name).satisfied_by?(version) self.dependencies.any? { |dep| if dep.runtime? then spec = Gem.loaded_specs[dep.name] diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index aebc36bc6c..0864f33478 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -570,7 +570,7 @@ class Gem::TestCase < MiniTest::Unit::TestCase def write_file(path) path = File.join @gemhome, path unless Pathname.new(path).absolute? dir = File.dirname path - FileUtils.mkdir_p dir + FileUtils.mkdir_p dir unless File.directory? dir open path, 'wb' do |io| yield io if block_given? diff --git a/lib/rubygems/version.rb b/lib/rubygems/version.rb index 54da49e8e8..2f6cfae6ed 100644 --- a/lib/rubygems/version.rb +++ b/lib/rubygems/version.rb @@ -219,7 +219,7 @@ class Gem::Version def bump @bump ||= begin - segments = self.segments.dup + segments = self.segments segments.pop while segments.any? { |s| String === s } segments.pop if segments.size > 1 @@ -298,7 +298,7 @@ class Gem::Version def release @release ||= if prerelease? - segments = self.segments.dup + segments = self.segments segments.pop while segments.any? { |s| String === s } self.class.new segments.join('.') else @@ -307,20 +307,14 @@ class Gem::Version end def segments # :nodoc: - - # segments is lazy so it can pick up version values that come from - # old marshaled versions, which don't go through marshal_load. - - @segments ||= @version.scan(/[0-9]+|[a-z]+/i).map do |s| - /^\d+$/ =~ s ? s.to_i : s - end + _segments.dup end ## # A recommended version for use with a ~> Requirement. def approximate_recommendation - segments = self.segments.dup + segments = self.segments segments.pop while segments.any? { |s| String === s } segments.pop while segments.size > 2 @@ -339,8 +333,8 @@ class Gem::Version return unless Gem::Version === other return 0 if @version == other._version - lhsegments = segments - rhsegments = other.segments + lhsegments = _segments + rhsegments = other._segments lhsize = lhsegments.size rhsize = rhsegments.size @@ -367,4 +361,14 @@ class Gem::Version def _version @version end + + def _segments + # segments is lazy so it can pick up version values that come from + # old marshaled versions, which don't go through marshal_load. + # since this version object is cached in @@all, its @segments should be frozen + + @segments ||= @version.scan(/[0-9]+|[a-z]+/i).map do |s| + /^\d+$/ =~ s ? s.to_i : s + end.freeze + end end -- cgit v1.2.3