From 73d85bd2f7abcc96d6bdea4e78aab9724a08cce9 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Thu, 4 May 2017 18:59:54 -0700 Subject: [PATCH] Support strict enforcement of internal dependency constraints --- lib/vagrant/bundler.rb | 22 ++++++++++++++++------ lib/vagrant/shared_helpers.rb | 13 +++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/vagrant/bundler.rb b/lib/vagrant/bundler.rb index 4df5101f3..ea406dc1e 100644 --- a/lib/vagrant/bundler.rb +++ b/lib/vagrant/bundler.rb @@ -215,7 +215,11 @@ module Vagrant update = {} if !update.is_a?(Hash) skips = [] source_list = {} + system_plugins = plugins.map do |plugin_name, plugin_info| + plugin_name if plugin_info["system"] + end.compact installer_set = VagrantSet.new(:both) + installer_set.system_plugins = system_plugins # Generate all required plugin deps plugin_deps = plugins.map do |name, info| @@ -239,7 +243,18 @@ module Vagrant Gem::Dependency.new(name, gem_version) end - @logger.debug("Dependency list for installation: #{plugin_deps}") + if Vagrant.strict_dependency_enforcement + @logger.debug("Enabling strict dependency enforcement") + plugin_deps += vagrant_internal_specs.map do |spec| + next if system_plugins.include?(spec.name) + Gem::Dependency.new(spec.name, spec.version) + end.compact + else + @logger.debug("Disabling strict dependency enforcement") + end + + @logger.debug("Dependency list for installation:\n - " \ + "#{plugin_deps.map{|d| "#{d.name} #{d.requirement}"}.join("\n - ")}") all_sources = source_list.values.flatten.uniq default_sources = DEFAULT_GEM_SOURCES & all_sources @@ -275,11 +290,6 @@ module Vagrant # Create the request set for the new plugins request_set = Gem::RequestSet.new(*plugin_deps) - system_plugins = plugins.map do |plugin_name, plugin_info| - plugin_name if plugin_info["system"] - end.compact - installer_set.system_plugins = system_plugins - installer_set = Gem::Resolver.compose_sets( installer_set, generate_builtin_set(system_plugins), diff --git a/lib/vagrant/shared_helpers.rb b/lib/vagrant/shared_helpers.rb index 4f0773ba5..2b0f767d6 100644 --- a/lib/vagrant/shared_helpers.rb +++ b/lib/vagrant/shared_helpers.rb @@ -116,4 +116,17 @@ module Vagrant def self.prerelease? Gem::Version.new(Vagrant::VERSION).prerelease? end + + # This allows control over dependency resolution when installing + # plugins into vagrant. When true, dependency libraries that Vagrant + # core relies upon will be hard constraints. + # + # @return [Boolean] + def self.strict_dependency_enforcement + if ENV["VAGRANT_DISABLE_STRICT_DEPENDENCY_ENFORCEMENT"] + false + else + true + end + end end