Skip to content

Commit

Permalink
Switch InstallCommand to use RequestSet to install
Browse files Browse the repository at this point in the history
Gem::DependencyInstaller is still used to set up the RequestSet but the
installation actions occur via RequestSet#install.  This makes --explain
and gem installation use the same gem installation order.

This also moves documentation generation into RequestSet#install.

This makes explain order and install order the same as part of #813
  • Loading branch information
drbrain committed Apr 23, 2014
1 parent d1299dc commit 7cd50b0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
7 changes: 2 additions & 5 deletions lib/rubygems/commands/install_command.rb
Expand Up @@ -216,10 +216,9 @@ def install_gem name, version # :nodoc:
install_gem_without_dependencies name, req
else
inst = Gem::DependencyInstaller.new options
request_set = inst.resolve_dependencies name, req

if options[:explain]
request_set = inst.resolve_dependencies name, req

puts "Gems to install:"

request_set.sorted_requests.each do |s|
Expand All @@ -228,11 +227,9 @@ def install_gem name, version # :nodoc:

return
else
inst.install name, req
@installed_specs.concat request_set.install options
end

@installed_specs.push(*inst.installed_gems)

show_install_errors inst.errors
end
end
Expand Down
14 changes: 13 additions & 1 deletion lib/rubygems/request_set.rb
Expand Up @@ -130,7 +130,8 @@ def import deps

def install options, &block # :yields: request, installer
if dir = options[:install_dir]
return install_into dir, false, options, &block
specs = install_into dir, false, options, &block
return specs
end

cache_dir = options[:cache_dir] || Gem.dir
Expand All @@ -157,6 +158,17 @@ def install options, &block # :yields: request, installer
end

specs
ensure
raise if $!
return specs if options[:gemdeps]

require 'rubygems/dependency_installer'
inst = Gem::DependencyInstaller.new options
inst.installed_gems.replace specs

Gem.done_installing_hooks.each do |hook|
hook.call inst, specs
end unless Gem.done_installing_hooks.empty?
end

##
Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/test_gem_dependency_installer.rb
Expand Up @@ -293,7 +293,7 @@ def test_install_dependency

Gem.done_installing do |installer, specs|
done_installing_ran = true
assert_equal inst, installer
refute_nil installer
assert_equal [@a1, @b1], specs
end

Expand Down
15 changes: 15 additions & 0 deletions test/rubygems/test_gem_request_set.rb
Expand Up @@ -42,6 +42,12 @@ def test_install_from_gemdeps
fetcher.gem 'a', 2
end

done_installing_ran = false

Gem.done_installing do |installer, specs|
done_installing_ran = true
end

rs = Gem::RequestSet.new
installed = []

Expand All @@ -61,6 +67,7 @@ def test_install_from_gemdeps
assert_path_exists 'gem.deps.rb.lock'

assert rs.remote
refute done_installing_ran
end

def test_install_from_gemdeps_install_dir
Expand Down Expand Up @@ -335,6 +342,12 @@ def test_sorted_requests
end

def test_install
done_installing_ran = false

Gem.done_installing do
done_installing_ran = true
end

spec_fetcher do |fetcher|
fetcher.gem "a", "1", "b" => "= 1"
fetcher.gem "b", "1"
Expand Down Expand Up @@ -363,6 +376,8 @@ def test_install
assert_path_exists File.join @gemhome, 'specifications', 'b-1.gemspec'

assert_equal %w[b-1 a-1], installed.map { |s| s.full_name }

assert done_installing_ran
end

def test_install_into
Expand Down

0 comments on commit 7cd50b0

Please sign in to comment.