Skip to content

Commit

Permalink
Fix universal lockfiles regression
Browse files Browse the repository at this point in the history
If a platform specific variant would not match the current Ruby, we would still be
considering it compatible with the initial resolution and adding its
platform to the lockfile, but we would later fail to materialize it for
installation due to not really being compatible.

Fix is to only add platforms for variants that are also compatible with
current Ruby and RubyGems versions.
  • Loading branch information
deivid-rodriguez committed Nov 20, 2023
1 parent d38522f commit 755e973
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
4 changes: 1 addition & 3 deletions bundler/lib/bundler/lazy_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ def materialize_for_installation
# bad gem.
def __materialize__(candidates, fallback_to_non_installable: Bundler.frozen_bundle?)
search = candidates.reverse.find do |spec|
spec.is_a?(StubSpecification) ||
(spec.matches_current_ruby? &&
spec.matches_current_rubygems?)
spec.is_a?(StubSpecification) || spec.matches_current_metadata?
end
if search.nil? && fallback_to_non_installable
search = candidates.last
Expand Down
4 changes: 4 additions & 0 deletions bundler/lib/bundler/match_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

module Bundler
module MatchMetadata
def matches_current_metadata?
matches_current_ruby? && matches_current_rubygems?
end

def matches_current_ruby?
@required_ruby_version.satisfied_by?(Gem.ruby_version)
end
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/spec_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def complete_platforms!(platforms)
valid_platform = lookup.all? do |_, specs|
spec = specs.first
matching_specs = spec.source.specs.search([spec.name, spec.version])
platform_spec = GemHelpers.select_best_platform_match(matching_specs, platform).first
platform_spec = GemHelpers.select_best_platform_match(matching_specs, platform).find(&:matches_current_metadata?)

if platform_spec
new_specs << LazySpecification.from_spec(platform_spec)
Expand Down
58 changes: 58 additions & 0 deletions bundler/spec/install/gemfile/specific_platform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,64 @@
end
end

it "does not fail when a platform variant is incompatible with the current ruby and another equivalent platform specific variant is part of the resolution", :rubygems => ">= 3.3.21" do
build_repo4 do
build_gem "nokogiri", "1.15.5"

build_gem "nokogiri", "1.15.5" do |s|
s.platform = "x86_64-linux"
s.required_ruby_version = "< #{current_ruby_minor}.dev"
end

build_gem "sass-embedded", "1.69.5"

build_gem "sass-embedded", "1.69.5" do |s|
s.platform = "x86_64-linux-gnu"
end
end

gemfile <<~G
source "#{file_uri_for(gem_repo4)}"
gem "nokogiri"
gem "sass-embedded"
G

expected_checksums = checksum_section do |c|
c.repo_gem gem_repo4, "nokogiri", "1.15.5"
c.no_checksum "sass-embedded", "1.69.5"
c.repo_gem gem_repo4, "sass-embedded", "1.69.5", "x86_64-linux-gnu"
end

simulate_platform "x86_64-linux" do
bundle "install --verbose", :artifice => "compact_index", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }

# locks all compatible platforms, excluding Java and Windows
expect(lockfile).to eq(<<~L)
GEM
remote: #{file_uri_for(gem_repo4)}/
specs:
nokogiri (1.15.5)
sass-embedded (1.69.5)
sass-embedded (1.69.5-x86_64-linux-gnu)
PLATFORMS
ruby
x86_64-linux
DEPENDENCIES
nokogiri
sass-embedded
CHECKSUMS
#{expected_checksums}
BUNDLED WITH
#{Bundler::VERSION}
L
end
end

private

def setup_multiplatform_gem
Expand Down

0 comments on commit 755e973

Please sign in to comment.