From 062ef52816b125e118e6806dc49d42e8415713ec Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 4 Jun 2019 21:30:05 -0700 Subject: [PATCH 1/3] Handle strict dependency enforcement when installed within system When installed outside of the official installer and not running within a bundler environment, properly activate core dependencies and properly enforce constraints. --- lib/vagrant/bundler.rb | 13 ++++++++++++- lib/vagrant/shared_helpers.rb | 8 ++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/bundler.rb b/lib/vagrant/bundler.rb index 6124eb181..b2980c839 100644 --- a/lib/vagrant/bundler.rb +++ b/lib/vagrant/bundler.rb @@ -313,6 +313,12 @@ module Vagrant @logger.debug("Enabling strict dependency enforcement") plugin_deps += vagrant_internal_specs.map do |spec| next if system_plugins.include?(spec.name) + # If we are not running within the installer and + # we are not within a bundler environment then we + # only want activated specs + if !Vagrant.in_installer? && !Vagrant.in_bundler? + next if !spec.activated? + end Gem::Dependency.new(spec.name, spec.version) end.compact else @@ -415,8 +421,13 @@ module Vagrant Gem::Resolver.compose_sets(*sets) end - # @return [Array<[Gem::Specification, String]>] spec and directory pairs + # @return [Array<[Gem::Specification]>] spec list def vagrant_internal_specs + # activate any dependencies up front so we can always + # pin them when resolving + Gem::Specification.find { |s| s.name == "vagrant" && s.activated? }. + runtime_dependencies.each { |d| gem d.name, *d.requirement.as_list } + # discover all the gems we have available list = {} directories = [Gem::Specification.default_specifications_dir] Gem::Specification.find_all{true}.each do |spec| diff --git a/lib/vagrant/shared_helpers.rb b/lib/vagrant/shared_helpers.rb index ada85f3ba..5cab18f39 100644 --- a/lib/vagrant/shared_helpers.rb +++ b/lib/vagrant/shared_helpers.rb @@ -35,6 +35,14 @@ module Vagrant !!ENV["VAGRANT_INSTALLER_ENV"] end + # This returns a true/false if we are running within a bundler environment + # + # @return [Boolean] + def self.in_bundler? + !!ENV["BUNDLE_GEMFILE"] && + !defined?(::Bundler).nil? + end + # Returns the path to the embedded directory of the Vagrant installer, # if there is one (if we're running in an installer). # From ce56739b2915da92995560eb5bf581e0d0ceb0d7 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 5 Jun 2019 09:14:37 -0700 Subject: [PATCH 2/3] Update bundler error text content --- templates/locales/en.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 5927d6b21..608ca2e45 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -703,10 +703,9 @@ en: 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 - caused by misconfigured plugin installations or transient network - issues. The error from Bundler is: + Vagrant failed to properly resolve required dependencies. These + errors can commonly be caused by misconfigured plugin installations + or transient network issues. The reported error is: %{message} cant_read_mac_addresses: |- From 07b9f39a54829f3abe50827df93f9a869a3b116f Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 5 Jun 2019 09:28:40 -0700 Subject: [PATCH 3/3] Clean up gem sources modifications Based on suggestions from @zenspider here: https://github.com/hashicorp/vagrant/commit/3daf3e532d8c206c1a97ce9fd2d19cdcf49024c4#r33408747 --- lib/vagrant/bundler.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/vagrant/bundler.rb b/lib/vagrant/bundler.rb index b2980c839..95a02cc7e 100644 --- a/lib/vagrant/bundler.rb +++ b/lib/vagrant/bundler.rb @@ -76,12 +76,8 @@ module Vagrant # Add HashiCorp RubyGems source if !Gem.sources.include?(HASHICORP_GEMSTORE) - current_sources = Gem.sources.sources.dup - Gem.sources.clear - Gem.sources << HASHICORP_GEMSTORE - current_sources.each do |src| - Gem.sources << src - end + sources = [HASHICORP_GEMSTORE] + Gem.sources.sources + Gem.sources.replace(sources) end # Generate dependencies for all registered plugins