Skip to content

Commit 83245e6

Browse files
committed
core: Within a Bundler env, don't manage Bundler
1 parent 2f49449 commit 83245e6

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

lib/vagrant/bundler.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def self.instance
1818
end
1919

2020
def initialize
21+
@enabled = !::Bundler::SharedHelpers.in_bundle?
22+
@enabled = true if ENV["VAGRANT_FORCE_BUNDLER"]
2123
@monitor = Monitor.new
2224

2325
@gem_home = ENV["GEM_HOME"]
@@ -37,6 +39,9 @@ def ui.silence(*args)
3739
# Initializes Bundler and the various gem paths so that we can begin
3840
# loading gems. This must only be called once.
3941
def init!(plugins)
42+
# If we're not enabled, then we don't do anything.
43+
return if !@enabled
44+
4045
# Setup the Bundler configuration
4146
@configfile = File.open(Tempfile.new("vagrant").path + "1", "w+")
4247
@configfile.close
@@ -202,6 +207,8 @@ def internal_install(plugins, update, **extra)
202207
end
203208

204209
def with_isolated_gem
210+
raise Errors::BundlerDisabled if !@enabled
211+
205212
# Remove bundler settings so that Bundler isn't loaded when building
206213
# native extensions because it causes all sorts of problems.
207214
old_rubyopt = ENV["RUBYOPT"]

lib/vagrant/errors.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ class BoxVerificationFailed < VagrantError
164164
error_key(:failed, "vagrant.actions.box.verify")
165165
end
166166

167+
class BundlerDisabled < VagrantError
168+
error_key(:bundler_disabled)
169+
end
170+
167171
class BundlerError < VagrantError
168172
error_key(:bundler_error)
169173
end

lib/vagrant/pre-rubygems.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,11 @@
55
if defined?(Bundler)
66
require "bundler/shared_helpers"
77
if Bundler::SharedHelpers.in_bundle?
8-
if ENV["VAGRANT_FORCE_PLUGINS"]
9-
puts "Vagrant appears to be running in a Bundler environment. Normally,"
10-
puts "plugins would not be loaded, but VAGRANT_FORCE_PLUGINS is enabled,"
11-
puts "so they will be."
12-
puts
13-
else
14-
puts "Vagrant appears to be running in a Bundler environment. Plugins"
15-
puts "will not be loaded and plugin commands are disabled."
16-
puts
17-
ENV["VAGRANT_NO_PLUGINS"] = "1"
18-
end
8+
puts "Vagrant appears to be running in a Bundler environment. Your "
9+
puts "existing Gemfile will be used. Vagrant will not auto-load any plugins."
10+
puts "You must load any plugins you want manually in a Vagrantfile. You can"
11+
puts "force Vagrant to take over with VAGRANT_FORCE_BUNDLER."
12+
puts
1913
end
2014
end
2115

templates/locales/en.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,13 @@ en:
269269
The box '%{name}' is still stored on disk in the Vagrant 1.0.x
270270
format. This box must be upgraded in order to work properly with
271271
this version of Vagrant.
272+
bundler_disabled: |-
273+
Vagrant's built-in bundler management mechanism is disabled because
274+
Vagrant is running in an external bundler environment. In these
275+
cases, plugin management does not work with Vagrant. To install
276+
plugins, use your own Gemfile. To load plugins, either put the
277+
plugins in the `plugins` group in your Gemfile or manually require
278+
them in a Vagrantfile.
272279
bundler_error: |-
273280
Bundler, the underlying system Vagrant uses to install plugins,
274281
reported an error. The error is shown below. These errors are usually

vagrant-spec.config.example.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
ENV["VAGRANT_FORCE_PLUGINS"] = "1"
2-
31
require_relative "test/acceptance/base"
42

53
Vagrant::Spec::Acceptance.configure do |c|

0 commit comments

Comments
 (0)