diff options
author | Bundlerbot <bot@bundler.io> | 2020-02-27 22:00:32 +0000 |
---|---|---|
committer | Bundlerbot <bot@bundler.io> | 2020-02-27 22:00:32 +0000 |
commit | 788a4071cf4e0b42f83e25ba2aedaf0b63546866 (patch) | |
tree | 3c214dbecf85e94ed499e6c842ec01b5197a7f32 /lib | |
parent | 0659182ff24faed7b4dc8479f1c056fae32815e4 (diff) | |
parent | a123d2aec2ad70122a24e2dc96268051811c9987 (diff) | |
download | bundler-788a4071cf4e0b42f83e25ba2aedaf0b63546866.tar.gz |
Merge #7580
7580: Automultiplatform again r=indirect a=deivid-rodriguez
This PR is a reintroduction of #7215, now that I consider the multiplatform feature usable enough.
### 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 is that the fact that some gems will be unused under some platforms is inherent to the multiplatform feature itself, so we shouldn't warn about it because it's expected.
Take the following Gemfile for example (a simplification of the default Gemfile Rails generators create):
```ruby
source "https://rubygems.org"
gem "rails"
gem "tzinfo-data", platforms: "jruby"
```
If I type that Gemfile, it means that I'm explicitly opting into the multiplatform feature. So the behavior I would want as a user when I run `bundle install` on it is:
* Resolve and lock the Gemfile for all platforms (`jruby` and whatever platform I'm running).
* Install the resolution for the platform that I'm currently running.
That way, when the other developers of my team using `jruby` install the `Gemfile`, they install a predictable, deterministic resolution.
Currently, the only way to get that behavior is to run:
```
$ bundle install
$ bundle lock --add-platform java
```
But there's no way to do it without getting a warning on the first `bundle install`, which annoys people because it makes you think you're doing something wrong.
If you only plan to use MRI, you shouldn't specify any jruby-specific gems in your Gemfile and write instead:
```ruby
source "https://rubygems.org"
gem "rails"
```
If on the other hand you only plan to use jruby, then you should not specify any `platform` option at all and write
```ruby
source "https://rubygems.org"
gem "rails"
gem "tzinfo-data"
```
So, to sum up, I think the range of platforms users expect to support can be guessed implicit from the Gemfile and the running platform. So we should resolve by default for all those platforms and don't warn about behavior that's most likely expected.
### What is your fix for the problem, implemented in this PR?
My fix is to do the right thing by default, and not warn users at all. That is:
* Resolve the gemfile and lock it for all platforms present in the Gemfile.
* Install gems for the current platform if requested.
### 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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/cli/outdated.rb | 6 | ||||
-rw-r--r-- | lib/bundler/definition.rb | 24 | ||||
-rw-r--r-- | lib/bundler/inline.rb | 2 | ||||
-rw-r--r-- | lib/bundler/settings.rb | 1 |
4 files changed, 13 insertions, 20 deletions
diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index 3d4922f8b5..5f065654b1 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -76,6 +76,8 @@ module Bundler next unless gems.empty? || gems.include?(current_spec.name) active_spec = retrieve_active_spec(definition, current_spec) + next unless active_spec + next unless filter_options_patch.empty? || update_present_via_semver_portions(current_spec, active_spec, options) gem_outdated = Gem::Version.new(active_spec.version) > Gem::Version.new(current_spec.version) @@ -144,6 +146,8 @@ module Bundler end def retrieve_active_spec(definition, current_spec) + return unless current_spec.match_platform(Bundler.local_platform) + if strict active_spec = definition.find_resolved_spec(current_spec) else @@ -231,8 +235,6 @@ module Bundler end def update_present_via_semver_portions(current_spec, active_spec, options) - return false if active_spec.nil? - current_major = current_spec.version.segments.first active_major = active_spec.version.segments.first diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index efd7618194..fca7d35aaa 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -117,7 +117,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 @@ -523,10 +523,6 @@ module Bundler raise InvalidOption, "Unable to remove the platform `#{platform}` since the only platforms are #{@platforms.join ", "}" end - def add_current_platform - current_platforms.each {|platform| add_platform(platform) } - end - def find_resolved_spec(current_spec) specs.find_by_name_and_platform(current_spec.name, current_spec.platform) end @@ -548,6 +544,12 @@ 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| @@ -892,17 +894,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.expanded_platforms - 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/inline.rb b/lib/bundler/inline.rb index f1f77a7a9c..59211193d4 100644 --- a/lib/bundler/inline.rb +++ b/lib/bundler/inline.rb @@ -58,7 +58,7 @@ def gemfile(install = false, options = {}, &gemfile) Bundler.ui = install ? ui : Bundler::UI::Silent.new if install || definition.missing_specs? - 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 afbb02397c..23ae66efa0 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -22,7 +22,6 @@ module Bundler disable_exec_load disable_local_branch_check disable_multisource - disable_platform_warnings disable_shared_gems disable_version_check force_ruby_platform |