summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-09-19 21:45:55 +0200
committerSamuel Giddins <segiddins@segiddins.me>2016-09-19 21:45:55 +0200
commit483e93709a96a51f63f039d19e56ce41a83c356b (patch)
tree37d3df5f596eac77fd15087fe26ee406690fbf77
parentc36e18098e3efc9f4bf63e4a05c98494b8c7b502 (diff)
downloadbundler-483e93709a96a51f63f039d19e56ce41a83c356b.tar.gz
[Definition] Print a helpful warning when a dependency is unused on any platform
-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 12951cdf9c..9fbacf2cb4 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..f9ecdeb799 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 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