-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Support force_version of gems to override dependency conflicts #4178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "spec_helper" | ||
|
|
||
| RSpec.describe "bundle install with a gemfile that forces a gem version" do | ||
| context "with a simple conflict" do | ||
| it "works" do | ||
| install_gemfile <<-G | ||
| source "#{file_uri_for(gem_repo1)}" | ||
| gem "rack_middleware" | ||
| gem "rack", "1.0.0", :force_version => true | ||
| G | ||
|
|
||
| expect(the_bundle).to include_gems("rack 1.0.0", "rack_middleware 1.0") | ||
| end | ||
|
|
||
| it "raises when forcing to an inexact version" do | ||
| gemfile <<-G | ||
| gem "rack", "> 1.0.0", :force_version => true | ||
| G | ||
|
|
||
| bundle :install, :quiet => true, :raise_on_error => false | ||
|
|
||
| expect(exitstatus).to_not eq(0) | ||
| expect(err).to include("Cannot use force_version for inexact version requirement `> 1.0.0`.") | ||
| end | ||
|
|
||
| it "raises when forcing without specifying a version" do | ||
| gemfile <<-G | ||
| gem "rack", :force_version => true | ||
| G | ||
|
|
||
| bundle :install, :quiet => true, :raise_on_error => false | ||
|
|
||
| expect(exitstatus).to_not eq(0) | ||
| expect(err).to include("Cannot use force_version for inexact version requirement `>= 0`.") | ||
| end | ||
|
|
||
| it "works when there's no conflict" do | ||
| install_gemfile <<-G | ||
| source "#{file_uri_for(gem_repo1)}" | ||
| gem "rack", "1.0.0", :force_version => true | ||
| G | ||
|
|
||
| expect(the_bundle).to include_gems("rack 1.0.0") | ||
| end | ||
|
|
||
| it "raises when gem doesn't exist" do | ||
| gemfile <<-G | ||
| source "#{file_uri_for(gem_repo1)}" | ||
| gem "rack_middleware" | ||
| gem "rack", "2.0.0", :force_version => true | ||
| G | ||
|
|
||
| bundle :install, :quiet => true, :raise_on_error => false | ||
|
|
||
| expect(exitstatus).to_not eq(0) | ||
| expect(err).to include("Could not find gem 'rack (= 2.0.0)") | ||
| end | ||
| end | ||
|
|
||
| context "with a complex conflict" do | ||
| it "works" do | ||
| install_gemfile <<-G | ||
| source "#{file_uri_for(gem_repo1)}" | ||
| gem "rails", "2.3.2" | ||
| gem "activesupport", "2.3.5", :force_version => true | ||
| G | ||
|
|
||
| expect(the_bundle).to include_gems("rails 2.3.2", "activesupport 2.3.5", "actionpack 2.3.2", "activerecord 2.3.2", "actionmailer 2.3.2", "activeresource 2.3.2") | ||
| end | ||
|
|
||
| it "resolves even with clashing requirements" do | ||
| build_repo4 do | ||
| build_gem "first_parent", %w[1.0.0] do |s| | ||
| s.add_dependency "wasabi", "~> 3.6" | ||
| end | ||
| build_gem "second_parent", %w[1.0.0] do |s| | ||
| s.add_dependency "wasabi", "~> 3.1.0" | ||
| end | ||
| build_gem "wasabi", %w[3.1.0 3.6.1] | ||
| end | ||
|
|
||
| install_gemfile <<-G | ||
| source "#{file_uri_for(gem_repo4)}" | ||
| gem "first_parent" | ||
| gem "second_parent" | ||
| gem "wasabi", "3.6.1", :force_version => true | ||
| G | ||
|
|
||
| expect(the_bundle).to include_gems("first_parent 1.0.0", "second_parent 1.0.0", "wasabi 3.6.1") | ||
| end | ||
|
|
||
| it "resolves even with complex multi-source" do | ||
| build_repo2 do | ||
| build_gem "sfmc-fuelsdk-ruby", %w[1.3.2] do |s| | ||
| s.add_dependency "wasabi", "3.6.1" | ||
| s.add_dependency "jwt", "~> 2.2" | ||
| end | ||
| build_gem "cognito-rack", %w[0.16.6] do |s| | ||
| s.add_dependency "jwt", "~> 2.2" | ||
| end | ||
| end | ||
|
|
||
| build_repo4 do | ||
| build_gem "skynet", %w[2.0.2] do |s| | ||
| s.add_dependency "sfmc-fuelsdk-ruby", "1.3.2" | ||
| end | ||
| build_gem "sfmc-fuelsdk-ruby", %w[1.3.0] do |s| | ||
| s.add_dependency "wasabi", "3.1.0" | ||
| s.add_dependency "jwt", [">= 1.0.0", "~> 1.0"] | ||
| end | ||
| build_gem "wasabi", %w[3.1.0 3.6.1] | ||
| build_gem "jwt", %w[1.0.0 2.2] | ||
| end | ||
|
|
||
| install_gemfile <<-G | ||
| source "#{file_uri_for(gem_repo4)}" | ||
| gem "skynet" | ||
| source "#{file_uri_for(gem_repo2)}" do | ||
| gem "sfmc-fuelsdk-ruby" | ||
| gem "cognito-rack" | ||
| end | ||
| G | ||
|
|
||
| gemfile <<-G | ||
| source "#{file_uri_for(gem_repo4)}" | ||
| gem "sfmc-fuelsdk-ruby", "1.3.0", :force_version => true | ||
| gem "jwt", "2.2", :force_version => true | ||
| gem "skynet" | ||
| source "#{file_uri_for(gem_repo2)}" do | ||
| gem "cognito-rack" | ||
| end | ||
| G | ||
|
|
||
| bundle "update sfmc-fuelsdk-ruby" | ||
|
|
||
| expect(the_bundle).to include_gems("skynet 2.0.2", "sfmc-fuelsdk-ruby 1.3.0", "wasabi 3.1.0") | ||
| end | ||
| end | ||
|
|
||
| context "shows indicator that force_version was active" do | ||
| it "works" do | ||
| gemfile <<-G | ||
| source "#{file_uri_for(gem_repo1)}" | ||
| gem "rack_middleware" | ||
| gem "rack", "1.0.0", :force_version => true | ||
| G | ||
|
|
||
| bundle :install | ||
|
|
||
| expect(out).to include("Installing rack 1.0.0 [version forced]") | ||
|
|
||
| if Gem::Version.create(Bundler::VERSION).segments.first < 3 | ||
| bundle :install | ||
|
|
||
| expect(out).to include("Using rack 1.0.0 [version forced]") | ||
| end | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, if I understand this new approach, you'd need to handle
required_ruby_versionandrequired_rubygems_versionspecially. Probably by changing them to be unconstrained? Otherwise even if all the requirements of the forced version are prioritized, they would still not be met in the case ofrequired_ruby_versionandrequired_rubygems_version. Right?This makes me wonder whether @simi's suggestion of providing a way of "monkeypatching requirements" of a gem would be better:
It would also make it possible to use the feature multiple times in a
Gemfilewhich I believe it could currently cause issues with this approach if they have conflicting requirements?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the monkey patch syntax because it requires bringing all the parents into the equation in the force_version case and I don't think adds enough extra information to make it worth it. Also, I'm a bit wracking my brain in how to implement.
Here is an implementation of two additional flags to
gem,:override_ruby_versionand `:override_rubygems_version: lukaso#7 which I can fold into this PR.The usage example is:
There is no easy or clear place to patch into the loading of
gemspecsthat I could find, so I had to place to overrides in a number of strategic places.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about the implementation either, I can see how it could get super tricky, but if we decided to do this, I was expecting to ship a single feature to accomplish this. Either
force_version: <exact_version>as in: "ignore what you have to ignore during resolution to make sure you give me this specific version", or a more finer grained approach of being able to monkeypatch the gemspec constraints used for resolution.I'll think about it more.