From 1f5dd35d16bccb86f4c03fa8f8b1d3bb745aa36f Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 7 Nov 2016 20:00:38 -0800 Subject: [PATCH] Remove bundler where no longer required --- bin/vagrant | 48 ------------------------ lib/vagrant.rb | 40 ++++++++++++++------ lib/vagrant/plugin/manager.rb | 8 ++-- lib/vagrant/shared_helpers.rb | 7 ++++ lib/vagrant/util/env.rb | 4 +- lib/vagrant/util/subprocess.rb | 4 +- test/unit/vagrant/plugin/manager_test.rb | 8 ++-- 7 files changed, 49 insertions(+), 70 deletions(-) diff --git a/bin/vagrant b/bin/vagrant index 0763ca89f..f0d638074 100755 --- a/bin/vagrant +++ b/bin/vagrant @@ -44,54 +44,6 @@ if argv.include?("--debug") ENV["VAGRANT_LOG"] = "debug" end -# Setup our dependencies by initializing Bundler. If we're using plugins, -# then also initialize the paths to the plugins. -begin - require "bundler" -rescue Errno::EINVAL - # Bundler can generate the EINVAL error during initial require, which means - # nothing has yet been setup (so no access to I18n). Note that vagrant has - # failed early and copy information related to problem and possible solution. - $stderr.puts "Vagrant failed to initialize at a very early stage:\n\n" - $stderr.puts "Vagrant received an \"EINVAL\" error while attempting to set some" - $stderr.puts "environment variables. This is usually caused by the total size of your" - $stderr.puts "environment variables being too large. Vagrant sets a handful of" - $stderr.puts "environment variables to function and requires this to work. Please" - $stderr.puts "delete some environment variables prior to executing Vagrant to" - $stderr.puts "fix this." - exit 255 -end - -if(defined?(Bundler)) - begin - $vagrant_bundler_runtime = Bundler.setup(:default, :plugins) - rescue Bundler::GemNotFound - $stderr.puts "Bundler, the underlying system used to manage Vagrant plugins," - $stderr.puts "is reporting that a plugin or its dependency can't be found." - $stderr.puts "This is usually caused by manual tampering with the 'plugins.json'" - $stderr.puts "file in the Vagrant home directory. To fix this error, please" - $stderr.puts "remove that file and reinstall all your plugins using `vagrant" - $stderr.puts "plugin install`." - rescue Bundler::VersionConflict => e - $stderr.puts "Vagrant experienced a version conflict with some installed plugins!" - $stderr.puts "This usually happens if you recently upgraded Vagrant. As part of the" - $stderr.puts "upgrade process, some existing plugins are no longer compatible with" - $stderr.puts "this version of Vagrant. The recommended way to fix this is to remove" - $stderr.puts "your existing plugins and reinstall them one-by-one. To remove all" - $stderr.puts "plugins:" - $stderr.puts "" - $stderr.puts " rm -r ~/.vagrant.d/plugins.json ~/.vagrant.d/gems" - $stderr.puts "" - $stderr.puts "Note if you have an alternate VAGRANT_HOME environmental variable" - $stderr.puts "set, the folders above will be in that directory rather than your" - $stderr.puts "user's home directory." - $stderr.puts "" - $stderr.puts "The error message is shown below:\n\n" - $stderr.puts e.message - exit 1 - end -end - # Stdout/stderr should not buffer output $stdout.sync = true $stderr.sync = true diff --git a/lib/vagrant.rb b/lib/vagrant.rb index 193fb7b0a..a15996c2c 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -1,12 +1,5 @@ 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." - abort -end - require 'rubygems' require 'log4r' @@ -72,10 +65,6 @@ global_logger.info("RubyGems version: #{Gem::VERSION}") ENV.each do |k, v| global_logger.info("#{k}=#{v.inspect}") if k =~ /^VAGRANT_/ end -global_logger.info("Plugins:") -Bundler.definition.specs_for([:plugins]).each do |spec| - global_logger.info(" - #{spec.name} = #{spec.version}") -end # We need these components always so instead of an autoload we # just require them explicitly here. @@ -256,7 +245,34 @@ end # Setup the plugin manager and load any defined plugins require_relative "vagrant/plugin/manager" plugins = Vagrant::Plugin::Manager.instance.installed_plugins -Vagrant::Bundler.instance.init!(plugins) unless ENV['VAGRANT_DISABLE_PLUGIN_INIT'] == "1" + +global_logger.info("Plugins:") +plugins.each do |plugin_name, plugin_info| + global_logger.info(" - #{plugin_name} = #{plugin_info[:version]}") +end + +if Vagrant.plugins_init? + begin + Vagrant::Bundler.instance.init!(plugins) + rescue Gem::ConflictError, Gem::DependencyError => e + $stderr.puts "Vagrant experienced a version conflict with some installed plugins!" + $stderr.puts "This usually happens if you recently upgraded Vagrant. As part of the" + $stderr.puts "upgrade process, some existing plugins are no longer compatible with" + $stderr.puts "this version of Vagrant. The recommended way to fix this is to remove" + $stderr.puts "your existing plugins and reinstall them one-by-one. To remove all" + $stderr.puts "plugins:" + $stderr.puts "" + $stderr.puts " vagrant expunge" + $stderr.puts "" + $stderr.puts "Note if you have an alternate VAGRANT_HOME environmental variable" + $stderr.puts "set, the folders above will be in that directory rather than your" + $stderr.puts "user's home directory." + $stderr.puts "" + $stderr.puts "The error message is shown below:\n\n" + $stderr.puts e.message + exit 1 + end +end # A lambda that knows how to load plugins from a single directory. plugin_load_proc = lambda do |directory| diff --git a/lib/vagrant/plugin/manager.rb b/lib/vagrant/plugin/manager.rb index dfaab2ecf..838c65a40 100644 --- a/lib/vagrant/plugin/manager.rb +++ b/lib/vagrant/plugin/manager.rb @@ -81,9 +81,9 @@ module Vagrant ) result - rescue ::Bundler::GemNotFound + rescue Gem::GemNotFoundException raise Errors::PluginGemNotFound, name: name - rescue ::Bundler::BundlerError => e + rescue Gem::Exception => e raise Errors::BundlerError, message: e.to_s end @@ -102,14 +102,14 @@ module Vagrant # Clean the environment, removing any old plugins Vagrant::Bundler.instance.clean(installed_plugins) - rescue ::Bundler::BundlerError => e + rescue Gem::Exception => e raise Errors::BundlerError, message: e.to_s end # Updates all or a specific set of plugins. def update_plugins(specific) Vagrant::Bundler.instance.update(installed_plugins, specific) - rescue ::Bundler::BundlerError => e + rescue Gem::Exception => e raise Errors::BundlerError, message: e.to_s end diff --git a/lib/vagrant/shared_helpers.rb b/lib/vagrant/shared_helpers.rb index fe114013e..ed9bf9595 100644 --- a/lib/vagrant/shared_helpers.rb +++ b/lib/vagrant/shared_helpers.rb @@ -38,6 +38,13 @@ module Vagrant ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"] end + # Should the plugin system be initialized + # + # @return [Boolean] + def self.plugins_init? + !ENV['VAGRANT_DISABLE_PLUGIN_INIT'] + end + # This returns whether or not 3rd party plugins should and can be loaded. # # @return [Boolean] diff --git a/lib/vagrant/util/env.rb b/lib/vagrant/util/env.rb index 689c9e5ac..6a8714e54 100644 --- a/lib/vagrant/util/env.rb +++ b/lib/vagrant/util/env.rb @@ -5,7 +5,9 @@ module Vagrant class Env def self.with_original_env original_env = ENV.to_hash - ENV.replace(::Bundler::ORIGINAL_ENV) if defined?(::Bundler::ORIGINAL_ENV) + if defined?(::Bundler) && defined?(::Bundler::ORIGINAL_ENV) + ENV.replace(::Bundler::ORIGINAL_ENV) + end ENV.update(Vagrant.original_env) yield ensure diff --git a/lib/vagrant/util/subprocess.rb b/lib/vagrant/util/subprocess.rb index 75bc101cc..3737d3897 100644 --- a/lib/vagrant/util/subprocess.rb +++ b/lib/vagrant/util/subprocess.rb @@ -297,7 +297,9 @@ module Vagrant def jailbreak(env = {}) return if ENV.key?("VAGRANT_SKIP_SUBPROCESS_JAILBREAK") - env.replace(::Bundler::ORIGINAL_ENV) if defined?(::Bundler::ORIGINAL_ENV) + if defined?(::Bundler) && defined?(::Bundler::ORIGINAL_ENV) + env.replace(::Bundler::ORIGINAL_ENV) + end env.merge!(Vagrant.original_env) # Bundler does this, so I guess we should as well, since I think it diff --git a/test/unit/vagrant/plugin/manager_test.rb b/test/unit/vagrant/plugin/manager_test.rb index ea8764b06..328c0b9da 100644 --- a/test/unit/vagrant/plugin/manager_test.rb +++ b/test/unit/vagrant/plugin/manager_test.rb @@ -45,14 +45,14 @@ describe Vagrant::Plugin::Manager do end it "masks GemNotFound with our error" do - expect(bundler).to receive(:install).and_raise(Bundler::GemNotFound) + expect(bundler).to receive(:install).and_raise(Gem::GemNotFoundException) expect { subject.install_plugin("foo") }. to raise_error(Vagrant::Errors::PluginGemNotFound) end it "masks bundler errors with our own error" do - expect(bundler).to receive(:install).and_raise(Bundler::InstallError) + expect(bundler).to receive(:install).and_raise(Gem::InstallError) expect { subject.install_plugin("foo") }. to raise_error(Vagrant::Errors::BundlerError) @@ -140,7 +140,7 @@ describe Vagrant::Plugin::Manager do end it "masks bundler errors with our own error" do - expect(bundler).to receive(:clean).and_raise(Bundler::InstallError) + expect(bundler).to receive(:clean).and_raise(Gem::InstallError) expect { subject.uninstall_plugin("foo") }. to raise_error(Vagrant::Errors::BundlerError) @@ -182,7 +182,7 @@ describe Vagrant::Plugin::Manager do describe "#update_plugins" do it "masks bundler errors with our own error" do - expect(bundler).to receive(:update).and_raise(Bundler::InstallError) + expect(bundler).to receive(:update).and_raise(Gem::InstallError) expect { subject.update_plugins([]) }. to raise_error(Vagrant::Errors::BundlerError)