Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ Lint/ScriptPermission:
Enabled: true
Exclude:
- "bundler/lib/bundler/templates/Executable"
- "bundler/lib/bundler/templates/Executable.*"

Lint/ShadowedArgument:
Enabled: true
Expand Down
1 change: 0 additions & 1 deletion Manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ bundler/lib/bundler/spec_set.rb
bundler/lib/bundler/stub_specification.rb
bundler/lib/bundler/templates/.document
bundler/lib/bundler/templates/Executable
bundler/lib/bundler/templates/Executable.bundler
bundler/lib/bundler/templates/Executable.standalone
bundler/lib/bundler/templates/Gemfile
bundler/lib/bundler/templates/newgem/CHANGELOG.md.tt
Expand Down
9 changes: 5 additions & 4 deletions bundler/lib/bundler/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ def run(options)
end

def generate_bundler_executable_stubs(spec, options = {})
if spec.name == "bundler"
Bundler.ui.warn "Bundler itself does not use binstubs because its version is selected by RubyGems"
return
end

if options[:binstubs_cmd] && spec.executables.empty?
options = {}
spec.runtime_dependencies.each do |dep|
Expand All @@ -115,10 +120,6 @@ def generate_bundler_executable_stubs(spec, options = {})
ruby_command = Thor::Util.ruby_command
ruby_command = ruby_command
template_path = File.expand_path("templates/Executable", __dir__)
if spec.name == "bundler"
template_path += ".bundler"
spec.executables = %(bundle)
end
template = File.read(template_path)

