Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Auto merge of #5003 - bundler:seg-warn-unused-deps, r=indirect
Browse files Browse the repository at this point in the history
[Definition] Print a helpful warning when a dependency is unused on a…

…ny platform

Should help address the confusion caused by https://github.com/bundler/bundler/issues/5001
  • Loading branch information
homu committed Sep 30, 2016
2 parents c899153 + f7f6087 commit 5ee7613
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
12 changes: 10 additions & 2 deletions lib/bundler/definition.rb
Expand Up @@ -808,8 +808,16 @@ def expand_dependencies(dependencies, remote = false)
deps = []
dependencies.each do |dep|
dep = Dependency.new(dep, ">= 0") unless dep.respond_to?(:name)
next unless remote || dep.current_platform?
dep.gem_platforms(@platforms).each do |p|
next if !remote && !dep.current_platform?
platforms = dep.gem_platforms(@platforms)
if platforms.empty?
Bundler.ui.warn \
"The dependency #{dep} will be unused by any of the platforms Bundler is installing for. " \
"Bundler is installing for #{@platforms.join ", "} but the dependency " \
"is only for #{dep.platforms.map {|p| Dependency::PLATFORM_MAP[p] }.join ", "}. " \
"To add those platforms to the bundle, run `bundle lock --add-platform #{dep.platforms.join ", "}`."
end
platforms.each do |p|
deps << DepProxy.new(dep, p) if remote || p == generic_local_platform
end
end
Expand Down
19 changes: 18 additions & 1 deletion spec/install/gemfile/platform_spec.rb
Expand Up @@ -184,7 +184,7 @@

gemfile <<-G
source "file://#{gem_repo1}"
gem "some_gem", platform: :rbx
gem "some_gem", :platform => :rbx
G

bundle "install --local"
Expand All @@ -204,6 +204,23 @@
bundle "install --local"
expect(out).not_to match(/Could not find gem 'some_gem/)
end

it "prints a helpful warning when a dependency is unused on any platform" do
simulate_platform "ruby"
simulate_ruby_engine "ruby"

gemfile <<-G
source "file://#{gem_repo1}"
gem "rack", :platform => :jruby
G

bundle! "install"

expect(out).to include <<-O.strip
The dependency #{Gem::Dependency.new("rack", ">= 0")} will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for java. To add those platforms to the bundle, run `bundle lock --add-platform jruby`.
O
end
end

describe "when a gem has no architecture" do
Expand Down

0 comments on commit 5ee7613

Please sign in to comment.