diff options
author | Bundlerbot <bot@bundler.io> | 2019-07-11 00:38:40 +0000 |
---|---|---|
committer | Bundlerbot <bot@bundler.io> | 2019-07-11 00:38:40 +0000 |
commit | 847db56c6b5d2156d27990d73a9949507693985a (patch) | |
tree | e8eb3c983e6752ffac19f01c87cc9566c47ec208 | |
parent | c17f24747a3e5254a57ef360ac8300d0244fd421 (diff) | |
parent | 78608acf836bed04c5e36f4c1201dcf7a7ec1420 (diff) | |
download | bundler-847db56c6b5d2156d27990d73a9949507693985a.tar.gz |
Merge #7215
7215: Auto multiplatform r=indirect a=deivid-rodriguez
### What was the end-user problem that led to this PR?
The problem was that currently if the gemfile include gems for specific platforms, like the default `gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] ` Rails uses, bundler will _always_ print a noisy warning, but I don't think users are doing anything wrong, just running `bundle install` on it.
Also, unless they run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`, and commit the resulting lockfile, they will continue to get the same warning over and over again.
### What was your diagnosis of the problem?
My diagnosis was that the right thing to do is that instead of warning users, bundler does the right thing by default. That is:
* Resolve the gemfile and lock it for all platforms present in the Gemfile.
* Install gems for the current platform if requested.
### What is your fix for the problem, implemented in this PR?
My fix is to do just that.
### Why did you choose this fix out of the possible options?
I chose this fix because I think it's better for our users. We currently have a specific setting to avoid this warning, which I guess we added given the complaints. We no longer need that setting, nor the warning, so I removed both.
Co-authored-by: David RodrÃguez <deivid.rodriguez@riseup.net>
-rw-r--r-- | lib/bundler/cli/outdated.rb | 2 | ||||
-rw-r--r-- | lib/bundler/definition.rb | 34 | ||||
-rw-r--r-- | lib/bundler/dependency.rb | 6 | ||||
-rw-r--r-- | lib/bundler/inline.rb | 2 | ||||
-rw-r--r-- | lib/bundler/settings.rb | 1 | ||||
-rw-r--r-- | man/bundle-config.ronn | 2 | ||||
-rw-r--r-- | spec/commands/lock_spec.rb | 4 | ||||
-rw-r--r-- | spec/install/gemfile/platform_spec.rb | 51 | ||||
-rw-r--r-- | spec/runtime/require_spec.rb | 2 |
9 files changed, 52 insertions, 52 deletions
diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index 857caf0a03..2075fe83c8 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -172,6 +172,8 @@ module Bundler end def retrieve_active_spec(strict, definition, current_spec) + return unless current_spec.match_platform(Bundler.local_platform) + if strict active_spec = definition.find_resolved_spec(current_spec) else diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 98fa2c1ef7..de3950a744 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -113,7 +113,7 @@ module Bundler end @unlocking ||= @unlock[:ruby] ||= (!@locked_ruby_version ^ !@ruby_version) - add_current_platform unless Bundler.frozen_bundle? + add_platforms unless Bundler.frozen_bundle? converge_path_sources_to_gemspec_sources @path_changes = converge_paths @@ -518,12 +518,6 @@ module Bundler raise InvalidOption, "Unable to remove the platform `#{platform}` since the only platforms are #{@platforms.join ", "}" end - def add_current_platform - current_platform = Bundler.local_platform - add_platform(current_platform) if Bundler.feature_flag.specific_platform? - add_platform(generic(current_platform)) - end - def find_resolved_spec(current_spec) specs.find_by_name_and_platform(current_spec.name, current_spec.platform) end @@ -545,6 +539,20 @@ module Bundler private + def add_platforms + (@dependencies.flat_map(&:expanded_platforms) + current_platforms).uniq.each do |platform| + add_platform(platform) + end + end + + def current_platforms + current_platform = Bundler.local_platform + [].tap do |platforms| + platforms << current_platform if Bundler.feature_flag.specific_platform? + platforms << generic(current_platform) + end + end + def change_reason if unlocking? unlock_reason = @unlock.reject {|_k, v| Array(v).empty? }.map do |k, v| @@ -884,17 +892,7 @@ module Bundler dependencies.each do |dep| 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? && !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. " \ - "Bundler is installing for #{@platforms.join ", "} but the dependency " \ - "is only for #{mapped_platforms.join ", "}. " \ - "To add those platforms to the bundle, " \ - "run `bundle lock --add-platform #{mapped_platforms.join " "}`." - end - platforms.each do |p| + dep.gem_platforms(sorted_platforms).each do |p| deps << DepProxy.new(dep, p) if remote || p == generic_local_platform end end diff --git a/lib/bundler/dependency.rb b/lib/bundler/dependency.rb index 55ffea02b6..6c2642163e 100644 --- a/lib/bundler/dependency.rb +++ b/lib/bundler/dependency.rb @@ -105,11 +105,15 @@ module Bundler def gem_platforms(valid_platforms) return valid_platforms if @platforms.empty? - @gem_platforms ||= @platforms.map {|pl| PLATFORM_MAP[pl] }.compact.uniq + @gem_platforms ||= expanded_platforms.compact.uniq valid_platforms & @gem_platforms end + def expanded_platforms + @platforms.map {|pl| PLATFORM_MAP[pl] } + end + def should_include? @should_include && current_env? && current_platform? end diff --git a/lib/bundler/inline.rb b/lib/bundler/inline.rb index 317bf892ab..fed31ba4e3 100644 --- a/lib/bundler/inline.rb +++ b/lib/bundler/inline.rb @@ -60,7 +60,7 @@ def gemfile(install = false, options = {}, &gemfile) Bundler.ui = ui if install if install || missing_specs.call - Bundler.settings.temporary(:inline => true, :disable_platform_warnings => true) do + Bundler.settings.temporary(:inline => true) do installer = Bundler::Installer.install(Bundler.root, definition, :system => true) installer.post_install_messages.each do |name, message| Bundler.ui.info "Post-install message from #{name}:\n#{message}" diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index 3888ac51d3..50cd04aef1 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -25,7 +25,6 @@ module Bundler disable_exec_load disable_local_branch_check disable_multisource - disable_platform_warnings disable_shared_gems disable_version_check force_ruby_platform diff --git a/man/bundle-config.ronn b/man/bundle-config.ronn index d4c13647fd..ffecc12f69 100644 --- a/man/bundle-config.ronn +++ b/man/bundle-config.ronn @@ -176,8 +176,6 @@ 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 unset 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/commands/lock_spec.rb b/spec/commands/lock_spec.rb index 5735b6c060..1d9813a835 100644 --- a/spec/commands/lock_spec.rb +++ b/spec/commands/lock_spec.rb @@ -284,7 +284,7 @@ RSpec.describe "bundle lock" do simulate_platform(mingw) { bundle! :lock } - expect(the_bundle.lockfile).to read_as(strip_whitespace(<<-G)) + lockfile_should_be <<-G GEM remote: #{file_uri_for(gem_repo4)}/ specs: @@ -309,7 +309,7 @@ RSpec.describe "bundle lock" do simulate_platform(rb) { bundle! :lock } - expect(the_bundle.lockfile).to read_as(strip_whitespace(<<-G)) + lockfile_should_be <<-G GEM remote: #{file_uri_for(gem_repo4)}/ specs: diff --git a/spec/install/gemfile/platform_spec.rb b/spec/install/gemfile/platform_spec.rb index c389c71032..d065e10600 100644 --- a/spec/install/gemfile/platform_spec.rb +++ b/spec/install/gemfile/platform_spec.rb @@ -102,7 +102,7 @@ RSpec.describe "bundle install across platforms" do gem "pry" G - expect(the_bundle.lockfile).to read_as strip_whitespace(<<-L) + lockfile_should_be <<-L GEM remote: #{file_uri_for(gem_repo4)}/ specs: @@ -160,7 +160,7 @@ RSpec.describe "bundle install across platforms" do #{Bundler::VERSION} L - expect(the_bundle.lockfile).to read_as good_lockfile + lockfile_should_be good_lockfile bad_lockfile = strip_whitespace <<-L GEM @@ -196,23 +196,23 @@ RSpec.describe "bundle install across platforms" do aggregate_failures do lockfile bad_lockfile bundle! :install - expect(the_bundle.lockfile).to read_as good_lockfile + lockfile_should_be good_lockfile lockfile bad_lockfile bundle! :update, :all => true - expect(the_bundle.lockfile).to read_as good_lockfile + lockfile_should_be good_lockfile lockfile bad_lockfile bundle! "update ffi" - expect(the_bundle.lockfile).to read_as good_lockfile + lockfile_should_be good_lockfile lockfile bad_lockfile bundle! "update empyrean" - expect(the_bundle.lockfile).to read_as good_lockfile + lockfile_should_be good_lockfile lockfile bad_lockfile bundle! :lock - expect(the_bundle.lockfile).to read_as good_lockfile + lockfile_should_be good_lockfile end end @@ -372,7 +372,7 @@ RSpec.describe "bundle install with platform conditionals" do 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 + it "resolves all platforms by default and without warning messages" do simulate_platform "ruby" simulate_ruby_engine "ruby" @@ -384,28 +384,27 @@ RSpec.describe "bundle install with platform conditionals" do bundle! "install" - expect(err).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 set disable_platform_warnings true" } + expect(err).to be_empty - 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_uri_for(gem_repo1)}" + lockfile_should_be <<-L + GEM + remote: #{file_uri_for(gem_repo1)}/ + specs: + rack (1.0.0) - gem "rack", :platform => [:mingw, :mswin, :x64_mingw, :jruby] - G + PLATFORMS + java + ruby + x64-mingw32 + x86-mingw32 + x86-mswin32 - bundle! "install" + DEPENDENCIES + rack - expect(out).not_to match(/The dependency (.*) will be unused/) - end + BUNDLED WITH + #{Bundler::VERSION} + L end end diff --git a/spec/runtime/require_spec.rb b/spec/runtime/require_spec.rb index 958d7cf26a..016fc14dfe 100644 --- a/spec/runtime/require_spec.rb +++ b/spec/runtime/require_spec.rb @@ -425,7 +425,7 @@ RSpec.describe "Bundler.require with platform specific dependencies" do source "#{file_uri_for(gem_repo1)}" platforms :#{not_local_tag} do - gem "fail", :require => "omgomg" + gem "platform_specific", :require => "omgomg" end gem "rack", "1.0.0" |