Skip to content

Commit 451d848

Browse files
deivid-rodriguezhsbt
authored andcommitted
Stop generating binstubs for Bundler itself
1 parent 56e2ef2 commit 451d848

File tree

5 files changed

+9
-340
lines changed

5 files changed

+9
-340
lines changed

lib/bundler/installer.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ def run(options)
9191
end
9292

9393
def generate_bundler_executable_stubs(spec, options = {})
94+
if spec.name == "bundler"
95+
Bundler.ui.warn "Bundler itself does not use binstubs because its version is selected by RubyGems"
96+
return
97+
end
98+
9499
if options[:binstubs_cmd] && spec.executables.empty?
95100
options = {}
96101
spec.runtime_dependencies.each do |dep|
@@ -115,10 +120,6 @@ def generate_bundler_executable_stubs(spec, options = {})
115120
ruby_command = Thor::Util.ruby_command
116121
ruby_command = ruby_command
117122
template_path = File.expand_path("templates/Executable", __dir__)
118-
if spec.name == "bundler"
119-
template_path += ".bundler"
120-
spec.executables = %(bundle)
121-
end
122123
template = File.read(template_path)
123124

124125
exists = []

lib/bundler/templates/Executable

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,6 @@
1010

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

13-
bundle_binstub = File.expand_path("bundle", __dir__)
14-
15-
if File.file?(bundle_binstub)
16-
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
17-
load(bundle_binstub)
18-
else
19-
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
20-
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
21-
end
22-
end
23-
2413
require "rubygems"
2514
require "bundler/setup"
2615

lib/bundler/templates/Executable.bundler

Lines changed: 0 additions & 109 deletions
This file was deleted.

spec/bundler/commands/binstubs_spec.rb

Lines changed: 0 additions & 214 deletions
Original file line numberDiff line numberDiff line change
@@ -85,220 +85,6 @@
8585
expect(err).to include("Cannot specify --all with specific gems")
8686
end
8787

