Permalink
Browse files

Pass down source_index from dependency installer so that -i works wit…

…h reinstall

git-svn-id: http://rubygems.rubyforge.org/svn/trunk@1834 3d4018f9-ac1a-0410-99e9-8a154d859a19
  • Loading branch information...
drbrain
drbrain committed Jul 1, 2008
1 parent 5a9e6dc commit 75e700fc8d1995e5dabaabd6d947ff01819d39df
Showing with 53 additions and 24 deletions.
  1. +3 −1 ChangeLog
  2. +16 −15 lib/rubygems/dependency_installer.rb
  3. +10 −8 lib/rubygems/installer.rb
  4. +24 −0 test/test_gem_installer.rb
View
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
2008-07-01 Eric Hodel <drbrain@segment7.net>
- * lib/rubygems/installer.rb: Add #gem_home, #bin_dir for hooks.
+ * lib/rubygems/installer.rb: Add #gem_home, #bin_dir for hooks. Use
+ DependencyInstaller's source_index so reinstallation via -i does not
+ fail.
* lib/rubygems/uninstaller.rb: Add #gem_home, #bin_dir for hooks.
2008-06-30 Eric Hodel <drbrain@segment7.net>
@@ -41,6 +41,13 @@ class Gem::DependencyInstaller
# :wrappers:: See Gem::Installer::new
def initialize(options = {})
+ if options[:install_dir] then
+ spec_dir = options[:install_dir], 'specifications'
+ @source_index = Gem::SourceIndex.from_gems_in spec_dir
+ else
+ @source_index = Gem.source_index
+ end
+
options = DEFAULT_OPTIONS.merge options
@bin_dir = options[:bin_dir]
@@ -57,13 +64,6 @@ def initialize(options = {})
@install_dir = options[:install_dir] || Gem.dir
@cache_dir = options[:cache_dir] || @install_dir
-
- if options[:install_dir] then
- spec_dir = File.join @install_dir, 'specifications'
- @source_index = Gem::SourceIndex.from_gems_in spec_dir
- else
- @source_index = Gem.source_index
- end
end
##
@@ -232,15 +232,16 @@ def install dep_or_name, version = Gem::Requirement.default
end
inst = Gem::Installer.new local_gem_path,
- :env_shebang => @env_shebang,
- :force => @force,
- :format_executable => @format_executable,
+ :bin_dir => @bin_dir,
+ :development => @development,
+ :env_shebang => @env_shebang,
+ :force => @force,
+ :format_executable => @format_executable,
:ignore_dependencies => @ignore_dependencies,
- :install_dir => @install_dir,
- :security_policy => @security_policy,
- :wrappers => @wrappers,
- :bin_dir => @bin_dir,
- :development => @development
+ :install_dir => @install_dir,
+ :security_policy => @security_policy,
+ :source_index => @source_index,
+ :wrappers => @wrappers
spec = inst.install
View
@@ -77,11 +77,12 @@ def initialize(gem, options={})
@gem = gem
options = {
- :force => false,
- :install_dir => Gem.dir,
- :exec_format => false,
- :env_shebang => false,
- :bin_dir => nil
+ :bin_dir => nil,
+ :env_shebang => false,
+ :exec_format => false,
+ :force => false,
+ :install_dir => Gem.dir,
+ :source_index => Gem.source_index,
}.merge options
@env_shebang = options[:env_shebang]
@@ -94,6 +95,7 @@ def initialize(gem, options={})
@wrappers = options[:wrappers]
@bin_dir = options[:bin_dir]
@development = options[:development]
+ @source_index = options[:source_index]
begin
@format = Gem::Format.from_file_by_path @gem, @security_policy
@@ -201,7 +203,7 @@ def install
@spec.loaded_from = File.join(@gem_home, 'specifications',
"#{@spec.full_name}.gemspec")
- Gem.source_index.add_spec @spec
+ @source_index.add_spec @spec
Gem.post_install_hooks.each do |hook|
hook.call self
@@ -228,10 +230,10 @@ def ensure_dependency(spec, dependency)
end
##
- # True if the gems in Gem.source_index satisfy +dependency+.
+ # True if the gems in the source_index satisfy +dependency+.
def installation_satisfies_dependency?(dependency)
- Gem.source_index.find_name(dependency.name, dependency.version_requirements).size > 0
+ @source_index.find_name(dependency.name, dependency.version_requirements).size > 0
end
##
View
@@ -597,6 +597,29 @@ def test_install_check_dependencies
end
end
+ def test_install_check_dependencies_install_dir
+ gemhome2 = "#{@gemhome}2"
+ @spec.add_dependency 'b'
+
+ b2 = quick_gem 'b', 2
+
+ FileUtils.mv @gemhome, gemhome2
+ Gem.source_index.gems.delete b2.full_name
+ source_index = Gem::SourceIndex.from_gems_in File.join(gemhome2,
+ 'specifications')
+
+ util_setup_gem
+
+ @installer = Gem::Installer.new @gem, :install_dir => gemhome2,
+ :source_index => source_index
+
+ use_ui @ui do
+ @installer.install
+ end
+
+ assert File.exist?(File.join(gemhome2, 'gems', @spec.full_name))
+ end
+
def test_install_force
use_ui @ui do
installer = Gem::Installer.new old_ruby_required, :force => true
@@ -650,6 +673,7 @@ def test_install_missing_dirs
assert File.exist?(File.join(@gemhome, 'specifications',
"#{@spec.full_name}.gemspec"))
end
+
unless win_platform? # File.chmod doesn't work
def test_install_user_local_fallback
Dir.mkdir util_inst_bindir

0 comments on commit 75e700f

Please sign in to comment.