Skip to content

Commit 4cb0d86

Browse files
Merge pull request #8486 from rubygems/deivid-rodriguez/improve-error-message-on-incompatible-gemspec-development-dependencies
Make Bundler never instantiate development dependencies (cherry picked from commit eaa9ad2)
1 parent 445d821 commit 4cb0d86

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

bundler/lib/bundler/definition.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -948,14 +948,6 @@ def converge_dependencies
948948
next
949949
end
950950

951-
# Gem::Dependency#== matches Gem::Dependency#type. As the lockfile
952-
# doesn't carry a notion of the dependency type, if you use
953-
# add_development_dependency in a gemspec that's loaded with the gemspec
954-
# directive, the lockfile dependencies and resolved dependencies end up
955-
# with a mismatch on #type. Work around that by setting the type on the
956-
# dep from the lockfile.
957-
locked_dep.instance_variable_set(:@type, dep.type)
958-
959951
# We already know the name matches from the hash lookup
960952
# so we only need to check the requirement now
961953
changes ||= dep.requirement != locked_dep.requirement

bundler/lib/bundler/dependency.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ def should_include?
111111
end
112112

113113
def gemspec_dev_dep?
114-
type == :development
114+
@gemspec_dev_dep ||= @options.fetch("gemspec_dev_dep", false)
115+
end
116+
117+
def gemfile_dep?
118+
!gemspec_dev_dep?
115119
end
116120

117121
def current_env?

bundler/lib/bundler/dsl.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def gemspec(opts = nil)
8282
end
8383

8484
spec.development_dependencies.each do |dep|
85-
add_dependency dep.name, dep.requirement.as_list, "type" => :development, "group" => development_group
85+
add_dependency dep.name, dep.requirement.as_list, "gemspec_dev_dep" => true, "group" => development_group
8686
end
8787
when 0
8888
raise InvalidOption, "There are no gemspecs at #{expanded_path}"
@@ -247,7 +247,7 @@ def add_dependency(name, version = nil, options = {})
247247

248248
gemspec_dep = [dep, current].find(&:gemspec_dev_dep?)
249249
if gemspec_dep
250-
gemfile_dep = [dep, current].find(&:runtime?)
250+
gemfile_dep = [dep, current].find(&:gemfile_dep?)
251251

252252
if gemfile_dep && !current_requirement_open
253253
Bundler.ui.warn "A gemspec development dependency (#{gemspec_dep.name}, #{gemspec_dep.requirement}) is being overridden by a Gemfile dependency (#{gemfile_dep.name}, #{gemfile_dep.requirement}).\n" \
@@ -264,7 +264,7 @@ def add_dependency(name, version = nil, options = {})
264264
if current_gemspec_range.intersects?(next_gemspec_range)
265265
dep = Dependency.new(name, current.requirement.as_list + dep.requirement.as_list, options)
266266
else
267-
raise GemfileError, "Two gemspecs have conflicting requirements on the same gem: #{dep} and #{current}"
267+
raise GemfileError, "Two gemspec development dependencies have conflicting requirements on the same gem: #{dep} and #{current}"
268268
end
269269
end
270270
else

bundler/spec/commands/install_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@
581581

582582
bundle :install, raise_on_error: false
583583

584-
expect(err).to include("Two gemspecs have conflicting requirements on the same gem: rubocop (~> 1.36.0, development) and rubocop (~> 2.0, development). Bundler cannot continue.")
584+
expect(err).to include("Two gemspec development dependencies have conflicting requirements on the same gem: rubocop (~> 1.36.0) and rubocop (~> 2.0). Bundler cannot continue.")
585585
end
586586

587587
it "warns when a Gemfile dependency is overriding a gemspec development dependency, with different requirements" do

0 commit comments

Comments
 (0)