summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHomu <homu@barosl.com>2016-09-30 18:24:30 +0900
committerHomu <homu@barosl.com>2016-09-30 18:24:30 +0900
commit5ee76130518832b12bb3dae22eae6cfd408309e3 (patch)
tree4394fc93449ec2a2a447484e3413a8120238b153
parentc8991533ff4a6c512e9b18e037c2da581c6d76fb (diff)
parentf7f608729bd73a777acd1751ae00642385edff13 (diff)
downloadbundler-5ee76130518832b12bb3dae22eae6cfd408309e3.tar.gz
Auto merge of #5003 - bundler:seg-warn-unused-deps, r=indirect
[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
-rw-r--r--lib/bundler/definition.rb12
-rw-r--r--spec/install/gemfile/platform_spec.rb19
2 files changed, 28 insertions, 3 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index 6c8fc1ddde..9be8184574 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -808,8 +808,16 @@ module Bundler
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
diff --git a/spec/install/gemfile/platform_spec.rb b/spec/install/gemfile/platform_spec.rb
index 58129bb313..9caa0b5731 100644
--- a/spec/install/gemfile/platform_spec.rb
+++ b/spec/install/gemfile/platform_spec.rb
@@ -184,7 +184,7 @@ describe "bundle install with platform conditionals" do
gemfile <<-G
source "file://#{gem_repo1}"
- gem "some_gem", platform: :rbx
+ gem "some_gem", :platform => :rbx
G
bundle "install --local"
@@ -204,6 +204,23 @@ describe "bundle install with platform conditionals" do
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