diff --git a/lib/vagrant/bundler.rb b/lib/vagrant/bundler.rb index bc605a35a..bae05fa20 100644 --- a/lib/vagrant/bundler.rb +++ b/lib/vagrant/bundler.rb @@ -18,6 +18,8 @@ module Vagrant end def initialize + @enabled = !::Bundler::SharedHelpers.in_bundle? + @enabled = true if ENV["VAGRANT_FORCE_BUNDLER"] @monitor = Monitor.new @gem_home = ENV["GEM_HOME"] @@ -37,6 +39,9 @@ module Vagrant # Initializes Bundler and the various gem paths so that we can begin # loading gems. This must only be called once. def init!(plugins) + # If we're not enabled, then we don't do anything. + return if !@enabled + # Setup the Bundler configuration @configfile = File.open(Tempfile.new("vagrant").path + "1", "w+") @configfile.close @@ -202,6 +207,8 @@ module Vagrant end def with_isolated_gem + raise Errors::BundlerDisabled if !@enabled + # Remove bundler settings so that Bundler isn't loaded when building # native extensions because it causes all sorts of problems. old_rubyopt = ENV["RUBYOPT"] diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index a0a38bf2e..0a7b1f479 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -164,6 +164,10 @@ module Vagrant error_key(:failed, "vagrant.actions.box.verify") end + class BundlerDisabled < VagrantError + error_key(:bundler_disabled) + end + class BundlerError < VagrantError error_key(:bundler_error) end diff --git a/lib/vagrant/pre-rubygems.rb b/lib/vagrant/pre-rubygems.rb index 9cea06038..451fdd263 100644 --- a/lib/vagrant/pre-rubygems.rb +++ b/lib/vagrant/pre-rubygems.rb @@ -5,17 +5,11 @@ if defined?(Bundler) require "bundler/shared_helpers" if Bundler::SharedHelpers.in_bundle? - if ENV["VAGRANT_FORCE_PLUGINS"] - puts "Vagrant appears to be running in a Bundler environment. Normally," - puts "plugins would not be loaded, but VAGRANT_FORCE_PLUGINS is enabled," - puts "so they will be." - puts - else - puts "Vagrant appears to be running in a Bundler environment. Plugins" - puts "will not be loaded and plugin commands are disabled." - puts - ENV["VAGRANT_NO_PLUGINS"] = "1" - end + puts "Vagrant appears to be running in a Bundler environment. Your " + puts "existing Gemfile will be used. Vagrant will not auto-load any plugins." + puts "You must load any plugins you want manually in a Vagrantfile. You can" + puts "force Vagrant to take over with VAGRANT_FORCE_BUNDLER." + puts end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 67fae5ae5..b6b0f90a8 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -269,6 +269,13 @@ en: The box '%{name}' is still stored on disk in the Vagrant 1.0.x format. This box must be upgraded in order to work properly with this version of Vagrant. + bundler_disabled: |- + Vagrant's built-in bundler management mechanism is disabled because + Vagrant is running in an external bundler environment. In these + cases, plugin management does not work with Vagrant. To install + plugins, use your own Gemfile. To load plugins, either put the + plugins in the `plugins` group in your Gemfile or manually require + them in a Vagrantfile. bundler_error: |- Bundler, the underlying system Vagrant uses to install plugins, reported an error. The error is shown below. These errors are usually diff --git a/vagrant-spec.config.example.rb b/vagrant-spec.config.example.rb index dd0dbfe36..59a39520d 100644 --- a/vagrant-spec.config.example.rb +++ b/vagrant-spec.config.example.rb @@ -1,5 +1,3 @@ -ENV["VAGRANT_FORCE_PLUGINS"] = "1" - require_relative "test/acceptance/base" Vagrant::Spec::Acceptance.configure do |c|