ruby-changes:72687
From: Hiroshi <ko1@a...>
Date: Tue, 26 Jul 2022 14:38:38 +0900 (JST)
Subject: [ruby-changes:72687] 9e6d07f346 (master): Merge rubygems/bundler HEAD
https://git.ruby-lang.org/ruby.git/commit/?id=9e6d07f346 From 9e6d07f3462d29f340114650da9f13a36b866d5f Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA <hsbt@r...> Date: Tue, 26 Jul 2022 13:43:48 +0900 Subject: Merge rubygems/bundler HEAD Merge from https://github.com/rubygems/rubygems/commit/2af2520b4a7ab1c6eb1fdc3d2ef4d8c062d96ad7 --- lib/bundler.rb | 3 +- lib/bundler/definition.rb | 33 ++++++++++++------ lib/bundler/dependency.rb | 5 +-- lib/bundler/force_platform.rb | 18 ---------- lib/bundler/incomplete_specification.rb | 12 +++++++ lib/bundler/lazy_specification.rb | 33 +++++++++--------- lib/bundler/remote_specification.rb | 9 ++--- lib/bundler/resolver.rb | 5 ++- lib/bundler/rubygems_ext.rb | 22 ++++++++++-- lib/bundler/spec_set.rb | 52 ++++++++++++++++------------ spec/bundler/install/gemfile/sources_spec.rb | 39 +++++++++++++++++++++ spec/bundler/install/yanked_spec.rb | 6 ++-- spec/bundler/resolver/basic_spec.rb | 2 +- spec/bundler/runtime/platform_spec.rb | 52 ++++++++++++++++++++++------ spec/bundler/runtime/setup_spec.rb | 1 + spec/bundler/support/builders.rb | 4 +-- spec/bundler/support/indexes.rb | 1 + 17 files changed, 199 insertions(+), 98 deletions(-) delete mode 100644 lib/bundler/force_platform.rb create mode 100644 lib/bundler/incomplete_specification.rb diff --git a/lib/bundler.rb b/lib/bundler.rb index 9fb9ce3e82..7df22ab3a5 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -53,6 +53,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler.rb#L53 autoload :GemHelpers, File.expand_path("bundler/gem_helpers", __dir__) autoload :GemVersionPromoter, File.expand_path("bundler/gem_version_promoter", __dir__) autoload :Graph, File.expand_path("bundler/graph", __dir__) + autoload :IncompleteSpecification, File.expand_path("bundler/incomplete_specification", __dir__) autoload :Index, File.expand_path("bundler/index", __dir__) autoload :Injector, File.expand_path("bundler/injector", __dir__) autoload :Installer, File.expand_path("bundler/installer", __dir__) @@ -455,7 +456,7 @@ EOF https://github.com/ruby/ruby/blob/trunk/lib/bundler.rb#L456 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/definition.rb b/lib/bundler/definition.rb index 8f43befe35..4cb829470a 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -138,13 +138,13 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/definition.rb#L138 @unlock[:gems] ||= @dependencies.map(&:name) else eager_unlock = expand_dependencies(@unlock[:gems] || [], true) - @unlock[:gems] = @locked_specs.for(eager_unlock, false, false).map(&:name) + @unlock[:gems] = @locked_specs.for(eager_unlock, false, platforms).map(&:name) end @dependency_changes = converge_dependencies @local_changes = converge_locals - @locked_specs_incomplete_for_platform = !@locked_specs.for(requested_dependencies & expand_dependencies(locked_dependencies), true, true) + @reresolve = nil @requires = compute_requires end @@ -279,11 +279,8 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/definition.rb#L279 end end else - last_resolve = converge_locked_specs - # 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, true) - Resolver.resolve(expanded_dependencies, source_requirements, last_resolve, gem_version_promoter, additional_base_requirements_for_resolve, platforms) + @reresolve = reresolve end end @@ -468,7 +465,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/definition.rb#L465 private :sources def nothing_changed? - !@source_changes && !@dependency_changes && !@new_platform && !@path_changes && !@local_changes && !@locked_specs_incomplete_for_platform + !@source_changes && !@dependency_changes && !@new_platform && !@path_changes && !@local_changes end def unlocking? @@ -477,8 +474,14 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/definition.rb#L474 private + def reresolve + last_resolve = converge_locked_specs + expanded_dependencies = expand_dependencies(dependencies + metadata_dependencies, true) + Resolver.resolve(expanded_dependencies, source_requirements, last_resolve, gem_version_promoter, additional_base_requirements_for_resolve, platforms) + end + def filter_specs(specs, deps) - SpecSet.new(specs).for(expand_dependencies(deps, true), false, false) + SpecSet.new(specs).for(expand_dependencies(deps, true), false, platforms) end def materialize(dependencies) @@ -502,6 +505,17 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/definition.rb#L505 raise GemNotFound, "Could not find #{missing_specs_list.join(" nor ")}" end + if @reresolve.nil? + incomplete_specs = specs.incomplete_specs + + if incomplete_specs.any? + Bundler.ui.debug("The lockfile does not have all gems needed for the current platform though, Bundler will still re-resolve dependencies") + @unlock[:gems].concat(incomplete_specs.map(&:name)) + @resolve = reresolve + specs = resolve.materialize(dependencies) + end + end + unless specs["bundler"].any? bundler = sources.metadata_source.specs.search(Gem::Dependency.new("bundler", VERSION)).last specs["bundler"] = bundler @@ -549,7 +563,6 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/definition.rb#L563 [@new_platform, "you added a new platform to your gemfile"], [@path_changes, "the gemspecs for path gems changed"], [@local_changes, "the gemspecs for git local gems changed"], - [@locked_specs_incomplete_for_platform, "the lockfile does not have all gems needed for the current platform"], ].select(&:first).map(&:last).join(", ") end @@ -725,7 +738,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/definition.rb#L738 # if we won't need the source (according to the lockfile), # don't error if the path/git source isn't available next if specs. - for(requested_dependencies, false, true). + for(requested_dependencies, false). none? {|locked_spec| locked_spec.source == s.source } raise diff --git a/lib/bundler/dependency.rb b/lib/bundler/dependency.rb index 2449cb6411..7f94079e09 100644 --- a/lib/bundler/dependency.rb +++ b/lib/bundler/dependency.rb @@ -1,14 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/dependency.rb#L1 # frozen_string_literal: true require "rubygems/dependency" -require_relative "force_platform" require_relative "shared_helpers" require_relative "rubygems_ext" module Bundler class Dependency < Gem::Dependency - include ForcePlatform - attr_reader :autorequire attr_reader :groups, :platforms, :gemfile, :git, :github, :branch, :ref, :force_ruby_platform @@ -112,7 +109,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/dependency.rb#L109 @env = options["env"] @should_include = options.fetch("should_include", true) @gemfile = options["gemfile"] - @force_ruby_platform = options.fetch("force_ruby_platform", default_force_ruby_platform) + @force_ruby_platform = options["force_ruby_platform"] @autorequire = Array(options["require"] || []) if options.key?("require") end diff --git a/lib/bundler/force_platform.rb b/lib/bundler/force_platform.rb deleted file mode 100644 index 0648ea9737..0000000000 --- a/lib/bundler/force_platform.rb +++ /dev/null @@ -1,18 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/dependency.rb#L0 -# frozen_string_literal: true - -module Bundler - module ForcePlatform - private - - # The `:force_ruby_platform` value used by dependencies for resolution, and - # by locked specifications for materialization is `false` by default, except - # for TruffleRuby. TruffleRuby generally needs to force the RUBY platform - # variant unless the name is explicitly allowlisted. - - def default_force_ruby_platform - return false unless Bundler.current_ruby.truffleruby? - - !Gem::Platform::REUSE_AS_BINARY_ON_TRUFFLERUBY.include?(name) - end - end -end diff --git a/lib/bundler/incomplete_specification.rb b/lib/bundler/incomplete_specification.rb new file mode 100644 index 0000000000..6d0b9b901c --- /dev/null +++ b/lib/bundler/incomplete_specification.rb @@ -0,0 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/incomplete_specification.rb#L1 +# frozen_string_literal: true + +module Bundler + class IncompleteSpecification + attr_reader :name, :platform + + def initialize(name, platform) + @name = name + @platform = platform + end + end +end diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb index 89b21efc04..21e75d2126 100644 --- a/lib/bundler/lazy_specification.rb +++ b/lib/bundler/lazy_specification.rb @@ -1,16 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/lazy_specification.rb#L1 # frozen_string_literal: true (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/