88-
context "when generating bundle binstub outside bundler" do
89-
it "should abort" do
90-
install_gemfile <<-G
91-
source "https://gem.repo1"
92-
gem "myrack"
93-
G
94-
95-
bundle "binstubs myrack"
96-
97-
File.open(bundled_app("bin/bundle"), "wb") do |file|
98-
file.print "OMG"
99-
end
100-
101-
sys_exec "bin/myrackup", raise_on_error: false
102-
103-
expect(err).to include("was not generated by Bundler")
104-
end
105-
end
106-
107-
context "the bundle binstub" do
108-
before do
109-
pristine_system_gems "bundler-#{system_bundler_version}"
110-
build_repo2 do
111-
build_gem "myrack", "1.2" do |s|
112-
s.executables = "myrackup"
113-
end
114-
115-
build_gem "prints_loaded_gems", "1.0" do |s|
116-
s.executables = "print_loaded_gems"
117-
s.bindir = "exe"
118-
s.write "exe/print_loaded_gems", <<~R
119-
#!/usr/bin/env ruby
120-
specs = Gem.loaded_specs.values.reject {|s| s.default_gem? }
121-
puts specs.map(&:full_name).sort.inspect
122-
R
123-
end
124-
125-
build_bundler locked_bundler_version
126-
end
127-
install_gemfile <<-G
128-
source "https://gem.repo2"
129-
gem "myrack"
130-
gem "prints_loaded_gems"
131-
G
132-
bundle "binstubs bundler myrack prints_loaded_gems"
133-
end
134-
135-
let(:system_bundler_version) { Bundler::VERSION }
136-
let(:locked_bundler_version) { nil }
137-
let(:lockfile_content) { lockfile.gsub(system_bundler_version, locked_bundler_version) }
138-
139-
it "runs bundler" do
140-
bundle "install --verbose", bundle_bin: "bin/bundle"
141-
expect(out).to include %(Using bundler #{system_bundler_version}\n)
142-
end
143-
144-
context "when BUNDLER_VERSION is set" do
145-
it "runs the correct version of bundler" do
146-
bundle "install", env: { "BUNDLER_VERSION" => "999.999.999" }, raise_on_error: false, bundle_bin: "bin/bundle"
147-
expect(exitstatus).to eq(42)
148-
expect(err).to include("Activating bundler (999.999.999) failed:").
149-
and include("To install the version of bundler this project requires, run `gem install bundler -v '999.999.999'`")
150-
end
151-
152-
it "runs the correct version of bundler even if a higher version is installed" do
153-
system_gems "bundler-999.999.998", "bundler-999.999.999"
154-
155-
bundle "install --verbose", env: { "BUNDLER_VERSION" => "999.999.998" }, raise_on_error: false, bundle_bin: "bin/bundle"
156-
expect(out).to include %(Using bundler 999.999.998\n)
157-
end
158-
end
159-
160-
context "when a lockfile exists with a locked bundler version" do
161-
let(:locked_bundler_version) { "999.999" }
162-
163-
context "and the version is newer" do
164-
before do
165-
lockfile lockfile_content
166-
end
167-
168-
it "runs the correct version of bundler" do
169-
bundle "install", raise_on_error: false, bundle_bin: "bin/bundle"
170-
expect(exitstatus).to eq(42)
171-
expect(err).to include("Activating bundler (~> 999.999) failed:").
172-
and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 999.999'`")
173-
end
174-
end
175-
176-
context "and the version is newer when given `gems.rb` and `gems.locked`" do
177-
before do
178-
gemfile bundled_app("gems.rb"), gemfile
179-
lockfile bundled_app("gems.locked"), lockfile_content
180-
end
181-
182-
it "runs the correct version of bundler" do
183-
bundle "install", env: { "BUNDLE_GEMFILE" => "gems.rb" }, raise_on_error: false, bundle_bin: "bin/bundle"
184-
185-
expect(exitstatus).to eq(42)
186-
expect(err).to include("Activating bundler (~> 999.999) failed:").
187-
and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 999.999'`")
188-
end
189-
end
190-
191-
context "and the version is older and a different major" do
192-
let(:system_bundler_version) { "55" }
193-
let(:locked_bundler_version) { "44" }
194-
195-
before do
196-
lockfile lockfile_content
197-
end
198-
199-
it "runs the correct version of bundler" do
200-
bundle "install", raise_on_error: false, bundle_bin: "bin/bundle"
201-
expect(exitstatus).to eq(42)
202-
expect(err).to include("Activating bundler (~> 44.0) failed:").
203-
and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 44.0'`")
204-
end
205-
end
206-
207-
context "and the version is older and a different major when given `gems.rb` and `gems.locked`" do
208-
let(:system_bundler_version) { "55" }
209-
let(:locked_bundler_version) { "44" }
210-
211-
before do
212-
gemfile bundled_app("gems.rb"), gemfile
213-
lockfile bundled_app("gems.locked"), lockfile_content
214-
end
215-
216-
it "runs the correct version of bundler" do
217-
bundle "install", env: { "BUNDLE_GEMFILE" => "gems.rb" }, raise_on_error: false, bundle_bin: "bin/bundle"
218-
expect(exitstatus).to eq(42)
219-
expect(err).to include("Activating bundler (~> 44.0) failed:").
220-
and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 44.0'`")
221-
end
222-
end
223-
224-
context "and the version is older and the same major" do
225-
let(:system_bundler_version) { "2.999.999" }
226-
let(:locked_bundler_version) { "2.3.0" }
227-
228-
before do
229-
lockfile lockfile_content
230-
end
231-
232-
it "installs and runs the exact version of bundler" do
233-
bundle "install --verbose", bundle_bin: "bin/bundle"
234-
expect(exitstatus).not_to eq(42)
235-
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.")
236-
expect(out).to include("Using bundler 2.3.0")
237-
expect(err).not_to include("Activating bundler (~> 2.3.0) failed:")
238-
end
239-
end
240-
241-
context "and the version is a pre-releaser" do
242-
let(:system_bundler_version) { "55" }
243-
let(:locked_bundler_version) { "2.12.0.a" }
244-
245-
before do
246-
lockfile lockfile_content
247-
end
248-
249-
it "runs the correct version of bundler when the version is a pre-release" do
250-
bundle "install", raise_on_error: false, bundle_bin: "bin/bundle"
251-
expect(exitstatus).to eq(42)
252-
expect(err).to include("Activating bundler (~> 2.12.a) failed:").
253-
and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 2.12.a'`")
254-
end
255-
end
256-
end
257-
258-
context "when update --bundler is called" do
259-
it "calls through to the latest bundler version" do
260-
bundle "update --bundler --verbose", bundle_bin: "bin/bundle"
261-
using_bundler_line = /Using bundler ([\w\.]+)\n/.match(out)
262-
expect(using_bundler_line).to_not be_nil
263-
latest_version = using_bundler_line[1]
264-
expect(Gem::Version.new(latest_version)).to be >= Gem::Version.new(system_bundler_version)
265-
end
266-
267-
it "calls through to the explicit bundler version" do
268-
bundle "update --bundler=999.999.999", raise_on_error: false, bundle_bin: "bin/bundle"
269-
expect(exitstatus).to eq(42)
270-
expect(err).to include("Activating bundler (999.999.999) failed:").
271-
and include("To install the version of bundler this project requires, run `gem install bundler -v '999.999.999'`")
272-
end
273-
end
274-
275-
context "without a lockfile" do
276-
it "falls back to the latest installed bundler" do
277-
FileUtils.rm bundled_app_lock
278-
bundle "install --verbose", bundle_bin: "bin/bundle"
279-
expect(out).to include "Using bundler #{system_bundler_version}\n"
280-
end
281-
end
282-
283-
context "using another binstub" do
284-
it "loads all gems" do
285-
sys_exec bundled_app("bin/print_loaded_gems").to_s
286-
expect(out).to eq %(["bundler-#{Bundler::VERSION}", "myrack-1.2", "prints_loaded_gems-1.0"])
287-
end
288-
289-
context "when requesting a different bundler version" do
290-
before { lockfile lockfile.gsub(Bundler::VERSION, "999.999.999") }
291-
292-
it "attempts to load that version" do
293-
sys_exec bundled_app("bin/myrackup").to_s, raise_on_error: false
294-
expect(exitstatus).to eq(42)
295-
expect(err).to include("Activating bundler (~> 999.999) failed:").
296-
and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 999.999'`")
297-
end
298-
end
299-
end
300-
end
301-
30288
it "installs binstubs from git gems" do
30389
FileUtils.mkdir_p(lib_path("foo/bin"))
30490
FileUtils.touch(lib_path("foo/bin/foo"))

spec/bundler/runtime/executable_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,17 @@
7777
expect(out).to eq("1.0")
7878
end
7979

80-
it "creates a bundle binstub" do
80+
it "does not create a bundle binstub" do
8181
gemfile <<-G
8282
source "https://gem.repo1"
8383
gem "bundler"
8484
G
8585

8686
bundle "binstubs bundler"
8787

88-
expect(bundled_app("bin/bundle")).to exist
88+
expect(bundled_app("bin/bundle")).not_to exist
89+
90+
expect(err).to include("Bundler itself does not use binstubs because its version is selected by RubyGems")
8991
end
9092

9193
it "does not generate bin stubs if the option was not specified" do

0 commit comments

Comments
 (0)