ruby-changes:72828
From: David <ko1@a...>
Date: Fri, 5 Aug 2022 16:36:57 +0900 (JST)
Subject: [ruby-changes:72828] 5a9db23734 (master): [rubygems/rubygems] Automatically remove "ruby" from lockfile if incomplete
https://git.ruby-lang.org/ruby.git/commit/?id=5a9db23734 From 5a9db23734e76c2915f1ccb8f87e992bc831598b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...> Date: Tue, 2 Aug 2022 17:45:28 +0200 Subject: [rubygems/rubygems] Automatically remove "ruby" from lockfile if incomplete https://github.com/rubygems/rubygems/commit/69d0b4e10b --- lib/bundler/definition.rb | 12 ++++ lib/bundler/spec_set.rb | 4 ++ .../install/gemfile/specific_platform_spec.rb | 71 ++++++++++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 34c23796e8..ccb3ab1cec 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -484,6 +484,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/definition.rb#L484 def reresolve last_resolve = converge_locked_specs + remove_ruby_from_platforms_if_necessary!(dependencies) 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 @@ -865,6 +866,17 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/definition.rb#L866 end end + def remove_ruby_from_platforms_if_necessary!(dependencies) + return if Bundler.frozen_bundle? || + Bundler.local_platform == Gem::Platform::RUBY || + !platforms.include?(Gem::Platform::RUBY) || + (@new_platform && platforms.last == Gem::Platform::RUBY) || + !@originally_locked_specs.incomplete_ruby_specs?(dependencies) + + remove_platform(Gem::Platform::RUBY) + add_current_platform + end + def source_map @source_map ||= SourceMap.new(sources, dependencies, @locked_specs) end diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb index 735cdac126..d7239f5c8c 100644 --- a/lib/bundler/spec_set.rb +++ b/lib/bundler/spec_set.rb @@ -91,6 +91,10 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/spec_set.rb#L91 SpecSet.new(materialized) end + def incomplete_ruby_specs?(deps) + self.class.new(self.for(deps, true, [Gem::Platform::RUBY])).incomplete_specs.any? + end + def missing_specs @specs.select {|s| s.is_a?(LazySpecification) } end diff --git a/spec/bundler/install/gemfile/specific_platform_spec.rb b/spec/bundler/install/gemfile/specific_platform_spec.rb index 48349aaef4..fe1c3b71fe 100644 --- a/spec/bundler/install/gemfile/specific_platform_spec.rb +++ b/spec/bundler/install/gemfile/specific_platform_spec.rb @@ -374,6 +374,77 @@ RSpec.describe "bundle install with specific platforms" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/install/gemfile/specific_platform_spec.rb#L374 ERROR end + it "automatically fixes the lockfile if RUBY platform is locked and some gem has no RUBY variant available" do + build_repo4 do + build_gem("sorbet-static-and-runtime", "0.5.10160") do |s| + s.add_runtime_dependency "sorbet", "= 0.5.10160" + s.add_runtime_dependency "sorbet-runtime", "= 0.5.10160" + end + + build_gem("sorbet", "0.5.10160") do |s| + s.add_runtime_dependency "sorbet-static", "= 0.5.10160" + end + + build_gem("sorbet-runtime", "0.5.10160") + + build_gem("sorbet-static", "0.5.10160") do |s| + s.platform = Gem::Platform.local + end + end + + gemfile <<~G + source "#{file_uri_for(gem_repo4)}" + + gem "sorbet-static-and-runtime" + G + + lockfile <<~L + GEM + remote: #{file_uri_for(gem_repo4)}/ + specs: + sorbet (0.5.10160) + sorbet-static (= 0.5.10160) + sorbet-runtime (0.5.10160) + sorbet-static (0.5.10160-#{Gem::Platform.local}) + sorbet-static-and-runtime (0.5.10160) + sorbet (= 0.5.10160) + sorbet-runtime (= 0.5.10160) + + PLATFORMS + #{lockfile_platforms_for([specific_local_platform, "ruby"])} + + DEPENDENCIES + sorbet-static-and-runtime + + BUNDLED WITH + #{Bundler::VERSION} + L + + bundle "update" + + expect(lockfile).to eq <<~L + GEM + remote: #{file_uri_for(gem_repo4)}/ + specs: + sorbet (0.5.10160) + sorbet-static (= 0.5.10160) + sorbet-runtime (0.5.10160) + sorbet-static (0.5.10160-#{Gem::Platform.local}) + sorbet-static-and-runtime (0.5.10160) + sorbet (= 0.5.10160) + sorbet-runtime (= 0.5.10160) + + PLATFORMS + #{lockfile_platforms} + + DEPENDENCIES + sorbet-static-and-runtime + + BUNDLED WITH + #{Bundler::VERSION} + L + end + it "can fallback to a source gem when platform gems are incompatible with current ruby version" do setup_multiplatform_gem_with_source_gem -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/