Skip to content

Commit

Permalink
core: Within a Bundler env, don't manage Bundler
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Jan 17, 2014
1 parent 2f49449 commit 83245e6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
7 changes: 7 additions & 0 deletions lib/vagrant/bundler.rb
Expand Up @@ -18,6 +18,8 @@ def self.instance
end

def initialize
@enabled = !::Bundler::SharedHelpers.in_bundle?
@enabled = true if ENV["VAGRANT_FORCE_BUNDLER"]
@monitor = Monitor.new

@gem_home = ENV["GEM_HOME"]
Expand All @@ -37,6 +39,9 @@ def ui.silence(*args)
# 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
Expand Down Expand Up @@ -202,6 +207,8 @@ def internal_install(plugins, update, **extra)
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"]
Expand Down
4 changes: 4 additions & 0 deletions lib/vagrant/errors.rb
Expand Up @@ -164,6 +164,10 @@ class BoxVerificationFailed < VagrantError
error_key(:failed, "vagrant.actions.box.verify")
end

class BundlerDisabled < VagrantError
error_key(:bundler_disabled)
end

class BundlerError < VagrantError
error_key(:bundler_error)
end
Expand Down
16 changes: 5 additions & 11 deletions lib/vagrant/pre-rubygems.rb
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions templates/locales/en.yml
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions 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|
Expand Down

0 comments on commit 83245e6

Please sign in to comment.