Skip to content

Commit

Permalink
[rubygems/rubygems] Fix error when gem specified twice in gemfile und…
Browse files Browse the repository at this point in the history
…er different platforms

rubygems/rubygems@83bc87ca98
  • Loading branch information
deivid-rodriguez authored and matzbot committed Dec 21, 2021
1 parent ef973aa commit b86a7ba
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/bundler/definition.rb
Expand Up @@ -87,10 +87,11 @@ def initialize(lockfile, dependencies, sources, unlock, ruby_version = nil, opti
@platforms = @locked_platforms.dup
@locked_bundler_version = @locked_gems.bundler_version
@locked_ruby_version = @locked_gems.ruby_version
@originally_locked_specs = SpecSet.new(@locked_gems.specs)

if unlock != true
@locked_deps = @locked_gems.dependencies
@locked_specs = SpecSet.new(@locked_gems.specs)
@locked_specs = @originally_locked_specs
@locked_sources = @locked_gems.sources
else
@unlock = {}
Expand Down Expand Up @@ -691,13 +692,16 @@ def converge_locked_specs
def converge_specs(specs)
deps = []
converged = []
specs.each do |s|
# Replace the locked dependency's source with the equivalent source from the Gemfile
dep = @dependencies.find {|d| s.satisfies?(d) }

if dep && (!dep.source || s.source.include?(dep.source))
@dependencies.each do |dep|
if specs[dep].any? {|s| s.satisfies?(dep) && (!dep.source || s.source.include?(dep.source)) }
deps << dep
end
end

specs.each do |s|
# Replace the locked dependency's source with the equivalent source from the Gemfile
dep = @dependencies.find {|d| s.satisfies?(d) }

s.source = (dep && dep.source) || sources.get(s.source) || sources.default_source unless Bundler.frozen_bundle?

Expand Down Expand Up @@ -830,7 +834,7 @@ def compute_requires

def additional_base_requirements_for_resolve
return [] unless @locked_gems && unlocking? && !sources.expired_sources?(@locked_gems.sources)
converge_specs(@locked_gems.specs).map do |locked_spec|
converge_specs(@originally_locked_specs).map do |locked_spec|
name = locked_spec.name
dep = Gem::Dependency.new(name, ">= #{locked_spec.version}")
DepProxy.get_proxy(dep, locked_spec.platform)
Expand Down
16 changes: 16 additions & 0 deletions spec/bundler/commands/install_spec.rb
Expand Up @@ -391,6 +391,22 @@
expect(err).to include("While it's not a problem now, it could cause errors if you change the version of one of them later.")
end

it "throws a warning if a gem is added twice under different platforms and does not crash when using the generated lockfile" do
build_repo2

install_gemfile <<-G
source "#{file_uri_for(gem_repo2)}"
gem "rack", :platform => :jruby
gem "rack"
G

bundle "install"

expect(err).to include("Your Gemfile lists the gem rack (>= 0) more than once.")
expect(err).to include("Remove any duplicate entries and specify the gem only once.")
expect(err).to include("While it's not a problem now, it could cause errors if you change the version of one of them later.")
end

it "does not throw a warning if a gem is added once in Gemfile and also inside a gemspec as a development dependency" do
build_lib "my-gem", :path => bundled_app do |s|
s.add_development_dependency "my-private-gem"
Expand Down

0 comments on commit b86a7ba

Please sign in to comment.