summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBundlerbot <bot@bundler.io>2019-07-29 07:57:34 +0000
committerBundlerbot <bot@bundler.io>2019-07-29 07:57:34 +0000
commit3af2211195811e1e0618c166387a53a677ab1438 (patch)
tree21f542509f21695c0ade5ffdfc39d8a69b7dbc31
parentcdd2075c71e2426e6fd77c1a340620753b14669e (diff)
parentcaf13e9e4fb2455199741dd81117f580f894af67 (diff)
downloadbundler-3af2211195811e1e0618c166387a53a677ab1438.tar.gz
Merge #7259
7259: Relax bundler binstub r=indirect a=deivid-rodriguez ### What was the end-user problem that led to this PR? The problem was that the logic to select bundler versions was different when bundler is run from a rubygems binstub that when bundler is run from a bundler binstub. ### What was your diagnosis of the problem? My diagnosis was that we should unify the logic. ### What is your fix for the problem, implemented in this PR? My fix is to use the same logic implemented in the rubygems version finder, namely, only fail if the major version of bundler does not match. ### Why did you choose this fix out of the possible options? I chose this fix because it makes things consistent. Fixes #7243. Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
-rw-r--r--lib/bundler/templates/Executable.bundler35
-rw-r--r--spec/commands/binstubs_spec.rb34
2 files changed, 43 insertions, 26 deletions
diff --git a/lib/bundler/templates/Executable.bundler b/lib/bundler/templates/Executable.bundler
index 3adac41e74..69f26bb9c0 100644
--- a/lib/bundler/templates/Executable.bundler
+++ b/lib/bundler/templates/Executable.bundler
@@ -31,7 +31,7 @@ m = Module.new do
bundler_version = a
end
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
- bundler_version = $1 || ">= 0.a"
+ bundler_version = $1
update_index = i
end
bundler_version
@@ -61,32 +61,41 @@ m = Module.new do
end
def bundler_version
- @bundler_version ||= begin
+ @bundler_version ||=
env_var_version || cli_arg_version ||
- lockfile_version || "#{Gem::Requirement.default}.a"
- end
+ lockfile_version
+ end
+
+ def bundler_requirement
+ return "#{Gem::Requirement.default}.a" unless bundler_version
+
+ bundler_gem_version = Gem::Version.new(bundler_version)
+
+ requirement = bundler_gem_version.approximate_recommendation
+
+ return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
+
+ requirement += ".a" if bundler_gem_version.prerelease?
+
+ requirement
end
def load_bundler!
ENV["BUNDLE_GEMFILE"] ||= gemfile
- # must dup string for RG < 1.8 compatibility
- activate_bundler(bundler_version.dup)
+ activate_bundler
end
- def activate_bundler(bundler_version)
- if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
- bundler_version = "< 2"
- end
+ def activate_bundler
gem_error = activation_error_handling do
- gem "bundler", bundler_version
+ gem "bundler", bundler_requirement
end
return if gem_error.nil?
require_error = activation_error_handling do
require "bundler/version"
end
- return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
- warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
+ return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
+ warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
exit 42
end
diff --git a/spec/commands/binstubs_spec.rb b/spec/commands/binstubs_spec.rb
index f3e8233570..748cf6362f 100644
--- a/spec/commands/binstubs_spec.rb
+++ b/spec/commands/binstubs_spec.rb
@@ -135,8 +135,8 @@ RSpec.describe "bundle binstubs <gem>" do
it "runs the correct version of bundler" do
sys_exec "#{bundled_app("bin/bundle")} install", "BUNDLER_VERSION" => "999.999.999"
expect(exitstatus).to eq(42) if exitstatus
- expect(err).to include("Activating bundler (999.999.999) failed:").
- and include("To install the version of bundler this project requires, run `gem install bundler -v '999.999.999'`")
+ expect(err).to include("Activating bundler (~> 999.999) failed:").
+ and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 999.999'`")
end
end
@@ -145,17 +145,25 @@ RSpec.describe "bundle binstubs <gem>" do
lockfile lockfile.gsub(system_bundler_version, "999.999.999")
sys_exec "#{bundled_app("bin/bundle")} install"
expect(exitstatus).to eq(42) if exitstatus
- expect(err).to include("Activating bundler (999.999.999) failed:").
- and include("To install the version of bundler this project requires, run `gem install bundler -v '999.999.999'`")
+ expect(err).to include("Activating bundler (~> 999.999) failed:").
+ and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 999.999'`")
end
- it "runs the correct version of bundler when the version is older" do
+ it "runs the correct version of bundler when the version is older and a different major" do
simulate_bundler_version "55"
lockfile lockfile.gsub(system_bundler_version, "44.0")
sys_exec "#{bundled_app("bin/bundle")} install"
expect(exitstatus).to eq(42) if exitstatus
- expect(err).to include("Activating bundler (44.0) failed:").
- and include("To install the version of bundler this project requires, run `gem install bundler -v '44.0'`")
+ expect(err).to include("Activating bundler (~> 44.0) failed:").
+ and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 44.0'`")
+ end
+
+ it "runs the available version of bundler when the version is older and the same major" do
+ simulate_bundler_version "55.1"
+ lockfile lockfile.gsub(system_bundler_version, "55.0")
+ sys_exec "#{bundled_app("bin/bundle")} install"
+ expect(exitstatus).not_to eq(42) if exitstatus
+ expect(err).not_to include("Activating bundler (~> 55.0) failed:")
end
it "runs the correct version of bundler when the version is a pre-release" do
@@ -163,8 +171,8 @@ RSpec.describe "bundle binstubs <gem>" do
lockfile lockfile.gsub(system_bundler_version, "2.12.0.a")
sys_exec "#{bundled_app("bin/bundle")} install"
expect(exitstatus).to eq(42) if exitstatus
- expect(err).to include("Activating bundler (2.12.0.a) failed:").
- and include("To install the version of bundler this project requires, run `gem install bundler -v '2.12.0.a'`")
+ expect(err).to include("Activating bundler (~> 2.12.a) failed:").
+ and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 2.12.a'`")
end
end
@@ -179,8 +187,8 @@ RSpec.describe "bundle binstubs <gem>" do
it "calls through to the explicit bundler version" do
sys_exec "#{bundled_app("bin/bundle")} update --bundler=999.999.999"
expect(exitstatus).to eq(42) if exitstatus
- expect(err).to include("Activating bundler (999.999.999) failed:").
- and include("To install the version of bundler this project requires, run `gem install bundler -v '999.999.999'`")
+ expect(err).to include("Activating bundler (~> 999.999) failed:").
+ and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 999.999'`")
end
end
@@ -205,8 +213,8 @@ RSpec.describe "bundle binstubs <gem>" do
it "attempts to load that version" do
sys_exec bundled_app("bin/rackup").to_s
expect(exitstatus).to eq(42) if exitstatus
- expect(err).to include("Activating bundler (999.999.999) failed:").
- and include("To install the version of bundler this project requires, run `gem install bundler -v '999.999.999'`")
+ expect(err).to include("Activating bundler (~> 999.999) failed:").
+ and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 999.999'`")
end
end
end