From 6d563b03f6ec105b54ebae6bc7fab2eee35e6eec Mon Sep 17 00:00:00 2001 From: Agrim Mittal Date: Mon, 26 Feb 2018 03:30:36 +0530 Subject: [PATCH 1/4] Add config variable and check for platform warnings --- lib/bundler/definition.rb | 2 +- lib/bundler/settings.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 0349af39f24..6b42fe0fb56 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -878,7 +878,7 @@ def expand_dependencies(dependencies, remote = false) 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 75e2d4dff2b..83c119a562a 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -26,6 +26,7 @@ class Settings disable_exec_load disable_local_branch_check disable_multisource + disable_platform_warnings disable_shared_gems disable_version_check error_on_stderr From 94d399d6894c0ca312386520388e48971dd286ed Mon Sep 17 00:00:00 2001 From: Agrim Mittal Date: Mon, 26 Feb 2018 04:28:18 +0530 Subject: [PATCH 2/4] Add documentation and tests for disable_platform_warnings --- man/bundle-config.ronn | 2 ++ spec/install/gemfile/platform_spec.rb | 47 ++++++++++++++++++++------- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/man/bundle-config.ronn b/man/bundle-config.ronn index 88ad8273136..7f8ae9face9 100644 --- a/man/bundle-config.ronn +++ b/man/bundle-config.ronn @@ -166,6 +166,8 @@ learn more about their operation in [bundle install(1)][bundle-install(1)]. 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`): + Whether Bundler should show platform warnings. * `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 d7d4e0a53cd..ec19005ef40 100644 --- a/spec/install/gemfile/platform_spec.rb +++ b/spec/install/gemfile/platform_spec.rb @@ -230,21 +230,46 @@ 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" + context "when disable_platform_warnings is false (by default)" do + before { bundle! "config disable_platform_warnings false" } - gemfile <<-G - source "file://#{gem_repo1}" + it "prints a helpful warning when a dependency is unused on any platform" do + simulate_platform "ruby" + simulate_ruby_engine "ruby" - gem "rack", :platform => [:mingw, :mswin, :x64_mingw, :jruby] - G + gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack", :platform => [:mingw, :mswin, :x64_mingw, :jruby] + G - bundle! "install" + 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 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 + 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 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 + end + + context "when disable_platform_warnings is true" do + before { bundle! "config disable_platform_warnings true" } + + it "doesnot 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 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 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 end end From 16831efe608dbb442cc5087e089ff48034b43684 Mon Sep 17 00:00:00 2001 From: Agrim Mittal Date: Thu, 1 Mar 2018 14:03:14 +0530 Subject: [PATCH 3/4] Fixed test when disable_platform_warnings is true --- spec/install/gemfile/platform_spec.rb | 32 +++++++++++---------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/spec/install/gemfile/platform_spec.rb b/spec/install/gemfile/platform_spec.rb index ec19005ef40..43374b0f8a3 100644 --- a/spec/install/gemfile/platform_spec.rb +++ b/spec/install/gemfile/platform_spec.rb @@ -230,31 +230,27 @@ expect(out).not_to match(/Could not find gem 'some_gem/) end - context "when disable_platform_warnings is false (by default)" do - before { bundle! "config disable_platform_warnings false" } - - it "prints a helpful warning when a dependency is unused on any platform" do - simulate_platform "ruby" - simulate_ruby_engine "ruby" + 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}" + gemfile <<-G + source "file://#{gem_repo1}" - gem "rack", :platform => [:mingw, :mswin, :x64_mingw, :jruby] - G + gem "rack", :platform => [:mingw, :mswin, :x64_mingw, :jruby] + G - bundle! "install" + 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 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 + 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 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 "doesnot print the warning when a dependency is unused on any platform" do + it "does not print the warning when a dependency is unused on any platform" do simulate_platform "ruby" simulate_ruby_engine "ruby" @@ -266,9 +262,7 @@ bundle! "install" - expect(out).not_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 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 + expect(out).not_to match(/The dependency (.*) will be unused/) end end end From 5e73a89511f07a83eccf26afba52a20509534ad5 Mon Sep 17 00:00:00 2001 From: Agrim Mittal Date: Thu, 1 Mar 2018 16:13:41 +0530 Subject: [PATCH 4/4] Update documentation for disable_platform_warnings --- man/bundle-config.ronn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/bundle-config.ronn b/man/bundle-config.ronn index 7f8ae9face9..35a400bdeb2 100644 --- a/man/bundle-config.ronn +++ b/man/bundle-config.ronn @@ -167,7 +167,7 @@ learn more about their operation in [bundle install(1)][bundle-install(1)]. instead of warnings. Use `bundle config --delete disable_multisource` to unset. * `disable_platform_warnings` (`BUNDLE_DISABLE_PLATFORM_WARNINGS`): - Whether Bundler should show 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`):