Skip to content

Commit ca1c46d

Browse files
deivid-rodriguezhsbt
authored andcommitted
[rubygems/rubygems] Ignore local specifications if they have incorrect dependencies
Currently ruby-dev installs an incorrect gemspec for rdoc, that does not declare its dependency on psych. This seems like a ruby-core bug, but it seems best for Bundler to ignore it, go with the remote specification instead, and print a warning. ruby/rubygems@227cafd657
1 parent c0a1e87 commit ca1c46d

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

lib/bundler/index.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ def merge!(other)
131131
return unless other
132132
other.each do |spec|
133133
if existing = find_by_spec(spec)
134+
unless dependencies_eql?(existing, spec)
135+
Bundler.ui.warn "Local specification for #{spec.full_name} has different dependencies than the remote gem, ignoring it"
136+
next
137+
end
138+
134139
add_duplicate(existing)
135140
end
136141
add spec
@@ -153,8 +158,8 @@ def subset?(other)
153158
end
154159

155160
def dependencies_eql?(spec, other_spec)
156-
deps = spec.dependencies.select {|d| d.type != :development }
157-
other_deps = other_spec.dependencies.select {|d| d.type != :development }
161+
deps = spec.runtime_dependencies
162+
other_deps = other_spec.runtime_dependencies
158163
deps.sort == other_deps.sort
159164
end
160165

spec/bundler/commands/lock_spec.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,64 @@
16091609
end
16101610
end
16111611

1612+
context "when a system gem has incorrect dependencies, different from remote gems" do
1613+
before do
1614+
build_repo4 do
1615+
build_gem "foo", "1.0.0" do |s|
1616+
s.add_dependency "bar"
1617+
end
1618+
1619+
build_gem "bar", "1.0.0"
1620+
end
1621+
1622+
system_gems "foo-1.0.0", gem_repo: gem_repo4, path: default_bundle_path
1623+
1624+
# simulate gemspec with wrong empty dependencies
1625+
foo_gemspec_path = default_bundle_path("specifications/foo-1.0.0.gemspec")
1626+
foo_gemspec = Gem::Specification.load(foo_gemspec_path.to_s)
1627+
foo_gemspec.dependencies.clear
1628+
File.write(foo_gemspec_path, foo_gemspec.to_ruby)
1629+
end
1630+
1631+
it "generates a lockfile using remote dependencies, and prints a warning" do
1632+
gemfile <<~G
1633+
source "https://gem.repo4"
1634+
1635+
gem "foo"
1636+
G
1637+
1638+
checksums = checksums_section_when_enabled do |c|
1639+
c.checksum gem_repo4, "foo", "1.0.0"
1640+
c.checksum gem_repo4, "bar", "1.0.0"
1641+
end
1642+
1643+
simulate_platform "x86_64-linux" do
1644+
bundle "lock --verbose"
1645+
end
1646+
1647+
expect(err).to eq("Local specification for foo-1.0.0 has different dependencies than the remote gem, ignoring it")
1648+
1649+
expect(lockfile).to eq <<~L
1650+
GEM
1651+
remote: https://gem.repo4/
1652+
specs:
1653+
bar (1.0.0)
1654+
foo (1.0.0)
1655+
bar
1656+
1657+
PLATFORMS
1658+
ruby
1659+
x86_64-linux
1660+
1661+
DEPENDENCIES
1662+
foo
1663+
#{checksums}
1664+
BUNDLED WITH
1665+
#{Bundler::VERSION}
1666+
L
1667+
end
1668+
end
1669+
16121670
it "properly shows resolution errors including OR requirements" do
16131671
build_repo4 do
16141672
build_gem "activeadmin", "2.13.1" do |s|

0 commit comments

Comments
 (0)