Skip to content

Commit

Permalink
Automatically remove "ruby" from lockfile if incomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez committed Aug 2, 2022
1 parent 321ad5c commit d546d3e
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bundler/lib/bundler/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ def unlocking?

def reresolve
last_resolve = converge_locked_specs
remove_ruby_from_platforms_if_necessary!
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
Expand Down Expand Up @@ -865,6 +866,16 @@ def additional_base_requirements_for_resolve
end
end

def remove_ruby_from_platforms_if_necessary!
return if Bundler.frozen_bundle? || @locked_gems.nil? || Bundler.settings[:force_ruby_platform] || !platforms.include?(Gem::Platform::RUBY)

platforms_without_ruby = platforms.reject {|p| p == Gem::Platform::RUBY }

return if platforms_without_ruby.none? {|pl| generic(pl) == Gem::Platform::RUBY } || !@originally_locked_specs.missing_ruby_specs?

@platforms = platforms_without_ruby
end

def source_map
@source_map ||= SourceMap.new(sources, dependencies, @locked_specs)
end
Expand Down
8 changes: 8 additions & 0 deletions bundler/lib/bundler/spec_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ def materialized_for_resolution
SpecSet.new(materialized)
end

def missing_ruby_specs?
lookup.any? do |name, specs|
specs.none? do |spec|
spec.match_platform(Gem::Platform::RUBY)
end
end
end

def missing_specs
@specs.select {|s| s.is_a?(LazySpecification) }
end
Expand Down
73 changes: 73 additions & 0 deletions bundler/spec/install/gemfile/specific_platform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,79 @@
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

expect(err).to be_empty
end

it "can fallback to a source gem when platform gems are incompatible with current ruby version" do
setup_multiplatform_gem_with_source_gem

Expand Down

0 comments on commit d546d3e

Please sign in to comment.