diff options
author | The Bundler Bot <bot@bundler.io> | 2018-03-01 11:20:47 +0000 |
---|---|---|
committer | Colby Swandale <me@colby.fyi> | 2018-10-05 16:15:43 +1000 |
commit | 66f86ee6b046c182749d9c5bfb77868223b23f84 (patch) | |
tree | 09f66d8fd0d84795656329676bac422043857909 | |
parent | 9256ce883bd0fbfff229d5f24ee08018fe4edfb5 (diff) | |
download | bundler-66f86ee6b046c182749d9c5bfb77868223b23f84.tar.gz |
Auto merge of #6309 - agrim123:disable_platform_warnings, r=colby-swandale
Add config variable and check for platform warnings
Thanks so much for the contribution!
To make reviewing this PR a bit easier, please fill out answers to the following questions.
### What was the end-user problem that led to this PR?
The user needed a way to turn off platform warnings.
### What was your diagnosis of the problem?
Creating a config variable to solve the above problem.
### What is your fix for the problem, implemented in this PR?
Added a key `disable_platform_warnings` in settings and placed check at the relevant place to disable warnings.
### Why did you choose this fix out of the possible options?
We will by default show warnings but the user might want to disable them, so using a config variable looked a good option.
Fixes #6124
(cherry picked from commit 23dfadcd8d561d48e89c7287cbbdd816e0a10ab8)
-rw-r--r-- | lib/bundler/definition.rb | 2 | ||||
-rw-r--r-- | lib/bundler/settings.rb | 1 | ||||
-rw-r--r-- | man/bundle-config.ronn | 2 | ||||
-rw-r--r-- | spec/install/gemfile/platform_spec.rb | 19 |
4 files changed, 23 insertions, 1 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 1585fc3125..6b176c2ae4 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -885,7 +885,7 @@ module Bundler dep = Dependency.new(dep, ">= 0") unless dep.respond_to?(:name) next if !remote && !dep.current_platform? platforms = dep.gem_platforms(sorted_platforms) - if platforms.empty? + if platforms.empty? && !Bundler.settings[:disable_platform_warnings] mapped_platforms = dep.platforms.map {|p| Dependency::PLATFORM_MAP[p] } Bundler.ui.warn \ "The dependency #{dep} will be unused by any of the platforms Bundler is installing for. " \ diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index f33e9453be..aec25c3e5e 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -25,6 +25,7 @@ module Bundler disable_exec_load disable_local_branch_check disable_multisource + disable_platform_warnings disable_shared_gems disable_version_check error_on_stderr diff --git a/man/bundle-config.ronn b/man/bundle-config.ronn index dc0b0b8ad9..a3930c6ce8 100644 --- a/man/bundle-config.ronn +++ b/man/bundle-config.ronn @@ -170,6 +170,8 @@ learn more about their operation in [bundle install(1)](bundle-install.1.html). When set, Gemfiles containing multiple sources will produce errors instead of warnings. Use `bundle config --delete disable_multisource` to unset. +* `disable_platform_warnings` (`BUNDLE_DISABLE_PLATFORM_WARNINGS`): + Disable warnings during bundle install when a dependency is unused on the current platform. * `disable_shared_gems` (`BUNDLE_DISABLE_SHARED_GEMS`): Stop Bundler from accessing gems installed to RubyGems' normal location. * `disable_version_check` (`BUNDLE_DISABLE_VERSION_CHECK`): diff --git a/spec/install/gemfile/platform_spec.rb b/spec/install/gemfile/platform_spec.rb index 5858c3af0a..6c226eb29f 100644 --- a/spec/install/gemfile/platform_spec.rb +++ b/spec/install/gemfile/platform_spec.rb @@ -389,6 +389,25 @@ RSpec.describe "bundle install with platform conditionals" do 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 x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`. O end + + context "when disable_platform_warnings is true" do + before { bundle! "config disable_platform_warnings true" } + + it "does not print the 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 => [:mingw, :mswin, :x64_mingw, :jruby] + G + + bundle! "install" + + expect(out).not_to match(/The dependency (.*) will be unused/) + end + end end RSpec.describe "when a gem has no architecture" do |