diff options
Diffstat (limited to 'lib')
37 files changed, 273 insertions, 189 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index b299cc8a28..d370d8a53a 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -440,7 +440,7 @@ EOF end def local_platform - return Gem::Platform::RUBY if settings[:force_ruby_platform] + return Gem::Platform::RUBY if settings[:force_ruby_platform] || Gem.platforms == [Gem::Platform::RUBY] Gem::Platform.local end diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 249f5b2027..421f42cb52 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -586,6 +586,7 @@ module Bundler method_option :git, :type => :boolean, :default => true, :desc => "Initialize a git repo inside your library." method_option :mit, :type => :boolean, :desc => "Generate an MIT license file. Set a default with `bundle config set --global gem.mit true`." method_option :rubocop, :type => :boolean, :desc => "Add rubocop to the generated Rakefile and gemspec. Set a default with `bundle config set --global gem.rubocop true`." + method_option :changelog, :type => :boolean, :desc => "Generate changelog file. Set a default with `bundle config set --global gem.changelog true`." method_option :test, :type => :string, :lazy_default => Bundler.settings["gem.test"] || "", :aliases => "-t", :banner => "Use the specified test framework for your library", :desc => "Generate a test directory for your library, either rspec, minitest or test-unit. Set a default with `bundle config set --global gem.test (rspec|minitest|test-unit)`." method_option :ci, :type => :string, :lazy_default => Bundler.settings["gem.ci"] || "", diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb index 17b4956fa0..0d773579e5 100644 --- a/lib/bundler/cli/gem.rb +++ b/lib/bundler/cli/gem.rb @@ -142,6 +142,18 @@ module Bundler templates.merge!("CODE_OF_CONDUCT.md.tt" => "CODE_OF_CONDUCT.md") end + if ask_and_set(:changelog, "Do you want to include a changelog?", + "A changelog is a file which contains a curated, chronologically ordered list of notable " \ + "changes for each version of a project. To make it easier for users and contributors to" \ + " see precisely what notable changes have been made between each release (or version) of" \ + " the project. Whether consumers or developers, the end users of software are" \ + " human beings who care about what's in the software. When the software changes, people " \ + "want to know why and how. see https://keepachangelog.com") + config[:changelog] = true + Bundler.ui.info "Changelog enabled in config" + templates.merge!("CHANGELOG.md.tt" => "CHANGELOG.md") + end + if ask_and_set(:rubocop, "Do you want to add rubocop as a dependency for gems you generate?", "RuboCop is a static code analyzer that has out-of-the-box rules for many " \ "of the guidelines in the community style guide. " \ diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 9f9a938dce..3c25149d33 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require_relative "lockfile_parser" -require "set" module Bundler class Definition @@ -83,11 +82,7 @@ module Bundler @lockfile_contents = Bundler.read_file(lockfile) @locked_gems = LockfileParser.new(@lockfile_contents) @locked_platforms = @locked_gems.platforms - if Bundler.settings[:force_ruby_platform] - @platforms = [Gem::Platform::RUBY] - else - @platforms = @locked_platforms.dup - end + @platforms = @locked_platforms.dup @locked_bundler_version = @locked_gems.bundler_version @locked_ruby_version = @locked_gems.ruby_version @@ -259,23 +254,18 @@ module Bundler def resolve @resolve ||= begin last_resolve = converge_locked_specs - resolve = - if Bundler.frozen_bundle? - Bundler.ui.debug "Frozen, using resolution from the lockfile" - last_resolve - elsif !unlocking? && nothing_changed? - Bundler.ui.debug("Found no changes, using resolution from the lockfile") - last_resolve - else - # Run a resolve against the locally available gems - Bundler.ui.debug("Found changes from the lockfile, re-resolving dependencies because #{change_reason}") - expanded_dependencies = expand_dependencies(dependencies + metadata_dependencies, @remote) - last_resolve.merge Resolver.resolve(expanded_dependencies, index, source_requirements, last_resolve, gem_version_promoter, additional_base_requirements_for_resolve, platforms) - end - - # filter out gems that _can_ be installed on multiple platforms, but don't need - # to be - resolve.for(expand_dependencies(dependencies, true), [], false, false, false) + if Bundler.frozen_bundle? + Bundler.ui.debug "Frozen, using resolution from the lockfile" + last_resolve + elsif !unlocking? && nothing_changed? + Bundler.ui.debug("Found no changes, using resolution from the lockfile") + last_resolve + else + # Run a resolve against the locally available gems + Bundler.ui.debug("Found changes from the lockfile, re-resolving dependencies because #{change_reason}") + expanded_dependencies = expand_dependencies(dependencies + metadata_dependencies, @remote) + Resolver.resolve(expanded_dependencies, index, source_requirements, last_resolve, gem_version_promoter, additional_base_requirements_for_resolve, platforms) + end end end @@ -604,7 +594,7 @@ module Bundler deps_for_source = @dependencies.select {|s| s.source == source } locked_deps_for_source = @locked_deps.values.select {|dep| dep.source == locked_source } - Set.new(deps_for_source) != Set.new(locked_deps_for_source) + deps_for_source.sort != locked_deps_for_source.sort end def specs_for_source_changed?(source) @@ -884,7 +874,7 @@ module Bundler dependencies.each do |dep| dep = Dependency.new(dep, ">= 0") unless dep.respond_to?(:name) next unless remote || dep.current_platform? - target_platforms = dep.gem_platforms(remote ? Resolver.sort_platforms(@platforms) : [generic_local_platform]) + target_platforms = dep.gem_platforms(remote ? @platforms : [generic_local_platform]) deps += expand_dependency_with_platforms(dep, target_platforms) end deps diff --git a/lib/bundler/index.rb b/lib/bundler/index.rb index f26f542fde..f945176037 100644 --- a/lib/bundler/index.rb +++ b/lib/bundler/index.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "set" - module Bundler class Index include Enumerable @@ -65,11 +63,14 @@ module Bundler def unsorted_search(query, base) results = local_search(query, base) - seen = results.map(&:full_name).to_set unless @sources.empty? + seen = results.map(&:full_name).uniq unless @sources.empty? @sources.each do |source| source.unsorted_search(query, base).each do |spec| - results << spec if seen.add?(spec.full_name) + next if seen.include?(spec.full_name) + + seen << spec.full_name + results << spec end end @@ -170,7 +171,7 @@ module Bundler def dependencies_eql?(spec, other_spec) deps = spec.dependencies.select {|d| d.type != :development } other_deps = other_spec.dependencies.select {|d| d.type != :development } - Set.new(deps) == Set.new(other_deps) + deps.sort == other_deps.sort end def add_source(index) diff --git a/lib/bundler/installer/standalone.rb b/lib/bundler/installer/standalone.rb index 11d5c490ab..2a3f5cfe35 100644 --- a/lib/bundler/installer/standalone.rb +++ b/lib/bundler/installer/standalone.rb @@ -55,9 +55,10 @@ module Bundler kernel = (class << ::Kernel; self; end) [kernel, ::Kernel].each do |k| if k.private_method_defined?(:gem_original_require) + private_require = k.private_method_defined?(:require) k.send(:remove_method, :require) k.send(:define_method, :require, k.instance_method(:gem_original_require)) - k.send(:private, :require) + k.send(:private, :require) if private_require end end END diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb index 59689c609c..04ba2a2364 100644 --- a/lib/bundler/lazy_specification.rb +++ b/lib/bundler/lazy_specification.rb @@ -4,22 +4,6 @@ require_relative "match_platform" module Bundler class LazySpecification - Identifier = Struct.new(:name, :version, :platform) - class Identifier - include Comparable - def <=>(other) - return unless other.is_a?(Identifier) - [name, version, platform_string] <=> [other.name, other.version, other.platform_string] - end - - protected - - def platform_string - platform_string = platform.to_s - platform_string == Index::RUBY ? Index::NULL : platform_string - end - end - include MatchPlatform attr_reader :name, :version, :dependencies, :platform @@ -108,7 +92,7 @@ module Bundler end def identifier - @__identifier ||= Identifier.new(name, version, platform) + @__identifier ||= [name, version, platform_string] end def git_version @@ -116,6 +100,13 @@ module Bundler " #{source.revision[0..6]}" end + protected + + def platform_string + platform_string = platform.to_s + platform_string == Index::RUBY ? Index::NULL : platform_string + end + private def to_ary diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index 8812ba5ede..0f17ba3afb 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -5,6 +5,8 @@ module Bundler require_relative "vendored_molinillo" require_relative "resolver/spec_group" + include GemHelpers + # Figures out the best possible configuration of gems that satisfies # the list of passed dependencies and any child dependencies without # causing any gem activation errors. @@ -16,7 +18,6 @@ module Bundler # <GemBundle>,nil:: If the list of dependencies can be resolved, a # collection of gemspecs is returned. Otherwise, nil is returned. def self.resolve(requirements, index, source_requirements = {}, base = [], gem_version_promoter = GemVersionPromoter.new, additional_base_requirements = [], platforms = nil) - platforms = Set.new(platforms) if platforms base = SpecSet.new(base) unless base.is_a?(SpecSet) resolver = new(index, source_requirements, base, gem_version_promoter, additional_base_requirements, platforms) result = resolver.start(requirements) @@ -36,9 +37,13 @@ module Bundler end additional_base_requirements.each {|d| @base_dg.add_vertex(d.name, d) } @platforms = platforms + @resolving_only_for_ruby = platforms == [Gem::Platform::RUBY] @gem_version_promoter = gem_version_promoter @use_gvp = Bundler.feature_flag.use_gem_version_promoter_for_major_updates? || !@gem_version_promoter.major? @lockfile_uses_separate_rubygems_sources = Bundler.feature_flag.disable_multisource? + + @variant_specific_names = [] + @generic_names = [] end def start(requirements) @@ -102,14 +107,24 @@ module Bundler include Molinillo::SpecificationProvider def dependencies_for(specification) - specification.dependencies_for_activated_platforms + all_dependencies = specification.dependencies_for_activated_platforms + + if @variant_specific_names.include?(specification.name) + @variant_specific_names |= all_dependencies.map(&:name) - @generic_names + else + generic_names, variant_specific_names = specification.partitioned_dependency_names_for_activated_platforms + @variant_specific_names |= variant_specific_names - @generic_names + @generic_names |= generic_names + end + + all_dependencies end def search_for(dependency_proxy) platform = dependency_proxy.__platform dependency = dependency_proxy.dep - @search_for[dependency_proxy] ||= begin - name = dependency.name + name = dependency.name + search_result = @search_for[dependency_proxy] ||= begin index = index_for(dependency) results = index.search(dependency, @base[name]) @@ -136,37 +151,48 @@ module Bundler end nested.reduce([]) do |groups, (version, specs)| next groups if locked_requirement && !locked_requirement.satisfied_by?(version) - spec_group = SpecGroup.new(specs) - groups << spec_group + + specs_by_platform = Hash.new do |current_specs, current_platform| + current_specs[current_platform] = select_best_platform_match(specs, current_platform) + end + + spec_group_ruby = SpecGroup.create_for(specs_by_platform, [Gem::Platform::RUBY], Gem::Platform::RUBY) + groups << spec_group_ruby if spec_group_ruby + + next groups if @resolving_only_for_ruby + + spec_group = SpecGroup.create_for(specs_by_platform, @platforms, platform) + groups << spec_group if spec_group + + groups end else [] end # GVP handles major itself, but it's still a bit risky to trust it with it # until we get it settled with new behavior. For 2.x it can take over all cases. - search = if !@use_gvp + if !@use_gvp spec_groups else @gem_version_promoter.sort_versions(dependency, spec_groups) end - selected_sgs = [] - search.each do |sg| - next unless sg.for?(platform) - sg_all_platforms = sg.copy_for(self.class.sort_platforms(@platforms).reverse) - next unless sg_all_platforms - - selected_sgs << sg_all_platforms + end - next if sg_all_platforms.activated_platforms == [Gem::Platform::RUBY] - # Add a spec group for "non platform specific spec" as the fallback - # spec group. - sg_ruby = sg.copy_for([Gem::Platform::RUBY]) - next unless sg_ruby + unless search_result.empty? + specific_dependency = @variant_specific_names.include?(name) + return search_result unless specific_dependency - selected_sgs.insert(-2, sg_ruby) + search_result.each do |sg| + if @generic_names.include?(name) + @variant_specific_names -= [name] + sg.activate_all_platforms! + else + sg.activate_platform!(platform) + end end - selected_sgs end + + search_result end def index_for(dependency) @@ -237,13 +263,6 @@ module Bundler end end - # Sort platforms from most general to most specific - def self.sort_platforms(platforms) - platforms.sort_by do |platform| - platform_sort_key(platform) - end - end - def self.platform_sort_key(platform) # Prefer specific platform to not specific platform return ["99-LAST", "", "", ""] if Gem::Platform::RUBY == platform diff --git a/lib/bundler/resolver/spec_group.rb b/lib/bundler/resolver/spec_group.rb index 7fba5043a7..73ffec5838 100644 --- a/lib/bundler/resolver/spec_group.rb +++ b/lib/bundler/resolver/spec_group.rb @@ -3,27 +3,37 @@ module Bundler class Resolver class SpecGroup - include GemHelpers - attr_accessor :name, :version, :source attr_accessor :activated_platforms - def initialize(all_specs) - @all_specs = all_specs - raise ArgumentError, "cannot initialize with an empty value" unless exemplary_spec = all_specs.first + def self.create_for(specs, all_platforms, specific_platform) + specific_platform_specs = specs[specific_platform] + return unless specific_platform_specs.any? + + platforms = all_platforms.select {|p| specs[p].any? } + + new(specific_platform_specs.first, specs, platforms) + end + + def initialize(exemplary_spec, specs, relevant_platforms) + @exemplary_spec = exemplary_spec @name = exemplary_spec.name @version = exemplary_spec.version @source = exemplary_spec.source - @activated_platforms = [] - @dependencies = nil - @specs = Hash.new do |specs, platform| - specs[platform] = select_best_platform_match(all_specs, platform) + @all_platforms = relevant_platforms + @activated_platforms = relevant_platforms + @dependencies = Hash.new do |dependencies, platforms| + dependencies[platforms] = dependencies_for(platforms) end + @partitioned_dependency_names = Hash.new do |partitioned_dependency_names, platforms| + partitioned_dependency_names[platforms] = partitioned_dependency_names_for(platforms) + end + @specs = specs end def to_specs - @activated_platforms.map do |p| + activated_platforms.map do |p| specs = @specs[p] next unless specs.any? @@ -35,17 +45,12 @@ module Bundler end.flatten.compact.uniq end - def copy_for(platforms) - platforms.select! {|p| for?(p) } - return unless platforms.any? - - copied_sg = self.class.new(@all_specs) - copied_sg.activated_platforms = platforms - copied_sg + def activate_platform!(platform) + self.activated_platforms = [platform] end - def for?(platform) - @specs[platform].any? + def activate_all_platforms! + self.activated_platforms = @all_platforms end def to_s @@ -54,11 +59,11 @@ module Bundler end def dependencies_for_activated_platforms - dependencies = @activated_platforms.map {|p| __dependencies[p] } - metadata_dependencies = @activated_platforms.map do |platform| - metadata_dependencies(@specs[platform].first, platform) - end - dependencies.concat(metadata_dependencies).flatten + @dependencies[activated_platforms] + end + + def partitioned_dependency_names_for_activated_platforms + @partitioned_dependency_names[activated_platforms] end def ==(other) @@ -84,27 +89,37 @@ module Bundler protected def sorted_activated_platforms - @activated_platforms.sort_by(&:to_s) + activated_platforms.sort_by(&:to_s) end private - def __dependencies - @dependencies = Hash.new do |dependencies, platform| - dependencies[platform] = [] - specs = @specs[platform] - if spec = specs.first - spec.dependencies.each do |dep| - next if dep.type == :development - dependencies[platform] << DepProxy.get_proxy(dep, platform) - end - end - dependencies[platform] + def dependencies_for(platforms) + platforms.map do |platform| + __dependencies(platform) + metadata_dependencies(platform) + end.flatten + end + + def partitioned_dependency_names_for(platforms) + return @dependencies[platforms].map(&:name), [] if platforms.size == 1 + + @dependencies[platforms].partition do |dep_proxy| + @dependencies[platforms].count {|dp| dp.dep == dep_proxy.dep } == platforms.size + end.map {|deps| deps.map(&:name) } + end + + def __dependencies(platform) + dependencies = [] + @specs[platform].first.dependencies.each do |dep| + next if dep.type == :development + dependencies << DepProxy.get_proxy(dep, platform) end + dependencies end - def metadata_dependencies(spec, platform) - return [] unless spec && spec.is_a?(Gem::Specification) + def metadata_dependencies(platform) + spec = @specs[platform].first + return [] unless spec.is_a?(Gem::Specification) dependencies = [] if !spec.required_ruby_version.nil? && !spec.required_ruby_version.none? dependencies << DepProxy.get_proxy(Gem::Dependency.new("Ruby\0", spec.required_ruby_version), platform) diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index ca0ab67fb8..09b79acbf9 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -194,11 +194,11 @@ module Bundler return @md5_available if defined?(@md5_available) @md5_available = begin require "openssl" - OpenSSL::Digest.digest("MD5", "") + ::OpenSSL::Digest.digest("MD5", "") true rescue LoadError true - rescue OpenSSL::Digest::DigestError + rescue ::OpenSSL::Digest::DigestError false end end diff --git a/lib/bundler/source_list.rb b/lib/bundler/source_list.rb index 731a791531..436891256d 100644 --- a/lib/bundler/source_list.rb +++ b/lib/bundler/source_list.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "set" - module Bundler class SourceList attr_reader :path_sources, @@ -99,7 +97,7 @@ module Bundler @rubygems_aggregate = replacement_rubygems if replacement_rubygems return true if !equal_sources?(lock_sources, replacement_sources) && !equivalent_sources?(lock_sources, replacement_sources) - return true if replacement_rubygems && rubygems_remotes.to_set != replacement_rubygems.remotes.to_set + return true if replacement_rubygems && rubygems_remotes.sort_by(&:to_s) != replacement_rubygems.remotes.sort_by(&:to_s) false end @@ -153,7 +151,7 @@ module Bundler end def equal_sources?(lock_sources, replacement_sources) - lock_sources.to_set == replacement_sources.to_set + lock_sources.sort_by(&:to_s) == replacement_sources.sort_by(&:to_s) end def equal_source?(source, other_source) diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb index 951e80231e..399c91fea5 100644 --- a/lib/bundler/spec_set.rb +++ b/lib/bundler/spec_set.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require "tsort" -require "set" module Bundler class SpecSet @@ -13,14 +12,16 @@ module Bundler end def for(dependencies, skip = [], check = false, match_current_platform = false, raise_on_missing = true) - handled = Set.new + handled = [] deps = dependencies.dup specs = [] skip += ["bundler"] loop do break unless dep = deps.shift - next if !handled.add?(dep) || skip.include?(dep.name) + next if handled.include?(dep) || skip.include?(dep.name) + + handled << dep specs_for_dep = spec_for_dependency(dep, match_current_platform) if specs_for_dep.any? diff --git a/lib/bundler/templates/newgem/CHANGELOG.md.tt b/lib/bundler/templates/newgem/CHANGELOG.md.tt new file mode 100644 index 0000000000..c9ea96d453 --- /dev/null +++ b/lib/bundler/templates/newgem/CHANGELOG.md.tt @@ -0,0 +1,5 @@ +## [Unreleased] + +## [0.1.0] - <%= Time.now.strftime('%F') %> + +- Initial release diff --git a/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb b/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb index d1d7045daf..936399ed2f 100644 --- a/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +++ b/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require 'set' require 'tsort' require_relative 'dependency_graph/log' diff --git a/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb b/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb index 41bc013143..1185a8ab05 100644 --- a/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb +++ b/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb @@ -59,7 +59,7 @@ module Bundler::Molinillo # @param [Set<Vertex>] vertices the set to add the predecessors to # @return [Set<Vertex>] the vertices of {#graph} where `self` is a # {#descendent?} - def _recursive_predecessors(vertices = Set.new) + def _recursive_predecessors(vertices = new_vertex_set) incoming_edges.each do |edge| vertex = edge.origin next unless vertices.add?(vertex) @@ -85,7 +85,7 @@ module Bundler::Molinillo # @param [Set<Vertex>] vertices the set to add the successors to # @return [Set<Vertex>] the vertices of {#graph} where `self` is an # {#ancestor?} - def _recursive_successors(vertices = Set.new) + def _recursive_successors(vertices = new_vertex_set) outgoing_edges.each do |edge| vertex = edge.destination next unless vertices.add?(vertex) @@ -128,7 +128,7 @@ module Bundler::Molinillo # Is there a path from `self` to `other` following edges in the # dependency graph? - # @return true iff there is a path following edges within this {#graph} + # @return whether there is a path following edges within this {#graph} def path_to?(other) _path_to?(other) end @@ -138,7 +138,7 @@ module Bundler::Molinillo # @param [Vertex] other the vertex to check if there's a path to # @param [Set<Vertex>] visited the vertices of {#graph} that have been visited # @return [Boolean] whether there is a path to `other` from `self` - def _path_to?(other, visited = Set.new) + def _path_to?(other, visited = new_vertex_set) return false unless visited.add?(self) return true if equal?(other) successors.any? { |v| v._path_to?(other, visited) } @@ -147,12 +147,18 @@ module Bundler::Molinillo # Is there a path from `other` to `self` following edges in the # dependency graph? - # @return true iff there is a path following edges within this {#graph} + # @return whether there is a path following edges within this {#graph} def ancestor?(other) other.path_to?(self) end alias is_reachable_from? ancestor? + + def new_vertex_set + require 'set' + Set.new + end + private :new_vertex_set end end end diff --git a/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb b/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb index 14ac26b39e..e210202b69 100644 --- a/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb +++ b/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb @@ -34,7 +34,7 @@ module Bundler::Molinillo # An error caused by attempting to fulfil a dependency that was circular # - # @note This exception will be thrown iff a {Vertex} is added to a + # @note This exception will be thrown if and only if a {Vertex} is added to a # {DependencyGraph} that has a {DependencyGraph::Vertex#path_to?} an # existing {DependencyGraph::Vertex} class CircularDependencyError < ResolverError diff --git a/lib/bundler/vendor/thor/lib/thor.rb b/lib/bundler/vendor/thor/lib/thor.rb index f2a03388cc..0794dbb522 100644 --- a/lib/bundler/vendor/thor/lib/thor.rb +++ b/lib/bundler/vendor/thor/lib/thor.rb @@ -1,7 +1,7 @@ -require "set" require_relative "thor/base" class Bundler::Thor + $thor_runner ||= false class << self # Allows for custom "Command" package naming. # @@ -323,7 +323,7 @@ class Bundler::Thor # ==== Parameters # Symbol ...:: A list of commands that should be affected. def stop_on_unknown_option!(*command_names) - stop_on_unknown_option.merge(command_names) + @stop_on_unknown_option = stop_on_unknown_option | command_names end def stop_on_unknown_option?(command) #:nodoc: @@ -337,7 +337,7 @@ class Bundler::Thor # ==== Parameters # Symbol ...:: A list of commands that should be affected. def disable_required_check!(*command_names) - disable_required_check.merge(command_names) + @disable_required_check = disable_required_check | command_names end def disable_required_check?(command) #:nodoc: @@ -347,12 +347,12 @@ class Bundler::Thor protected def stop_on_unknown_option #:nodoc: - @stop_on_unknown_option ||= Set.new + @stop_on_unknown_option ||= [] end # help command has the required check disabled by default. def disable_required_check #:nodoc: - @disable_required_check ||= Set.new([:help]) + @disable_required_check ||= [:help] end # The method responsible for dispatching given the args. @@ -398,7 +398,6 @@ class Bundler::Thor # the namespace should be displayed as arguments. # def banner(command, namespace = nil, subcommand = false) - $thor_runner ||= false command.formatted_usage(self, $thor_runner, subcommand).split("\n").map do |formatted_usage| "#{basename} #{formatted_usage}" end.join("\n") diff --git a/lib/bundler/vendor/thor/lib/thor/actions.rb b/lib/bundler/vendor/thor/lib/thor/actions.rb index a5368d07f3..de9323b2db 100644 --- a/lib/bundler/vendor/thor/lib/thor/actions.rb +++ b/lib/bundler/vendor/thor/lib/thor/actions.rb @@ -219,7 +219,7 @@ class Bundler::Thor contents = if is_uri require "open-uri" - open(path, "Accept" => "application/x-thor-template", &:read) + URI.open(path, "Accept" => "application/x-thor-template", &:read) else open(path, &:read) end diff --git a/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb b/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb index afdbd53dd0..62c82b3dba 100644 --- a/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +++ b/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb @@ -251,7 +251,8 @@ class Bundler::Thor # path<String>:: path of the file to be changed # flag<Regexp|String>:: the regexp or string to be replaced # replacement<String>:: the replacement, can be also given as a block - # config<Hash>:: give :verbose => false to not log the status. + # config<Hash>:: give :verbose => false to not log the status, and + # :force => true, to force the replacement regardles of runner behavior. # # ==== Example # @@ -262,9 +263,10 @@ class Bundler::Thor # end # def gsub_file(path, flag, *args, &block) - return unless behavior == :invoke config = args.last.is_a?(Hash) ? args.pop : {} + return unless behavior == :invoke || config.fetch(:force, false) + path = File.expand_path(path, destination_root) say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true) diff --git a/lib/bundler/vendor/thor/lib/thor/error.rb b/lib/bundler/vendor/thor/lib/thor/error.rb index 1553afd201..7d57129b83 100644 --- a/lib/bundler/vendor/thor/lib/thor/error.rb +++ b/lib/bundler/vendor/thor/lib/thor/error.rb @@ -1,5 +1,5 @@ class Bundler::Thor - Correctable = if defined?(DidYouMean::SpellChecker) && defined?(DidYouMean::Correctable) + Correctable = if defined?(DidYouMean::SpellChecker) && defined?(DidYouMean::Correctable) # rubocop:disable Naming/ConstantName # In order to support versions of Ruby that don't have keyword # arguments, we need our own spell checker class that doesn't take key # words. Even though this code wouldn't be hit because of the check diff --git a/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb b/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb index d0f43e2d97..3a5d82cf29 100644 --- a/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb +++ b/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb @@ -30,7 +30,11 @@ class Bundler::Thor arguments.each do |argument| if !argument.default.nil? - @assigns[argument.human_name] = argument.default + begin + @assigns[argument.human_name] = argument.default.dup + rescue TypeError # Compatibility shim for un-dup-able Fixnum in Ruby < 2.4 + @assigns[argument.human_name] = argument.default + end elsif argument.required? @non_assigned_required << argument end diff --git a/lib/bundler/vendor/thor/lib/thor/parser/options.rb b/lib/bundler/vendor/thor/lib/thor/parser/options.rb index 6d1342ee3c..3a8927d09c 100644 --- a/lib/bundler/vendor/thor/lib/thor/parser/options.rb +++ b/lib/bundler/vendor/thor/lib/thor/parser/options.rb @@ -133,15 +133,16 @@ class Bundler::Thor protected - def assign_result!(option, result) - if option.repeatable && option.type == :hash - (@assigns[option.human_name] ||= {}).merge!(result) - elsif option.repeatable - (@assigns[option.human_name] ||= []) << result - else - @assigns[option.human_name] = result + def assign_result!(option, result) + if option.repeatable && option.type == :hash + (@assigns[option.human_name] ||= {}).merge!(result) + elsif option.repeatable + (@assigns[option.human_name] ||= []) << result + else + @assigns[option.human_name] = result + end end - end + # Check if the current value in peek is a registered switch. # # Two booleans are returned. The first is true if the current value diff --git a/lib/bundler/vendor/thor/lib/thor/shell/basic.rb b/lib/bundler/vendor/thor/lib/thor/shell/basic.rb index be48358cb1..2dddd4a53a 100644 --- a/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +++ b/lib/bundler/vendor/thor/lib/thor/shell/basic.rb @@ -94,6 +94,8 @@ class Bundler::Thor # say("I know you knew that.") # def say(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/)) + return if quiet? + buffer = prepare_message(message, *color) buffer << "\n" if force_new_line && !message.to_s.end_with?("\n") @@ -230,8 +232,9 @@ class Bundler::Thor paras = message.split("\n\n") paras.map! do |unwrapped| - counter = 0 - unwrapped.split(" ").inject do |memo, word| + words = unwrapped.split(" ") + counter = words.first.length + words.inject do |memo, word| word = word.gsub(/\n\005/, "\n").gsub(/\005/, "\n") counter = 0 if word.include? "\n" if (counter + word.length + 1) < width diff --git a/lib/bundler/vendor/thor/lib/thor/shell/color.rb b/lib/bundler/vendor/thor/lib/thor/shell/color.rb index 29f280202d..dc167ed3cc 100644 --- a/lib/bundler/vendor/thor/lib/thor/shell/color.rb +++ b/lib/bundler/vendor/thor/lib/thor/shell/color.rb @@ -97,7 +97,11 @@ class Bundler::Thor protected def can_display_colors? - stdout.tty? && !are_colors_disabled? + are_colors_supported? && !are_colors_disabled? + end + + def are_colors_supported? + stdout.tty? && ENV["TERM"] != "dumb" end def are_colors_disabled? diff --git a/lib/bundler/vendor/thor/lib/thor/version.rb b/lib/bundler/vendor/thor/lib/thor/version.rb index 1b222da995..a3efa9f762 100644 --- a/lib/bundler/vendor/thor/lib/thor/version.rb +++ b/lib/bundler/vendor/thor/lib/thor/version.rb @@ -1,3 +1,3 @@ class Bundler::Thor - VERSION = "1.0.1" + VERSION = "1.1.0" end diff --git a/lib/bundler/version.rb b/lib/bundler/version.rb index 35007186b5..f9569c8f78 100644 --- a/lib/bundler/version.rb +++ b/lib/bundler/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: false module Bundler - VERSION = "2.2.7".freeze + VERSION = "2.2.9".freeze def self.bundler_major_version @bundler_major_version ||= VERSION.split(".").first.to_i diff --git a/lib/rubygems.rb b/lib/rubygems.rb index f90e6c5c85..41b1353e1f 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -8,7 +8,7 @@ require 'rbconfig' module Gem - VERSION = "3.2.7".freeze + VERSION = "3.2.9".freeze end # Must be first since it unloads the prelude from 1.9.2 @@ -275,7 +275,7 @@ module Gem unless spec = specs.first msg = "can't find gem #{dep} with executable #{exec_name}" - if name == "bundler" && bundler_message = Gem::BundlerVersionFinder.missing_version_message + if dep.filters_bundler? && bundler_message = Gem::BundlerVersionFinder.missing_version_message msg = bundler_message end raise Gem::GemNotFoundException, msg diff --git a/lib/rubygems/dependency.rb b/lib/rubygems/dependency.rb index 68f3e3d991..3721204ab2 100644 --- a/lib/rubygems/dependency.rb +++ b/lib/rubygems/dependency.rb @@ -277,7 +277,7 @@ class Gem::Dependency requirement.satisfied_by?(spec.version) && env_req.satisfied_by?(spec.version) end.map(&:to_spec) - Gem::BundlerVersionFinder.filter!(matches) if name == "bundler".freeze && !requirement.specific? + Gem::BundlerVersionFinder.filter!(matches) if filters_bundler? if platform_only matches.reject! do |spec| @@ -295,6 +295,10 @@ class Gem::Dependency @requirement.specific? end + def filters_bundler? + name == "bundler".freeze && !specific? + end + def to_specs matches = matching_specs true diff --git a/lib/rubygems/resolver/index_specification.rb b/lib/rubygems/resolver/index_specification.rb index 2aa6b419ba..9ea76f40ba 100644 --- a/lib/rubygems/resolver/index_specification.rb +++ b/lib/rubygems/resolver/index_specification.rb @@ -35,9 +35,12 @@ class Gem::Resolver::IndexSpecification < Gem::Resolver::Specification ## # The required_ruby_version constraint for this specification + # + # A fallback is included because when generated, some marshalled specs have it + # set to +nil+. def required_ruby_version - spec.required_ruby_version + spec.required_ruby_version || Gem::Requirement.default end ## diff --git a/lib/rubygems/resolver/molinillo/lib/molinillo/delegates/specification_provider.rb b/lib/rubygems/resolver/molinillo/lib/molinillo/delegates/specification_provider.rb index 2ddb0ac426..b765226fb0 100644 --- a/lib/rubygems/resolver/molinillo/lib/molinillo/delegates/specification_provider.rb +++ b/lib/rubygems/resolver/molinillo/lib/molinillo/delegates/specification_provider.rb @@ -26,6 +26,13 @@ module Gem::Resolver::Molinillo end end + # (see Gem::Resolver::Molinillo::SpecificationProvider#dependencies_equal?) + def dependencies_equal?(dependencies, other_dependencies) + with_no_such_dependency_error_handling do + specification_provider.dependencies_equal?(dependencies, other_dependencies) + end + end + # (see Gem::Resolver::Molinillo::SpecificationProvider#name_for) def name_for(dependency) with_no_such_dependency_error_handling do diff --git a/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb b/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb index 773bb3417f..16430a79f5 100644 --- a/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb +++ b/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require 'set' require 'tsort' require_relative 'dependency_graph/log' diff --git a/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb b/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb index f4cc333dd1..77114951b2 100644 --- a/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb +++ b/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb @@ -59,7 +59,7 @@ module Gem::Resolver::Molinillo # @param [Set<Vertex>] vertices the set to add the predecessors to # @return [Set<Vertex>] the vertices of {#graph} where `self` is a # {#descendent?} - def _recursive_predecessors(vertices = Set.new) + def _recursive_predecessors(vertices = new_vertex_set) incoming_edges.each do |edge| vertex = edge.origin next unless vertices.add?(vertex) @@ -85,7 +85,7 @@ module Gem::Resolver::Molinillo # @param [Set<Vertex>] vertices the set to add the successors to # @return [Set<Vertex>] the vertices of {#graph} where `self` is an # {#ancestor?} - def _recursive_successors(vertices = Set.new) + def _recursive_successors(vertices = new_vertex_set) outgoing_edges.each do |edge| vertex = edge.destination next unless vertices.add?(vertex) @@ -138,7 +138,7 @@ module Gem::Resolver::Molinillo # @param [Vertex] other the vertex to check if there's a path to # @param [Set<Vertex>] visited the vertices of {#graph} that have been visited # @return [Boolean] whether there is a path to `other` from `self` - def _path_to?(other, visited = Set.new) + def _path_to?(other, visited = new_vertex_set) return false unless visited.add?(self) return true if equal?(other) successors.any? { |v| v._path_to?(other, visited) } @@ -147,12 +147,18 @@ module Gem::Resolver::Molinillo # Is there a path from `other` to `self` following edges in the # dependency graph? - # @return true iff there is a path following edges within this {#graph} + # @return whether there is a path following edges within this {#graph} def ancestor?(other) other.path_to?(self) end alias is_reachable_from? ancestor? + + def new_vertex_set + require 'set' + Set.new + end + private :new_vertex_set end end end diff --git a/lib/rubygems/resolver/molinillo/lib/molinillo/errors.rb b/lib/rubygems/resolver/molinillo/lib/molinillo/errors.rb index a6e182e84d..ada03a901c 100644 --- a/lib/rubygems/resolver/molinillo/lib/molinillo/errors.rb +++ b/lib/rubygems/resolver/molinillo/lib/molinillo/errors.rb @@ -121,7 +121,7 @@ module Gem::Resolver::Molinillo t = ''.dup depth = 2 tree.each do |req| - t << ' ' * depth << req.to_s + t << ' ' * depth << printable_requirement.call(req) unless tree.last == req if spec = conflict.activated_by_name[name_for(req)] t << %( was resolved to #{version_for_spec.call(spec)}, which) diff --git a/lib/rubygems/resolver/molinillo/lib/molinillo/modules/specification_provider.rb b/lib/rubygems/resolver/molinillo/lib/molinillo/modules/specification_provider.rb index a44b9c0d5d..9448dc7bf3 100644 --- a/lib/rubygems/resolver/molinillo/lib/molinillo/modules/specification_provider.rb +++ b/lib/rubygems/resolver/molinillo/lib/molinillo/modules/specification_provider.rb @@ -45,6 +45,17 @@ module Gem::Resolver::Molinillo true end + # Determines whether two arrays of dependencies are equal, and thus can be + # grouped. + # + # @param [Array<Object>] dependencies + # @param [Array<Object>] other_dependencies + # @return [Boolean] whether `dependencies` and `other_dependencies` should + # be considered equal. + def dependencies_equal?(dependencies, other_dependencies) + dependencies == other_dependencies + end + # Returns the name for the given `dependency`. # @note This method should be 'pure', i.e. the return value should depend # only on the `dependency` parameter. diff --git a/lib/rubygems/resolver/molinillo/lib/molinillo/resolution.rb b/lib/rubygems/resolver/molinillo/lib/molinillo/resolution.rb index f1c60ec544..8b40e59e42 100644 --- a/lib/rubygems/resolver/molinillo/lib/molinillo/resolution.rb +++ b/lib/rubygems/resolver/molinillo/lib/molinillo/resolution.rb @@ -329,11 +329,11 @@ module Gem::Resolver::Molinillo # Look for past conflicts that could be unwound to affect the # requirement tree for the current conflict + all_reqs = last_detail_for_current_unwind.all_requirements + all_reqs_size = all_reqs.size relevant_unused_unwinds = unused_unwind_options.select do |alternative| - intersecting_requirements = - last_detail_for_current_unwind.all_requirements & - alternative.requirements_unwound_to_instead - next if intersecting_requirements.empty? + diff_reqs = all_reqs - alternative.requirements_unwound_to_instead + next if diff_reqs.size == all_reqs_size # Find the highest index unwind whilst looping through current_detail = alternative if alternative > current_detail alternative @@ -344,8 +344,12 @@ module Gem::Resolver::Molinillo state.unused_unwind_options += unwind_details.reject { |detail| detail.state_index == -1 } # Update the requirements_unwound_to_instead on any relevant unused unwinds - relevant_unused_unwinds.each { |d| d.requirements_unwound_to_instead << current_detail.state_requirement } - unwind_details.each { |d| d.requirements_unwound_to_instead << current_detail.state_requirement } + relevant_unused_unwinds.each do |d| + (d.requirements_unwound_to_instead << current_detail.state_requirement).uniq! + end + unwind_details.each do |d| + (d.requirements_unwound_to_instead << current_detail.state_requirement).uniq! + end current_detail end @@ -803,7 +807,7 @@ module Gem::Resolver::Molinillo possibilities.reverse_each do |possibility| dependencies = dependencies_for(possibility) - if current_possibility_set && current_possibility_set.dependencies == dependencies + if current_possibility_set && dependencies_equal?(current_possibility_set.dependencies, dependencies) current_possibility_set.possibilities.unshift(possibility) else possibility_sets.unshift(PossibilitySet.new(dependencies, [possibility])) diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 4e1a3a3801..73062afe53 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -827,7 +827,9 @@ class Gem::Specification < Gem::BasicSpecification if @@stubs @@stubs_by_name[name] || [] else - @@stubs_by_name[name] ||= stubs_for_pattern("#{name}-*.gemspec") + @@stubs_by_name[name] ||= stubs_for_pattern("#{name}-*.gemspec").select do |s| + s.name == name + end end end @@ -848,7 +850,9 @@ class Gem::Specification < Gem::BasicSpecification specs.sort! do |a, b| names = a.name <=> b.name next names if names.nonzero? - b.version <=> a.version + versions = b.version <=> a.version + next versions if versions.nonzero? + b.platform == Gem::Platform::RUBY ? -1 : 1 end end @@ -1084,20 +1088,15 @@ class Gem::Specification < Gem::BasicSpecification end def self._latest_specs(specs, prerelease = false) # :nodoc: - result = Hash.new {|h,k| h[k] = {} } - native = {} + result = {} specs.reverse_each do |spec| next if spec.version.prerelease? unless prerelease - native[spec.name] = spec.version if spec.platform == Gem::Platform::RUBY - result[spec.name][spec.platform] = spec + result[spec.name] = spec end - result.map(&:last).map(&:values).flatten.reject do |spec| - minimum = native[spec.name] - minimum && spec.version < minimum - end.sort_by{|tup| tup.name } + result.map(&:last).flatten.sort_by{|tup| tup.name } end ## @@ -2552,7 +2551,7 @@ class Gem::Specification < Gem::BasicSpecification begin dependencies.each do |dep| next unless dep.runtime? - dep.to_specs.each do |dep_spec| + dep.matching_specs(true).each do |dep_spec| next if visited.has_key?(dep_spec) visited[dep_spec] = true trail.push(dep_spec) diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index 0f3791f03d..e2763561c6 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -311,7 +311,7 @@ class Gem::TestCase < Minitest::Test ENV['XDG_CONFIG_HOME'] = nil ENV['XDG_DATA_HOME'] = nil ENV['SOURCE_DATE_EPOCH'] = nil - ENV["TMPDIR"] = @tmp + ENV['BUNDLER_VERSION'] = nil @current_dir = Dir.pwd @fetcher = nil @@ -322,13 +322,10 @@ class Gem::TestCase < Minitest::Test # capture output Gem::DefaultUserInteraction.ui = Gem::MockGemUi.new - tmpdir = File.realpath Dir.tmpdir - tmpdir.tap(&Gem::UNTAINT) - - @tempdir = File.join(tmpdir, "test_rubygems_#{$$}") + @tempdir = Dir.mktmpdir("test_rubygems_", @tmp) @tempdir.tap(&Gem::UNTAINT) - FileUtils.mkdir_p @tempdir + ENV["TMPDIR"] = @tempdir @orig_SYSTEM_WIDE_CONFIG_FILE = Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE Gem::ConfigFile.send :remove_const, :SYSTEM_WIDE_CONFIG_FILE @@ -367,7 +364,9 @@ class Gem::TestCase < Minitest::Test Dir.chdir @tempdir ENV['HOME'] = @userhome + Gem.instance_variable_set :@config_file, nil Gem.instance_variable_set :@user_home, nil + Gem.instance_variable_set :@config_home, nil Gem.instance_variable_set :@data_home, nil Gem.instance_variable_set :@gemdeps, nil Gem.instance_variable_set :@env_requirements_by_name, nil |