Fix up local gem plugin installation when not published remotely

This commit is contained in:
Chris Roberts 2016-11-11 14:25:03 -08:00
parent ea13988367
commit 6e40d46c50
2 changed files with 24 additions and 22 deletions

View File

@ -140,19 +140,14 @@ module Vagrant
# @param [String] path Path to a local gem file. # @param [String] path Path to a local gem file.
# @return [Gem::Specification] # @return [Gem::Specification]
def install_local(path) def install_local(path)
installer = Gem::Installer.at(path, plugin_source = Gem::Source::SpecificFile.new(path)
ignore_dependencies: true,
install_dir: plugin_gem_path.to_s
)
installer.install
new_spec = installer.spec
plugin_info = { plugin_info = {
new_spec.name => { plugin_source.spec.name => {
'gem_version' => new_spec.version.to_s 'local_source' => plugin_source
} }
} }
internal_install(plugin_info, {}) internal_install(plugin_info, {})
new_spec plugin_source.spec
end end
# Update updates the given plugins, or every plugin if none is given. # Update updates the given plugins, or every plugin if none is given.
@ -231,6 +226,8 @@ module Vagrant
update = {} unless update.is_a?(Hash) update = {} unless update.is_a?(Hash)
installer_set = Gem::Resolver::InstallerSet.new(:both)
# Generate all required plugin deps # Generate all required plugin deps
plugin_deps = plugins.map do |name, info| plugin_deps = plugins.map do |name, info|
if update == true || (update[:gems].respond_to?(:include?) && update[:gems].include?(name)) if update == true || (update[:gems].respond_to?(:include?) && update[:gems].include?(name))
@ -238,6 +235,9 @@ module Vagrant
else else
gem_version = info['gem_version'].to_s.empty? ? '> 0' : info['gem_version'] gem_version = info['gem_version'].to_s.empty? ? '> 0' : info['gem_version']
end end
if plugin_source = info.delete("local_source")
installer_set.add_local(plugin_source.spec.name, plugin_source.spec, plugin_source)
end
Gem::Dependency.new(name, gem_version) Gem::Dependency.new(name, gem_version)
end end
@ -254,7 +254,7 @@ module Vagrant
request_set.import(existing_deps) request_set.import(existing_deps)
# Generate the required solution set for new plugins # Generate the required solution set for new plugins
solution = request_set.resolve(Gem::Resolver::InstallerSet.new(:both)) solution = request_set.resolve(installer_set)
# If any items in the solution set are local but not activated, turn them on # If any items in the solution set are local but not activated, turn them on
solution.each do |activation_request| solution.each do |activation_request|

View File

@ -47,7 +47,6 @@ module Vagrant
local_spec = Vagrant::Bundler.instance.install_local(name) local_spec = Vagrant::Bundler.instance.install_local(name)
name = local_spec.name name = local_spec.name
opts[:version] = local_spec.version.to_s opts[:version] = local_spec.version.to_s
local = true
end end
plugins = installed_plugins plugins = installed_plugins
@ -57,21 +56,24 @@ module Vagrant
"sources" => opts[:sources], "sources" => opts[:sources],
} }
result = nil if local_spec.nil?
install_lambda = lambda do result = nil
Vagrant::Bundler.instance.install(plugins, local).each do |spec| install_lambda = lambda do
next if spec.name != name Vagrant::Bundler.instance.install(plugins, local).each do |spec|
next if result && result.version >= spec.version next if spec.name != name
result = spec next if result && result.version >= spec.version
result = spec
end
end end
end
if opts[:verbose] if opts[:verbose]
Vagrant::Bundler.instance.verbose(&install_lambda) Vagrant::Bundler.instance.verbose(&install_lambda)
else
install_lambda.call
end
else else
install_lambda.call result = local_spec
end end
# Add the plugin to the state file # Add the plugin to the state file
@user_file.add_plugin( @user_file.add_plugin(
result.name, result.name,