exists = []
Expand Down
11 changes: 0 additions & 11 deletions bundler/lib/bundler/templates/Executable
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("<%= relative_gemfile_path %>", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

Expand Down
109 changes: 0 additions & 109 deletions bundler/lib/bundler/templates/Executable.bundler

This file was deleted.

214 changes: 0 additions & 214 deletions bundler/spec/commands/binstubs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,220 +85,6 @@
expect(err).to include("Cannot specify --all with specific gems")
end

context "when generating bundle binstub outside bundler" do
it "should abort" do
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack"
G

bundle "binstubs myrack"

File.open(bundled_app("bin/bundle"), "wb") do |file|
file.print "OMG"
end

sys_exec "bin/myrackup", raise_on_error: false

expect(err).to include("was not generated by Bundler")
end
end

context "the bundle binstub" do
before do
pristine_system_gems "bundler-#{system_bundler_version}"
build_repo2 do
build_gem "myrack", "1.2" do |s|
s.executables = "myrackup"
end

build_gem "prints_loaded_gems", "1.0" do |s|
s.executables = "print_loaded_gems"
s.bindir = "exe"
s.write "exe/print_loaded_gems", <<~R
#!/usr/bin/env ruby
specs = Gem.loaded_specs.values.reject {|s| s.default_gem? }
puts specs.map(&:full_name).sort.inspect
R
end

build_bundler locked_bundler_version
end
install_gemfile <<-G
source "https://gem.repo2"
gem "myrack"
gem "prints_loaded_gems"
G
bundle "binstubs bundler myrack prints_loaded_gems"
end

let(:system_bundler_version) { Bundler::VERSION }
let(:locked_bundler_version) { nil }
let(:lockfile_content) { lockfile.gsub(system_bundler_version, locked_bundler_version) }

it "runs bundler" do
bundle "install --verbose", bundle_bin: "bin/bundle"
expect(out).to include %(Using bundler #{system_bundler_version}\n)
end

context "when BUNDLER_VERSION is set" do
it "runs the correct version of bundler" do
bundle "install", env: { "BUNDLER_VERSION" => "999.999.999" }, raise_on_error: false, bundle_bin: "bin/bundle"
expect(exitstatus).to eq(42)
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'`")
end

it "runs the correct version of bundler even if a higher version is installed" do
system_gems "bundler-999.999.998", "bundler-999.999.999"

bundle "install --verbose", env: { "BUNDLER_VERSION" => "999.999.998" }, raise_on_error: false, bundle_bin: "bin/bundle"
expect(out).to include %(Using bundler 999.999.998\n)
end
end

context "when a lockfile exists with a locked bundler version" do
let(:locked_bundler_version) { "999.999" }

context "and the version is newer" do
before do
lockfile lockfile_content
end

it "runs the correct version of bundler" do
bundle "install", raise_on_error: false, bundle_bin: "bin/bundle"
expect(exitstatus).to eq(42)
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

context "and the version is newer when given `gems.rb` and `gems.locked`" do
before do
gemfile bundled_app("gems.rb"), gemfile
lockfile bundled_app("gems.locked"), lockfile_content
end

it "runs the correct version of bundler" do
bundle "install", env: { "BUNDLE_GEMFILE" => "gems.rb" }, raise_on_error: false, bundle_bin: "bin/bundle"

expect(exitstatus).to eq(42)
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

context "and the version is older and a different major" do
let(:system_bundler_version) { "55" }
let(:locked_bundler_version) { "44" }

before do
lockfile lockfile_content
end

it "runs the correct version of bundler" do
bundle "install", raise_on_error: false, bundle_bin: "bin/bundle"
expect(exitstatus).to eq(42)
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
end

context "and the version is older and a different major when given `gems.rb` and `gems.locked`" do
let(:system_bundler_version) { "55" }
let(:locked_bundler_version) { "44" }

before do
gemfile bundled_app("gems.rb"), gemfile
lockfile bundled_app("gems.locked"), lockfile_content
end

it "runs the correct version of bundler" do
bundle "install", env: { "BUNDLE_GEMFILE" => "gems.rb" }, raise_on_error: false, bundle_bin: "bin/bundle"
expect(exitstatus).to eq(42)
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
end

context "and the version is older and the same major" do
let(:system_bundler_version) { "2.999.999" }
let(:locked_bundler_version) { "2.3.0" }

before do
lockfile lockfile_content
end

it "installs and runs the exact version of bundler" do
bundle "install --verbose", bundle_bin: "bin/bundle"
expect(exitstatus).not_to eq(42)
expect(out).to include("Bundler 2.999.999 is running, but your lockfile was generated with 2.3.0. Installing Bundler 2.3.0 and restarting using that version.")
expect(out).to include("Using bundler 2.3.0")
expect(err).not_to include("Activating bundler (~> 2.3.0) failed:")
end
end

context "and the version is a pre-releaser" do
let(:system_bundler_version) { "55" }
let(:locked_bundler_version) { "2.12.0.a" }

before do
lockfile lockfile_content
end

it "runs the correct version of bundler when the version is a pre-release" do
bundle "install", raise_on_error: false, bundle_bin: "bin/bundle"
expect(exitstatus).to eq(42)
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
end

context "when update --bundler is called" do
it "calls through to the latest bundler version" do
bundle "update --bundler --verbose", bundle_bin: "bin/bundle"
using_bundler_line = /Using bundler ([\w\.]+)\n/.match(out)
expect(using_bundler_line).to_not be_nil
latest_version = using_bundler_line[1]
expect(Gem::Version.new(latest_version)).to be >= Gem::Version.new(system_bundler_version)
end

it "calls through to the explicit bundler version" do
bundle "update --bundler=999.999.999", raise_on_error: false, bundle_bin: "bin/bundle"
expect(exitstatus).to eq(42)
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'`")
end
end

context "without a lockfile" do
it "falls back to the latest installed bundler" do
FileUtils.rm bundled_app_lock
bundle "install --verbose", bundle_bin: "bin/bundle"
expect(out).to include "Using bundler #{system_bundler_version}\n"
end
end

context "using another binstub" do
it "loads all gems" do
sys_exec bundled_app("bin/print_loaded_gems").to_s
expect(out).to eq %(["bundler-#{Bundler::VERSION}", "myrack-1.2", "prints_loaded_gems-1.0"])
end

context "when requesting a different bundler version" do
before { lockfile lockfile.gsub(Bundler::VERSION, "999.999.999") }

it "attempts to load that version" do
sys_exec bundled_app("bin/myrackup").to_s, raise_on_error: false
expect(exitstatus).to eq(42)
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
end

it "installs binstubs from git gems" do
FileUtils.mkdir_p(lib_path("foo/bin"))
FileUtils.touch(lib_path("foo/bin/foo"))
Expand Down
Loading
Loading