diff --git a/bin/vagrant b/bin/vagrant index ef6789565..ad4407d0b 100755 --- a/bin/vagrant +++ b/bin/vagrant @@ -20,9 +20,27 @@ if argv.include?("-v") || argv.include?("--version") exit 0 end +# This is kind of hacky, and I'd love to find a better way to do this, but +# if we're accessing the plugin interface, we want to NOT load plugins +# for this run, because they can actually interfere with the function +# of the plugin interface. +argv.each do |arg| + if !arg.start_with?("-") + if arg == "plugin" + ENV["VAGRANT_NO_PLUGINS"] = "1" + ENV["VAGRANT_VAGRANTFILE"] = "plugin_command_#{Time.now.to_i}" + end + + break + end +end + +# Require some stuff that is NOT dependent on RubyGems +require "vagrant/shared_helpers" + # First, make sure that we're executing using the proper Bundler context # with our plugins. If we're not, then load that and reload Vagrant. -if !ENV["VAGRANT_INTERNAL_BUNDLERIZED"] +if !ENV["VAGRANT_INTERNAL_BUNDLERIZED"] && Vagrant.plugins_enabled? require "rbconfig" ruby_path = File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"]) Kernel.exec( @@ -39,25 +57,12 @@ if argv.include?("--debug") ENV["VAGRANT_LOG"] = "debug" end -# This is kind of hacky, and I'd love to find a better way to do this, but -# if we're accessing the plugin interface, we want to NOT load plugins -# for this run, because they can actually interfere with the function -# of the plugin interface. -argv.each do |arg| - if !arg.start_with?("-") - if arg == "plugin" - ENV["VAGRANT_NO_PLUGINS"] = "1" - ENV["VAGRANT_VAGRANTFILE"] = "plugin_command_#{Time.now.to_i}" - end - - break - end +# Setup our dependencies by initializing Bundler if we're using plugins +if Vagrant.plugins_enabled? + require "bundler" + Bundler.setup end -# Setup our dependencies by initializing Bundler -require "bundler" -Bundler.setup - require 'log4r' require 'vagrant' require 'vagrant/cli' diff --git a/lib/vagrant.rb b/lib/vagrant.rb index 83c801c89..263234301 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -3,7 +3,9 @@ ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"] = "/Applications/Vagrant/embedded" -if !defined?(Bundler) +require "vagrant/shared_helpers" + +if Vagrant.plugins_enabled? && !defined?(Bundler) puts "It appears that Vagrant was not properly loaded. Specifically," puts "the bundler context Vagrant requires was not setup. Please execute" puts "vagrant using only the `vagrant` executable." @@ -80,7 +82,6 @@ end # just require them explicitly here. require "vagrant/plugin" require "vagrant/registry" -require "vagrant/shared_helpers" module Vagrant autoload :Action, 'vagrant/action' diff --git a/lib/vagrant/bundler.rb b/lib/vagrant/bundler.rb index 3dc7b4514..785f74f27 100644 --- a/lib/vagrant/bundler.rb +++ b/lib/vagrant/bundler.rb @@ -1,6 +1,8 @@ require "pathname" require "tempfile" +require "bundler" + require_relative "shared_helpers" require_relative "version" @@ -21,8 +23,6 @@ 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) - raise "Bundler already initialized" if defined?(::Bundler) - # Setup the Bundler configuration @configfile = File.open(Tempfile.new("vagrant").path + "1", "w+") @configfile.close @@ -39,9 +39,6 @@ module Vagrant "#{Vagrant.user_data_path.join("gems")}#{::File::PATH_SEPARATOR}#{@gem_path}" Gem.clear_paths - # Load Bundler now - require "bundler" - # Do some additional Bundler initialization ::Bundler.ui = ::Bundler::UI.new if !::Bundler.ui.respond_to?(:silence) diff --git a/lib/vagrant/pre-rubygems.rb b/lib/vagrant/pre-rubygems.rb index 40ab97dd3..f90b7cc40 100644 --- a/lib/vagrant/pre-rubygems.rb +++ b/lib/vagrant/pre-rubygems.rb @@ -2,10 +2,6 @@ # initializes the Bundler context so that Vagrant and its associated plugins # can load properly, and then execs out into Vagrant again. -require_relative "bundler" -require_relative "plugin/manager" -require_relative "shared_helpers" - if defined?(Bundler) require "bundler/shared_helpers" if Bundler::SharedHelpers.in_bundle? @@ -16,6 +12,10 @@ if defined?(Bundler) end end +require_relative "bundler" +require_relative "plugin/manager" +require_relative "shared_helpers" + plugins = [] plugins = Vagrant::Plugin::Manager.instance.installed_plugins if Vagrant.plugins_enabled? Vagrant::Bundler.instance.init!(plugins)