Skip to content

Commit

Permalink
Merge pull request #10894 from chrisroberts/e-deps-system
Browse files Browse the repository at this point in the history
Handle strict dependency enforcement when installed within system
  • Loading branch information
chrisroberts committed Jun 5, 2019
2 parents a0c0386 + 07b9f39 commit b90d013
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
21 changes: 14 additions & 7 deletions lib/vagrant/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,8 @@ def init!(plugins, repair=false)

# 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
Expand Down Expand Up @@ -313,6 +309,12 @@ def internal_install(plugins, update, **extra)
@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
Expand Down Expand Up @@ -415,8 +417,13 @@ def generate_vagrant_set
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|
Expand Down
8 changes: 8 additions & 0 deletions lib/vagrant/shared_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ def self.in_installer?
!!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).
#
Expand Down
7 changes: 3 additions & 4 deletions templates/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,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: |-
Expand Down

0 comments on commit b90d013

Please sign in to comment.